All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Rosbrook <rosbrookn@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: george.dunlap@citrix.com, Nick Rosbrook <rosbrookn@ainfosec.com>,
	Ian Jackson <iwj@xenproject.org>, Wei Liu <wl@xen.org>,
	Anthony PERARD <anthony.perard@citrix.com>
Subject: [RFC v2 2/7] libxl: add Function class to IDL
Date: Tue,  2 Mar 2021 20:46:14 -0500	[thread overview]
Message-ID: <2193e7fbc7c359b2e32551370ef57ba371658281.1614734296.git.rosbrookn@ainfosec.com> (raw)
In-Reply-To: <cover.1614734296.git.rosbrookn@ainfosec.com>
In-Reply-To: <cover.1614734296.git.rosbrookn@ainfosec.com>

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(-)

diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py
index 3e40c3d5dc..484e121746 100644
--- a/tools/golang/xenlight/gengotypes.py
+++ b/tools/golang/xenlight/gengotypes.py
@@ -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
diff --git a/tools/libs/light/gentypes.py b/tools/libs/light/gentypes.py
index 37de0f68b3..f9957b79a2 100644
--- a/tools/libs/light/gentypes.py
+++ b/tools/libs/light/gentypes.py
@@ -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)
 
diff --git a/tools/libs/light/idl.py b/tools/libs/light/idl.py
index d7367503b4..20278c272a 100644
--- a/tools/libs/light/idl.py
+++ b/tools/libs/light/idl.py
@@ -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)
-- 
2.17.1



  parent reply	other threads:[~2021-03-03  1:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03  1:46 [RFC v2 0/7] add function support to IDL Nick Rosbrook
2021-03-03  1:46 ` [RFC v2 1/7] libxl: remove extra whitespace from gentypes.py Nick Rosbrook
2021-05-04 14:39   ` Anthony PERARD
2021-03-03  1:46 ` Nick Rosbrook [this message]
2021-03-03  1:46 ` [RFC v2 3/7] libxl: add PASS_BY_CONST_REFERENCE to idl Nick Rosbrook
2021-03-03  1:46 ` [RFC v2 4/7] libxl: add DeviceFunction classes to IDL Nick Rosbrook
2021-03-03  1:46 ` [RFC v2 5/7] libxl: add device function definitions to libxl_types.idl Nick Rosbrook
2021-05-04 15:43   ` Anthony PERARD
2021-05-04 17:26     ` Nick Rosbrook
2021-03-03  1:46 ` [RFC v2 6/7] libxl: implement device add/remove/destroy functions generation Nick Rosbrook
2021-05-04 15:02   ` Anthony PERARD
2021-05-04 17:29     ` Nick Rosbrook
2021-03-03  1:46 ` [RFC v2 7/7] libxl: replace LIBXL_DEFINE_DEVICE* macro usage with generated code Nick Rosbrook
2021-03-03  9:48 ` [RFC v2 0/7] add function support to IDL Ian Jackson
2021-03-03 13:41   ` Nick Rosbrook
2021-04-21 21:28     ` Nick Rosbrook
2021-05-04 15:46 ` Anthony PERARD
2021-05-04 17:31   ` Nick Rosbrook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2193e7fbc7c359b2e32551370ef57ba371658281.1614734296.git.rosbrookn@ainfosec.com \
    --to=rosbrookn@gmail.com \
    --cc=anthony.perard@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=rosbrookn@ainfosec.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.