5 fi = open("code.c", "rb")
6 foc = open("opcodes.c", "wb")
7 foh = open("opcodes.h", "wb")
9 foh.write("#ifndef __opcodes_h__\n")
10 foh.write("#define __opcodes_h__\n")
11 foh.write("#include \"abc.h\"\n")
12 foh.write("#include \"pool.h\"\n")
13 foh.write("#include \"code.h\"\n")
15 foc.write("#include \"opcodes.h\"\n")
17 R = re.compile('{(0x..),\s*"([^"]*)"\s*,\s*"([^"]*)"[^}]*}\s*')
19 for line in fi.readlines():
23 op,name,params = m.group(1),m.group(2),m.group(3)
29 for iteration in range(iterations):
32 params = params.strip()
41 type,pname="char*","name"
43 type,pname="multiname_t*","name"
45 type,pname="char*","s"
49 type,pname="abc_method_body_t*","m"
51 type,pname="abc_method_t*","m"
53 type,pname="abc_class_t*","m"
55 type,pname="code_t*","label"
57 type,pname="lookupswitch_t*","l"
59 type,pname="void*","debuginfo"
61 type,pname="int","reg"
63 type,pname="double","f"
67 type,pname="unsigned int","u"
69 raise "Unknown type "+c
74 pname += str(seen[pname])
80 foh.write("code_t* abc_%s(code_t*prev%s);\n" % (name, paramstr))
82 foc.write("code_t* abc_%s(code_t*prev%s)\n" % (name, paramstr))
84 foc.write(" code_t*self = add_opcode(prev, %s);\n" % op)
86 for pname,c in zip(names,params):
89 foc.write(" self->data[%d] = multiname_fromstring(%s);\n" % (i,pname));
91 foc.write(" self->data[%d] = multiname_clone(%s);\n" % (i,pname));
93 foc.write(" self->data[%d] = (void*)(ptroff_t)%s;\n" % (i,pname))
95 foc.write(" self->data[%d] = (void*)(ptroff_t)%s;\n" % (i,pname))
97 foc.write(" double*fp = malloc(sizeof(double));\n")
98 foc.write(" *fp = %s;\n" % (pname))
99 foc.write(" self->data[%d] = fp;\n" % (i))
101 foc.write(" self->data[%d] = (void*)(ptroff_t)%s;\n" % (i,pname))
103 foc.write(" self->data[%d] = strdup(%s);\n" % (i,pname))
105 foc.write(" self->data[%d] = %s;\n" % (i,pname))
107 foc.write(" self->data[%d] = %s;\n" % (i,pname))
109 foc.write(" self->data[%d] = %s;\n" % (i,pname))
111 foc.write(" self->data[%d] = 0; //placeholder\n" % i)
112 foc.write(" self->branch = %s;\n" % pname)
114 foc.write(" self->data[%d] = %s;\n" % (i,pname))
116 foc.write(" /* FIXME: write debuginfo %s */\n" % pname)
118 raise "Unknown type "+c
120 foc.write(" return self;\n")
123 foh.write("#define "+name+"(")
124 foh.write(",".join(["method"]+names))
125 foh.write(") (method->code = abc_"+name+"(")
126 foh.write(",".join(["method->code"]+names))
129 foh.write("#endif\n")
134 #{0x75, "convert_d", ""},