new file mode 100644
@@ -0,0 +1,259 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: Linaro Limited 2023
+//
+// Convert QOM set_property() API to QDev set_prop() API equivalent
+//
+// Only bool / string / link properties are automatically converted.
+// Integer properties must be converted manually, since the QOM
+// object_property_set_[u]int() helpers don't specify the type size.
+
+
+//
+// bool
+//
+
+// bool OBJECT
+@@
+typedef DeviceState;
+identifier dev;
+expression prop, val;
+@@
+ DeviceState *dev;
+ ...
+- object_property_set_bool(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_bit(dev, prop, val);
+
+// bool dev
+@@
+expression dev;
+expression prop, val;
+@@
+- object_property_set_bool(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_bit(dev, prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+ qdev_realize(dev, ...);
+|
+ qdev_realize_and_unref(dev, ...);
+)
+
+// bool DEVICE(dev)
+@@
+expression dev;
+expression prop, val;
+@@
+- object_property_set_bool(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_bit(DEVICE(dev), prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+ qdev_realize(DEVICE(dev), ...);
+|
+ qdev_realize_and_unref(DEVICE(dev), ...);
+)
+
+// bool DEVICE(obj)
+@@
+expression obj;
+expression prop, val;
+@@
+- object_property_set_bool(obj, prop, val, ... /* &error_abort */);
++ qdev_prop_set_bit(DEVICE(obj), prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(obj), ...);
+|
+ qdev_realize(DEVICE(obj), ...);
+|
+ qdev_realize_and_unref(DEVICE(obj), ...);
+)
+
+
+//
+// str
+//
+
+// str OBJECT
+@@
+typedef DeviceState;
+identifier dev;
+expression prop, val;
+@@
+ DeviceState *dev;
+ ...
+- object_property_set_str(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_string(dev, prop, val);
+
+// str dev
+@@
+expression dev;
+expression prop, val;
+@@
+- object_property_set_str(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_string(dev, prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+ qdev_realize(dev, ...);
+|
+ qdev_realize_and_unref(dev, ...);
+)
+
+// str DEVICE(dev)
+@@
+expression dev;
+expression prop, val;
+@@
+- object_property_set_str(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_string(DEVICE(dev), prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+ qdev_realize(DEVICE(dev), ...);
+|
+ qdev_realize_and_unref(DEVICE(dev), ...);
+)
+
+// str DEVICE(obj)
+@@
+expression obj;
+expression prop, val;
+@@
+- object_property_set_str(obj, prop, val, ... /* &error_abort */);
++ qdev_prop_set_string(DEVICE(obj), prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(obj), ...);
+|
+ qdev_realize(DEVICE(obj), ...);
+|
+ qdev_realize_and_unref(DEVICE(obj), ...);
+)
+
+
+// int OBJECT
+@@
+typedef DeviceState;
+identifier dev;
+expression prop, val;
+@@
+ DeviceState *dev;
+ ...
+- object_property_set_int(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_XintXX(dev, prop, val);
+
+// int dev
+@@
+expression dev;
+expression prop, val;
+@@
+- object_property_set_int(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_XintXX(dev, prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+ qdev_realize(dev, ...);
+|
+ qdev_realize_and_unref(dev, ...);
+)
+
+// int DEVICE(dev)
+@@
+expression dev;
+expression prop, val;
+@@
+- object_property_set_int(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_XintXX(DEVICE(dev), prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+ qdev_realize(DEVICE(dev), ...);
+|
+ qdev_realize_and_unref(DEVICE(dev), ...);
+)
+
+// int DEVICE(obj)
+@@
+expression obj;
+expression prop, val;
+@@
+- object_property_set_int(obj, prop, val, ... /* &error_abort */);
++ qdev_prop_set_XintXX(DEVICE(obj), prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(obj), ...);
+|
+ qdev_realize(DEVICE(obj), ...);
+|
+ qdev_realize_and_unref(DEVICE(obj), ...);
+)
+
+//
+// link
+//
+
+// link OBJECT
+@@
+typedef DeviceState;
+identifier dev;
+expression prop, val;
+@@
+ DeviceState *dev;
+ ...
+- object_property_set_link(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_link(dev, prop, val);
+
+// link dev
+@@
+expression dev;
+expression prop, val;
+@@
+- object_property_set_link(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_link(dev, prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+ qdev_realize(dev, ...);
+|
+ qdev_realize_and_unref(dev, ...);
+)
+
+// link DEVICE(dev)
+@@
+expression dev;
+expression prop, val;
+@@
+- object_property_set_link(OBJECT(dev), prop, val, ... /* &error_abort */);
++ qdev_prop_set_link(DEVICE(dev), prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+ qdev_realize(DEVICE(dev), ...);
+|
+ qdev_realize_and_unref(DEVICE(dev), ...);
+)
+
+// link DEVICE(obj)
+@@
+expression obj;
+expression prop, val;
+@@
+- object_property_set_link(obj, prop, val, ... /* &error_abort */);
++ qdev_prop_set_link(DEVICE(obj), prop, val);
+ ...
+(
+ sysbus_realize(SYS_BUS_DEVICE(obj), ...);
+|
+ qdev_realize(DEVICE(obj), ...);
+|
+ qdev_realize_and_unref(DEVICE(obj), ...);
+)
Script I used to generate the following patches. This is not an automatic conversion as object_property_set_[u]int() does not specify the type size. Each integer property must then be converted manually. Therefore this script doesn't seem relevant to be committed in the repository. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- scripts/coccinelle/qom-qdev-prop.cocci | 259 +++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 scripts/coccinelle/qom-qdev-prop.cocci