commit a7e2799c7c3c790c83e015b48ba34ac0975b93bb Author: Anthony Liguori Date: Thu Jul 16 22:16:02 2009 -0500 Introduce macro for defining qdev properties. Signed-off-by: Anthony Liguori diff --git a/hw/escc.c b/hw/escc.c index 9abd092..43230b9 100644 --- a/hw/escc.c +++ b/hw/escc.c @@ -952,21 +952,9 @@ static SysBusDeviceInfo escc_info = { .qdev.name = "escc", .qdev.size = sizeof(SerialState), .qdev.props = (Property[]) { - { - .name = "frequency", - .info = &qdev_prop_uint32, - .offset = offsetof(SerialState, frequency), - }, - { - .name = "it_shift", - .info = &qdev_prop_uint32, - .offset = offsetof(SerialState, it_shift), - }, - { - .name = "disabled", - .info = &qdev_prop_uint32, - .offset = offsetof(SerialState, disabled), - }, + QDEV_PROP(SerialState, frequency), + QDEV_PROP(SerialState, it_shift), + QDEV_PROP(SerialState, disabled), { .name = "chrB", .info = &qdev_prop_ptr, diff --git a/hw/qdev.h b/hw/qdev.h index 11744fa..957ce22 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -143,6 +143,25 @@ void do_info_qtree(Monitor *mon); /*** qdev-properties.c ***/ +#define CHOOSE(a, b, c) __builtin_choose_expr(a, b, c) +#define TYPES_COMPAT(a, b) __builtin_types_compatible_p(a, b) +#define TYPEOF_FIELD(type, field) typeof(((type *)0)->field) +#define BUILD_BUG() sizeof(char[-1]) + +#define QDEV_PROP(type, field) \ + { \ + .name = stringify(field), \ + .offset = offsetof(type, field), \ + .info = \ + CHOOSE(TYPES_COMPAT(TYPEOF_FIELD(type, field), uint32_t), \ + &qdev_prop_uint32, \ + CHOOSE(TYPES_COMPAT(TYPEOF_FIELD(type, field), int32_t), \ + &qdev_prop_uint32, \ + CHOOSE(TYPES_COMPAT(TYPEOF_FIELD(type, field), void *), \ + &qdev_prop_ptr, \ + NULL))), \ + } + extern PropertyInfo qdev_prop_uint16; extern PropertyInfo qdev_prop_uint32; extern PropertyInfo qdev_prop_hex32;