aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2012-01-31 16:34:38 +0000
committerIan Campbell <ian.campbell@citrix.com>2012-01-31 16:34:38 +0000
commita6beb5286e7ca1d478ef391396be49b4f6d2ca35 (patch)
treee649090f00988dde2ca2b569980a1b8f5f330131 /tools
parent15873321439d3588e0276c7cfddb0a11f71c897d (diff)
downloadxen-a6beb5286e7ca1d478ef391396be49b4f6d2ca35.tar.gz
xen-a6beb5286e7ca1d478ef391396be49b4f6d2ca35.tar.bz2
xen-a6beb5286e7ca1d478ef391396be49b4f6d2ca35.zip
libxl: Rename libxl IDL infrastructure.
Originally libxltypes.py provided the infrastructure and libxl.idl provided the specific types. In 23887:a543e10211f7 libxl.idl became libxl_types.idl (to allow for libxl_types_internal.idl) which means we now have libxl_types.FOO and libxltypes.FOO providing different things and annoying people in tab completion. Rename the infrastructure as idl. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <Ian.Jackson@eu.citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/libxl/Makefile2
-rw-r--r--tools/libxl/gentest.py23
-rw-r--r--tools/libxl/gentypes.py34
-rw-r--r--tools/libxl/idl.py (renamed from tools/libxl/libxltypes.py)0
-rw-r--r--tools/libxl/idl.txt50
-rw-r--r--tools/ocaml/libs/xl/Makefile2
-rw-r--r--tools/ocaml/libs/xl/genwrap.py35
-rw-r--r--tools/python/Makefile2
-rw-r--r--tools/python/genwrap.py27
9 files changed, 86 insertions, 89 deletions
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 113b7c2e50..d5893d7ef2 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -111,7 +111,7 @@ libxl_internal_json.h: _libxl_types_internal_json.h
$(LIBXL_OBJS) $(LIBXLU_OBJS) $(XL_OBJS): libxl.h
$(LIBXL_OBJS): libxl_internal.h
-_libxl_type%.h _libxl_type%_json.h _libxl_type%.c: libxl_type%.idl gentypes.py libxltypes.py
+_libxl_type%.h _libxl_type%_json.h _libxl_type%.c: libxl_type%.idl gentypes.py idl.py
$(PYTHON) gentypes.py libxl_type$*.idl __libxl_type$*.h __libxl_type$*_json.h __libxl_type$*.c
$(call move-if-changed,__libxl_type$*.h,_libxl_type$*.h)
$(call move-if-changed,__libxl_type$*_json.h,_libxl_type$*_json.h)
diff --git a/tools/libxl/gentest.py b/tools/libxl/gentest.py
index ac7a400060..06d35369cf 100644
--- a/tools/libxl/gentest.py
+++ b/tools/libxl/gentest.py
@@ -4,7 +4,7 @@ import sys
import re
import random
-import libxltypes
+import idl
def randomize_char(c):
if random.random() < 0.5:
@@ -25,9 +25,9 @@ handcoded = ["libxl_cpumap", "libxl_key_value_list",
def gen_rand_init(ty, v, indent = " ", parent = None):
s = ""
- if isinstance(ty, libxltypes.Enumeration):
+ if isinstance(ty, idl.Enumeration):
s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), randomize_enum(ty))
- elif isinstance(ty, libxltypes.KeyedUnion):
+ elif isinstance(ty, idl.KeyedUnion):
if parent is None:
raise Exception("KeyedUnion type must have a parent")
s += "switch (%s) {\n" % (parent + ty.keyvar_name)
@@ -37,7 +37,7 @@ def gen_rand_init(ty, v, indent = " ", parent = None):
s += gen_rand_init(f.type, fexpr, indent + " ", nparent)
s += " break;\n"
s += "}\n"
- elif isinstance(ty, libxltypes.Struct) \
+ elif isinstance(ty, idl.Struct) \
and (parent is None or ty.json_fn is None):
for f in [f for f in ty.fields if not f.const]:
(nparent,fexpr) = ty.member(v, f, parent is None)
@@ -45,10 +45,10 @@ def gen_rand_init(ty, v, indent = " ", parent = None):
elif hasattr(ty, "rand_init") and ty.rand_init is not None:
s += "%s(%s);\n" % (ty.rand_init,
ty.pass_arg(v, isref=parent is None,
- passby=libxltypes.PASS_BY_REFERENCE))
+ passby=idl.PASS_BY_REFERENCE))
elif ty.typename in ["libxl_uuid", "libxl_mac", "libxl_hwcap"]:
s += "rand_bytes((uint8_t *)%s, sizeof(*%s));\n" % (v,v)
- elif ty.typename in ["libxl_domid"] or isinstance(ty, libxltypes.Number):
+ elif ty.typename in ["libxl_domid"] or isinstance(ty, idl.Number):
s += "%s = rand() %% (sizeof(%s)*8);\n" % \
(ty.pass_arg(v, parent is None),
ty.pass_arg(v, parent is None))
@@ -74,8 +74,7 @@ if __name__ == '__main__':
random.seed()
- idl = sys.argv[1]
- (builtins,types) = libxltypes.parse(idl)
+ (builtins,types) = idl.parse(sys.argv[1])
impl = sys.argv[2]
f = open(impl, "w")
@@ -215,10 +214,10 @@ static void libxl_cpuarray_rand_init(libxl_cpuarray *p)
if ty.typename not in handcoded:
f.write("static void %s_rand_init(%s);\n" % \
(ty.typename,
- ty.make_arg("p", passby=libxltypes.PASS_BY_REFERENCE)))
+ ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
f.write("static void %s_rand_init(%s)\n" % \
(ty.typename,
- ty.make_arg("p", passby=libxltypes.PASS_BY_REFERENCE)))
+ ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
f.write("{\n")
f.write(gen_rand_init(ty, "p"))
f.write("}\n")
@@ -252,7 +251,7 @@ int main(int argc, char **argv)
for ty in [t for t in types if t.json_fn is not None]:
arg = ty.typename + "_val"
f.write(" %s_rand_init(%s);\n" % (ty.typename, \
- ty.pass_arg(arg, isref=False, passby=libxltypes.PASS_BY_REFERENCE)))
+ ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE)))
f.write(" s = %s_to_json(ctx, %s);\n" % \
(ty.typename, ty.pass_arg(arg, isref=False)))
f.write(" printf(\"%%s: %%s\\n\", \"%s\", s);\n" % ty.typename)
@@ -265,7 +264,7 @@ int main(int argc, char **argv)
f.write(" printf(\"Testing Enumerations\\n\");\n")
f.write(" printf(\"--------------------\\n\");\n")
f.write(" printf(\"\\n\");\n")
- for ty in [t for t in types if isinstance(t,libxltypes.Enumeration)]:
+ for ty in [t for t in types if isinstance(t,idl.Enumeration)]:
f.write(" printf(\"%s -- to string:\\n\");\n" % (ty.typename))
for v in ty.values:
f.write(" printf(\"\\t%s = %%d = \\\"%%s\\\"\\n\", " \
diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py
index 7ecc11d572..ae4a6b6a7a 100644
--- a/tools/libxl/gentypes.py
+++ b/tools/libxl/gentypes.py
@@ -3,10 +3,10 @@
import sys
import re
-import libxltypes
+import idl
def libxl_C_instance_of(ty, instancename):
- if isinstance(ty, libxltypes.Aggregate) and ty.typename is None:
+ if isinstance(ty, idl.Aggregate) and ty.typename is None:
if instancename is None:
return libxl_C_type_define(ty)
else:
@@ -16,7 +16,7 @@ def libxl_C_instance_of(ty, instancename):
def libxl_C_type_define(ty, indent = ""):
s = ""
- if isinstance(ty, libxltypes.Enumeration):
+ if isinstance(ty, idl.Enumeration):
if ty.typename is None:
s += "enum {\n"
else:
@@ -31,7 +31,7 @@ def libxl_C_type_define(ty, indent = ""):
else:
s += "} %s" % ty.typename
- elif isinstance(ty, libxltypes.Aggregate):
+ elif isinstance(ty, idl.Aggregate):
if ty.typename is None:
s += "%s {\n" % ty.kind
else:
@@ -53,7 +53,7 @@ def libxl_C_type_define(ty, indent = ""):
def libxl_C_type_dispose(ty, v, indent = " ", parent = None):
s = ""
- if isinstance(ty, libxltypes.KeyedUnion):
+ if isinstance(ty, idl.KeyedUnion):
if parent is None:
raise Exception("KeyedUnion type must have a parent")
s += "switch (%s) {\n" % (parent + ty.keyvar_name)
@@ -63,7 +63,7 @@ def libxl_C_type_dispose(ty, v, indent = " ", parent = None):
s += libxl_C_type_dispose(f.type, fexpr, indent + " ", nparent)
s += " break;\n"
s += "}\n"
- elif isinstance(ty, libxltypes.Struct) and (parent is None or ty.dispose_fn is None):
+ elif isinstance(ty, idl.Struct) and (parent is None or ty.dispose_fn is None):
for f in [f for f in ty.fields if not f.const]:
(nparent,fexpr) = ty.member(v, f, parent is None)
s += libxl_C_type_dispose(f.type, fexpr, "", nparent)
@@ -79,11 +79,11 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None):
s = ""
if parent is None:
s += "yajl_gen_status s;\n"
- if isinstance(ty, libxltypes.Enumeration):
+ if isinstance(ty, idl.Enumeration):
s += "s = libxl__yajl_gen_enum(hand, %s_to_string(%s));\n" % (ty.typename, ty.pass_arg(v, parent is None))
s += "if (s != yajl_gen_status_ok)\n"
s += " goto out;\n"
- elif isinstance(ty, libxltypes.KeyedUnion):
+ elif isinstance(ty, idl.KeyedUnion):
if parent is None:
raise Exception("KeyedUnion type must have a parent")
s += "switch (%s) {\n" % (parent + ty.keyvar_name)
@@ -93,7 +93,7 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None):
s += libxl_C_type_gen_json(f.type, fexpr, indent + " ", nparent)
s += " break;\n"
s += "}\n"
- elif isinstance(ty, libxltypes.Struct) and (parent is None or ty.json_fn is None):
+ elif isinstance(ty, idl.Struct) and (parent is None or ty.json_fn is None):
s += "s = yajl_gen_map_open(hand);\n"
s += "if (s != yajl_gen_status_ok)\n"
s += " goto out;\n"
@@ -123,7 +123,7 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None):
def libxl_C_type_to_json(ty, v, indent = " "):
s = ""
gen = "(libxl__gen_json_callback)&%s_gen_json" % ty.typename
- s += "return libxl__object_to_json(ctx, \"%s\", %s, (void *)%s);\n" % (ty.typename, gen, ty.pass_arg(v, passby=libxltypes.PASS_BY_REFERENCE))
+ s += "return libxl__object_to_json(ctx, \"%s\", %s, (void *)%s);\n" % (ty.typename, gen, ty.pass_arg(v, passby=idl.PASS_BY_REFERENCE))
if s != "":
s = indent + s
@@ -171,9 +171,9 @@ if __name__ == '__main__':
print >>sys.stderr, "Usage: gentypes.py <idl> <header> <header-json> <implementation>"
sys.exit(1)
- (_, idl, header, header_json, impl) = sys.argv
+ (_, idlname, header, header_json, impl) = sys.argv
- (builtins,types) = libxltypes.parse(idl)
+ (builtins,types) = idl.parse(idlname)
print "outputting libxl type definitions to %s" % header
@@ -198,9 +198,9 @@ if __name__ == '__main__':
f.write("void %s(%s);\n" % (ty.dispose_fn, ty.make_arg("p")))
if ty.json_fn is not None:
f.write("char *%s_to_json(libxl_ctx *ctx, %s);\n" % (ty.typename, ty.make_arg("p")))
- if isinstance(ty, libxltypes.Enumeration):
+ if isinstance(ty, idl.Enumeration):
f.write("const char *%s_to_string(%s);\n" % (ty.typename, ty.make_arg("p")))
- f.write("int %s_from_string(const char *s, %s);\n" % (ty.typename, ty.make_arg("e", passby=libxltypes.PASS_BY_REFERENCE)))
+ f.write("int %s_from_string(const char *s, %s);\n" % (ty.typename, ty.make_arg("e", passby=idl.PASS_BY_REFERENCE)))
f.write("extern libxl_enum_string_table %s_string_table[];\n" % (ty.typename))
f.write("\n")
@@ -225,7 +225,7 @@ if __name__ == '__main__':
""" % (header_json_define, header_json_define, " ".join(sys.argv)))
for ty in [ty for ty in types+builtins if ty.json_fn is not None]:
- f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" % (ty.typename, ty.make_arg("p", passby=libxltypes.PASS_BY_REFERENCE)))
+ f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" % (ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
f.write("\n")
f.write("""#endif /* %s */\n""" % header_json_define)
@@ -262,7 +262,7 @@ if __name__ == '__main__':
f.write("}\n")
f.write("\n")
- for ty in [t for t in types if isinstance(t,libxltypes.Enumeration)]:
+ for ty in [t for t in types if isinstance(t,idl.Enumeration)]:
f.write("const char *%s_to_string(%s e)\n" % (ty.typename, ty.typename))
f.write("{\n")
f.write(libxl_C_enum_to_string(ty, "e"))
@@ -278,7 +278,7 @@ if __name__ == '__main__':
f.write("\n")
for ty in [t for t in types if t.json_fn is not None]:
- f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s)\n" % (ty.typename, ty.make_arg("p", passby=libxltypes.PASS_BY_REFERENCE)))
+ f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s)\n" % (ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
f.write("{\n")
f.write(libxl_C_type_gen_json(ty, "p"))
f.write("}\n")
diff --git a/tools/libxl/libxltypes.py b/tools/libxl/idl.py
index 880b7ca71d..880b7ca71d 100644
--- a/tools/libxl/libxltypes.py
+++ b/tools/libxl/idl.py
diff --git a/tools/libxl/idl.txt b/tools/libxl/idl.txt
index 6f2d05bf26..adf872d6be 100644
--- a/tools/libxl/idl.txt
+++ b/tools/libxl/idl.txt
@@ -1,10 +1,10 @@
-libxltypes IDL
---------------
+libxl IDL
+---------
Each type in the libxl interface is represented by an object of type
-libxltypes.Type (or a subclass thereof). Every local variable defined
-by the .idl file must be an instance of libxltypes.Type (e.g. you may
-not define Python functions or any other construct other than defining
+idl.Type (or a subclass thereof). Every local variable defined by
+the .idl file must be an instance of idl.Type (e.g. you may not
+define Python functions or any other construct other than defining
variables)
The name of the type must be passed as the first argument to the
@@ -16,9 +16,9 @@ The Type.typename contains the C name of the type _including_ the
namespace element while Type.rawname is always set to the 'base' name
of the type.
-The libxltypes.Type base class has several other properties which
-apply to all types. The properties are set by passing a named
-parameter to the constructor.
+The idl.Type base class has several other properties which apply
+to all types. The properties are set by passing a named parameter to
+the constructor.
Type.namespace: (default: "libxl_")
@@ -28,12 +28,12 @@ Type.namespace: (default: "libxl_")
If the typename is not None then the namespace is prepended to the
type.
-Type.passby: (default: libxltypes.PASS_BY_VALUE)
+Type.passby: (default: idl.PASS_BY_VALUE)
Defines the manner in which a type should be passed to C
functions. Valid values for this fields are:
- libxltypes.PASS_BY_VALUE
- libxltypes.PASS_BY_REFERENCE
+ idl.PASS_BY_VALUE
+ idl.PASS_BY_REFERENCE
Type.dispose_fn: (default: typename + "_dispose" or None if type == None)
@@ -57,12 +57,12 @@ Type.autogenerate_json: (default: True)
Other simple type-Classes
-------------------------
-libxltype.Builtin
+idl.Builtin
Instances of this class represent types which are predefined within
the system.
-libxltype.UInt
+idl.UInt
Instances of this class represent the standard uint<N>_t types.
@@ -72,12 +72,12 @@ libxltype.UInt
Complex type-Classes
--------------------
-libxltype.Enumeration
+idl.Enumeration
A class representing an enumeration (named integer values).
The values are available in the list Enumeration.values. Each
- element in the list is of type libxltype.EnumerationValue.
+ element in the list is of type idl.EnumerationValue.
Each EnumerationValue has the following properties:
@@ -95,37 +95,37 @@ libxltype.Enumeration
and any namespace (e.g. "VALUE")
EnumerationValue.value The integer value associated with this name.
-libxltype.Aggregate
+idl.Aggregate
Base class for type-Classes which contain a number of other types
(e.g. structs and unions).
The contained types are available in the list Aggregate.fields. Each
- element in the list is of type libxltype.Field representing a member
- of the aggregate.
+ element in the list is of type idl.Field representing a member of the
+ aggregate.
Each field has the following properties:
- Field.type The type of the member (a libxltypes.Type).
+ Field.type The type of the member (a idl.Type).
Field.name The name of the member (can be None for anonymous
fields).
Field.const Boolean, true if the member is const.
-libxltype.Struct
+idl.Struct
- A subclass of libxltype.Aggregate representing the C struct type.
+ A subclass of idl.Aggregate representing the C struct type.
Struct.kind == "struct"
-libxltype.Union
+idl.Union
- A subclass of libxltype.Aggregate representing the C union type.
+ A subclass of idl.Aggregate representing the C union type.
Union.kind == "union"
-libxltype.KeyedUnion
+idl.KeyedUnion
- A subclass of libxltype.Aggregate which represents the C union type
+ A subclass of idl.Aggregate which represents the C union type
where the currently valid member of the union can be determined based
upon another member in the containing type.
diff --git a/tools/ocaml/libs/xl/Makefile b/tools/ocaml/libs/xl/Makefile
index b1f12d058a..fe75abb582 100644
--- a/tools/ocaml/libs/xl/Makefile
+++ b/tools/ocaml/libs/xl/Makefile
@@ -46,7 +46,7 @@ xenlight.mli: xenlight.mli.in _libxl_types.mli.in
$(Q)mv xenlight.mli.tmp xenlight.mli
_libxl_types.ml.in _libxl_types.mli.in _libxl_types.inc: genwrap.py $(XEN_ROOT)/tools/libxl/libxl_types.idl \
- $(XEN_ROOT)/tools/libxl/libxltypes.py
+ $(XEN_ROOT)/tools/libxl/idl.py
PYTHONPATH=$(XEN_ROOT)/tools/libxl $(PYTHON) genwrap.py \
$(XEN_ROOT)/tools/libxl/libxl_types.idl \
_libxl_types.mli.in _libxl_types.ml.in _libxl_types.inc
diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py
index 4e318bebc8..f83581848b 100644
--- a/tools/ocaml/libs/xl/genwrap.py
+++ b/tools/ocaml/libs/xl/genwrap.py
@@ -2,7 +2,7 @@
import sys,os
-import libxltypes
+import idl
# typename -> ( ocaml_type, c_from_ocaml, ocaml_from_c )
builtins = {
@@ -39,7 +39,7 @@ def stub_fn_name(ty, name):
def ocaml_type_of(ty):
if ty.rawname == "domid":
return "domid"
- elif isinstance(ty,libxltypes.UInt):
+ elif isinstance(ty,idl.UInt):
if ty.width in [8, 16]:
# handle as ints
width = None
@@ -52,14 +52,14 @@ def ocaml_type_of(ty):
else:
return "int"
- elif isinstance(ty,libxltypes.Builtin):
+ elif isinstance(ty,idl.Builtin):
if not builtins.has_key(ty.typename):
raise NotImplementedError("Unknown Builtin %s (%s)" % (ty.typename, type(ty)))
typename,_,_ = builtins[ty.typename]
if not typename:
raise NotImplementedError("No typename for Builtin %s (%s)" % (ty.typename, type(ty)))
return typename
- elif isinstance(ty,libxltypes.Aggregate):
+ elif isinstance(ty,idl.Aggregate):
return ty.rawname.capitalize() + ".t"
else:
return ty.rawname
@@ -73,11 +73,11 @@ def gen_ocaml_ml(ty, interface, indent=""):
s = ("""(* %s interface *)\n""" % ty.typename)
else:
s = ("""(* %s implementation *)\n""" % ty.typename)
- if isinstance(ty, libxltypes.Enumeration):
+ if isinstance(ty, idl.Enumeration):
s = "type %s = \n" % ty.rawname
for v in ty.values:
s += "\t | %s\n" % v.rawname
- elif isinstance(ty, libxltypes.Aggregate):
+ elif isinstance(ty, idl.Aggregate):
s = ""
if ty.typename is None:
raise NotImplementedError("%s has no typename" % type(ty))
@@ -115,7 +115,7 @@ def gen_ocaml_ml(ty, interface, indent=""):
def c_val(ty, c, o, indent="", parent = None):
s = indent
- if isinstance(ty,libxltypes.UInt):
+ if isinstance(ty,idl.UInt):
if ty.width in [8, 16]:
# handle as ints
width = None
@@ -127,14 +127,14 @@ def c_val(ty, c, o, indent="", parent = None):
s += "%s = Int%d_val(%s);" % (c, width, o)
else:
s += "%s = Int_val(%s);" % (c, o)
- elif isinstance(ty,libxltypes.Builtin):
+ elif isinstance(ty,idl.Builtin):
if not builtins.has_key(ty.typename):
raise NotImplementedError("Unknown Builtin %s (%s)" % (ty.typename, type(ty)))
_,fn,_ = builtins[ty.typename]
if not fn:
raise NotImplementedError("No c_val fn for Builtin %s (%s)" % (ty.typename, type(ty)))
s += "%s;" % (fn % { "o": o, "c": c })
- elif isinstance(ty,libxltypes.Enumeration) and (parent is None):
+ elif isinstance(ty,idl.Enumeration) and (parent is None):
n = 0
s += "switch(Int_val(%s)) {\n" % o
for e in ty.values:
@@ -142,7 +142,7 @@ def c_val(ty, c, o, indent="", parent = None):
n += 1
s += " default: failwith_xl(\"cannot convert value to %s\", lg); break;\n" % ty.typename
s += "}"
- elif isinstance(ty, libxltypes.Aggregate) and (parent is None):
+ elif isinstance(ty, idl.Aggregate) and (parent is None):
n = 0
for f in ty.fields:
if f.type.private:
@@ -151,14 +151,14 @@ def c_val(ty, c, o, indent="", parent = None):
s += "%s\n" % c_val(f.type, fexpr, "Field(%s, %d)" % (o,n), parent=nparent)
n = n + 1
else:
- s += "%s_val(gc, lg, %s, %s);" % (ty.rawname, ty.pass_arg(c, parent is None, passby=libxltypes.PASS_BY_REFERENCE), o)
+ s += "%s_val(gc, lg, %s, %s);" % (ty.rawname, ty.pass_arg(c, parent is None, passby=idl.PASS_BY_REFERENCE), o)
return s.replace("\n", "\n%s" % indent)
def gen_c_val(ty, indent=""):
s = "/* Convert caml value to %s */\n" % ty.rawname
- s += "static int %s_val (caml_gc *gc, struct caml_logger *lg, %s, value v)\n" % (ty.rawname, ty.make_arg("c_val", passby=libxltypes.PASS_BY_REFERENCE))
+ s += "static int %s_val (caml_gc *gc, struct caml_logger *lg, %s, value v)\n" % (ty.rawname, ty.make_arg("c_val", passby=idl.PASS_BY_REFERENCE))
s += "{\n"
s += "\tCAMLparam1(v);\n"
s += "\n"
@@ -172,7 +172,7 @@ def gen_c_val(ty, indent=""):
def ocaml_Val(ty, o, c, indent="", parent = None):
s = indent
- if isinstance(ty,libxltypes.UInt):
+ if isinstance(ty,idl.UInt):
if ty.width in [8, 16]:
# handle as ints
width = None
@@ -184,14 +184,14 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
s += "%s = caml_copy_int%d(%s);" % (o, width, c)
else:
s += "%s = Val_int(%s);" % (o, c)
- elif isinstance(ty,libxltypes.Builtin):
+ elif isinstance(ty,idl.Builtin):
if not builtins.has_key(ty.typename):
raise NotImplementedError("Unknown Builtin %s (%s)" % (ty.typename, type(ty)))
_,_,fn = builtins[ty.typename]
if not fn:
raise NotImplementedError("No ocaml Val fn for Builtin %s (%s)" % (ty.typename, type(ty)))
s += "%s = %s;" % (o, fn % { "c": c })
- elif isinstance(ty,libxltypes.Enumeration) and (parent is None):
+ elif isinstance(ty,idl.Enumeration) and (parent is None):
n = 0
s += "switch(%s) {\n" % c
for e in ty.values:
@@ -199,7 +199,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
n += 1
s += " default: failwith_xl(\"cannot convert value from %s\", lg); break;\n" % ty.typename
s += "}"
- elif isinstance(ty,libxltypes.Aggregate) and (parent is None):
+ elif isinstance(ty,idl.Aggregate) and (parent is None):
s += "{\n"
s += "\tvalue %s_field;\n" % ty.rawname
s += "\n"
@@ -258,8 +258,7 @@ if __name__ == '__main__':
print >>sys.stderr, "Usage: genwrap.py <idl> <mli> <ml> <c-inc>"
sys.exit(1)
- idl = sys.argv[1]
- (_,types) = libxltypes.parse(idl)
+ (_,types) = idl.parse(sys.argv[1])
# Do not generate these yet.
blacklist = [
diff --git a/tools/python/Makefile b/tools/python/Makefile
index b7bc501f9e..d2cbf70836 100644
--- a/tools/python/Makefile
+++ b/tools/python/Makefile
@@ -11,7 +11,7 @@ $(eval $(genpath-target))
.PHONY: build
build: genpath genwrap.py $(XEN_ROOT)/tools/libxl/libxl_types.idl \
- $(XEN_ROOT)/tools/libxl/libxltypes.py
+ $(XEN_ROOT)/tools/libxl/idl.py
PYTHONPATH=$(XEN_ROOT)/tools/libxl $(PYTHON) genwrap.py \
$(XEN_ROOT)/tools/libxl/libxl_types.idl \
xen/lowlevel/xl/_pyxl_types.h \
diff --git a/tools/python/genwrap.py b/tools/python/genwrap.py
index 5f44410bea..aa5c723c3d 100644
--- a/tools/python/genwrap.py
+++ b/tools/python/genwrap.py
@@ -2,23 +2,23 @@
import sys,os
-import libxltypes
+import idl
(TYPE_BOOL, TYPE_INT, TYPE_UINT, TYPE_STRING, TYPE_AGGREGATE) = range(5)
def py_type(ty):
- if ty == libxltypes.bool:
+ if ty == idl.bool:
return TYPE_BOOL
- if isinstance(ty, libxltypes.Enumeration):
+ if isinstance(ty, idl.Enumeration):
return TYPE_UINT
- if isinstance(ty, libxltypes.Number):
+ if isinstance(ty, idl.Number):
if ty.signed:
return TYPE_INT
else:
return TYPE_UINT
- if isinstance(ty, libxltypes.Aggregate):
+ if isinstance(ty, idl.Aggregate):
return TYPE_AGGREGATE
- if ty == libxltypes.string:
+ if ty == idl.string:
return TYPE_STRING
return None
@@ -38,7 +38,7 @@ def fsanitize(name):
def py_decls(ty):
l = []
- if isinstance(ty, libxltypes.Aggregate):
+ if isinstance(ty, idl.Aggregate):
l.append('_hidden Py_%s *Py%s_New(void);\n'%(ty.rawname, ty.rawname))
l.append('_hidden int Py%s_Check(PyObject *self);\n'%ty.rawname)
for f in ty.fields:
@@ -211,10 +211,10 @@ def py_initfuncs(types):
l.append('void genwrap__init(PyObject *m)')
l.append('{')
for ty in types:
- if isinstance(ty, libxltypes.Enumeration):
+ if isinstance(ty, idl.Enumeration):
for v in ty.values:
l.append(' PyModule_AddIntConstant(m, "%s", %s);' % (v.rawname, v.name))
- elif isinstance(ty, libxltypes.Aggregate):
+ elif isinstance(ty, idl.Aggregate):
l.append(' if (PyType_Ready(&Py%s_Type) >= 0) {'%ty.rawname)
l.append(' Py_INCREF(&Py%s_Type);'%ty.rawname)
l.append(' PyModule_AddObject(m, "%s", (PyObject *)&Py%s_Type);'%(ty.rawname, ty.rawname))
@@ -227,7 +227,7 @@ def py_initfuncs(types):
def tree_frob(types):
ret = types[:]
- for ty in [ty for ty in ret if isinstance(ty, libxltypes.Aggregate)]:
+ for ty in [ty for ty in ret if isinstance(ty, idl.Aggregate)]:
ty.fields = filter(lambda f:f.name is not None and f.type.typename is not None, ty.fields)
return ret
@@ -236,8 +236,7 @@ if __name__ == '__main__':
print >>sys.stderr, "Usage: genwrap.py <idl> <decls> <defns>"
sys.exit(1)
- idl = sys.argv[1]
- (_,types) = libxltypes.parse(idl)
+ (_,types) = idl.parse(sys.argv[1])
types = tree_frob(types)
@@ -278,7 +277,7 @@ _hidden PyObject *genwrap__ll_get(long long val);
_hidden int genwrap__ll_set(PyObject *v, long long *val, long long mask);
""" % " ".join(sys.argv))
- for ty in [ty for ty in types if isinstance(ty, libxltypes.Aggregate)]:
+ for ty in [ty for ty in types if isinstance(ty, idl.Aggregate)]:
f.write('/* Internal API for %s wrapper */\n'%ty.typename)
f.write(py_wrapstruct(ty))
f.write(py_decls(ty))
@@ -307,7 +306,7 @@ _hidden int genwrap__ll_set(PyObject *v, long long *val, long long mask);
for ty in types:
if ty.private:
continue
- if isinstance(ty, libxltypes.Aggregate):
+ if isinstance(ty, idl.Aggregate):
f.write('/* Attribute get/set functions for %s */\n'%ty.typename)
for a in ty.fields:
if a.type.private: