From patchwork Sun Feb 11 09:35:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 10211271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3A36260329 for ; Sun, 11 Feb 2018 10:05:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 174FB28B50 for ; Sun, 11 Feb 2018 10:05:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 086EC28E6E; Sun, 11 Feb 2018 10:05:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EE04D28E14 for ; Sun, 11 Feb 2018 10:05:19 +0000 (UTC) Received: from localhost ([::1]:42154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekoVa-00070z-Hv for patchwork-qemu-devel@patchwork.kernel.org; Sun, 11 Feb 2018 05:05:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eko3l-0007Bf-KH for qemu-devel@nongnu.org; Sun, 11 Feb 2018 04:36:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eko3d-0006R9-F9 for qemu-devel@nongnu.org; Sun, 11 Feb 2018 04:36:33 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54019 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eko3c-0006Pp-SK for qemu-devel@nongnu.org; Sun, 11 Feb 2018 04:36:25 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A7FB404084E; Sun, 11 Feb 2018 09:36:16 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-43.ams2.redhat.com [10.36.116.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF48BFFD06; Sun, 11 Feb 2018 09:36:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9FDF01138651; Sun, 11 Feb 2018 10:36:07 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Sun, 11 Feb 2018 10:35:45 +0100 Message-Id: <20180211093607.27351-8-armbru@redhat.com> In-Reply-To: <20180211093607.27351-1-armbru@redhat.com> References: <20180211093607.27351-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 11 Feb 2018 09:36:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 11 Feb 2018 09:36:16 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 07/29] qapi: Turn generators into modules X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Eric Blake Reviewed-by: Marc-André Lureau Reviewed-by: Michael Roth --- scripts/qapi-commands.py | 43 ++++++++++++++++++-------------- scripts/qapi-event.py | 43 ++++++++++++++++++-------------- scripts/qapi-introspect.py | 54 ++++++++++++++++++++++------------------ scripts/qapi-types.py | 56 ++++++++++++++++++++++------------------- scripts/qapi-visit.py | 62 +++++++++++++++++++++++++--------------------- 5 files changed, 143 insertions(+), 115 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index e97e16e828..8584cb5873 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -255,16 +255,17 @@ 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 = ''' + 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" @@ -279,23 +280,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 3f98e2491a..e7e07f0055 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -171,16 +171,17 @@ 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 = ''' + 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" @@ -191,22 +192,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 2418b80a82..b098b95053 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -167,38 +167,44 @@ 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 = ''' + for o, a in opts: + if o in ('-u', '--unmask-non-abi-names'): + opt_unmask = True + + blurb = ''' * QAPI/QMP schema introspection ''' -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 "%(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 5ff2bfcf41..10955d1c01 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -240,45 +240,51 @@ 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 = ''' + for o, a in opts: + if o in ('-b', '--builtins'): + opt_builtins = True + + blurb = ''' * Schema-defined QAPI types ''' -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 "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 0a1eff7736..6d829c4d1d 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -323,49 +323,55 @@ 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 = ''' + for o, a in opts: + if o in ('-b', '--builtins'): + opt_builtins = True + + blurb = ''' * Schema-defined QAPI visitors ''' -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 "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)