mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
qapi: New classes QAPIGenC, QAPIGenH, QAPIGenDoc
These classes encapsulate accumulating and writing output. Convert C code generation to QAPIGenC and QAPIGenH. The conversion is rather shallow: most of the output accumulation is not converted. Left for later. The indentation machinery uses a single global variable indent_level, even though we generally interleave creation of a .c and its .h. It should become instance variable of QAPIGenC. Also left for later. Documentation generation isn't converted, and QAPIGenDoc isn't used. This will change shortly. 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-6-armbru@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> [eblake: fix nits spotted by Michael] Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
d46eec4260
commit
47a6ea9aab
6 changed files with 117 additions and 98 deletions
|
@ -258,12 +258,10 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
|
|||
|
||||
blurb = ' * Schema-defined QAPI/QMP commands'
|
||||
|
||||
(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
|
||||
'qmp-marshal.c', 'qmp-commands.h',
|
||||
blurb, __doc__)
|
||||
|
||||
fdef.write(mcgen('''
|
||||
genc = QAPIGenC(blurb, __doc__)
|
||||
genh = QAPIGenH(blurb, __doc__)
|
||||
|
||||
genc.add(mcgen('''
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/module.h"
|
||||
|
@ -278,20 +276,23 @@ fdef.write(mcgen('''
|
|||
#include "%(prefix)sqmp-commands.h"
|
||||
|
||||
''',
|
||||
prefix=prefix))
|
||||
prefix=prefix))
|
||||
|
||||
fdecl.write(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)))
|
||||
prefix=prefix, c_prefix=c_name(prefix, protect=False)))
|
||||
|
||||
schema = QAPISchema(input_file)
|
||||
vis = QAPISchemaGenCommandVisitor()
|
||||
schema.visit(vis)
|
||||
fdef.write(vis.defn)
|
||||
fdecl.write(vis.decl)
|
||||
genc.add(vis.defn)
|
||||
genh.add(vis.decl)
|
||||
|
||||
close_output(fdef, fdecl)
|
||||
if do_c:
|
||||
genc.write(output_dir, prefix + 'qmp-marshal.c')
|
||||
if do_h:
|
||||
genh.write(output_dir, prefix + 'qmp-commands.h')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue