qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 10/11] qapi/commands: Simplify command registry generation


From: John Snow
Subject: Re: [PATCH 10/11] qapi/commands: Simplify command registry generation
Date: Thu, 14 Jan 2021 21:15:50 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0

On 12/18/20 3:54 PM, Markus Armbruster wrote:
QAPISchemaGenCommandVisitor.visit_command() needs to generate the
marshalling function into the current module, and also generate its
registration into the ./init system module.  The latter is done
somewhat awkwardly: .__init__() creates a QAPIGenCCode that will not
be written out, each .visit_command() adds its registration to it, and
.visit_end() copies its contents into the ./init module it creates.

Instead provide the means to temporarily switch to another module.
Create the ./init module in .visit_begin(), and generate its initial
part.  Add registrations to it in .visit_command().  Finish it in
.visit_end().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
  scripts/qapi/commands.py | 49 ++++++++++++++++++----------------------
  1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 4911166339..396485cc1a 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -23,7 +23,6 @@ from typing import (
  from .common import c_name, mcgen
  from .gen import (
      QAPIGenC,
-    QAPIGenCCode,
      QAPISchemaModularCVisitor,
      build_params,
      ifcontext,
@@ -237,28 +236,11 @@ def gen_register_command(name: str,
      return ret
-def gen_registry(registry: str, prefix: str) -> str:
-    ret = mcgen('''
-
-void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds)
-{
-    QTAILQ_INIT(cmds);
-
-''',
-                c_prefix=c_name(prefix, protect=False))
-    ret += registry
-    ret += mcgen('''
-}
-''')
-    return ret
-
-
  class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor):
      def __init__(self, prefix: str):
          super().__init__(
              prefix, 'qapi-commands',
              ' * Schema-defined QAPI/QMP commands', None, __doc__)
-        self._regy = QAPIGenCCode(None)
          self._visited_ret_types: Dict[QAPIGenC, Set[QAPISchemaType]] = {}
def _begin_user_module(self, name: str) -> None:
@@ -285,7 +267,7 @@ class 
QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor):
  ''',
                               types=types))
- def visit_end(self) -> None:
+    def visit_begin(self, schema) -> None:

visit_begin(self, schema: QAPISchema) -> None: ...

:~)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]