unicorn/qemu
Markus Armbruster 428eadd9e0
qapi-visit: Simplify how we visit common union members
For a simple union SU, gen_visit_union() generates a visit of its
single tag member, like this:

visit_type_SUKind(v, "type", &(*obj)->type, &err);

For a flat union FU with base B, it generates a visit of its base
fields:

visit_type_B_fields(v, (B **)obj, &err);

Instead, we can simply visit the common members using the same fields
visit function we use for structs, generated with
gen_visit_struct_fields(). This function visits the base if any, then
the local members.

For a simple union SU, visit_type_SU_fields() contains exactly the old
tag member visit, because there is no base, and the tag member is the
only member. For instance, the code generated for qapi-schema.json's
KeyValue changes like this:

+static void visit_type_KeyValue_fields(Visitor *v, KeyValue **obj, Error **errp)
+{
+ Error *err = NULL;
+
+ visit_type_KeyValueKind(v, "type", &(*obj)->type, &err);
+ if (err) {
+ goto out;
+ }
+
+out:
+ error_propagate(errp, err);
+}
+
void visit_type_KeyValue(Visitor *v, const char *name, KeyValue **obj, Error **errp)
{
Error *err = NULL;
@@ -4863,7 +4911,7 @@ void visit_type_KeyValue(Visitor *v, con
if (!*obj) {
goto out_obj;
}
- visit_type_KeyValueKind(v, "type", &(*obj)->type, &err);
+ visit_type_KeyValue_fields(v, obj, &err);
if (err) {
goto out_obj;
}

For a flat union FU, visit_type_FU_fields() contains exactly the old
base fields visit, because there is a base, but no members. For
instance, the code generated for qapi-schema.json's CpuInfo changes
like this:

static void visit_type_CpuInfoBase_fields(Visitor *v, CpuInfoBase **obj, Error **errp);

+static void visit_type_CpuInfo_fields(Visitor *v, CpuInfo **obj, Error **errp)
+{
+ Error *err = NULL;
+
+ visit_type_CpuInfoBase_fields(v, (CpuInfoBase **)obj, &err);
+ if (err) {
+ goto out;
+ }
+
+out:
+ error_propagate(errp, err);
+}
+
static void visit_type_CpuInfoX86_fields(Visitor *v, CpuInfoX86 **obj, Error **errp)
...
@@ -3485,7 +3509,7 @@ void visit_type_CpuInfo(Visitor *v, cons
if (!*obj) {
goto out_obj;
}
- visit_type_CpuInfoBase_fields(v, (CpuInfoBase **)obj, &err);
+ visit_type_CpuInfo_fields(v, obj, &err);
if (err) {
goto out_obj;
}

As you see, the generated code grows a bit, but in practice, it's lost
in the noise: qapi-schema.json's qapi-visit.c gains roughly 1%.

This simplification became possible with commit 441cbac "qapi-visit:
Convert to QAPISchemaVisitor, fixing bugs". It's a step towards
unifying gen_struct() and gen_union().

Backports commit d7445b57f4342d50c25b5bc1746048fa3720511b from qemu
2018-02-20 15:48:54 -05:00
..
crypto crypto: Clean up includes 2018-02-19 00:47:40 -05:00
default-configs arm64eb: add support for ARM64 big endian. 2017-04-24 23:30:01 +08:00
docs docs: clarify memory region lifecycle 2018-02-12 15:11:21 -05:00
fpu all: Clean up includes 2018-02-19 01:34:28 -05:00
hw x86: Clean up includes 2018-02-19 01:00:09 -05:00
include qom: Correct object_property_get_int() description 2018-02-20 11:52:16 -05:00
qapi qmp: Don't abuse stack to track qmp-output root 2018-02-20 08:09:56 -05:00
qobject qapi: Convert QType into QAPI built-in enum type 2018-02-19 21:47:05 -05:00
qom cpu: Add callback to check architectural watchpoint match 2018-02-20 11:43:56 -05:00
scripts qapi-visit: Simplify how we visit common union members 2018-02-20 15:48:54 -05:00
target-arm target-arm: Add PMUSERENR_EL0 register 2018-02-20 15:36:31 -05:00
target-i386 target-i386: Implement FSGSBASE 2018-02-20 14:45:58 -05:00
target-m68k m68k: Clean up includes 2018-02-19 01:06:05 -05:00
target-mips mips: Clean up includes 2018-02-19 00:45:08 -05:00
target-sparc sparc: Clean up includes 2018-02-19 00:52:41 -05:00
tcg target-i386: Implement BNDMK 2018-02-20 14:02:31 -05:00
util error: New error_fatal 2018-02-20 08:22:27 -05:00
aarch64.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
aarch64eb.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
accel.c all: Clean up includes 2018-02-19 01:34:28 -05:00
arm.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
armeb.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
CODING_STYLE import 2015-08-21 15:04:50 +08:00
configure tcg: Drop ia64 host support 2018-02-04 18:33:02 -05:00
COPYING import 2015-08-21 15:04:50 +08:00
COPYING.LIB import 2015-08-21 15:04:50 +08:00
cpu-exec-common.c exec: Clean up includes 2018-02-19 00:49:55 -05:00
cpu-exec.c exec: Clean up includes 2018-02-19 00:49:55 -05:00
cpus.c exec: Clean up includes 2018-02-19 00:49:55 -05:00
cputlb.c exec: Clean up includes 2018-02-19 00:49:55 -05:00
exec.c exec: Clean up includes 2018-02-19 00:49:55 -05:00
gen_all_header.sh arm64eb: add support for ARM64 big endian. 2017-04-24 23:30:01 +08:00
glib_compat.c crypto: introduce new module for computing hash digests 2018-02-17 15:23:17 -05:00
HACKING import 2015-08-21 15:04:50 +08:00
header_gen.py target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
ioport.c all: Clean up includes 2018-02-19 01:34:28 -05:00
LICENSE import 2015-08-21 15:04:50 +08:00
m68k.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
Makefile qapi: Turn generators' mandatory option -i into an argument 2018-02-19 15:22:27 -05:00
Makefile.objs crypto: move crypto objects out of libqemuutil.la 2018-02-17 15:23:50 -05:00
Makefile.target tcg: split tcg_op_defs to -common 2018-02-17 15:23:51 -05:00
memory.c qom: Swap 'name' next to visitor in ObjectPropertyAccessor 2018-02-19 23:14:37 -05:00
memory_mapping.c all: Clean up includes 2018-02-19 01:34:28 -05:00
mips.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
mips64.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
mips64el.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
mipsel.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
powerpc.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
qapi-schema.json qapi: Lazy creation of array types 2018-02-19 18:55:35 -05:00
qemu-log.c all: Clean up includes 2018-02-19 01:34:28 -05:00
qemu-timer.c all: Clean up includes 2018-02-19 01:34:28 -05:00
rules.mak import 2015-08-21 15:04:50 +08:00
softmmu_template.h exec.c: Pass MemTxAttrs to iotlb_to_region so it uses the right AS 2018-02-17 23:19:00 -05:00
sparc.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
sparc64.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00
tcg-runtime.c all: Clean up includes 2018-02-19 01:34:28 -05:00
translate-all.c all: Clean up includes 2018-02-19 01:34:28 -05:00
translate-all.h translate-all: remove unnecessary argument to tb_invalidate_phys_range 2018-02-13 09:04:51 -05:00
translate-common.c exec: Clean up includes 2018-02-19 00:49:55 -05:00
unicorn_common.h qom/cpu: Add MemoryRegion property 2018-02-18 21:54:50 -05:00
VERSION import 2015-08-21 15:04:50 +08:00
vl.c vl.c: Remove periods and exclamation points from error messages 2018-02-17 15:24:14 -05:00
vl.h import 2015-08-21 15:04:50 +08:00
x86_64.h target-arm: Implement checking of fired watchpoint 2018-02-20 11:50:29 -05:00