[Scummvm-cvs-logs] SF.net SVN: scummvm:[42061] tools/branches/gsoc2009-decompiler/decompiler
kjdf at users.sourceforge.net
kjdf at users.sourceforge.net
Fri Jul 3 16:21:31 CEST 2009
Revision: 42061
http://scummvm.svn.sourceforge.net/scummvm/?rev=42061&view=rev
Author: kjdf
Date: 2009-07-03 14:21:31 +0000 (Fri, 03 Jul 2009)
Log Message:
-----------
decompiler: cleaned up debug output a bit
Modified Paths:
--------------
tools/branches/gsoc2009-decompiler/decompiler/decompiler.cpp
tools/branches/gsoc2009-decompiler/decompiler/graph.h
tools/branches/gsoc2009-decompiler/decompiler/instruction.h
tools/branches/gsoc2009-decompiler/decompiler/parser.h
tools/branches/gsoc2009-decompiler/decompiler/syntax.h
Modified: tools/branches/gsoc2009-decompiler/decompiler/decompiler.cpp
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/decompiler.cpp 2009-07-03 14:18:20 UTC (rev 42060)
+++ tools/branches/gsoc2009-decompiler/decompiler/decompiler.cpp 2009-07-03 14:21:31 UTC (rev 42061)
@@ -16,11 +16,13 @@
options_description visible("Allowed options");
visible.add_options()
("help", "this message")
- ("disasm", "print disassembly and exit")
- ("blocks", "print basic blocks and exit")
- ("graph", "print graph and exit")
+ ("disasm", "print disassembly")
+ ("blocks", "print basic blocks")
+ ("graph-intervals", value<unsigned>(), "print arg-th graph intervals")
+ ("graph-struct", "print graph with marked structure information")
("decompile", "print decompiled program and exit")
- ("fontname", value<string>()->default_value("Courier"), "font to use with graphical output");
+ ("no-remove-jumps", "don't remove jumps-to-jumps")
+ ("fontname", value<string>()->default_value("Courier"), "font to use with dot output");
options_description options("Allowed options");
options.add(visible).add_options()
("inputfile", value<string>(), "input file");
@@ -39,8 +41,6 @@
return vars;
}
-#include <sstream>
-
int main(int argc, char **argv) {
variables_map vars = parseArgs(argc, argv);
Script script(new Scumm6Parser, vars["inputfile"].as<string>().c_str());
@@ -57,11 +57,19 @@
cout << block->toString() << endl;
exit(0);
}
- cfg.removeJumpsToJumps();
+ if (!vars.count("no-remove-jumps"))
+ cfg.removeJumpsToJumps();
cfg.orderBlocks();
cfg.removeUnreachableBlocks();
+ if (vars.count("graph-intervals")) {
+ cfg.assignIntervals();
+ for (unsigned i = 0; i < vars["graph-intervals"].as<unsigned>(); i++)
+ cfg.extendIntervals();
+ cout << cfg.graphvizToString(vars["fontname"].as<string>());
+ exit(0);
+ }
cfg.loopStruct();
- if (vars.count("graph")) {
+ if (vars.count("graph-struct")) {
cout << cfg.graphvizToString(vars["fontname"].as<string>());
exit(0);
}
Modified: tools/branches/gsoc2009-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/graph.h 2009-07-03 14:18:20 UTC (rev 42060)
+++ tools/branches/gsoc2009-decompiler/decompiler/graph.h 2009-07-03 14:21:31 UTC (rev 42061)
@@ -121,6 +121,8 @@
std::string graphvizToString(const std::string &fontname="", int fontsize=0);
+ void assignIntervals(); // can be called multiple times
+ void extendIntervals();
private:
LoopType loopType(Block *head, Block *latch);
@@ -132,9 +134,6 @@
int orderVisit(Block *u, int number); // visit blocks recursively, depth first, helper for orderBlocks
void replaceEdges(Block *from, Block *oldTo, Block *newTo);
- void assignIntervals(); // can be called multiple times
- void extendIntervals();
-
};
#endif
Modified: tools/branches/gsoc2009-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/instruction.h 2009-07-03 14:18:20 UTC (rev 42060)
+++ tools/branches/gsoc2009-decompiler/decompiler/instruction.h 2009-07-03 14:21:31 UTC (rev 42061)
@@ -12,9 +12,9 @@
std::string _description;
uint32 _addr;
- virtual std::string toString() {
+ virtual std::string toString(unsigned i=0) {
std::ostringstream ret;
- ret << _description << " [" << phex(_addr-8) << "]" << std::endl;
+ ret << "[" << phex(_addr) << "] " << spaces(i) << _description << std::endl;
return ret.str();
}
@@ -30,9 +30,9 @@
uint32 target() {
return _addr+_offset;
}
- std::string toString() {
+ std::string toString(unsigned i=0) {
std::ostringstream ret;
- ret << _description << " (" << phex(target()-8) << ") [" << phex(_addr-8) << "]" << std::endl;
+ ret << "[" << phex(_addr) << "] " << spaces(i) << _description << " (" << phex(target()) << ")" << std::endl;
return ret.str();
}
Modified: tools/branches/gsoc2009-decompiler/decompiler/parser.h
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/parser.h 2009-07-03 14:18:20 UTC (rev 42060)
+++ tools/branches/gsoc2009-decompiler/decompiler/parser.h 2009-07-03 14:21:31 UTC (rev 42061)
@@ -433,7 +433,8 @@
ifstream f;
f.open(filename, ios::binary);
parseHeader(f);
- while (_reader->readInstruction(f, script, (uint32) f.tellg()))
+ std::streamoff start = f.tellg();
+ while (_reader->readInstruction(f, script, (uint32) (f.tellg()-start)))
;
}
Modified: tools/branches/gsoc2009-decompiler/decompiler/syntax.h
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/syntax.h 2009-07-03 14:18:20 UTC (rev 42060)
+++ tools/branches/gsoc2009-decompiler/decompiler/syntax.h 2009-07-03 14:21:31 UTC (rev 42061)
@@ -29,7 +29,7 @@
};
std::string toString(unsigned i) {
- return spaces(i) + _instruction->toString();
+ return _instruction->toString(i);
}
};
@@ -43,7 +43,7 @@
std::string toString(unsigned i) {
std::ostringstream ret;
- ret << spaces(i) << "goto " << phex(_address-8) << std::endl;
+ ret << spaces(i) << "goto " << phex(_address) << std::endl;
return ret.str();
}
};
@@ -56,7 +56,7 @@
std::string toString(unsigned i) {
std::ostringstream ret;
- ret << std::endl << spaces(i) << "while (";
+ ret << std::endl << spaces(i) << "while (" << std::endl;
foreach (InstructionWrapper* insn, _condition)
ret << insn->toString(i);
ret << spaces(i) << ") {" << std::endl;
@@ -75,10 +75,10 @@
std::string toString(unsigned i) {
std::ostringstream ret;
- ret << std::endl << spaces(i) << "do {";
+ ret << std::endl << spaces(i) << "do {" << std::endl;
foreach (Statement *stmt, _body)
ret << stmt->toString(i+4);
- ret << spaces(i) << "} while (";
+ ret << spaces(i) << "} while (" << std::endl;
foreach (InstructionWrapper* insn, _condition)
ret << insn->toString(i);
ret << spaces(i) << ")" << std::endl << std::endl;
@@ -95,7 +95,7 @@
std::string toString(unsigned i) {
std::ostringstream ret;
- ret << std::endl << spaces(i) << "if (";
+ ret << std::endl << spaces(i) << "if (" << std::endl;
foreach (InstructionWrapper* insn, _condition)
ret << insn->toString(i);
ret << spaces(i) << ") {" << std::endl;
@@ -158,7 +158,7 @@
CondJump *condjump = dynamic_cast<CondJump*>(insn);
if (condjump) {
IfThenElse *ifte = new IfThenElse;
- ifte->_condition.push_back(new InstructionWrapper(new Instruction("not", 999999)));
+ ifte->_condition.push_back(new InstructionWrapper(new Instruction("not", 0xffff)));
ifte->_consequence.push_back(new Goto(jump->target()));
seq.push_back(ifte);
} else if (jump)
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