aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/qapi-commands.py43
-rw-r--r--scripts/qapi-event.py43
-rw-r--r--scripts/qapi-introspect.py54
-rw-r--r--scripts/qapi-types.py56
-rw-r--r--scripts/qapi-visit.py62
5 files changed, 143 insertions, 115 deletions
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index e75e32e489..c20b22020e 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -255,14 +255,15 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
self._regy += gen_register_command(name, success_response)
-(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
+def main(argv):
+ (input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
-blurb = ' * Schema-defined QAPI/QMP commands'
+ blurb = ' * Schema-defined QAPI/QMP commands'
-genc = QAPIGenC(blurb, __doc__)
-genh = QAPIGenH(blurb, __doc__)
+ genc = QAPIGenC(blurb, __doc__)
+ genh = QAPIGenH(blurb, __doc__)
-genc.add(mcgen('''
+ genc.add(mcgen('''
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/module.h"
@@ -277,23 +278,27 @@ genc.add(mcgen('''
#include "%(prefix)sqmp-commands.h"
''',
- prefix=prefix))
+ prefix=prefix))
-genh.add(mcgen('''
+ genh.add(mcgen('''
#include "%(prefix)sqapi-types.h"
#include "qapi/qmp/dispatch.h"
void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds);
''',
- prefix=prefix, c_prefix=c_name(prefix, protect=False)))
-
-schema = QAPISchema(input_file)
-vis = QAPISchemaGenCommandVisitor(prefix)
-schema.visit(vis)
-genc.add(vis.defn)
-genh.add(vis.decl)
-
-if do_c:
- genc.write(output_dir, prefix + 'qmp-marshal.c')
-if do_h:
- genh.write(output_dir, prefix + 'qmp-commands.h')
+ prefix=prefix, c_prefix=c_name(prefix, protect=False)))
+
+ schema = QAPISchema(input_file)
+ vis = QAPISchemaGenCommandVisitor(prefix)
+ schema.visit(vis)
+ genc.add(vis.defn)
+ genh.add(vis.decl)
+
+ if do_c:
+ genc.write(output_dir, prefix + 'qmp-marshal.c')
+ if do_h:
+ genh.write(output_dir, prefix + 'qmp-commands.h')
+
+
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index f65ccdc8ea..1f8bf62c8b 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -171,14 +171,15 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
self._event_names.append(name)
-(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
+def main(argv):
+ (input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
-blurb = ' * Schema-defined QAPI/QMP events'
+ blurb = ' * Schema-defined QAPI/QMP events'
-genc = QAPIGenC(blurb, __doc__)
-genh = QAPIGenH(blurb, __doc__)
+ genc = QAPIGenC(blurb, __doc__)
+ genh = QAPIGenH(blurb, __doc__)
-genc.add(mcgen('''
+ genc.add(mcgen('''
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "%(prefix)sqapi-event.h"
@@ -189,22 +190,26 @@ genc.add(mcgen('''
#include "qapi/qmp-event.h"
''',
- prefix=prefix))
+ prefix=prefix))
-genh.add(mcgen('''
+ genh.add(mcgen('''
#include "qapi/util.h"
#include "%(prefix)sqapi-types.h"
''',
- prefix=prefix))
-
-schema = QAPISchema(input_file)
-vis = QAPISchemaGenEventVisitor(prefix)
-schema.visit(vis)
-genc.add(vis.defn)
-genh.add(vis.decl)
-
-if do_c:
- genc.write(output_dir, prefix + 'qapi-event.c')
-if do_h:
- genh.write(output_dir, prefix + 'qapi-event.h')
+ prefix=prefix))
+
+ schema = QAPISchema(input_file)
+ vis = QAPISchemaGenEventVisitor(prefix)
+ schema.visit(vis)
+ genc.add(vis.defn)
+ genh.add(vis.decl)
+
+ if do_c:
+ genc.write(output_dir, prefix + 'qapi-event.c')
+ if do_h:
+ genh.write(output_dir, prefix + 'qapi-event.h')
+
+
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index 5d9a7abeb8..cac219b4d8 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -167,36 +167,42 @@ const char %(c_name)s[] = %(c_string)s;
arg_type = arg_type or self._schema.the_empty_object_type
self._gen_json(name, 'event', {'arg-type': self._use_type(arg_type)})
-# Debugging aid: unmask QAPI schema's type names
-# We normally mask them, because they're not QMP wire ABI
-opt_unmask = False
-(input_file, output_dir, do_c, do_h, prefix, opts) = \
- parse_command_line('u', ['unmask-non-abi-names'])
+def main(argv):
+ # Debugging aid: unmask QAPI schema's type names
+ # We normally mask them, because they're not QMP wire ABI
+ opt_unmask = False
-for o, a in opts:
- if o in ('-u', '--unmask-non-abi-names'):
- opt_unmask = True
+ (input_file, output_dir, do_c, do_h, prefix, opts) = \
+ parse_command_line('u', ['unmask-non-abi-names'])
-blurb = ' * QAPI/QMP schema introspection'
+ for o, a in opts:
+ if o in ('-u', '--unmask-non-abi-names'):
+ opt_unmask = True
-genc = QAPIGenC(blurb, __doc__)
-genh = QAPIGenH(blurb, __doc__)
+ blurb = ' * QAPI/QMP schema introspection'
-genc.add(mcgen('''
+ genc = QAPIGenC(blurb, __doc__)
+ genh = QAPIGenH(blurb, __doc__)
+
+ genc.add(mcgen('''
#include "qemu/osdep.h"
#include "%(prefix)sqmp-introspect.h"
''',
- prefix=prefix))
-
-schema = QAPISchema(input_file)
-vis = QAPISchemaGenIntrospectVisitor(prefix, opt_unmask)
-schema.visit(vis)
-genc.add(vis.defn)
-genh.add(vis.decl)
-
-if do_c:
- genc.write(output_dir, prefix + 'qmp-introspect.c')
-if do_h:
- genh.write(output_dir, prefix + 'qmp-introspect.h')
+ prefix=prefix))
+
+ schema = QAPISchema(input_file)
+ vis = QAPISchemaGenIntrospectVisitor(prefix, opt_unmask)
+ schema.visit(vis)
+ genc.add(vis.defn)
+ genh.add(vis.decl)
+
+ if do_c:
+ genc.write(output_dir, prefix + 'qmp-introspect.c')
+ if do_h:
+ genh.write(output_dir, prefix + 'qmp-introspect.h')
+
+
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 6ef8c40d5b..7d23544228 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -240,43 +240,49 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
self.decl += gen_object(name, None, [variants.tag_member], variants)
self._gen_type_cleanup(name)
-# If you link code generated from multiple schemata, you want only one
-# instance of the code for built-in types. Generate it only when
-# opt_builtins, enabled by command line option -b. See also
-# QAPISchemaGenTypeVisitor.visit_end().
-opt_builtins = False
-(input_file, output_dir, do_c, do_h, prefix, opts) = \
- parse_command_line('b', ['builtins'])
+def main(argv):
+ # If you link code generated from multiple schemata, you want only one
+ # instance of the code for built-in types. Generate it only when
+ # opt_builtins, enabled by command line option -b. See also
+ # QAPISchemaGenTypeVisitor.visit_end().
+ opt_builtins = False
-for o, a in opts:
- if o in ('-b', '--builtins'):
- opt_builtins = True
+ (input_file, output_dir, do_c, do_h, prefix, opts) = \
+ parse_command_line('b', ['builtins'])
-blurb = ' * Schema-defined QAPI types'
+ for o, a in opts:
+ if o in ('-b', '--builtins'):
+ opt_builtins = True
-genc = QAPIGenC(blurb, __doc__)
-genh = QAPIGenH(blurb, __doc__)
+ blurb = ' * Schema-defined QAPI types'
-genc.add(mcgen('''
+ genc = QAPIGenC(blurb, __doc__)
+ genh = QAPIGenH(blurb, __doc__)
+
+ genc.add(mcgen('''
#include "qemu/osdep.h"
#include "qapi/dealloc-visitor.h"
#include "%(prefix)sqapi-types.h"
#include "%(prefix)sqapi-visit.h"
''',
- prefix=prefix))
+ prefix=prefix))
-genh.add(mcgen('''
+ genh.add(mcgen('''
#include "qapi/util.h"
'''))
-schema = QAPISchema(input_file)
-vis = QAPISchemaGenTypeVisitor(opt_builtins)
-schema.visit(vis)
-genc.add(vis.defn)
-genh.add(vis.decl)
+ schema = QAPISchema(input_file)
+ vis = QAPISchemaGenTypeVisitor(opt_builtins)
+ schema.visit(vis)
+ genc.add(vis.defn)
+ genh.add(vis.decl)
+
+ if do_c:
+ genc.write(output_dir, prefix + 'qapi-types.c')
+ if do_h:
+ genh.write(output_dir, prefix + 'qapi-types.h')
+
-if do_c:
- genc.write(output_dir, prefix + 'qapi-types.c')
-if do_h:
- genh.write(output_dir, prefix + 'qapi-types.h')
+if __name__ == '__main__':
+ main(sys.argv)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index d5ca480421..3c23a9389d 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -323,47 +323,53 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
self.decl += gen_visit_decl(name)
self.defn += gen_visit_alternate(name, variants)
-# If you link code generated from multiple schemata, you want only one
-# instance of the code for built-in types. Generate it only when
-# opt_builtins, enabled by command line option -b. See also
-# QAPISchemaGenVisitVisitor.visit_end().
-opt_builtins = False
-(input_file, output_dir, do_c, do_h, prefix, opts) = \
- parse_command_line('b', ['builtins'])
+def main(argv):
+ # If you link code generated from multiple schemata, you want only one
+ # instance of the code for built-in types. Generate it only when
+ # opt_builtins, enabled by command line option -b. See also
+ # QAPISchemaGenVisitVisitor.visit_end().
+ opt_builtins = False
-for o, a in opts:
- if o in ('-b', '--builtins'):
- opt_builtins = True
+ (input_file, output_dir, do_c, do_h, prefix, opts) = \
+ parse_command_line('b', ['builtins'])
-blurb = ' * Schema-defined QAPI visitors'
+ for o, a in opts:
+ if o in ('-b', '--builtins'):
+ opt_builtins = True
-genc = QAPIGenC(blurb, __doc__)
-genh = QAPIGenH(blurb, __doc__)
+ blurb = ' * Schema-defined QAPI visitors'
-genc.add(mcgen('''
+ genc = QAPIGenC(blurb, __doc__)
+ genh = QAPIGenH(blurb, __doc__)
+
+ genc.add(mcgen('''
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qapi/error.h"
#include "qapi/qmp/qerror.h"
#include "%(prefix)sqapi-visit.h"
''',
- prefix=prefix))
+ prefix=prefix))
-genh.add(mcgen('''
+ genh.add(mcgen('''
#include "qapi/visitor.h"
#include "%(prefix)sqapi-types.h"
''',
- prefix=prefix))
-
-schema = QAPISchema(input_file)
-vis = QAPISchemaGenVisitVisitor(opt_builtins)
-schema.visit(vis)
-genc.add(vis.defn)
-genh.add(vis.decl)
-
-if do_c:
- genc.write(output_dir, prefix + 'qapi-visit.c')
-if do_h:
- genh.write(output_dir, prefix + 'qapi-visit.h')
+ prefix=prefix))
+
+ schema = QAPISchema(input_file)
+ vis = QAPISchemaGenVisitVisitor(opt_builtins)
+ schema.visit(vis)
+ genc.add(vis.defn)
+ genh.add(vis.decl)
+
+ if do_c:
+ genc.write(output_dir, prefix + 'qapi-visit.c')
+ if do_h:
+ genh.write(output_dir, prefix + 'qapi-visit.h')
+
+
+if __name__ == '__main__':
+ main(sys.argv)