diff options
author | Vladimir Menshakov | 2011-06-17 00:30:39 +0400 |
---|---|---|
committer | Vladimir Menshakov | 2011-06-17 00:31:36 +0400 |
commit | 6fe3e63ed1dc190c9ef6cf21b0d1890b5ebea03a (patch) | |
tree | 2c0a91032b20c846ae5f258749cfbab179800fdc /devtools | |
parent | 1a58262ca72fd09748755463299e54749d5c63ae (diff) | |
download | scummvm-rg350-6fe3e63ed1dc190c9ef6cf21b0d1890b5ebea03a.tar.gz scummvm-rg350-6fe3e63ed1dc190c9ef6cf21b0d1890b5ebea03a.tar.bz2 scummvm-rg350-6fe3e63ed1dc190c9ef6cf21b0d1890b5ebea03a.zip |
DREAMWEB: replaced generated code with c++ style stubs
Diffstat (limited to 'devtools')
-rw-r--r-- | devtools/tasmrecover/tasm/cpp.py | 155 | ||||
-rw-r--r-- | devtools/tasmrecover/tasm/proc.py | 2 |
2 files changed, 74 insertions, 83 deletions
diff --git a/devtools/tasmrecover/tasm/cpp.py b/devtools/tasmrecover/tasm/cpp.py index da21efe21d..324772120e 100644 --- a/devtools/tasmrecover/tasm/cpp.py +++ b/devtools/tasmrecover/tasm/cpp.py @@ -36,20 +36,19 @@ class cpp: self.failed = list(blacklist) self.translated = [] self.proc_addr = [] - self.forwards = [] + self.methods = [] self.fd.write("""%s #include \"%s\" namespace %s { - """ %(banner, header, namespace)) def expand_cb(self, match): name = match.group(0).lower() if len(name) == 2 and \ ((name[0] in ['a', 'b', 'c', 'd'] and name[1] in ['h', 'x', 'l']) or name in ['si', 'di', 'es', 'ds', 'cs']): - return "context.%s" %name + return "%s" %name if self.indirection == -1: try: @@ -74,7 +73,7 @@ namespace %s { if size == 0: raise Exception("invalid var '%s' size %u" %(name, size)) if self.indirection == 0: - value = "context.data.%s(k%s)" %("byte" if size == 1 else "word", name.capitalize()) + value = "data.%s(k%s)" %("byte" if size == 1 else "word", name.capitalize()) elif self.indirection == -1: value = "%s" %g.offset self.indirection = 0 @@ -135,7 +134,7 @@ namespace %s { m = re.match(r'seg\s+(.*?)$', expr) if m is not None: - return "context.data" + return "data" match_id = True m = re.match(r'offset\s+(.*?)$', expr) @@ -174,7 +173,7 @@ namespace %s { plus = "" match_id = False #print "COMMON_REG: ", reg, plus - expr = "context.%s%s" %(reg, plus) + expr = "%s%s" %(reg, plus) expr = re.sub(r'\b([0-9][a-fA-F0-9]*)h', '0x\\1', expr) expr = re.sub(r'\b([0-1]+)b', parse_bin, expr) @@ -188,9 +187,9 @@ namespace %s { if indirection == 1: if size == 1: - expr = "context.%s.byte(%s)" %(seg_prefix, expr) + expr = "%s.byte(%s)" %(seg_prefix, expr) elif size == 2: - expr = "context.%s.word(%s)" %(seg_prefix, expr) + expr = "%s.word(%s)" %(seg_prefix, expr) else: expr = "@invalid size 0" elif indirection == 0: @@ -238,12 +237,11 @@ namespace %s { jump_proc = True if jump_proc: - self.add_forward(name) - return "{ %s(context); return; }" %name + return "{ %s(); return; }" %name else: # TODO: name or self.resolve_label(name) or self.mangle_label(name)?? if name in self.proc.retlabels: - return "return /* (%s) */" % (name,) + return "return /* (%s) */" % (name) return "goto %s" %self.resolve_label(name) def _label(self, name): @@ -256,17 +254,12 @@ namespace %s { print "+scheduling function %s..." %name self.proc_queue.append(name) - def add_forward(self, name): - if name not in self.forwards and name not in self.failed: - self.forwards.append(name) - def _call(self, name): name = name.lower() if name == 'ax': - self.body += "\t__dispatch_call(context, %s);\n" %self.expand('ax', 2) + self.body += "\t__dispatch_call(%s);\n" %self.expand('ax', 2) return - self.body += "\t%s(context);\n" %name - self.add_forward(name); + self.body += "\t%s();\n" %name self.schedule(name) def _ret(self): @@ -289,111 +282,111 @@ namespace %s { self.body += "\t%s = %s;\n" %self.parse2(dst, src) def _add(self, dst, src): - self.body += "\tcontext._add(%s, %s);\n" %self.parse2(dst, src) + self.body += "\t_add(%s, %s);\n" %self.parse2(dst, src) def _sub(self, dst, src): - self.body += "\tcontext._sub(%s, %s);\n" %self.parse2(dst, src) + self.body += "\t_sub(%s, %s);\n" %self.parse2(dst, src) def _and(self, dst, src): - self.body += "\tcontext._and(%s, %s);\n" %self.parse2(dst, src) + self.body += "\t_and(%s, %s);\n" %self.parse2(dst, src) def _or(self, dst, src): - self.body += "\tcontext._or(%s, %s);\n" %self.parse2(dst, src) + self.body += "\t_or(%s, %s);\n" %self.parse2(dst, src) def _xor(self, dst, src): - self.body += "\tcontext._xor(%s, %s);\n" %self.parse2(dst, src) + self.body += "\t_xor(%s, %s);\n" %self.parse2(dst, src) def _neg(self, dst): dst = self.expand(dst) - self.body += "\tcontext._neg(%s);\n" %(dst) + self.body += "\t_neg(%s);\n" %(dst) def _cbw(self): - self.body += "\tcontext.ax.cbw();\n" + self.body += "\tax.cbw();\n" def _shr(self, dst, src): - self.body += "\tcontext._shr(%s, %s);\n" %self.parse2(dst, src) + self.body += "\t_shr(%s, %s);\n" %self.parse2(dst, src) def _shl(self, dst, src): - self.body += "\tcontext._shl(%s, %s);\n" %self.parse2(dst, src) + self.body += "\t_shl(%s, %s);\n" %self.parse2(dst, src) #def _sar(self, dst, src): - # self.body += "\tcontext._sar(%s%s);\n" %self.parse2(dst, src) + # self.body += "\t_sar(%s%s);\n" %self.parse2(dst, src) #def _sal(self, dst, src): - # self.body += "\tcontext._sal(%s, %s);\n" %self.parse2(dst, src) + # self.body += "\t_sal(%s, %s);\n" %self.parse2(dst, src) #def _rcl(self, dst, src): - # self.body += "\tcontext._rcl(%s, %s);\n" %self.parse2(dst, src) + # self.body += "\t_rcl(%s, %s);\n" %self.parse2(dst, src) #def _rcr(self, dst, src): - # self.body += "\tcontext._rcr(%s, %s);\n" %self.parse2(dst, src) + # self.body += "\t_rcr(%s, %s);\n" %self.parse2(dst, src) def _mul(self, src): src = self.expand(src) - self.body += "\tcontext._mul(%s);\n" %(src) + self.body += "\t_mul(%s);\n" %(src) def _div(self, src): src = self.expand(src) - self.body += "\tcontext._div(%s);\n" %(src) + self.body += "\t_div(%s);\n" %(src) def _inc(self, dst): dst = self.expand(dst) - self.body += "\tcontext._inc(%s);\n" %(dst) + self.body += "\t_inc(%s);\n" %(dst) def _dec(self, dst): dst = self.expand(dst) - self.body += "\tcontext._dec(%s);\n" %(dst) + self.body += "\t_dec(%s);\n" %(dst) def _cmp(self, a, b): - self.body += "\tcontext._cmp(%s, %s);\n" %self.parse2(a, b) + self.body += "\t_cmp(%s, %s);\n" %self.parse2(a, b) def _test(self, a, b): - self.body += "\tcontext._test(%s, %s);\n" %self.parse2(a, b) + self.body += "\t_test(%s, %s);\n" %self.parse2(a, b) def _js(self, label): - self.body += "\tif (context.flags.s())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (flags.s())\n\t\t%s;\n" %(self.jump_to_label(label)) def _jns(self, label): - self.body += "\tif (!context.flags.s())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (!flags.s())\n\t\t%s;\n" %(self.jump_to_label(label)) def _jz(self, label): - self.body += "\tif (context.flags.z())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (flags.z())\n\t\t%s;\n" %(self.jump_to_label(label)) def _jnz(self, label): - self.body += "\tif (!context.flags.z())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (!flags.z())\n\t\t%s;\n" %(self.jump_to_label(label)) def _jl(self, label): - self.body += "\tif (context.flags.l())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (flags.l())\n\t\t%s;\n" %(self.jump_to_label(label)) def _jg(self, label): - self.body += "\tif (!context.flags.le())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (!flags.le())\n\t\t%s;\n" %(self.jump_to_label(label)) def _jle(self, label): - self.body += "\tif (context.flags.le())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (flags.le())\n\t\t%s;\n" %(self.jump_to_label(label)) def _jge(self, label): - self.body += "\tif (!context.flags.l())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (!flags.l())\n\t\t%s;\n" %(self.jump_to_label(label)) def _jc(self, label): - self.body += "\tif (context.flags.c())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (flags.c())\n\t\t%s;\n" %(self.jump_to_label(label)) def _jnc(self, label): - self.body += "\tif (!context.flags.c())\n\t\t%s;\n" %(self.jump_to_label(label)) + self.body += "\tif (!flags.c())\n\t\t%s;\n" %(self.jump_to_label(label)) def _xchg(self, dst, src): - self.body += "\tcontext._xchg(%s, %s);\n" %self.parse2(dst, src) + self.body += "\t_xchg(%s, %s);\n" %self.parse2(dst, src) def _jmp(self, label): self.body += "\t%s;\n" %(self.jump_to_label(label)) def _loop(self, label): - self.body += "\tif (--context.cx)\n\t\t%s;\n" %self.jump_to_label(label) + self.body += "\tif (--cx)\n\t\t%s;\n" %self.jump_to_label(label) def _push(self, regs): p = str(); for r in regs: r = self.expand(r) - p += "\tcontext.push(%s);\n" %(r) + p += "\tpush(%s);\n" %(r) self.body += p def _pop(self, regs): @@ -402,35 +395,35 @@ namespace %s { self.temps_count -= 1 i = self.temps_count r = self.expand(r) - p += "\t%s = context.pop();\n" %r + p += "\t%s = pop();\n" %r self.body += p def _rep(self): - self.body += "\twhile(context.cx--)\n\t" + self.body += "\twhile(cx--)\n\t" def _lodsb(self): - self.body += "\tcontext._lodsb();\n" + self.body += "\t_lodsb();\n" def _lodsw(self): - self.body += "\tcontext._lodsw();\n" + self.body += "\t_lodsw();\n" def _stosb(self, n): - self.body += "\tcontext._stosb(%s);\n" %("" if n == 1 else n) + self.body += "\t_stosb(%s);\n" %("" if n == 1 else n) def _stosw(self, n): - self.body += "\tcontext._stosw(%s);\n" %("" if n == 1 else n) + self.body += "\t_stosw(%s);\n" %("" if n == 1 else n) def _movsb(self, n): - self.body += "\tcontext._movsb(%s);\n" %("" if n == 1 else n) + self.body += "\t_movsb(%s);\n" %("" if n == 1 else n) def _movsw(self, n): - self.body += "\tcontext._movsw(%s);\n" %("" if n == 1 else n) + self.body += "\t_movsw(%s);\n" %("" if n == 1 else n) def _stc(self): - self.body += "\tcontext.flags._c = true;\n " + self.body += "\tflags._c = true;\n " def _clc(self): - self.body += "\tcontext.flags._c = false;\n " + self.body += "\tflags._c = false;\n " def __proc(self, name, def_skip = 0): try: @@ -457,7 +450,7 @@ namespace %s { self.proc_addr.append((name, self.proc.offset)) self.body = str() - self.body += "void %s(Context &context) {\n\tSTACK_CHECK(context);\n" %name; + self.body += "void %sContext::%s() {\n\tSTACK_CHECK;\n" %(self.namespace, name); self.proc.optimize() self.unbounded = [] self.proc.visit(self, skip) @@ -505,7 +498,7 @@ namespace %s { fd = open(fname, "wt") fd.write("namespace %s {\n" %self.namespace) for p in procs: - fd.write("void %s(Context &context) {\n\t::error(\"%s\");\n}\n\n" %(p, p)) + fd.write("void %sContext::%s() {\n\t::error(\"%s\");\n}\n\n" %(self.namespace, p, p)) fd.write("} /*namespace %s */\n" %self.namespace) fd.close() @@ -526,13 +519,11 @@ namespace %s { print "continuing on %s" %name self.proc_done.append(name) self.__proc(name) + self.methods.append(name) self.write_stubs("_stubs.cpp", self.failed) + self.methods += self.failed done, failed = len(self.proc_done), len(self.failed) - for f in self.forwards: - if f not in self.failed: - self.fd.write("void %s(Context &context);\n" %f) - self.fd.write("\n") self.fd.write("\n".join(self.translated)) self.fd.write("\n\n") @@ -546,20 +537,19 @@ namespace %s { n += 1 if (n & 0xf) == 0: data_impl += "\n\t\t" - data_impl += "};\n\tcontext.ds.assign(src, src + sizeof(src));\n" + data_impl += "};\n\tds.assign(src, src + sizeof(src));\n" self.hd.write( """\n#include "dreamweb/runtime.h" namespace %s { - void __dispatch_call(Context &context, unsigned addr); - void __start(Context &context); +class %sContext : public Context { +public: + void __start(); + void __dispatch_call(uint16 addr); -""" %(self.namespace)) - for f in self.failed: - self.hd.write("\tvoid %s(Context &context);\n" %f) - - offsets_decl = "\n" +""" +%(self.namespace, self.namespace)) offsets = [] for k, v in self.context.get_globals().items(): if isinstance(v, op.var): @@ -569,20 +559,21 @@ namespace %s { offsets = sorted(offsets, key=lambda t: t[1]) for o in offsets: - offsets_decl += "\tconst static uint16 k%s = %s;\n" %o - offsets_decl += "\n" - self.hd.write(offsets_decl); + self.hd.write("\tconst static uint16 k%s = %s;\n" %o) + self.hd.write("\n") + for p in set(self.methods): + self.hd.write("\tvoid %s();\n" %p) - self.hd.write("\n}\n\n#endif\n") + self.hd.write("};\n}\n\n#endif\n") self.hd.close() - self.fd.write("\nvoid __start(Context &context) { %s%s(context); \n}\n" %(data_impl, start)) + self.fd.write("\nvoid %sContext::__start() { %s%s(); \n}\n" %(self.namespace, data_impl, start)) - self.fd.write("\nvoid __dispatch_call(Context &context, unsigned addr) {\n\tswitch(addr) {\n") + self.fd.write("\nvoid %sContext::__dispatch_call(uint16 addr) {\n\tswitch(addr) {\n" %self.namespace) self.proc_addr.sort(cmp = lambda x, y: x[1] - y[1]) for name,addr in self.proc_addr: - self.fd.write("\t\tcase 0x%04x: %s(context); break;\n" %(addr, name)) - self.fd.write("\t\tdefault: ::error(\"invalid call to %04x dispatched\", (uint16)context.ax);") + self.fd.write("\t\tcase 0x%04x: %s(); break;\n" %(addr, name)) + self.fd.write("\t\tdefault: ::error(\"invalid call to %04x dispatched\", (uint16)ax);") self.fd.write("\n\t}\n}\n\n} /*namespace*/\n") self.fd.close() diff --git a/devtools/tasmrecover/tasm/proc.py b/devtools/tasmrecover/tasm/proc.py index 6db3b7a682..c304438984 100644 --- a/devtools/tasmrecover/tasm/proc.py +++ b/devtools/tasmrecover/tasm/proc.py @@ -61,7 +61,7 @@ class proc: if i + 1 >= len(stmts): break if isinstance(stmts[i + 1], cls): - stmts[i + 1].repeat = 'context.cx' + stmts[i + 1].repeat = 'cx' del stmts[i] i += 1 return |