diff mbox series

[RFC,v2,3/7] libxl: add PASS_BY_CONST_REFERENCE to idl

Message ID 4b7f52dd28516aa286ab6db90536835b8caed022.1614734296.git.rosbrookn@ainfosec.com (mailing list archive)
State New
Headers show
Series add function support to IDL | expand

Commit Message

Nick Rosbrook March 3, 2021, 1:46 a.m. UTC
Currently, there is only support for PASS_BY_{REFERENCE,VALUE} in the IDL.
As a piece of adding function support, add logic for PASS_BY_CONST_REFERENCE
so that function generation code can use Type.make_arg() for function
signatures that require const reference parameters.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
---
 tools/libs/light/idl.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/tools/libs/light/idl.py b/tools/libs/light/idl.py
index 20278c272a..a8a4768efc 100644
--- a/tools/libs/light/idl.py
+++ b/tools/libs/light/idl.py
@@ -4,6 +4,7 @@  import sys
 
 PASS_BY_VALUE = 1
 PASS_BY_REFERENCE = 2
+PASS_BY_CONST_REFERENCE = 3
 
 DIR_NONE = 0
 DIR_IN   = 1
@@ -40,7 +41,7 @@  class Type(object):
             raise ValueError
 
         self.passby = kwargs.setdefault('passby', PASS_BY_VALUE)
-        if self.passby not in [PASS_BY_VALUE, PASS_BY_REFERENCE]:
+        if self.passby not in [PASS_BY_VALUE, PASS_BY_REFERENCE, PASS_BY_CONST_REFERENCE]:
             raise ValueError
 
         self.private = kwargs.setdefault('private', False)
@@ -109,6 +110,8 @@  class Type(object):
 
         if passby == PASS_BY_REFERENCE:
             return "%s *%s" % (self.typename, n)
+        elif passby == PASS_BY_CONST_REFERENCE:
+            return "const %s *%s" % (self.typename, n)
         else:
             return "%s %s" % (self.typename, n)
 
@@ -116,7 +119,7 @@  class Type(object):
         if passby is None: passby = self.passby
         if isref is None: isref = self.passby == PASS_BY_REFERENCE
 
-        if passby == PASS_BY_REFERENCE:
+        if passby in [PASS_BY_REFERENCE, PASS_BY_CONST_REFERENCE]:
             if isref:
                 return "%s" % (n)
             else:
@@ -272,7 +275,7 @@  class KeyedUnion(Aggregate):
             raise ValueError
 
         kv_kwargs = dict([(x.lstrip('keyvar_'),y) for (x,y) in kwargs.items() if x.startswith('keyvar_')])
-        
+
         self.keyvar = Field(keyvar_type, keyvar_name, **kv_kwargs)
 
         for f in fields:
@@ -392,6 +395,7 @@  def parse(f):
         elif isinstance(t,type(object)) and issubclass(t, Function):
             globs[n] = t
         elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE',
+                   'PASS_BY_CONST_REFERENCE',
                    'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH',
                    'namespace', 'hidden']:
             globs[n] = t