[Scummvm-cvs-logs] SF.net SVN: scummvm:[41449] tools/branches/gsoc2009-decompiler/decompiler

kjdf at users.sourceforge.net kjdf at users.sourceforge.net
Thu Jun 11 14:02:19 CEST 2009


Revision: 41449
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41449&view=rev
Author:   kjdf
Date:     2009-06-11 12:02:19 +0000 (Thu, 11 Jun 2009)

Log Message:
-----------
decompiler: -disasm is back by popular demand

Modified Paths:
--------------
    tools/branches/gsoc2009-decompiler/decompiler/cfg.h
    tools/branches/gsoc2009-decompiler/decompiler/decompiler.cc
    tools/branches/gsoc2009-decompiler/decompiler/decompiler.rb
    tools/branches/gsoc2009-decompiler/decompiler/instruction.h

Modified: tools/branches/gsoc2009-decompiler/decompiler/cfg.h
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/cfg.h	2009-06-11 12:02:01 UTC (rev 41448)
+++ tools/branches/gsoc2009-decompiler/decompiler/cfg.h	2009-06-11 12:02:19 UTC (rev 41449)
@@ -29,42 +29,30 @@
 
 
 struct BasicBlock : public Node {
+
 	index_t _start, _end;
+
 	BasicBlock(index_t start, index_t end) : Node(), _start(start), _end(end) {
 	}
 
-	void printInsns(vector<Instruction*> &v) {
-		printHeader(v);
+	void printHeader(Script &script) {
+		printf("%d (%04x..%04x)", _id, script[_start]->_addr-8, script[_end-1]->_addr-8);
+	}
+
+	virtual void print(Script &script) {
+		printf("=== ");
+		printHeader(script);
 		printf(" in(");
 		for (unsigned i = 0; i < _in.size(); i++)
 			printf("%d%s", _in[i]->_id, i == _in.size()-1 ? "" : ",");
 		printf(") out(");
-		printOuts();
+		for (unsigned i = 0; i < _out.size(); i++)
+			printf("%d%s", _out[i]->_id, i == _out.size()-1 ? "" : ",");
 		printf("):\n");
-		for (unsigned i = _start; i < _end; i++) {
-			if (i >= 1 && v[i]->_addr == v[i-1]->_addr)
-				printf("         |           %s", v[i]->_description.c_str());
-			else
-				printf("[d] %04x | [r] %04x: %s", v[i]->_addr-8, v[i]->_addr, v[i]->_description.c_str());
-			Jump *j = dynamic_cast<Jump*>(v[i]);
-			if (j) {
-				uint32 jaddr = j->_addr+j->_offset;
-				printf(" ([d] %04x | [r] %04x)", jaddr-8, jaddr);
-			}
-			printf("\n");
-		}
-	}
-	virtual void printOuts() {
-	};
-	void printHeader(vector<Instruction*> &v) {
-		printf("%d (%04x..%04x)", _id, v[_start]->_addr-8, v[_end-1]->_addr-8);
-	}
-	virtual void print(vector<Instruction*> &v) {
-		printf("=== ");
-		printInsns(v);
+		for (unsigned i = _start; i < _end; i++)
+			script.print(i);
 		printf("===\n\n");
 	}
-
 };
 
 
@@ -75,21 +63,20 @@
 
 	void printBasicBlocks() {
 		for (uint32 i = 0; i < _blocks.size(); i++)
-			_blocks[i]->print(_script._instructions);
+			_blocks[i]->print(_script);
 	}
 
 	void printDot() {
 		printf("digraph G {\n");
-		vector<Instruction*> *_v = &_script._instructions;
 		for (uint32 i = 0; i < _blocks.size(); i++) {
 			BasicBlock *bb = _blocks[i];
 			for (uint32 j = 0; j < bb->_out.size(); j++) {
-				printf("\""); bb->printHeader(*_v); printf("\"");
+				printf("\""); bb->printHeader(_script); printf("\"");
 				printf(" -> ");
-				printf("\""); ((BasicBlock*)bb->_out[j])->printHeader(*_v); printf("\"");
+				printf("\""); ((BasicBlock*)bb->_out[j])->printHeader(_script); printf("\"");
 				printf(" %s\n", j == 0 ? "[style=bold]" : "");
 			}
-			printf("\""); bb->printHeader(*_v); printf("\"\n");
+			printf("\""); bb->printHeader(_script); printf("\"\n");
 		}
 		printf("}\n");
 	}

Modified: tools/branches/gsoc2009-decompiler/decompiler/decompiler.cc
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/decompiler.cc	2009-06-11 12:02:01 UTC (rev 41448)
+++ tools/branches/gsoc2009-decompiler/decompiler/decompiler.cc	2009-06-11 12:02:19 UTC (rev 41449)
@@ -33,6 +33,9 @@
 	}
 	Script script(new Scumm6Parser(), argv[argno]);
 	CFG *cfg = new CFG(script);
+	if (g_disasm)
+		for (index_t i = 0; i < script.size(); i++)
+			script.print(i);
 	if (g_blocks)
 		cfg->printBasicBlocks();
 	if (g_graph)

Modified: tools/branches/gsoc2009-decompiler/decompiler/decompiler.rb
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/decompiler.rb	2009-06-11 12:02:01 UTC (rev 41448)
+++ tools/branches/gsoc2009-decompiler/decompiler/decompiler.rb	2009-06-11 12:02:19 UTC (rev 41449)
@@ -11,12 +11,14 @@
 
 def graph filename
    tmpfile = Tempfile.new 'decompiler'
-   `./decompiler -graph #{filename} | dot -T svg -o #{tmpfile.path}`
+   system "./decompiler -graph #{filename} | dot -T svg -o #{tmpfile.path}"
    `#{$image_viewer} #{tmpfile.path}`
 end
 
 
-opts = GetoptLong.new(['--graph', '-g', GetoptLong::NO_ARGUMENT])
+opts = GetoptLong.new(['--disasm', '-d', GetoptLong::NO_ARGUMENT],
+                      ['--blocks', '-b', GetoptLong::NO_ARGUMENT],
+                      ['--graph',  '-g', GetoptLong::NO_ARGUMENT])
 
 if ARGV.size < 1
    usage
@@ -28,6 +30,12 @@
    when '--help'
       usage
       exit
+   when '--disasm'
+      system "./decompiler -disasm #{ARGV[0]}"
+      exit
+   when '--blocks'
+      system "./decompiler -blocks #{ARGV[0]}"
+      exit
    when '--graph'
       graph ARGV[0]
       exit

Modified: tools/branches/gsoc2009-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/instruction.h	2009-06-11 12:02:01 UTC (rev 41448)
+++ tools/branches/gsoc2009-decompiler/decompiler/instruction.h	2009-06-11 12:02:19 UTC (rev 41449)
@@ -66,6 +66,17 @@
 		return _instructions.size();
 	}
 
+	void print(index_t i) {
+		if (i >= 1 && _instructions[i]->_addr == _instructions[i-1]->_addr)
+			printf("         |           %s", _instructions[i]->_description.c_str());
+		else
+			printf("[d] %04x | [r] %04x: %s", _instructions[i]->_addr-8, _instructions[i]->_addr, _instructions[i]->_description.c_str());
+		Jump *j = dynamic_cast<Jump*>(_instructions[i]);
+		if (j)
+			printf(" ([d] %04x | [r] %04x)", j->target()-8, j->target());
+		printf("\n");
+	}
+
 };
 
 


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