[Scummvm-cvs-logs] SF.net SVN: scummvm:[41448] tools/branches/gsoc2009-decompiler/decompiler
kjdf at users.sourceforge.net
kjdf at users.sourceforge.net
Thu Jun 11 14:02:01 CEST 2009
Revision: 41448
http://scummvm.svn.sourceforge.net/scummvm/?rev=41448&view=rev
Author: kjdf
Date: 2009-06-11 12:02:01 +0000 (Thu, 11 Jun 2009)
Log Message:
-----------
decompiler: added wrapper script for decompiler, cleaned up CFG a bit more
Modified Paths:
--------------
tools/branches/gsoc2009-decompiler/decompiler/cfg.h
Added Paths:
-----------
tools/branches/gsoc2009-decompiler/decompiler/decompiler.rb
Modified: tools/branches/gsoc2009-decompiler/decompiler/cfg.h
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/cfg.h 2009-06-11 08:41:03 UTC (rev 41447)
+++ tools/branches/gsoc2009-decompiler/decompiler/cfg.h 2009-06-11 12:02:01 UTC (rev 41448)
@@ -29,14 +29,8 @@
struct BasicBlock : public Node {
- enum Type {
- TwoWay,
- OneWay,
- End
- };
- Type _type;
index_t _start, _end;
- BasicBlock(Type type, index_t start, index_t end) : Node(), _type(type), _start(start), _end(end) {
+ BasicBlock(index_t start, index_t end) : Node(), _start(start), _end(end) {
}
void printInsns(vector<Instruction*> &v) {
@@ -89,24 +83,13 @@
vector<Instruction*> *_v = &_script._instructions;
for (uint32 i = 0; i < _blocks.size(); i++) {
BasicBlock *bb = _blocks[i];
- if (bb->_type == BasicBlock::TwoWay) {
+ for (uint32 j = 0; j < bb->_out.size(); j++) {
printf("\""); bb->printHeader(*_v); printf("\"");
printf(" -> ");
- printf("\""); ((BasicBlock*)bb->_out[0])->printHeader(*_v); printf("\"");
- printf(" [style=bold]\n");
- printf("\""); bb->printHeader(*_v); printf("\"");
- printf(" -> ");
- printf("\""); ((BasicBlock*)bb->_out[1])->printHeader(*_v); printf("\"");
- printf("\n");
- } else if (bb->_type == BasicBlock::OneWay) {
- printf("\""); bb->printHeader(*_v); printf("\"");
- printf(" -> ");
- printf("\""); ((BasicBlock*)bb->_out[0])->printHeader(*_v); printf("\"");
- printf(" [style=bold]\n");
- } else if (bb->_type == BasicBlock::End) {
- printf("\""); bb->printHeader(*_v); printf("\"");
- printf("\n");
+ printf("\""); ((BasicBlock*)bb->_out[j])->printHeader(*_v); printf("\"");
+ printf(" %s\n", j == 0 ? "[style=bold]" : "");
}
+ printf("\""); bb->printHeader(*_v); printf("\"\n");
}
printf("}\n");
}
@@ -143,18 +126,12 @@
}
index_t bbstart = 0;
for (index_t i = 0; i < script.size(); i++)
- if (dynamic_cast<CondJump*>(script[i])) {
- _blocks.push_back(new BasicBlock(BasicBlock::TwoWay, bbstart, i+1));
+ if (targets.find(i+1) != targets.end() || dynamic_cast<Jump*>(script[i])) {
+ _blocks.push_back(new BasicBlock(bbstart, i+1));
bbstart = i+1;
- } else if (dynamic_cast<Jump*>(script[i])) {
- _blocks.push_back(new BasicBlock(BasicBlock::OneWay, bbstart, i+1));
- bbstart = i+1;
- } else if (targets.find(i+1) != targets.end()) {
- _blocks.push_back(new BasicBlock(BasicBlock::OneWay, bbstart, i+1));
- bbstart = i+1;
}
if (bbstart != script.size())
- _blocks.push_back(new BasicBlock(BasicBlock::End, bbstart, script.size()));
+ _blocks.push_back(new BasicBlock(bbstart, script.size()));
for (index_t i = 0; i < script.size(); i++) {
BasicBlock *bb = blockByEnd(i+1);
if ((j = dynamic_cast<Jump*>(script[i])))
Added: tools/branches/gsoc2009-decompiler/decompiler/decompiler.rb
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/decompiler.rb (rev 0)
+++ tools/branches/gsoc2009-decompiler/decompiler/decompiler.rb 2009-06-11 12:02:01 UTC (rev 41448)
@@ -0,0 +1,35 @@
+#! /usr/bin/env ruby
+
+require 'getoptlong'
+require 'tempfile'
+
+$image_viewer = 'eog'
+
+def usage
+ puts "decompiler.rb [--graph] file.dmp"
+end
+
+def graph filename
+ tmpfile = Tempfile.new 'decompiler'
+ `./decompiler -graph #{filename} | dot -T svg -o #{tmpfile.path}`
+ `#{$image_viewer} #{tmpfile.path}`
+end
+
+
+opts = GetoptLong.new(['--graph', '-g', GetoptLong::NO_ARGUMENT])
+
+if ARGV.size < 1
+ usage
+ exit
+end
+
+for opt, arg in opts
+ case opt
+ when '--help'
+ usage
+ exit
+ when '--graph'
+ graph ARGV[0]
+ exit
+ end
+end
Property changes on: tools/branches/gsoc2009-decompiler/decompiler/decompiler.rb
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
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