[Scummvm-cvs-logs] SF.net SVN: scummvm:[51652] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Mon Aug 2 21:26:46 CEST 2010
Revision: 51652
http://scummvm.svn.sourceforge.net/scummvm/?rev=51652&view=rev
Author: pidgeot
Date: 2010-08-02 19:26:46 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Add option to output unreachable groups
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp
tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/graph.h
tools/branches/gsoc2010-decompiler/decompiler/instruction.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp 2010-08-02 19:05:12 UTC (rev 51651)
+++ tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp 2010-08-02 19:26:46 UTC (rev 51652)
@@ -128,7 +128,6 @@
return;
}
gr->_stackLevel = level;
- PUT(g, gr)
if (boost::out_degree(g, _g) == 0)
return;
@@ -159,7 +158,7 @@
GroupPtr grNext = GET(next);
expectedStackLevel = grCur->_stackLevel;
- if (expectedStackLevel > grNext->_stackLevel)
+ if (expectedStackLevel > grNext->_stackLevel && grNext->_stackLevel >= 0)
expectedStackLevel = grNext->_stackLevel;
grCur->_stackLevel = expectedStackLevel;
Modified: tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp 2010-08-02 19:05:12 UTC (rev 51651)
+++ tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp 2010-08-02 19:26:46 UTC (rev 51652)
@@ -55,7 +55,8 @@
("dump-disassembly,d", po::value<std::string>()->implicit_value(""), "Dump the disassembly to a file. Leave out filename to output to stdout.")
("dump-graph,g", po::value<std::string>()->implicit_value(""), "Output the control flow graph in dot format to a file. Leave out filename to output to stdout.")
("only-disassembly,D", "Stops after disassembly. Implies -d.")
- ("only-graph,G", "Stops after control flow graph has been generated. Implies -g.");
+ ("only-graph,G", "Stops after control flow graph has been generated. Implies -g.")
+ ("show-unreachable,u", "Show the address and contents of unreachable groups in the script.");
po::options_description args("");
args.add(visible).add_options()
@@ -163,6 +164,33 @@
CodeGenerator *cg = engine->getCodeGenerator(std::cout);
cg->generate(g);
+ if (vm.count("show-unreachable")) {
+ std::vector<GroupPtr> unreachable;
+ VertexRange vr = boost::vertices(g);
+ for (VertexIterator v = vr.first; v != vr.second; ++v)
+ {
+ GroupPtr gr = boost::get(boost::vertex_name, g, *v);
+ if (gr->_stackLevel == -1)
+ unreachable.push_back(gr);
+ }
+ if (!unreachable.empty()) {
+ for (size_t i = 0; i < unreachable.size(); i++) {
+ if (i == 0) {
+ if (unreachable.size() == 1)
+ std::cout << boost::format("\n%d unreachable group detected.\n") % unreachable.size();
+ else
+ std::cout << boost::format("\n%d unreachable groups detected.\n") % unreachable.size();
+ }
+ std::cout << "Group " << (i+1) << ":\n";
+ ConstInstIterator inst = unreachable[i]->_start;
+ do {
+ std::cout << *inst;
+ } while (inst++ != unreachable[i]->_end);
+ std::cout << "----------\n";
+ }
+ }
+ }
+
// Free memory
delete cf;
delete cg;
Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp 2010-08-02 19:05:12 UTC (rev 51651)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp 2010-08-02 19:26:46 UTC (rev 51652)
@@ -20,8 +20,6 @@
*
*/
-#include <boost/format.hpp>
-
#include "disassembler.h"
Disassembler::Disassembler() {
@@ -36,31 +34,7 @@
void Disassembler::doDumpDisassembly(std::ostream &output) {
InstIterator inst;
for (inst = _insts.begin(); inst != _insts.end(); ++inst) {
- output << boost::format("%08x: %s") % inst->_address % inst->_name;
- std::vector<Parameter>::iterator param;
- for (param = inst->_params.begin(); param != inst->_params.end(); ++param) {
- if (param != inst->_params.begin())
- output << ",";
- if (inst->_type == kCondJump || inst->_type == kCondJumpRel || inst->_type == kJump || inst->_type == kJumpRel || inst->_type == kCall) {
- switch (param->_type) {
- case kSByte:
- case kShort:
- case kInt:
- output << boost::format(" 0x%X") % param->getSigned();
- break;
- case kByte:
- case kUShort:
- case kUInt:
- output << boost::format(" 0x%X") % param->getUnsigned();
- break;
- default:
- output << " " << param->_value;
- break;
- }
- } else
- output << " " << param->_value;
- }
- output << boost::format(" (%d)") % inst->_stackChange << "\n";
+ output << *inst;
}
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-08-02 19:05:12 UTC (rev 51651)
+++ tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-08-02 19:26:46 UTC (rev 51652)
@@ -306,6 +306,7 @@
break;
}
output << "\\n";
+ output << "Expected stack level: " << group->_stackLevel << "\\n";
if (group->_startElse)
output << "Start of else\\n";
for (ElseEndIterator it = group->_endElse.begin(); it != group->_endElse.end(); ++it) {
Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-08-02 19:05:12 UTC (rev 51651)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-08-02 19:26:46 UTC (rev 51652)
@@ -25,6 +25,7 @@
#include <string>
#include <vector>
+#include <boost/format.hpp>
#include <boost/variant.hpp>
#include "common/scummsys.h"
@@ -105,6 +106,35 @@
InstType _type; ///< The instruction type.
std::vector<Parameter> _params; ///< Array of parameters used for the instruction.
std::string _codeGenData; ///< String containing metadata for code generation. Start with 0xC0 to force custom handling. See the extended documentation for details.
+
+ friend std::ostream &operator<<(std::ostream &output, const Instruction &inst) {
+ output << boost::format("%08x: %s") % inst._address % inst._name;
+ std::vector<Parameter>::const_iterator param;
+ for (param = inst._params.begin(); param != inst._params.end(); ++param) {
+ if (param != inst._params.begin())
+ output << ",";
+ if (inst._type == kCondJump || inst._type == kCondJumpRel || inst._type == kJump || inst._type == kJumpRel || inst._type == kCall) {
+ switch (param->_type) {
+ case kSByte:
+ case kShort:
+ case kInt:
+ output << boost::format(" 0x%X") % param->getSigned();
+ break;
+ case kByte:
+ case kUShort:
+ case kUInt:
+ output << boost::format(" 0x%X") % param->getUnsigned();
+ break;
+ default:
+ output << " " << param->_value;
+ break;
+ }
+ } else
+ output << " " << param->_value;
+ }
+ output << boost::format(" (%d)") % inst._stackChange << "\n";
+ return output;
+ }
};
/**
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