aboutsummaryrefslogtreecommitdiffstats
path: root/tools/ocaml
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2011-04-20 17:13:08 +0100
committerIan Campbell <ian.campbell@citrix.com>2011-04-20 17:13:08 +0100
commite6f1957781e6075ef2a84306040fe7ca135acb77 (patch)
tree34a1eb8ea7cfb0b41dd9c1ff309df36aa22fa504 /tools/ocaml
parent8e49e3c25664f0765df38b0516f5ec179101e5b8 (diff)
downloadxen-e6f1957781e6075ef2a84306040fe7ca135acb77.tar.gz
xen-e6f1957781e6075ef2a84306040fe7ca135acb77.tar.bz2
xen-e6f1957781e6075ef2a84306040fe7ca135acb77.zip
tools: ocaml: lay ground work for auto generating xl datatypes.
Doesn't actually generate anything yet but puts all the moving parts into place. In particular sets up the xl.ml.in+_libxl_types.ml.in->xl.ml transformation using sed. This appears to be the only/best way to do this for ocaml due to the lack of a preprocessor and/or an include mechanism which has an inmpact on namespacing. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson.citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com>
Diffstat (limited to 'tools/ocaml')
-rw-r--r--tools/ocaml/libs/xl/Makefile28
-rw-r--r--tools/ocaml/libs/xl/genwrap.py42
-rw-r--r--tools/ocaml/libs/xl/xl.ml.in (renamed from tools/ocaml/libs/xl/xl.ml)2
-rw-r--r--tools/ocaml/libs/xl/xl.mli.in (renamed from tools/ocaml/libs/xl/xl.mli)2
-rw-r--r--tools/ocaml/libs/xl/xl_stubs.c4
5 files changed, 77 insertions, 1 deletions
diff --git a/tools/ocaml/libs/xl/Makefile b/tools/ocaml/libs/xl/Makefile
index 8e31b72424..8e87973814 100644
--- a/tools/ocaml/libs/xl/Makefile
+++ b/tools/ocaml/libs/xl/Makefile
@@ -15,8 +15,36 @@ xl_C_OBJS = xl_stubs
OCAML_LIBRARY = xl
+GENERATED_FILES += xl.ml xl.mli
+GENERATED_FILES += _libxl_types.ml.in _libxl_types.mli.in
+GENERATED_FILES += _libxl_types.inc
+
all: $(INTF) $(LIBS)
+xl.ml: xl.ml.in _libxl_types.ml.in
+ $(Q)sed -e '1i(*\
+ * AUTO-GENERATED FILE DO NOT EDIT\
+ * Generated from xl.ml.in and _libxl_types.ml.in\
+ *)\
+' \
+ -e '/^(\* @@LIBXL_TYPES@@ \*)$$/r_libxl_types.ml.in' \
+ < xl.ml.in > xl.ml
+
+xl.mli: xl.mli.in _libxl_types.mli.in
+ $(Q)sed -e '1i(*\
+ * AUTO-GENERATED FILE DO NOT EDIT\
+ * Generated from xl.mli.in and _libxl_types.mli.in\
+ *)\
+' \
+ -e '/^(\* @@LIBXL_TYPES@@ \*)$$/r_libxl_types.mli.in' \
+ < xl.mli.in > xl.mli
+
+_libxl_types.ml.in _libxl_types.mli.in _libxl_types.inc: genwrap.py $(XEN_ROOT)/tools/libxl/libxl.idl \
+ $(XEN_ROOT)/tools/libxl/libxltypes.py
+ PYTHONPATH=$(XEN_ROOT)/tools/libxl $(PYTHON) genwrap.py \
+ $(XEN_ROOT)/tools/libxl/libxl.idl \
+ _libxl_types.mli.in _libxl_types.ml.in _libxl_types.inc
+
libs: $(LIBS)
.PHONY: install
diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py
new file mode 100644
index 0000000000..3f1c6e5245
--- /dev/null
+++ b/tools/ocaml/libs/xl/genwrap.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+
+import sys,os
+
+import libxltypes
+
+def autogen_header(open_comment, close_comment):
+ s = open_comment + " AUTO-GENERATED FILE DO NOT EDIT " + close_comment + "\n"
+ s += open_comment + " autogenerated by \n"
+ s += reduce(lambda x,y: x + " ", range(len(open_comment + " ")), "")
+ s += "%s" % " ".join(sys.argv)
+ s += "\n " + close_comment + "\n\n"
+ return s
+
+if __name__ == '__main__':
+ if len(sys.argv) < 4:
+ print >>sys.stderr, "Usage: genwrap.py <idl> <mli> <ml> <c-inc>"
+ sys.exit(1)
+
+ idl = sys.argv[1]
+ (_,types) = libxltypes.parse(idl)
+
+
+ _ml = sys.argv[3]
+ ml = open(_ml, 'w')
+ ml.write(autogen_header("(*", "*)"))
+
+ _mli = sys.argv[2]
+ mli = open(_mli, 'w')
+ mli.write(autogen_header("(*", "*)"))
+
+ _cinc = sys.argv[4]
+ cinc = open(_cinc, 'w')
+ cinc.write(autogen_header("/*", "*/"))
+
+ # TODO: autogenerate something
+
+ ml.write("(* END OF AUTO-GENERATED CODE *)\n")
+ ml.close()
+ mli.write("(* END OF AUTO-GENERATED CODE *)\n")
+ mli.close()
+ cinc.close()
diff --git a/tools/ocaml/libs/xl/xl.ml b/tools/ocaml/libs/xl/xl.ml.in
index 8b504b494e..96f116eb6b 100644
--- a/tools/ocaml/libs/xl/xl.ml
+++ b/tools/ocaml/libs/xl/xl.ml.in
@@ -17,6 +17,8 @@ exception Error of string
type domid = int
+(* @@LIBXL_TYPES@@ *)
+
type console_type =
| CONSOLETYPE_XENCONSOLED
| CONSOLETYPE_IOEMU
diff --git a/tools/ocaml/libs/xl/xl.mli b/tools/ocaml/libs/xl/xl.mli.in
index d52a37174e..55cfd25416 100644
--- a/tools/ocaml/libs/xl/xl.mli
+++ b/tools/ocaml/libs/xl/xl.mli.in
@@ -17,6 +17,8 @@ exception Error of string
type domid = int
+(* @@LIBXL_TYPES@@ *)
+
type console_type =
| CONSOLETYPE_XENCONSOLED
| CONSOLETYPE_IOEMU
diff --git a/tools/ocaml/libs/xl/xl_stubs.c b/tools/ocaml/libs/xl/xl_stubs.c
index ebbf476e97..62b3e3dc91 100644
--- a/tools/ocaml/libs/xl/xl_stubs.c
+++ b/tools/ocaml/libs/xl/xl_stubs.c
@@ -26,7 +26,7 @@
#include <stdint.h>
#include <string.h>
-#include "libxl.h"
+#include <libxl.h>
struct caml_logger {
struct xentoollog_logger logger;
@@ -130,6 +130,8 @@ static int string_string_tuple_array_val (caml_gc *gc, char ***c_val, value v)
#endif
+#include "_libxl_types.inc"
+
static int device_disk_val(caml_gc *gc, libxl_device_disk *c_val, value v)
{
CAMLparam1(v);