@@ -725,7 +725,7 @@ def xenlight_golang_fmt_name(name, exported = True):
if __name__ == '__main__':
idlname = sys.argv[1]
- (builtins, types) = idl.parse(idlname)
+ (builtins, types, _) = idl.parse(idlname)
for b in builtins:
name = b.typename
@@ -592,7 +592,7 @@ if __name__ == '__main__':
(_, idlname, header, header_private, header_json, impl) = sys.argv
- (builtins,types) = idl.parse(idlname)
+ (builtins,types,_) = idl.parse(idlname)
print("outputting libxl type definitions to %s" % header)
@@ -347,6 +347,35 @@ class OrderedDict(dict):
def ordered_items(self):
return [(x,self[x]) for x in self.__ordered]
+class Function(object):
+ """
+ A general description of a function signature.
+
+ Attributes:
+ name (str): name of the function, excluding namespace.
+ params (list of (str,Type)): list of function parameters.
+ return_type (Type): the Type (if any), returned by the function.
+ """
+ def __init__(self, name=None, params=None, return_type=None, namespace=None):
+
+ if namespace is None:
+ self.namespace = _get_default_namespace()
+ else:
+ self.namespace = namespace
+
+ self.name = self.namespace + name
+ self.rawname = name
+ self.params = params
+ self.return_type = return_type
+
+class CtxFunction(Function):
+ """ A function that requires a libxl_ctx. """
+ def __init__(self, name=None, params=None, return_type=None):
+ ctx = Builtin("ctx", passby=PASS_BY_REFERENCE)
+ params.insert(0, ("ctx", ctx))
+
+ Function.__init__(self, name, params, return_type)
+
def parse(f):
print("Parsing %s" % f, file=sys.stderr)
@@ -358,6 +387,10 @@ def parse(f):
globs[n] = t
elif isinstance(t,type(object)) and issubclass(t, Type):
globs[n] = t
+ elif isinstance(t, Function):
+ globs[n] = t
+ elif isinstance(t,type(object)) and issubclass(t, Function):
+ globs[n] = t
elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE',
'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH',
'namespace', 'hidden']:
@@ -370,8 +403,9 @@ def parse(f):
% (e.lineno, f, e.text))
types = [t for t in locs.ordered_values() if isinstance(t,Type)]
+ funcs = [f for f in locs.ordered_values() if isinstance(f,Function)]
builtins = [t for t in types if isinstance(t,Builtin)]
types = [t for t in types if not isinstance(t,Builtin)]
- return (builtins,types)
+ return (builtins,types,funcs)
Add a Function and CtxFunction classes to idl.py to allow generator scripts to generate wrappers which are repetitive and straight forward when doing so by hand. Examples of such functions are the device_add/remove functions. To start, a Function has attributes for namespace, name, parameters, and return type. The CtxFunction class extends this by indicating that a libxl_ctx is a required parmeter. Also, add logic to idl.parse to return the list of functions found in an IDL file. For now, have users of idl.py -- i.e. libxl/gentypes.py and golang/xenlight/gengotypes.py -- ignore the list of functions returned. Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com> --- tools/golang/xenlight/gengotypes.py | 2 +- tools/libs/light/gentypes.py | 2 +- tools/libs/light/idl.py | 36 ++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-)