aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi-types.py
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2018-02-26 13:39:37 -0600
committerEric Blake <eblake@redhat.com>2018-03-02 13:14:09 -0600
commit26df4e7fab06422b21e11d039c64243ca4003147 (patch)
tree6ec019a9caa809c7b14e812829afbcb840d612b1 /scripts/qapi-types.py
parent93b564c444edc41901d0f7e922833eeb751f8249 (diff)
qapi: Turn generators into modules
The next commit will introduce a common driver program for all generators. The generators need to be modules for that. qapi2texi.py already is. Make the other generators follow suit. The changes are actually trivial. Obvious in the diffs once you view them with whitespace changes ignored. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20180211093607.27351-8-armbru@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> [eblake: minor tweak to keep 'blurb' one line] Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi-types.py')
-rw-r--r--scripts/qapi-types.py56
1 files changed, 31 insertions, 25 deletions
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)