From 47a6ea9aab1d857015684cda387ffba05a036721 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 26 Feb 2018 13:19:40 -0600 Subject: 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 Reviewed-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <20180211093607.27351-6-armbru@redhat.com> Reviewed-by: Michael Roth [eblake: fix nits spotted by Michael] Signed-off-by: Eric Blake --- scripts/qapi-event.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'scripts/qapi-event.py') diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index 9de5c6748e..e063f6b8d1 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -174,11 +174,10 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): blurb = ' * Schema-defined QAPI/QMP events' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, - 'qapi-event.c', 'qapi-event.h', - blurb, __doc__) +genc = QAPIGenC(blurb, __doc__) +genh = QAPIGenH(blurb, __doc__) -fdef.write(mcgen(''' +genc.add(mcgen(''' #include "qemu/osdep.h" #include "qemu-common.h" #include "%(prefix)sqapi-event.h" @@ -189,21 +188,24 @@ fdef.write(mcgen(''' #include "qapi/qmp-event.h" ''', - prefix=prefix)) + prefix=prefix)) -fdecl.write(mcgen(''' +genh.add(mcgen(''' #include "qapi/util.h" #include "%(prefix)sqapi-types.h" ''', - prefix=prefix)) + prefix=prefix)) event_enum_name = c_name(prefix + 'QAPIEvent', protect=False) schema = QAPISchema(input_file) vis = QAPISchemaGenEventVisitor() 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 + 'qapi-event.c') +if do_h: + genh.write(output_dir, prefix + 'qapi-event.h') -- cgit v1.2.3-55-g7522