[Scummvm-cvs-logs] SF.net SVN: scummvm:[52023] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Thu Aug 12 02:54:06 CEST 2010
Revision: 52023
http://scummvm.svn.sourceforge.net/scummvm/?rev=52023&view=rev
Author: pidgeot
Date: 2010-08-12 00:54:04 +0000 (Thu, 12 Aug 2010)
Log Message:
-----------
DECOMPILER: Add explanatory comments
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
tools/branches/gsoc2010-decompiler/decompiler/codegen.h
tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
tools/branches/gsoc2010-decompiler/decompiler/graph.h
tools/branches/gsoc2010-decompiler/decompiler/instruction.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp 2010-08-12 00:37:09 UTC (rev 52022)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp 2010-08-12 00:54:04 UTC (rev 52023)
@@ -178,11 +178,10 @@
}
// Print output
- // TODO: Proper indenting
GroupPtr p = GET(entryPoint);
while (p != NULL) {
for (std::vector<CodeLine>::iterator it = p->_code.begin(); it != p->_code.end(); ++it) {
- if (it->_unindentBefore /*&& _indentLevel != 0*/)
+ if (it->_unindentBefore)
_indentLevel--;
_output << boost::format("%08X: %s") % p->_start->_address % indentString(it->_line) << std::endl;
if (it->_indentAfter)
Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.h 2010-08-12 00:37:09 UTC (rev 52022)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.h 2010-08-12 00:54:04 UTC (rev 52023)
@@ -35,16 +35,19 @@
class Function;
+/**
+ * Types of stack entries.
+ */
enum StackEntryType {
- seInt,
- seVar,
- seBinOp,
- seUnaryOp,
- seDup,
- seArray,
- seString,
- seList,
- seCall
+ seInt, ///< Integer
+ seVar, ///< Variable
+ seBinOp, ///< Binary operation
+ seUnaryOp, ///< Unary operation
+ seDup, ///< Duplicated entry
+ seArray, ///< Array access
+ seString, ///< String
+ seList, ///< List
+ seCall ///< Function call
};
class StackEntry;
Modified: tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp 2010-08-12 00:37:09 UTC (rev 52022)
+++ tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp 2010-08-12 00:54:04 UTC (rev 52023)
@@ -38,11 +38,14 @@
ControlFlow::ControlFlow(const std::vector<Instruction> &insts, Engine *engine) : _insts(insts) {
_engine = engine;
+ // Automatically add a function if we're not supposed to look for more functions and no functions are defined
+ // This avoids a special case for when no real functions exist in the script
if (engine->_functions.empty() && !_engine->detectMoreFuncs())
engine->_functions[insts.begin()->_address] = Function(insts.begin(), insts.end());
GroupPtr prev = NULL;
int id = 0;
+ // Create vertices
for (ConstInstIterator it = insts.begin(); it != insts.end(); ++it) {
GraphVertex cur = boost::add_vertex(_g);
_addrMap[it->_address] = cur;
@@ -50,12 +53,14 @@
PUT_ID(cur, id);
id++;
+ // Add reference to vertex if function starts here
if (_engine->_functions.find(it->_address) != _engine->_functions.end())
_engine->_functions[it->_address]._v = cur;
prev = GET(cur);
}
+ // Add regular edges
FuncMap::iterator fn;
GraphVertex last;
bool addEdge = false;
@@ -77,6 +82,7 @@
}
+ // Add jump edges
for (ConstInstIterator it = insts.begin(); it != insts.end(); ++it) {
switch(it->_type) {
case kJump:
@@ -185,6 +191,7 @@
return;
}
if (fn->second._startIt == fn->second._endIt) {
+ // We already know this is an entry point, we only need to detect the end point
detectEndPoint = true;
break;
}
@@ -279,13 +286,16 @@
}
expectedStackLevel = grCur->_stackLevel;
+ // If expected stack level decreases in next vertex, then use next vertex level as expected level
if (expectedStackLevel > grNext->_stackLevel && grNext->_stackLevel >= 0) {
expectedStackLevel = grNext->_stackLevel;
+ // Also set the stack level of the current group to remember that we expect it to be lower
grCur->_stackLevel = expectedStackLevel;
}
stackLevel += curInst->_stackChange;
+ // For stack operations, the new stack level becomes the expected stack level starting from the next group
if (curInst->_type == kStack) {
expectedStackLevel = stackLevel;
grNext->_stackLevel = stackLevel;
Modified: tools/branches/gsoc2010-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-08-12 00:37:09 UTC (rev 52022)
+++ tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-08-12 00:54:04 UTC (rev 52023)
@@ -323,6 +323,7 @@
output << " ";
if (param->_type != kString) {
if (inst->_type == kCondJump || inst->_type == kCondJumpRel || inst->_type == kJump || inst->_type == kJumpRel || inst->_type == kCall) {
+ // Output numerical arguments to jumps in hexadecimal
switch (param->_type) {
case kSByte:
case kShort:
@@ -363,6 +364,7 @@
};
namespace boost {
+
/**
* Add a reference to a pointer.
*/
@@ -377,8 +379,9 @@
if (--(p->_refCount) == 0)
delete p;
}
-}
+} // End of namespace boost
+
class Engine;
/**
Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-08-12 00:37:09 UTC (rev 52022)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-08-12 00:54:04 UTC (rev 52023)
@@ -120,6 +120,7 @@
if (param != inst._params.begin())
output << ",";
if (inst._type == kCondJump || inst._type == kCondJumpRel || inst._type == kJump || inst._type == kJumpRel || inst._type == kCall) {
+ // Output numerical arguments to jumps in hexadecimal
switch (param->_type) {
case kSByte:
case kShort:
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