Forked from anonymous/qemumachine-eliminate.py
Last active
September 4, 2015 16:32
-
-
Save ehabkost/582fe4969205975febb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re, sys | |
fieldre = re.compile(r'^ *\.([a-z0-9_]+) *= *(.*?),? *([^,]*?)\n', re.M) | |
def fixmachine(m): | |
print >>sys.stderr,"whole: %r" % (m.group(0)) | |
name = m.group(2) | |
if name.endswith('_machine'): | |
name = name[:-len('_machine')] | |
fields = m.group(4) | |
print >>sys.stderr,"fields: %r" % (fields) | |
namestr = re.search(r'\.name *= *(.*?),? *\n', fields, re.M).group(1) | |
def fixfield(m): | |
if m.group(1) == 'name': | |
return '' | |
else: | |
cmt = m.group(3) | |
if cmt: | |
cmt = re.sub(r' *\/\/ *(.*)$', r' /* \1 */', cmt, flags=re.M) | |
return ' mc->%s = %s;%s\n' % (m.group(1), m.group(2), cmt) | |
return ''' | |
static void %s_machine_init(MachineClass *mc) | |
{ | |
%s} | |
DEFINE_MACHINE(%s, %s_machine_init); | |
'''.lstrip() % (name, fieldre.sub(fixfield, fields), namestr, name) | |
s = sys.stdin.read() | |
s = re.sub(r'(static *|const *)*QEMUMachine ([a-z0-9_]+) *= *\{(\n| )*(.*?) *\};\n', fixmachine, s, flags=re.DOTALL) | |
s = re.sub(r'^ *qemu_register_machine\(&([a-z0-9_]+)\);\n', '', s, flags=re.M) | |
s = re.sub(r'static void ([a-z0-9_]+)\(void\)\n{\n}\n*((.+\n)?)machine_init\(\1\);?\n', r'\2', s, flags=re.DOTALL) | |
sys.stdout.write(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment