qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qapi: Generate separate .h, .c for each module

Our qapi-schema.json is composed of modules connected by include
directives, but the generated code is monolithic all the same: one
qapi-types.h with all the types, one qapi-visit.h with all the
visitors, and so forth. These monolithic headers get included all
over the place. In my "build everything" tree, adding a QAPI type
recompiles about 4800 out of 5100 objects.

We wouldn't write such monolithic headers by hand. It stands to
reason that we shouldn't generate them, either.

Split up generated qapi-types.h to mirror the schema's modular
structure: one header per module. Name the main module's header
qapi-types.h, and sub-module D/B.json's header D/qapi-types-B.h.

Mirror the schema's includes in the headers, so that qapi-types.h gets
you everything exactly as before. If you need less, you can include
one or more of the sub-module headers. To be exploited shortly.

Split up qapi-types.c, qapi-visit.h, qapi-visit.c, qmp-commands.h,
qmp-commands.c, qapi-event.h, qapi-event.c the same way.
qmp-introspect.h, qmp-introspect.c and qapi.texi remain monolithic.

The split of qmp-commands.c duplicates static helper function
qmp_marshal_output_str() in qapi-commands-char.c and
qapi-commands-misc.c. This happens when commands returning the same
type occur in multiple modules. Not worth avoiding.

Since I'm going to rename qapi-event.[ch] to qapi-events.[ch], and
qmp-commands.[ch] to qapi-commands.[ch], name the shards that way
already, to reduce churn. This requires temporary hacks in
commands.py and events.py. Similarly, c_name() must temporarily
be taught to munge '/' in common.py. They'll go away with the rename.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20180211093607.27351-23-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: declare a dummy variable in each .c file, to shut up OSX
toolchain warnings about empty .o files, including hacking c_name()]
Signed-off-by: Eric Blake <eblake@redhat.com>

authored by

Markus Armbruster and committed by
Eric Blake
252dc310 3da7a416

+310 -22
+60
.gitignore
··· 31 31 /qapi-gen-timestamp 32 32 /qapi-builtin-types.[ch] 33 33 /qapi-builtin-visit.[ch] 34 + /qapi/qapi-commands-block-core.[ch] 35 + /qapi/qapi-commands-block.[ch] 36 + /qapi/qapi-commands-char.[ch] 37 + /qapi/qapi-commands-common.[ch] 38 + /qapi/qapi-commands-crypto.[ch] 39 + /qapi/qapi-commands-introspect.[ch] 40 + /qapi/qapi-commands-migration.[ch] 41 + /qapi/qapi-commands-net.[ch] 42 + /qapi/qapi-commands-rocker.[ch] 43 + /qapi/qapi-commands-run-state.[ch] 44 + /qapi/qapi-commands-sockets.[ch] 45 + /qapi/qapi-commands-tpm.[ch] 46 + /qapi/qapi-commands-trace.[ch] 47 + /qapi/qapi-commands-transaction.[ch] 48 + /qapi/qapi-commands-ui.[ch] 49 + /qapi/qapi-events-block-core.[ch] 50 + /qapi/qapi-events-block.[ch] 51 + /qapi/qapi-events-char.[ch] 52 + /qapi/qapi-events-common.[ch] 53 + /qapi/qapi-events-crypto.[ch] 54 + /qapi/qapi-events-introspect.[ch] 55 + /qapi/qapi-events-migration.[ch] 56 + /qapi/qapi-events-net.[ch] 57 + /qapi/qapi-events-rocker.[ch] 58 + /qapi/qapi-events-run-state.[ch] 59 + /qapi/qapi-events-sockets.[ch] 60 + /qapi/qapi-events-tpm.[ch] 61 + /qapi/qapi-events-trace.[ch] 62 + /qapi/qapi-events-transaction.[ch] 63 + /qapi/qapi-events-ui.[ch] 64 + /qapi/qapi-types-block-core.[ch] 65 + /qapi/qapi-types-block.[ch] 66 + /qapi/qapi-types-char.[ch] 67 + /qapi/qapi-types-common.[ch] 68 + /qapi/qapi-types-crypto.[ch] 69 + /qapi/qapi-types-introspect.[ch] 70 + /qapi/qapi-types-migration.[ch] 71 + /qapi/qapi-types-net.[ch] 72 + /qapi/qapi-types-rocker.[ch] 73 + /qapi/qapi-types-run-state.[ch] 74 + /qapi/qapi-types-sockets.[ch] 75 + /qapi/qapi-types-tpm.[ch] 76 + /qapi/qapi-types-trace.[ch] 77 + /qapi/qapi-types-transaction.[ch] 78 + /qapi/qapi-types-ui.[ch] 34 79 /qapi-types.[ch] 80 + /qapi/qapi-visit-block-core.[ch] 81 + /qapi/qapi-visit-block.[ch] 82 + /qapi/qapi-visit-char.[ch] 83 + /qapi/qapi-visit-common.[ch] 84 + /qapi/qapi-visit-crypto.[ch] 85 + /qapi/qapi-visit-introspect.[ch] 86 + /qapi/qapi-visit-migration.[ch] 87 + /qapi/qapi-visit-net.[ch] 88 + /qapi/qapi-visit-rocker.[ch] 89 + /qapi/qapi-visit-run-state.[ch] 90 + /qapi/qapi-visit-sockets.[ch] 91 + /qapi/qapi-visit-tpm.[ch] 92 + /qapi/qapi-visit-trace.[ch] 93 + /qapi/qapi-visit-transaction.[ch] 94 + /qapi/qapi-visit-ui.[ch] 35 95 /qapi-visit.[ch] 36 96 /qapi-event.[ch] 37 97 /qapi-doc.texi
+120
Makefile
··· 92 92 GENERATED_FILES = qemu-version.h config-host.h qemu-options.def 93 93 GENERATED_FILES += qapi-builtin-types.h qapi-builtin-types.c 94 94 GENERATED_FILES += qapi-types.h qapi-types.c 95 + GENERATED_FILES += qapi/qapi-types-block-core.h qapi/qapi-types-block-core.c 96 + GENERATED_FILES += qapi/qapi-types-block.h qapi/qapi-types-block.c 97 + GENERATED_FILES += qapi/qapi-types-char.h qapi/qapi-types-char.c 98 + GENERATED_FILES += qapi/qapi-types-common.h qapi/qapi-types-common.c 99 + GENERATED_FILES += qapi/qapi-types-crypto.h qapi/qapi-types-crypto.c 100 + GENERATED_FILES += qapi/qapi-types-introspect.h qapi/qapi-types-introspect.c 101 + GENERATED_FILES += qapi/qapi-types-migration.h qapi/qapi-types-migration.c 102 + GENERATED_FILES += qapi/qapi-types-net.h qapi/qapi-types-net.c 103 + GENERATED_FILES += qapi/qapi-types-rocker.h qapi/qapi-types-rocker.c 104 + GENERATED_FILES += qapi/qapi-types-run-state.h qapi/qapi-types-run-state.c 105 + GENERATED_FILES += qapi/qapi-types-sockets.h qapi/qapi-types-sockets.c 106 + GENERATED_FILES += qapi/qapi-types-tpm.h qapi/qapi-types-tpm.c 107 + GENERATED_FILES += qapi/qapi-types-trace.h qapi/qapi-types-trace.c 108 + GENERATED_FILES += qapi/qapi-types-transaction.h qapi/qapi-types-transaction.c 109 + GENERATED_FILES += qapi/qapi-types-ui.h qapi/qapi-types-ui.c 95 110 GENERATED_FILES += qapi-builtin-visit.h qapi-builtin-visit.c 96 111 GENERATED_FILES += qapi-visit.h qapi-visit.c 112 + GENERATED_FILES += qapi/qapi-visit-block-core.h qapi/qapi-visit-block-core.c 113 + GENERATED_FILES += qapi/qapi-visit-block.h qapi/qapi-visit-block.c 114 + GENERATED_FILES += qapi/qapi-visit-char.h qapi/qapi-visit-char.c 115 + GENERATED_FILES += qapi/qapi-visit-common.h qapi/qapi-visit-common.c 116 + GENERATED_FILES += qapi/qapi-visit-crypto.h qapi/qapi-visit-crypto.c 117 + GENERATED_FILES += qapi/qapi-visit-introspect.h qapi/qapi-visit-introspect.c 118 + GENERATED_FILES += qapi/qapi-visit-migration.h qapi/qapi-visit-migration.c 119 + GENERATED_FILES += qapi/qapi-visit-net.h qapi/qapi-visit-net.c 120 + GENERATED_FILES += qapi/qapi-visit-rocker.h qapi/qapi-visit-rocker.c 121 + GENERATED_FILES += qapi/qapi-visit-run-state.h qapi/qapi-visit-run-state.c 122 + GENERATED_FILES += qapi/qapi-visit-sockets.h qapi/qapi-visit-sockets.c 123 + GENERATED_FILES += qapi/qapi-visit-tpm.h qapi/qapi-visit-tpm.c 124 + GENERATED_FILES += qapi/qapi-visit-trace.h qapi/qapi-visit-trace.c 125 + GENERATED_FILES += qapi/qapi-visit-transaction.h qapi/qapi-visit-transaction.c 126 + GENERATED_FILES += qapi/qapi-visit-ui.h qapi/qapi-visit-ui.c 97 127 GENERATED_FILES += qmp-commands.h qmp-commands.c 128 + GENERATED_FILES += qapi/qapi-commands-block-core.h qapi/qapi-commands-block-core.c 129 + GENERATED_FILES += qapi/qapi-commands-block.h qapi/qapi-commands-block.c 130 + GENERATED_FILES += qapi/qapi-commands-char.h qapi/qapi-commands-char.c 131 + GENERATED_FILES += qapi/qapi-commands-common.h qapi/qapi-commands-common.c 132 + GENERATED_FILES += qapi/qapi-commands-crypto.h qapi/qapi-commands-crypto.c 133 + GENERATED_FILES += qapi/qapi-commands-introspect.h qapi/qapi-commands-introspect.c 134 + GENERATED_FILES += qapi/qapi-commands-migration.h qapi/qapi-commands-migration.c 135 + GENERATED_FILES += qapi/qapi-commands-net.h qapi/qapi-commands-net.c 136 + GENERATED_FILES += qapi/qapi-commands-rocker.h qapi/qapi-commands-rocker.c 137 + GENERATED_FILES += qapi/qapi-commands-run-state.h qapi/qapi-commands-run-state.c 138 + GENERATED_FILES += qapi/qapi-commands-sockets.h qapi/qapi-commands-sockets.c 139 + GENERATED_FILES += qapi/qapi-commands-tpm.h qapi/qapi-commands-tpm.c 140 + GENERATED_FILES += qapi/qapi-commands-trace.h qapi/qapi-commands-trace.c 141 + GENERATED_FILES += qapi/qapi-commands-transaction.h qapi/qapi-commands-transaction.c 142 + GENERATED_FILES += qapi/qapi-commands-ui.h qapi/qapi-commands-ui.c 98 143 GENERATED_FILES += qapi-event.h qapi-event.c 144 + GENERATED_FILES += qapi/qapi-events-block-core.h qapi/qapi-events-block-core.c 145 + GENERATED_FILES += qapi/qapi-events-block.h qapi/qapi-events-block.c 146 + GENERATED_FILES += qapi/qapi-events-char.h qapi/qapi-events-char.c 147 + GENERATED_FILES += qapi/qapi-events-common.h qapi/qapi-events-common.c 148 + GENERATED_FILES += qapi/qapi-events-crypto.h qapi/qapi-events-crypto.c 149 + GENERATED_FILES += qapi/qapi-events-introspect.h qapi/qapi-events-introspect.c 150 + GENERATED_FILES += qapi/qapi-events-migration.h qapi/qapi-events-migration.c 151 + GENERATED_FILES += qapi/qapi-events-net.h qapi/qapi-events-net.c 152 + GENERATED_FILES += qapi/qapi-events-rocker.h qapi/qapi-events-rocker.c 153 + GENERATED_FILES += qapi/qapi-events-run-state.h qapi/qapi-events-run-state.c 154 + GENERATED_FILES += qapi/qapi-events-sockets.h qapi/qapi-events-sockets.c 155 + GENERATED_FILES += qapi/qapi-events-tpm.h qapi/qapi-events-tpm.c 156 + GENERATED_FILES += qapi/qapi-events-trace.h qapi/qapi-events-trace.c 157 + GENERATED_FILES += qapi/qapi-events-transaction.h qapi/qapi-events-transaction.c 158 + GENERATED_FILES += qapi/qapi-events-ui.h qapi/qapi-events-ui.c 99 159 GENERATED_FILES += qmp-introspect.c qmp-introspect.h 100 160 GENERATED_FILES += qapi-doc.texi 101 161 ··· 524 584 525 585 qapi-builtin-types.c qapi-builtin-types.h \ 526 586 qapi-types.c qapi-types.h \ 587 + qapi/qapi-types-block-core.c qapi/qapi-types-block-core.h \ 588 + qapi/qapi-types-block.c qapi/qapi-types-block.h \ 589 + qapi/qapi-types-char.c qapi/qapi-types-char.h \ 590 + qapi/qapi-types-common.c qapi/qapi-types-common.h \ 591 + qapi/qapi-types-crypto.c qapi/qapi-types-crypto.h \ 592 + qapi/qapi-types-introspect.c qapi/qapi-types-introspect.h \ 593 + qapi/qapi-types-migration.c qapi/qapi-types-migration.h \ 594 + qapi/qapi-types-net.c qapi/qapi-types-net.h \ 595 + qapi/qapi-types-rocker.c qapi/qapi-types-rocker.h \ 596 + qapi/qapi-types-run-state.c qapi/qapi-types-run-state.h \ 597 + qapi/qapi-types-sockets.c qapi/qapi-types-sockets.h \ 598 + qapi/qapi-types-tpm.c qapi/qapi-types-tpm.h \ 599 + qapi/qapi-types-trace.c qapi/qapi-types-trace.h \ 600 + qapi/qapi-types-transaction.c qapi/qapi-types-transaction.h \ 601 + qapi/qapi-types-ui.c qapi/qapi-types-ui.h \ 527 602 qapi-builtin-visit.c qapi-builtin-visit.h \ 528 603 qapi-visit.c qapi-visit.h \ 604 + qapi/qapi-visit-block-core.c qapi/qapi-visit-block-core.h \ 605 + qapi/qapi-visit-block.c qapi/qapi-visit-block.h \ 606 + qapi/qapi-visit-char.c qapi/qapi-visit-char.h \ 607 + qapi/qapi-visit-common.c qapi/qapi-visit-common.h \ 608 + qapi/qapi-visit-crypto.c qapi/qapi-visit-crypto.h \ 609 + qapi/qapi-visit-introspect.c qapi/qapi-visit-introspect.h \ 610 + qapi/qapi-visit-migration.c qapi/qapi-visit-migration.h \ 611 + qapi/qapi-visit-net.c qapi/qapi-visit-net.h \ 612 + qapi/qapi-visit-rocker.c qapi/qapi-visit-rocker.h \ 613 + qapi/qapi-visit-run-state.c qapi/qapi-visit-run-state.h \ 614 + qapi/qapi-visit-sockets.c qapi/qapi-visit-sockets.h \ 615 + qapi/qapi-visit-tpm.c qapi/qapi-visit-tpm.h \ 616 + qapi/qapi-visit-trace.c qapi/qapi-visit-trace.h \ 617 + qapi/qapi-visit-transaction.c qapi/qapi-visit-transaction.h \ 618 + qapi/qapi-visit-ui.c qapi/qapi-visit-ui.h \ 529 619 qmp-commands.h qmp-commands.c \ 620 + qapi/qapi-commands-block-core.c qapi/qapi-commands-block-core.h \ 621 + qapi/qapi-commands-block.c qapi/qapi-commands-block.h \ 622 + qapi/qapi-commands-char.c qapi/qapi-commands-char.h \ 623 + qapi/qapi-commands-common.c qapi/qapi-commands-common.h \ 624 + qapi/qapi-commands-crypto.c qapi/qapi-commands-crypto.h \ 625 + qapi/qapi-commands-introspect.c qapi/qapi-commands-introspect.h \ 626 + qapi/qapi-commands-migration.c qapi/qapi-commands-migration.h \ 627 + qapi/qapi-commands-net.c qapi/qapi-commands-net.h \ 628 + qapi/qapi-commands-rocker.c qapi/qapi-commands-rocker.h \ 629 + qapi/qapi-commands-run-state.c qapi/qapi-commands-run-state.h \ 630 + qapi/qapi-commands-sockets.c qapi/qapi-commands-sockets.h \ 631 + qapi/qapi-commands-tpm.c qapi/qapi-commands-tpm.h \ 632 + qapi/qapi-commands-trace.c qapi/qapi-commands-trace.h \ 633 + qapi/qapi-commands-transaction.c qapi/qapi-commands-transaction.h \ 634 + qapi/qapi-commands-ui.c qapi/qapi-commands-ui.h \ 530 635 qapi-event.c qapi-event.h \ 636 + qapi/qapi-events-block-core.c qapi/qapi-events-block-core.h \ 637 + qapi/qapi-events-block.c qapi/qapi-events-block.h \ 638 + qapi/qapi-events-char.c qapi/qapi-events-char.h \ 639 + qapi/qapi-events-common.c qapi/qapi-events-common.h \ 640 + qapi/qapi-events-crypto.c qapi/qapi-events-crypto.h \ 641 + qapi/qapi-events-introspect.c qapi/qapi-events-introspect.h \ 642 + qapi/qapi-events-migration.c qapi/qapi-events-migration.h \ 643 + qapi/qapi-events-net.c qapi/qapi-events-net.h \ 644 + qapi/qapi-events-rocker.c qapi/qapi-events-rocker.h \ 645 + qapi/qapi-events-run-state.c qapi/qapi-events-run-state.h \ 646 + qapi/qapi-events-sockets.c qapi/qapi-events-sockets.h \ 647 + qapi/qapi-events-tpm.c qapi/qapi-events-tpm.h \ 648 + qapi/qapi-events-trace.c qapi/qapi-events-trace.h \ 649 + qapi/qapi-events-transaction.c qapi/qapi-events-transaction.h \ 650 + qapi/qapi-events-ui.c qapi/qapi-events-ui.h \ 531 651 qmp-introspect.h qmp-introspect.c \ 532 652 qapi-doc.texi: \ 533 653 qapi-gen-timestamp ;
+64 -1
Makefile.objs
··· 3 3 stub-obj-y = stubs/ crypto/ 4 4 util-obj-y = util/ qobject/ qapi/ 5 5 util-obj-y += qapi-builtin-types.o 6 + util-obj-y += qapi-types.o 7 + util-obj-y += qapi/qapi-types-block-core.o 8 + util-obj-y += qapi/qapi-types-block.o 9 + util-obj-y += qapi/qapi-types-char.o 10 + util-obj-y += qapi/qapi-types-common.o 11 + util-obj-y += qapi/qapi-types-crypto.o 12 + util-obj-y += qapi/qapi-types-introspect.o 13 + util-obj-y += qapi/qapi-types-migration.o 14 + util-obj-y += qapi/qapi-types-net.o 15 + util-obj-y += qapi/qapi-types-rocker.o 16 + util-obj-y += qapi/qapi-types-run-state.o 17 + util-obj-y += qapi/qapi-types-sockets.o 18 + util-obj-y += qapi/qapi-types-tpm.o 19 + util-obj-y += qapi/qapi-types-trace.o 20 + util-obj-y += qapi/qapi-types-transaction.o 21 + util-obj-y += qapi/qapi-types-ui.o 6 22 util-obj-y += qapi-builtin-visit.o 7 - util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o 23 + util-obj-y += qapi-visit.o 24 + util-obj-y += qapi/qapi-visit-block-core.o 25 + util-obj-y += qapi/qapi-visit-block.o 26 + util-obj-y += qapi/qapi-visit-char.o 27 + util-obj-y += qapi/qapi-visit-common.o 28 + util-obj-y += qapi/qapi-visit-crypto.o 29 + util-obj-y += qapi/qapi-visit-introspect.o 30 + util-obj-y += qapi/qapi-visit-migration.o 31 + util-obj-y += qapi/qapi-visit-net.o 32 + util-obj-y += qapi/qapi-visit-rocker.o 33 + util-obj-y += qapi/qapi-visit-run-state.o 34 + util-obj-y += qapi/qapi-visit-sockets.o 35 + util-obj-y += qapi/qapi-visit-tpm.o 36 + util-obj-y += qapi/qapi-visit-trace.o 37 + util-obj-y += qapi/qapi-visit-transaction.o 38 + util-obj-y += qapi/qapi-visit-ui.o 39 + util-obj-y += qapi-event.o 40 + util-obj-y += qapi/qapi-events-block-core.o 41 + util-obj-y += qapi/qapi-events-block.o 42 + util-obj-y += qapi/qapi-events-char.o 43 + util-obj-y += qapi/qapi-events-common.o 44 + util-obj-y += qapi/qapi-events-crypto.o 45 + util-obj-y += qapi/qapi-events-introspect.o 46 + util-obj-y += qapi/qapi-events-migration.o 47 + util-obj-y += qapi/qapi-events-net.o 48 + util-obj-y += qapi/qapi-events-rocker.o 49 + util-obj-y += qapi/qapi-events-run-state.o 50 + util-obj-y += qapi/qapi-events-sockets.o 51 + util-obj-y += qapi/qapi-events-tpm.o 52 + util-obj-y += qapi/qapi-events-trace.o 53 + util-obj-y += qapi/qapi-events-transaction.o 54 + util-obj-y += qapi/qapi-events-ui.o 55 + util-obj-y += qmp-introspect.o 8 56 9 57 chardev-obj-y = chardev/ 10 58 ··· 81 129 # qapi 82 130 83 131 common-obj-y += qmp-commands.o 132 + common-obj-y += qapi/qapi-commands-block-core.o 133 + common-obj-y += qapi/qapi-commands-block.o 134 + common-obj-y += qapi/qapi-commands-char.o 135 + common-obj-y += qapi/qapi-commands-common.o 136 + common-obj-y += qapi/qapi-commands-crypto.o 137 + common-obj-y += qapi/qapi-commands-introspect.o 138 + common-obj-y += qapi/qapi-commands-migration.o 139 + common-obj-y += qapi/qapi-commands-net.o 140 + common-obj-y += qapi/qapi-commands-rocker.o 141 + common-obj-y += qapi/qapi-commands-run-state.o 142 + common-obj-y += qapi/qapi-commands-sockets.o 143 + common-obj-y += qapi/qapi-commands-tpm.o 144 + common-obj-y += qapi/qapi-commands-trace.o 145 + common-obj-y += qapi/qapi-commands-transaction.o 146 + common-obj-y += qapi/qapi-commands-ui.o 84 147 common-obj-y += qmp-introspect.o 85 148 common-obj-y += qmp.o hmp.o 86 149 endif
+24 -11
scripts/qapi/commands.py
··· 223 223 return ret 224 224 225 225 226 - class QAPISchemaGenCommandVisitor(QAPISchemaMonolithicCVisitor): 226 + class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): 227 227 228 228 def __init__(self, prefix): 229 - QAPISchemaMonolithicCVisitor.__init__( 230 - self, prefix, 'qmp-commands', 229 + QAPISchemaModularCVisitor.__init__( 230 + self, prefix, 'qapi-commands', 231 231 ' * Schema-defined QAPI/QMP commands', __doc__) 232 232 self._regy = '' 233 - self._visited_ret_types = set() 233 + self._visited_ret_types = {} 234 + 235 + # Temporary HACK: 236 + def _module_basename(self, what, name): 237 + basename = QAPISchemaModularCVisitor._module_basename(self, what, name) 238 + if name == self._main_module: 239 + return re.sub(r'qapi-commands', 'qmp-commands', basename) 240 + return basename 241 + 242 + def _begin_module(self, name): 243 + self._visited_ret_types[self._genc] = set() 234 244 self._genc.add(mcgen(''' 235 245 #include "qemu/osdep.h" 236 246 #include "qemu-common.h" ··· 246 256 #include "%(prefix)sqmp-commands.h" 247 257 248 258 ''', 249 - prefix=prefix)) 259 + prefix=self._prefix)) 250 260 self._genh.add(mcgen(''' 251 261 #include "%(prefix)sqapi-types.h" 252 262 #include "qapi/qmp/dispatch.h" 253 263 254 - void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); 255 264 ''', 256 - prefix=prefix, 257 - c_prefix=c_name(prefix, protect=False))) 265 + prefix=self._prefix)) 258 266 259 267 def visit_end(self): 260 - self._genc.add(gen_registry(self._regy, self._prefix)) 268 + (genc, genh) = self._module[self._main_module] 269 + genh.add(mcgen(''' 270 + void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); 271 + ''', 272 + c_prefix=c_name(self._prefix, protect=False))) 273 + genc.add(gen_registry(self._regy, self._prefix)) 261 274 262 275 def visit_command(self, name, info, arg_type, ret_type, 263 276 gen, success_response, boxed): 264 277 if not gen: 265 278 return 266 279 self._genh.add(gen_command_decl(name, arg_type, boxed, ret_type)) 267 - if ret_type and ret_type not in self._visited_ret_types: 268 - self._visited_ret_types.add(ret_type) 280 + if ret_type and ret_type not in self._visited_ret_types[self._genc]: 281 + self._visited_ret_types[self._genc].add(ret_type) 269 282 self._genc.add(gen_marshal_output(ret_type)) 270 283 self._genh.add(gen_marshal_decl(name)) 271 284 self._genc.add(gen_marshal(name, arg_type, boxed, ret_type))
+28 -5
scripts/qapi/common.py
··· 1775 1775 type_name = prefix 1776 1776 return camel_to_upper(type_name) + '_' + c_name(const_name, False).upper() 1777 1777 1778 + # Temporary HACK for '/': 1778 1779 if hasattr(str, 'maketrans'): 1779 - c_name_trans = str.maketrans('.-', '__') 1780 + c_name_trans = str.maketrans('.-/', '___') 1780 1781 else: 1781 - c_name_trans = string.maketrans('.-', '__') 1782 + c_name_trans = string.maketrans('.-/', '___') 1782 1783 1783 1784 1784 1785 # Map @name to a valid C identifier. ··· 2035 2036 ''', 2036 2037 blurb=self._blurb, copyright=self._copyright) 2037 2038 2039 + def _bottom(self, fname): 2040 + return mcgen(''' 2041 + /* Dummy declaration to prevent empty .o file */ 2042 + char dummy_%(name)s; 2043 + ''', 2044 + name=c_name(fname)) 2045 + 2038 2046 2039 2047 class QAPIGenH(QAPIGenC): 2040 2048 ··· 2073 2081 self._blurb = blurb 2074 2082 self._pydoc = pydoc 2075 2083 self._module = {} 2084 + self._main_module = None 2076 2085 2077 2086 def _module_basename(self, what, name): 2078 2087 if name is None: 2079 2088 return re.sub(r'-', '-builtin-', what) 2080 - return self._prefix + what 2089 + basename = os.path.join(os.path.dirname(name), 2090 + self._prefix + what) 2091 + if name == self._main_module: 2092 + return basename 2093 + return basename + '-' + os.path.splitext(os.path.basename(name))[0] 2081 2094 2082 2095 def _add_module(self, name, blurb): 2096 + if self._main_module is None and name is not None: 2097 + self._main_module = name 2083 2098 genc = QAPIGenC(blurb, self._pydoc) 2084 2099 genh = QAPIGenH(blurb, self._pydoc) 2085 2100 self._module[name] = (genc, genh) ··· 2088 2103 def _set_module(self, name): 2089 2104 self._genc, self._genh = self._module[name] 2090 2105 2091 - def write(self, output_dir, opt_builtins): 2106 + def write(self, output_dir, opt_builtins=False): 2092 2107 for name in self._module: 2093 2108 if name is None and not opt_builtins: 2094 2109 continue ··· 2101 2116 pass 2102 2117 2103 2118 def visit_module(self, name): 2104 - if len(self._module) != 1: 2119 + if name in self._module: 2120 + self._set_module(name) 2105 2121 return 2106 2122 self._add_module(name, self._blurb) 2107 2123 self._begin_module(name) 2124 + 2125 + def visit_include(self, name, info): 2126 + basename = self._module_basename(self._what, name) 2127 + self._genh.preamble_add(mcgen(''' 2128 + #include "%(basename)s.h" 2129 + ''', 2130 + basename=basename))
+14 -5
scripts/qapi/events.py
··· 148 148 return ret 149 149 150 150 151 - class QAPISchemaGenEventVisitor(QAPISchemaMonolithicCVisitor): 151 + class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): 152 152 153 153 def __init__(self, prefix): 154 - QAPISchemaMonolithicCVisitor.__init__( 155 - self, prefix, 'qapi-event', 154 + QAPISchemaModularCVisitor.__init__( 155 + self, prefix, 'qapi-events', 156 156 ' * Schema-defined QAPI/QMP events', __doc__) 157 157 self._enum_name = c_name(prefix + 'QAPIEvent', protect=False) 158 158 self._event_names = [] 159 + 160 + # Temporary HACK: 161 + def _module_basename(self, what, name): 162 + basename = QAPISchemaModularCVisitor._module_basename(self, what, name) 163 + if name == self._main_module: 164 + return re.sub(r'qapi-events', 'qapi-event', basename) 165 + return basename 166 + 167 + def _begin_module(self, name): 159 168 self._genc.add(mcgen(''' 160 169 #include "qemu/osdep.h" 161 170 #include "qemu-common.h" ··· 167 176 #include "qapi/qmp-event.h" 168 177 169 178 ''', 170 - prefix=prefix)) 179 + prefix=self._prefix)) 171 180 self._genh.add(mcgen(''' 172 181 #include "qapi/util.h" 173 182 #include "%(prefix)sqapi-types.h" 174 183 175 184 ''', 176 - prefix=prefix)) 185 + prefix=self._prefix)) 177 186 178 187 def visit_end(self): 179 188 self._genh.add(gen_enum(self._enum_name, self._event_names))