diff options
author | Markus Armbruster | 2018-02-26 20:50:08 +0100 |
---|---|---|
committer | Eric Blake | 2018-03-02 20:14:10 +0100 |
commit | 71b3f0459c460c9e16a47372ccddbfa6e2c7aadf (patch) | |
tree | cd09eb26b84f76dbe839460bdb55a45e3f269dbc /scripts/qapi/introspect.py | |
parent | qapi: Rename generated qmp-marshal.c to qmp-commands.c (diff) | |
download | qemu-71b3f0459c460c9e16a47372ccddbfa6e2c7aadf.tar.gz qemu-71b3f0459c460c9e16a47372ccddbfa6e2c7aadf.tar.xz qemu-71b3f0459c460c9e16a47372ccddbfa6e2c7aadf.zip |
qapi: Make code-generating visitors use QAPIGen more
The use of QAPIGen is rather shallow so far: most of the output
accumulation is not converted. Take the next step: convert output
accumulation in the code-generating visitor classes. Helper functions
outside these classes are not converted.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20180211093607.27351-20-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
[eblake: rebase to earlier guardstart cleanup]
Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi/introspect.py')
-rw-r--r-- | scripts/qapi/introspect.py | 56 |
1 files changed, 23 insertions, 33 deletions
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 1e4f065164..f571cc134c 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -40,22 +40,26 @@ def to_c_string(string): return '"' + string.replace('\\', r'\\').replace('"', r'\"') + '"' -class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): +class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor): + def __init__(self, prefix, unmask): - self._prefix = prefix + QAPISchemaMonolithicCVisitor.__init__( + self, prefix, 'qmp-introspect', + ' * QAPI/QMP schema introspection', __doc__) self._unmask = unmask - self.defn = None - self.decl = None self._schema = None - self._jsons = None - self._used_types = None - self._name_map = None - - def visit_begin(self, schema): - self._schema = schema self._jsons = [] self._used_types = [] self._name_map = {} + self._genc.add(mcgen(''' +#include "qemu/osdep.h" +#include "%(prefix)sqmp-introspect.h" + +''', + prefix=prefix)) + + def visit_begin(self, schema): + self._schema = schema def visit_end(self): # visit the types that are actually used @@ -67,21 +71,21 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): # TODO can generate awfully long lines jsons.extend(self._jsons) name = c_name(self._prefix, protect=False) + 'qmp_schema_json' - self.decl = mcgen(''' + self._genh.add(mcgen(''' extern const char %(c_name)s[]; ''', - c_name=c_name(name)) + c_name=c_name(name))) lines = to_json(jsons).split('\n') c_string = '\n '.join([to_c_string(line) for line in lines]) - self.defn = mcgen(''' + self._genc.add(mcgen(''' const char %(c_name)s[] = %(c_string)s; ''', - c_name=c_name(name), - c_string=c_string) + c_name=c_name(name), + c_string=c_string)) self._schema = None - self._jsons = None - self._used_types = None - self._name_map = None + self._jsons = [] + self._used_types = [] + self._name_map = {} def visit_needed(self, entity): # Ignore types on first pass; visit_end() will pick up used types @@ -169,20 +173,6 @@ const char %(c_name)s[] = %(c_string)s; def gen_introspect(schema, output_dir, prefix, opt_unmask): - blurb = ' * QAPI/QMP schema introspection' - genc = QAPIGenC(blurb, __doc__) - genh = QAPIGenH(blurb, __doc__) - - genc.add(mcgen(''' -#include "qemu/osdep.h" -#include "%(prefix)sqmp-introspect.h" - -''', - prefix=prefix)) - vis = QAPISchemaGenIntrospectVisitor(prefix, opt_unmask) schema.visit(vis) - genc.add(vis.defn) - genh.add(vis.decl) - genc.write(output_dir, prefix + 'qmp-introspect.c') - genh.write(output_dir, prefix + 'qmp-introspect.h') + vis.write(output_dir) |