qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RfC PATCH] qdev: helper macros for properties


From: Anthony Liguori
Subject: Re: [Qemu-devel] [RfC PATCH] qdev: helper macros for properties
Date: Thu, 16 Jul 2009 22:17:41 -0500
User-agent: Thunderbird 2.0.0.21 (X11/20090320)

Paul Brook wrote:
On Wednesday 15 July 2009, Gerd Hoffmann wrote:
  Hi,

New revision of the helper macros for defining properties, going on top
of all other qdev patches posted today.

IMO this should have been part of the initial properties rework, not a followup change. Use of these macros should not be optional.

For the common case, I'd rather something like the following. Very GCC specific.

Regards,

Anthony Liguori

Paul



commit a7e2799c7c3c790c83e015b48ba34ac0975b93bb
Author: Anthony Liguori <address@hidden>
Date:   Thu Jul 16 22:16:02 2009 -0500

    Introduce macro for defining qdev properties.
    
    Signed-off-by: Anthony Liguori <address@hidden>

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;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]