Hi Zoltan,
On 2/5/25 01:20, 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 <balaton@eik.bme.hu>
> ---
> 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 765dc8dd35..6e52d4d10c 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -744,7 +744,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); \
> @@ -752,8 +753,11 @@ struct MachineState {
> } \
> static const TypeInfo machine_initfn##_typeinfo = { \
> .name = MACHINE_TYPE_NAME(namestr), \
> - .parent = TYPE_MACHINE, \
> + .parent = TYPE_##PARENT_NAME, \
As it doesn't save much, lets simply pass the full PARENT_TYPE,
not PARENT_NAME. But, do we really need it?
> .class_init = machine_initfn##_class_init, \
> + .instance_size = sizeof(InstanceName), \
> + .abstract = ABSTRACT, \
> + .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
> }; \
> static void machine_initfn##_register_types(void) \
> { \
> @@ -761,6 +765,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_0[];
> extern const size_t hw_compat_10_0_len;
>