Skip to content

Instantly share code, notes, and snippets.

Created August 18, 2015 17:55
Show Gist options
  • Save anonymous/884c45260d864a68d6d8 to your computer and use it in GitHub Desktop.
Save anonymous/884c45260d864a68d6d8 to your computer and use it in GitHub Desktop.
import re, sys
def fixmachine(m):
fieldre = re.compile(r'^ *\.([a-z0-9_]+) *= *(.*?),? *([^,]*)\n', re.M)
name = m.group(2)
fields = m.group(4)
namestr = re.search(r'\.name *= *(.*?),? *\n', fields, re.M).group(1)
def fixfield(m):
if m.group(1) == 'name':
return ''
else:
return ' mc->%s = %s;%s\n' % (m.group(1), m.group(2), m.group(3) and ' %s' % (m.group(3)) or '')
return '''
static void %s_machine_init(MachineClass *mc)
{
%s}
DEFINE_MACHINE(%s, %s_machine_init);
'''.strip() % (name, fieldre.sub(fixfield, fields), namestr, name)
def fixreg(m):
return ''
s = sys.stdin.read()
machinedecl = re.compile(r'(static *|const *)*QEMUMachine ([a-z0-9_]+) *= *\{(\n| )*(.*?) *\};', re.DOTALL)
machinereg = re.compile(r'^ *qemu_register_machine\(&([a-z0-9_]+)\);\n', re.M)
emptyreg = re.compile(r'static void ([a-z0-9_]+)\(void\)\n{\n}\n*(.*)\nmachine_init\(\1\);?\n', re.DOTALL)
s = machinedecl.sub(fixmachine, s)
s = machinereg.sub(fixreg, s)
s = emptyreg.sub(r'\2', s)
sys.stdout.write(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment