5 # Generate opcodes.h, opcodes.h
7 # Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
25 fi = open("code.c", "rb")
26 foc = open("opcodes.c", "wb")
27 foh = open("opcodes.h", "wb")
29 foh.write("#ifndef __opcodes_h__\n")
30 foh.write("#define __opcodes_h__\n")
31 foh.write("#include \"abc.h\"\n")
32 foh.write("#include \"pool.h\"\n")
33 foh.write("#include \"code.h\"\n")
35 foc.write("#include \"opcodes.h\"\n")
37 R = re.compile('{(0x..),\s*"([^"]*)"\s*,\s*"([^"]*)"[^}]*}\s*')
39 for line in fi.readlines():
43 op,name,params = m.group(1),m.group(2),m.group(3)
46 if "2" in params or "s" in params:
49 for iteration in range(iterations):
52 params = params.strip()
61 type,pname="char*","name"
63 type,pname="multiname_t*","name"
66 type,pname="char*","name"
68 type,pname="string_t*","s"
70 type,pname="namespace_t*","ns"
74 type,pname="abc_method_t*","m"
76 type,pname="abc_method_body_t*","m"
78 type,pname="abc_class_t*","m"
80 type,pname="code_t*","label"
82 type,pname="lookupswitch_t*","l"
84 type,pname="void*","debuginfo"
86 type,pname="int","reg"
88 type,pname="double","f"
92 type,pname="unsigned int","u"
94 raise "Unknown type "+c
99 pname += str(seen[pname])
105 foh.write("code_t* abc_%s(code_t*prev%s);\n" % (name, paramstr))
107 foc.write("code_t* abc_%s(code_t*prev%s)\n" % (name, paramstr))
109 foc.write(" code_t*self = add_opcode(prev, %s);\n" % op)
111 for pname,c in zip(names,params):
114 foc.write(" self->data[%d] = multiname_fromstring(%s);\n" % (i,pname));
116 foc.write(" self->data[%d] = multiname_clone(%s);\n" % (i,pname));
118 foc.write(" self->data[%d] = (void*)(ptroff_t)%s;\n" % (i,pname))
120 foc.write(" self->data[%d] = (void*)(ptroff_t)%s;\n" % (i,pname))
122 foc.write(" self->data[%d] = namespace_clone(%s);\n" % (i,pname))
124 foc.write(" double*fp = malloc(sizeof(double));\n")
125 foc.write(" *fp = %s;\n" % (pname))
126 foc.write(" self->data[%d] = fp;\n" % (i))
128 foc.write(" self->data[%d] = (void*)(ptroff_t)%s;\n" % (i,pname))
131 foc.write(" self->data[%d] = string_new4(%s);\n" % (i,pname))
133 foc.write(" self->data[%d] = string_dup3(%s);\n" % (i,pname))
135 foc.write(" self->data[%d] = %s;\n" % (i,pname))
137 foc.write(" self->data[%d] = %s;\n" % (i,pname))
139 foc.write(" self->data[%d] = %s;\n" % (i,pname))
141 foc.write(" self->data[%d] = 0; //placeholder\n" % i)
142 foc.write(" self->branch = %s;\n" % pname)
144 foc.write(" self->data[%d] = %s;\n" % (i,pname))
146 foc.write(" /* FIXME: write debuginfo %s */\n" % pname)
148 raise "Unknown type "+c
150 foc.write(" return self;\n")
153 foh.write("#define "+name+"(")
154 foh.write(",".join(["method"]+names))
155 foh.write(") (method->code = abc_"+name+"(")
156 foh.write(",".join(["method->code"]+names))
159 foh.write("#define OPCODE_"+name.upper()+" "+op+"\n")
161 foh.write("#endif\n")
166 #{0x75, "convert_d", ""},