From e6f1957781e6075ef2a84306040fe7ca135acb77 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 20 Apr 2011 17:13:08 +0100 Subject: [PATCH] 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 Acked-by: Ian Jackson Committed-by: Ian Jackson --- .hgignore | 5 +++ tools/ocaml/libs/xl/Makefile | 28 +++++++++++++++ tools/ocaml/libs/xl/genwrap.py | 42 +++++++++++++++++++++++ tools/ocaml/libs/xl/{xl.ml => xl.ml.in} | 2 ++ tools/ocaml/libs/xl/{xl.mli => xl.mli.in} | 2 ++ tools/ocaml/libs/xl/xl_stubs.c | 4 ++- 6 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tools/ocaml/libs/xl/genwrap.py rename tools/ocaml/libs/xl/{xl.ml => xl.ml.in} (99%) rename tools/ocaml/libs/xl/{xl.mli => xl.mli.in} (99%) diff --git a/.hgignore b/.hgignore index 2c2dc4bd3e..b497e634e3 100644 --- a/.hgignore +++ b/.hgignore @@ -295,6 +295,11 @@ ^tools/ocaml/.*/.*\.cmx?a$ ^tools/ocaml/.*/META$ ^tools/ocaml/.*/\.ocamldep\.make$ +^tools/ocaml/libs/xl/_libxl_types\.ml\.in$ +^tools/ocaml/libs/xl/_libxl_types\.mli\.in$ +^tools/ocaml/libs/xl/_libxl_types\.inc$ +^tools/ocaml/libs/xl/xl\.ml$ +^tools/ocaml/libs/xl/xl\.mli$ ^tools/ocaml/xenstored/oxenstored$ ^xen/\.banner.*$ ^xen/BLOG$ 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 " + 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 similarity index 99% rename from tools/ocaml/libs/xl/xl.ml rename to 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 similarity index 99% rename from tools/ocaml/libs/xl/xl.mli rename to 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 #include -#include "libxl.h" +#include 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); -- 2.39.5