qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] Object cast macro change-pattern automation.


From: Hu Tao
Subject: Re: [Qemu-devel] Object cast macro change-pattern automation.
Date: Fri, 21 Jun 2013 15:49:48 +0800
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Jun 21, 2013 at 02:21:02PM +1000, Peter Crosthwaite wrote:
> 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

Very helpful. Thanks!

> 
> 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.

I extended the script a bit more to search for the struct and insert the
fragment, as follows:


#!/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
echo "String is ${STRING}"
echo
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})"

found=""
grep "^.*struct ${STATE_STRUCT} *{" ${1}
if [ $? -eq 0 ]; then
    found=${1}
else
    files=$(sed -n "s/^#include \"\(.*\)\"/\1/ p" ${1})
    for f in $(echo $files); do
        f=$(echo "include/$f")
        grep "^.*struct ${STATE_STRUCT} *{" ${f}
        if [ $? -eq 0 ]; then
            found=${f}
            break
        fi
    done
fi

if [ "${found}" == "" ]; then
    echo "not found file."
    exit 1
fi

# define TYPE_FOO

sed -i  "/^.*struct ${STATE_STRUCT} *{\$/i#define TYPE_${2} \"${STRING}\"" 
${found}
sed -i  "/^.*struct ${STATE_STRUCT} *{\$/i\\\n" ${found}
sed -i  "/^.*struct ${STATE_STRUCT} *{\$/i#define ${2}(obj) \\\\" ${found}
sed -i  "/^.*struct ${STATE_STRUCT} *{\$/i\ \ \ \ OBJECT_CHECK(${STATE_STRUCT}, 
(obj), TYPE_${2})" ${found}
sed -i  "/^.*struct ${STATE_STRUCT} *{\$/i\\\n" ${found}



reply via email to

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