aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2019-02-18 14:23:13 +0000
committerPeter Maydell <peter.maydell@linaro.org>2019-02-18 14:23:13 +0000
commita0430dd8abb8a2f31c5ee919daab2e3d76353c04 (patch)
tree601f2da2585768ec18e5201bda9acbf0c0bbe021 /scripts/qapi
parent1c5d9d8f111b9cfc0722c7edcdc3b090736972e5 (diff)
parent183e4281a30962729b760dfe8bed5aab27238b0c (diff)
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2019-02-18' into staging
QAPI patches for 2019-02-18 # gpg: Signature made Mon 18 Feb 2019 13:44:30 GMT # gpg: using RSA key 3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2019-02-18: qapi: move RTC_CHANGE to the target schema qmp: Deprecate query-events in favor of query-qmp-schema Revert "qapi-events: add 'if' condition to implicit event enum" qapi: remove qmp_unregister_command() qapi: make query-cpu-definitions depend on specific targets qapi: make query-cpu-model-expansion depend on s390 or x86 qapi: make query-gic-capabilities depend on TARGET_ARM target.json: add a note about query-cpu* not being s390x-specific qapi: make s390 commands depend on TARGET_S390X qapi: make rtc-reset-reinjection and SEV depend on TARGET_I386 qapi: New module target.json build: Deal with all of QAPI's .o in qapi/Makefile.objs build-sys: move qmp-introspect per target qapi: Generate QAPIEvent stuff into separate files qapi: Prepare for system modules other than 'builtin' qapi: Clean up modular built-in code generation a bit qapi: Fix up documentation for recent commit a95291007b2 qapi: Belatedly document modular code generation Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'scripts/qapi')
-rw-r--r--scripts/qapi/commands.py2
-rw-r--r--scripts/qapi/common.py55
-rw-r--r--scripts/qapi/events.py38
-rw-r--r--scripts/qapi/types.py4
-rw-r--r--scripts/qapi/visit.py4
5 files changed, 71 insertions, 32 deletions
diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 0f3c991918..ebf488953d 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -242,7 +242,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor):
self._regy = QAPIGenCCode()
self._visited_ret_types = {}
- def _begin_module(self, name):
+ def _begin_user_module(self, name):
self._visited_ret_types[self._genc] = set()
commands = self._module_basename('qapi-commands', name)
types = self._module_basename('qapi-types', name)
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index c89edc0cb0..c327ae5036 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1868,6 +1868,7 @@ class QAPISchema(object):
def visit(self, visitor):
visitor.visit_begin(self)
module = None
+ visitor.visit_module(module)
for entity in self._entity_list:
if visitor.visit_needed(entity):
if entity.module != module:
@@ -2321,47 +2322,73 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor):
self._what = what
self._blurb = blurb
self._pydoc = pydoc
+ self._genc = None
+ self._genh = None
self._module = {}
self._main_module = None
+ @staticmethod
+ def _is_user_module(name):
+ return name and not name.startswith('./')
+
+ @staticmethod
+ def _is_builtin_module(name):
+ return not name
+
def _module_basename(self, what, name):
- if name is None:
- return re.sub(r'-', '-builtin-', what)
- basename = os.path.join(os.path.dirname(name),
- self._prefix + what)
- if name == self._main_module:
- return basename
- return basename + '-' + os.path.splitext(os.path.basename(name))[0]
+ ret = '' if self._is_builtin_module(name) else self._prefix
+ if self._is_user_module(name):
+ dirname, basename = os.path.split(name)
+ ret += what
+ if name != self._main_module:
+ ret += '-' + os.path.splitext(basename)[0]
+ ret = os.path.join(dirname, ret)
+ else:
+ name = name[2:] if name else 'builtin'
+ ret += re.sub(r'-', '-' + name + '-', what)
+ return ret
def _add_module(self, name, blurb):
- if self._main_module is None and name is not None:
- self._main_module = name
genc = QAPIGenC(blurb, self._pydoc)
genh = QAPIGenH(blurb, self._pydoc)
self._module[name] = (genc, genh)
self._set_module(name)
+ def _add_user_module(self, name, blurb):
+ assert self._is_user_module(name)
+ if self._main_module is None:
+ self._main_module = name
+ self._add_module(name, blurb)
+
+ def _add_system_module(self, name, blurb):
+ self._add_module(name and './' + name, blurb)
+
def _set_module(self, name):
self._genc, self._genh = self._module[name]
def write(self, output_dir, opt_builtins=False):
for name in self._module:
- if name is None and not opt_builtins:
+ if self._is_builtin_module(name) and not opt_builtins:
continue
basename = self._module_basename(self._what, name)
(genc, genh) = self._module[name]
genc.write(output_dir, basename + '.c')
genh.write(output_dir, basename + '.h')
- def _begin_module(self, name):
+ def _begin_user_module(self, name):
pass
def visit_module(self, name):
if name in self._module:
self._set_module(name)
- return
- self._add_module(name, self._blurb)
- self._begin_module(name)
+ elif self._is_builtin_module(name):
+ # The built-in module has not been created. No code may
+ # be generated.
+ self._genc = None
+ self._genh = None
+ else:
+ self._add_user_module(name, self._blurb)
+ self._begin_user_module(name)
def visit_include(self, name, info):
basename = self._module_basename(self._what, name)
diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py
index d86a2d2b3e..2067660be4 100644
--- a/scripts/qapi/events.py
+++ b/scripts/qapi/events.py
@@ -142,13 +142,15 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
self._event_enum_members = []
self._event_emit_name = c_name(prefix + 'qapi_event_emit')
- def _begin_module(self, name):
+ def _begin_user_module(self, name):
+ events = self._module_basename('qapi-events', name)
types = self._module_basename('qapi-types', name)
visit = self._module_basename('qapi-visit', name)
self._genc.add(mcgen('''
#include "qemu/osdep.h"
#include "qemu-common.h"
-#include "%(prefix)sqapi-events.h"
+#include "%(prefix)sqapi-emit-events.h"
+#include "%(events)s.h"
#include "%(visit)s.h"
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
@@ -156,26 +158,34 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
#include "qapi/qmp-event.h"
''',
- visit=visit, prefix=self._prefix))
+ events=events, visit=visit,
+ prefix=self._prefix))
self._genh.add(mcgen('''
#include "qapi/util.h"
#include "%(types)s.h"
-
''',
types=types))
def visit_end(self):
- (genc, genh) = self._module[self._main_module]
- genh.add(gen_enum(self._event_enum_name,
- self._event_enum_members))
- genc.add(gen_enum_lookup(self._event_enum_name,
- self._event_enum_members))
- genh.add(mcgen('''
+ self._add_system_module('emit', ' * QAPI Events emission')
+ self._genc.preamble_add(mcgen('''
+#include "qemu/osdep.h"
+#include "%(prefix)sqapi-emit-events.h"
+''',
+ prefix=self._prefix))
+ self._genh.preamble_add(mcgen('''
+#include "qapi/util.h"
+'''))
+ self._genh.add(gen_enum(self._event_enum_name,
+ self._event_enum_members))
+ self._genc.add(gen_enum_lookup(self._event_enum_name,
+ self._event_enum_members))
+ self._genh.add(mcgen('''
void %(event_emit)s(%(event_enum)s event, QDict *qdict);
''',
- event_emit=self._event_emit_name,
- event_enum=self._event_enum_name))
+ event_emit=self._event_emit_name,
+ event_enum=self._event_enum_name))
def visit_event(self, name, info, ifcond, arg_type, boxed):
with ifcontext(ifcond, self._genh, self._genc):
@@ -183,7 +193,9 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict);
self._genc.add(gen_event_send(name, arg_type, boxed,
self._event_enum_name,
self._event_emit_name))
- self._event_enum_members.append(QAPISchemaMember(name, ifcond))
+ # Note: we generate the enum member regardless of @ifcond, to
+ # keep the enumeration usable in target-independent code.
+ self._event_enum_members.append(QAPISchemaMember(name))
def gen_events(schema, output_dir, prefix):
diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py
index 62d4cf9f95..2bd6fcd44f 100644
--- a/scripts/qapi/types.py
+++ b/scripts/qapi/types.py
@@ -183,7 +183,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor):
QAPISchemaModularCVisitor.__init__(
self, prefix, 'qapi-types', ' * Schema-defined QAPI types',
__doc__)
- self._add_module(None, ' * Built-in QAPI types')
+ self._add_system_module(None, ' * Built-in QAPI types')
self._genc.preamble_add(mcgen('''
#include "qemu/osdep.h"
#include "qapi/dealloc-visitor.h"
@@ -194,7 +194,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor):
#include "qapi/util.h"
'''))
- def _begin_module(self, name):
+ def _begin_user_module(self, name):
types = self._module_basename('qapi-types', name)
visit = self._module_basename('qapi-visit', name)
self._genc.preamble_add(mcgen('''
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 82eab72b21..826b8066e1 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -284,7 +284,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
QAPISchemaModularCVisitor.__init__(
self, prefix, 'qapi-visit', ' * Schema-defined QAPI visitors',
__doc__)
- self._add_module(None, ' * Built-in QAPI visitors')
+ self._add_system_module(None, ' * Built-in QAPI visitors')
self._genc.preamble_add(mcgen('''
#include "qemu/osdep.h"
#include "qemu-common.h"
@@ -298,7 +298,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
''',
prefix=prefix))
- def _begin_module(self, name):
+ def _begin_user_module(self, name):
types = self._module_basename('qapi-types', name)
visit = self._module_basename('qapi-visit', name)
self._genc.preamble_add(mcgen('''