[Scummvm-cvs-logs] SF.net SVN: scummvm: [28681] tools/branches/gsoc2007-decompiler/finalD/ decompiler.py
brixxie at users.sourceforge.net
brixxie at users.sourceforge.net
Mon Aug 20 21:49:31 CEST 2007
Revision: 28681
http://scummvm.svn.sourceforge.net/scummvm/?rev=28681&view=rev
Author: brixxie
Date: 2007-08-20 12:49:31 -0700 (Mon, 20 Aug 2007)
Log Message:
-----------
added cmdl interface
Modified Paths:
--------------
tools/branches/gsoc2007-decompiler/finalD/decompiler.py
Modified: tools/branches/gsoc2007-decompiler/finalD/decompiler.py
===================================================================
--- tools/branches/gsoc2007-decompiler/finalD/decompiler.py 2007-08-20 19:19:58 UTC (rev 28680)
+++ tools/branches/gsoc2007-decompiler/finalD/decompiler.py 2007-08-20 19:49:31 UTC (rev 28681)
@@ -12,60 +12,118 @@
from altgraph import Dot
-class Decompiler:
- """The Core"""
- pass
+# class Decompiler:
+# """The Core"""
+# def __init__(self, args, frontends):
+# """Initialize Decompiler instance with file."""
+# self.disasm = None
+
+# self.opt_parser = OptionParser()
+# self.opt_parser.add_option("-d", "--disassemble",
+# action="store_true",
+# dest="disonly",
+# default=False)
+# for opt, frontend in frontends:
+# self.opt_paser.add(opt,
+# action="store_const",
+# const=frontend,
+# dest="disasm")
+
+# (options, rest_args) = self.opt_parser.parse_args(args)
+# self.disasm = options.disasm.parse_options(rest_args)
+
+# def decompile(self):
+# """Decompile the script in self.file"""
+# decoded = disasm.decode()
+# if self.options.disonly:
+# decoded_tuples = decoded.items()
+# decoded_tuples.sort(key=lambda t: t[0])
+# for off, instr in decoded_tuples:
+# print "[%.4X] %s;" % (off, instr)
+# print "END"
+
+
if __name__ == '__main__':
- parser = OptionParser()
+ # preliminary cmd line interface
+ usage = "usage: %prog [options] <1|2|3|4|5> <file>"
+ parser = OptionParser(usage=usage)
parser.add_option("-d", "--disassemble", dest="disonly",
- action="store_true", default=False)
+ action="store_true", default=False,
+ help="disassemble only")
parser.add_option("-g", "--graphviz", dest="dotty",
- action="store_true", default=False)
+ action="store_true", default=False,
+ help="launch dotty showing the control flow graph")
+ parser.add_option("-i", "--indy", action="store_true",
+ dest="indy", default=False,
+ help="use Indy3-256 specific hacks")
+ parser.add_option("-z", "--zak", action="store_true",
+ dest="zak", default=False,
+ help="use Zak256 specific hacks")
+ parser.add_option("-u", "--unblocked", action="store_true",
+ dest="unblocked", default=False,
+ help="script has no header")
+ parser.add_option("-x", "--halt-on-error", action="store_true",
+ dest="hoe", default=False,
+ help="halt on error")
(options, args) = parser.parse_args()
- f = open(args[0], 'r')
- sc = scumm.SCUMM345(array.array('B', f.read()),
- 3,
- indy_flag = True,
- halt_on_error = False)
+ if len(args) != 2:
+ parser.print_help()
+ exit(2)
+
+ if args[0] in ('1', '2', '3', '4', '5'):
+ version = int(args[0])
+ else:
+ parser.print_help()
+ exit(2)
+
try:
- sc.parse_header()
- dis = disasm.Disasm(sc)
- decoded = dis.decode()
- if decoded:
- if not options.disonly:
- blocks = cfg.gen_basic_blocks(decoded)
- graph = cfg.gen_control_flow_graph(blocks, decoded)
- if options.dotty:
- Dot.Dot(graph).display()
- cfg.set_immediate_dominators(graph)
- intervals = cfg.gen_intervals(graph)
- dseq = cfg.gen_derived_sequence(graph, intervals)
-# for dg, di in dseq:
-# print dg
-# for nid in dg.node_list():
-# print dg.node_data(nid)
-# for eid in dg.edge_list():
-# print dg.edge_by_id(eid)
-# print di
-# print '-'*72
- cfg.loop_struct(dseq)
- cfg.two_way_struct(graph)
- cfg.comp_conds_struct(graph)
-# for nid in graph.node_list():
-# block = graph.node_data(nid)
-# print block
-# for instr in block.instrs:
-# print decoded[instr]
- pc = PseudoCode(graph, decoded)
- pc.generate_code()
- else:
- decoded_tuples = decoded.items()
- decoded_tuples.sort(key=lambda t: t[0])
- for off, instr in decoded_tuples:
- print "[%.4X] %s;" % (off, instr)
- except:
- print "ERRRRRRRRRRRRRRRRRRRRRRRRRRRRRROOOOOOOOOOOOOOOOOOOOOORRRRRRRRRRRR"
- print args[0]
- raise
- print "END"
+ f = open(args[1], 'r')
+ data_arr = array.array('B', f.read())
+ if version in (3,4,5):
+ sc = scumm.SCUMM345(data_arr, version,
+ indy_flag = options.indy,
+ zak_flag = options.zak,
+ unblocked = options.unblocked,
+ halt_on_error = options.hoe)
+ else:
+ sc = scumm.SCUMM12(data_arr, version,
+ indy_flag = options.indy,
+ zak_flag = options.zak,
+ unblocked = options.unblocked,
+ halt_on_error = options.hoe)
+ try:
+ sc.parse_header()
+ dis = disasm.Disasm(sc)
+ decoded = dis.decode()
+ if decoded:
+ if not options.disonly:
+ blocks = cfg.gen_basic_blocks(decoded)
+ graph = cfg.gen_control_flow_graph(blocks, decoded)
+ cfg.set_immediate_dominators(graph)
+ intervals = cfg.gen_intervals(graph)
+ dseq = cfg.gen_derived_sequence(graph, intervals)
+ cfg.loop_struct(dseq)
+ cfg.comp_conds_struct(graph)
+ cfg.two_way_struct(graph)
+ if options.dotty:
+ Dot.Dot(graph).display()
+# for nid in graph.node_list():
+# block = graph.node_data(nid)
+# print block
+# for instr in block.instrs:
+# print decoded[instr]
+ pc = PseudoCode(graph, decoded)
+ pc.generate_code()
+ else:
+ decoded_tuples = decoded.items()
+ decoded_tuples.sort(key=lambda t: t[0])
+ for off, instr in decoded_tuples:
+ print "[%.4X] %s;" % (off, instr)
+ except:
+ print "An error occured while decompiling %s" % args[1]
+ raise
+ print "END"
+ except IOError:
+ print "Error opening '%s'" % args[1]
+ exit(-1)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list