qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 06/17] qapi: qapi-visit.py, add gen support for exis


From: Michael Roth
Subject: [Qemu-devel] [PATCH 06/17] qapi: qapi-visit.py, add gen support for existing types
Date: Mon, 4 Jun 2012 20:00:07 -0500

For qidl-annotated devices, we generate visitors for existing types,
rather than defined the types via qapi. Modify qapi-visit.py so that we
can pass it a header containing the type definition rather that having
it expect a generated one.

Signed-off-by: Michael Roth <address@hidden>
---
 scripts/qapi-visit.py |   34 +++++++++++++++++++++++++++++-----
 1 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 6562226..a319e66 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -229,8 +229,10 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj, const 
char *name, Error **e
                 name=name)
 
 try:
-    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
-                                   ["source", "header", "prefix=", 
"output-dir="])
+    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:ei:",
+                                   ["source", "header", "prefix=",
+                                    "output-dir=", "existing-types",
+                                    "include="])
 except getopt.GetoptError, err:
     print str(err)
     sys.exit(1)
@@ -239,9 +241,11 @@ output_dir = ""
 prefix = ""
 c_file = 'qapi-visit.c'
 h_file = 'qapi-visit.h'
+includes = []
 
 do_c = False
 do_h = False
+existing_types = False
 
 for o, a in opts:
     if o in ("-p", "--prefix"):
@@ -252,6 +256,10 @@ for o, a in opts:
         do_c = True
     elif o in ("-h", "--header"):
         do_h = True
+    elif o in ("-e", "--existing-types"):
+        existing_types = True
+    elif o in ("-i", "--include"):
+        includes.append(a)
 
 if not do_c and not do_h:
     do_c = True
@@ -316,19 +324,35 @@ fdecl.write(mcgen('''
 #define %(guard)s
 
 #include "qapi/qapi-visit-core.h"
-#include "%(prefix)sqapi-types.h"
 ''',
                   prefix=prefix, guard=guardname(h_file)))
 
+if not existing_types:
+    fdecl.write(mcgen('''
+#include "%(prefix)sqapi-types.h"
+''',
+                prefix=prefix))
+
+for include in includes:
+    fdecl.write(mcgen('''
+#include "%(include)s"
+''',
+                include=include))
+
+
 exprs = parse_schema(sys.stdin)
 
 for expr in exprs:
     if expr.has_key('type'):
         ret = generate_visit_struct(expr['type'], expr['data'])
-        ret += generate_visit_list(expr['type'], expr['data'])
+        if not existing_types:
+            ret += generate_visit_list(expr['type'], expr['data'])
         fdef.write(ret)
 
-        ret = generate_declaration(expr['type'], expr['data'])
+        if existing_types:
+            ret = generate_declaration(expr['type'], expr['data'], False)
+        else:
+            ret = generate_declaration(expr['type'], expr['data'], True)
         fdecl.write(ret)
     elif expr.has_key('union'):
         ret = generate_visit_union(expr['union'], expr['data'])
-- 
1.7.4.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]