+Pierrick
On 20/10/25 17:05, Philippe Mathieu-Daudé wrote:
On 18/10/25 17:11, BALATON Zoltan wrote:
Add a more general DEFINE_MACHINE_EXTENDED macro and define simpler
versions with less parameters based on that. This is inspired by how
the OBJECT_DEFINE macros do this in a similar way to allow using the
shortened definition in more complex cases too.
Signed-off-by: BALATON Zoltan <[email protected]>
---
include/hw/boards.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 665b620121..fd3d549ff5 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -762,7 +762,8 @@ struct MachineState {
} \
} while (0)
-#define DEFINE_MACHINE(namestr, machine_initfn) \
+#define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
+ machine_initfn, ABSTRACT, ...) \
static void machine_initfn##_class_init(ObjectClass *oc, const
void *data) \
{ \
MachineClass *mc = MACHINE_CLASS(oc); \
@@ -770,8 +771,11 @@ struct MachineState {
} \
static const TypeInfo machine_initfn##_typeinfo = { \
.name = MACHINE_TYPE_NAME(namestr), \
- .parent = TYPE_MACHINE, \
+ .parent = TYPE_##PARENT_NAME, \
.class_init = machine_initfn##_class_init, \
+ .instance_size = sizeof(InstanceName), \
+ .abstract = ABSTRACT, \
IIUC we don't want to have abstract type with interfaces, but
only QOM leaves. So maybe better always use .abstract = false in
DEFINE_MACHINE_EXTENDED()?
+ .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
IIUC Richard asked for array argument in order to save .rodata?
}; \
static void machine_initfn##_register_types(void) \
{ \
@@ -779,6 +783,14 @@ struct MachineState {
} \
type_init(machine_initfn##_register_types)
+#define DEFINE_MACHINE(namestr, machine_initfn) \
+ DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
machine_initfn, \
+ false, { })
+
+#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
+ DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
machine_initfn, \
+ false, __VA_ARGS__)
+
extern GlobalProperty hw_compat_10_1[];
extern const size_t hw_compat_10_1_len;