qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Object cast macro change-pattern automation.
@ 2013-06-21  4:21 Peter Crosthwaite
  2013-06-21  7:36 ` Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Peter Crosthwaite @ 2013-06-21  4:21 UTC (permalink / raw)
  To: Hu Tao, Andreas Färber; +Cc: qemu-devel@nongnu.org Developers

Hi Andreas, Hu,

I thought Id share with you a little script I made (not very polished)
that I used to help with some of my patches creating the QOM cast
macros (mainly the PCI ones). May be useful in speeding up the
QOMification effort. Andreas, im guessing you may have something
similar going if your able to comment? I know Hu mentioned he wanted
to work on QOMification of sysbus - which is a big job so stuff like
this may make life easier.

example usage:

$ source ./object_macro_maker hw/timer/xilinx_timer.c XILINX_TIMER

1st arg is target file, 2 arg is the name of the type, I.e. FOO in TYPE_FOO

It will automatically find replace usages of the string literal type
inplace and give you a fragment to copy-paste into the source defining
the type string and object cast macro.

It has the limitation that it only works with files that define a
single QOM type. I didnt bother trying to generalise as such files are
the exception and not the rule.

Example output below:

diff --git a/hw/timer/xilinx_timer.c b/hw/timer/xilinx_timer.c
index 0c39cff..ae09170 100644
--- a/hw/timer/xilinx_timer.c
+++ b/hw/timer/xilinx_timer.c
@@ -218,7 +218,7 @@ static int xilinx_timer_init(SysBusDevice *dev)
         ptimer_set_freq(xt->ptimer, t->freq_hz);
     }

-    memory_region_init_io(&t->mmio, &timer_ops, t, "xlnx.xps-timer",
+    memory_region_init_io(&t->mmio, &timer_ops, t, TYPE_XILINX_TIMER,
                           R_MAX * 4 * num_timers(t));
     sysbus_init_mmio(dev, &t->mmio);
     return 0;
@@ -241,7 +241,7 @@ static void xilinx_timer_class_init(ObjectClass
*klass, void *data)
 }

 static const TypeInfo xilinx_timer_info = {
-    .name          = "xlnx.xps-timer",
+    .name          = TYPE_XILINX_TIMER,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(struct timerblock),
     .class_init    = xilinx_timer_class_init,
State Struct is struct timerblock
------------------ cut here ------------------------
#define TYPE_XILINX_TIMER "xlnx.xps-timer"

#define XILINX_TIMER(obj) \
    OBJECT_CHECK(struct timerblock, (obj), TYPE_XILINX_TIMER)
-----------------------------------------------------------------


And the script itself:

#!/bin/bash

sed -n '/^static const TypeInfo.*$/,/^};.*$/p' $1 | \
                        grep "\(\.instance_size\|\.name\)"\
                        > typeinfo.tmp
cat typeinfo.tmp
STRING=$(grep -o "\".*\"" typeinfo.tmp | sed 's/\"//g')

echo "String is ${STRING}"
sed "s/\"${STRING}\"/TYPE_${2}/g" -i ${1}
git diff ${1} | cat

STATE_STRUCT=$(grep -o "(.*)" typeinfo.tmp | sed "s/(//" | sed "s/)//")
echo "State Struct is ${STATE_STRUCT}"
echo "------------------ cut here ------------------------"

echo "#define TYPE_${2} \"${STRING}\""
echo ""
echo "#define ${2}(obj) \\"
echo "    OBJECT_CHECK(${STATE_STRUCT}, (obj), TYPE_${2})"


Regards,
Peter

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-06-21 12:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-21  4:21 [Qemu-devel] Object cast macro change-pattern automation Peter Crosthwaite
2013-06-21  7:36 ` Paolo Bonzini
2013-06-21  7:44   ` Peter Crosthwaite
2013-06-21  8:40     ` Andreas Färber
2013-06-21 12:24     ` Paolo Bonzini
2013-06-21  7:45   ` Hu Tao
2013-06-21  7:49 ` Hu Tao
2013-06-21  9:33 ` Andreas Färber
2013-06-21 10:38   ` Peter Crosthwaite

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).