[Scummvm-cvs-logs] SF.net SVN: scummvm:[51190] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Fri Jul 23 04:42:09 CEST 2010
Revision: 51190
http://scummvm.svn.sourceforge.net/scummvm/?rev=51190&view=rev
Author: pidgeot
Date: 2010-07-23 02:42:09 +0000 (Fri, 23 Jul 2010)
Log Message:
-----------
Add argument ordering for lBinaryOp and kSpecial
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
tools/branches/gsoc2010-decompiler/decompiler/codegen.h
tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp 2010-07-23 01:38:34 UTC (rev 51189)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp 2010-07-23 02:42:09 UTC (rev 51190)
@@ -48,7 +48,7 @@
return stream.str();
}
-CodeGenerator::CodeGenerator(Engine *engine, std::ostream &output) : _output(output) {
+CodeGenerator::CodeGenerator(Engine *engine, std::ostream &output, ArgOrder binOrder, ArgOrder callOrder) : _output(output), _binOrder(binOrder), _callOrder(callOrder) {
_engine = engine;
_indentLevel = 0;
}
@@ -168,9 +168,12 @@
case kComparison:
//TODO: Allow specification of order in which operands appear on stack
{
- EntryPtr rhs = _stack.pop();
- EntryPtr lhs = _stack.pop();
- _stack.push(new BinaryOpEntry(lhs, rhs, it->_codeGenData));
+ EntryPtr op1 = _stack.pop();
+ EntryPtr op2 = _stack.pop();
+ if (_binOrder == kFIFO)
+ _stack.push(new BinaryOpEntry(op2, op1, it->_codeGenData));
+ else if (_binOrder == kLIFO)
+ _stack.push(new BinaryOpEntry(op1, op2, it->_codeGenData));
break;
}
case kCondJump:
@@ -213,7 +216,7 @@
uint32 dest = _engine->getDestAddress(it);
if (dest != _curGroup->_next->_start->_address) {
std::stringstream s;
- s << boost::format("goto %X") % dest;
+ s << boost::format("jump %X") % dest;
addOutputLine(s.str());
}
}
@@ -247,11 +250,17 @@
addOutputLine("}");
}
+void CodeGenerator::addArg(EntryPtr p) {
+ if (_callOrder == kFIFO)
+ _argList.push_front(p);
+ else if (_callOrder == kLIFO)
+ _argList.push_back(p);
+}
+
void CodeGenerator::processSpecialMetadata(const Instruction inst, char c) {
- // TODO: Allow subclasses to decide if they want push_front or push_back.
switch (c) {
case 'p':
- _argList.push_front(_stack.pop());
+ addArg(_stack.pop());
break;
default:
std::cerr << boost::format("Unknown character in metadata: %c\n") % c ;
Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.h 2010-07-23 01:38:34 UTC (rev 51189)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.h 2010-07-23 02:42:09 UTC (rev 51190)
@@ -368,12 +368,22 @@
const int kIndentAmount = 2; ///< How many spaces to use for each indent.
/**
+ * Enumeration for the different argument/operand orderings.
+ */
+enum ArgOrder {
+ kFIFO, ///< First argument is pushed to stack first.
+ kLIFO ///< First argument is pushed to stack last.
+};
+
+/**
* Base class for code generators.
*/
class CodeGenerator {
private:
- Engine *_engine; ///< Pointer to the Engine used for the script.
- Graph _g; ///< The annotated graph of the script.
+ Engine *_engine; ///< Pointer to the Engine used for the script.
+ Graph _g; ///< The annotated graph of the script.
+ const ArgOrder _binOrder; ///< Order of operands for binary operations.
+ const ArgOrder _callOrder; ///< Order of operands for call arguments.
/**
* Processes a GraphVertex.
@@ -427,6 +437,13 @@
*/
virtual void processSpecialMetadata(const Instruction inst, char c);
+ /**
+ * Add an argument to the argument list.
+ *
+ * @param p The argument to add.
+ */
+ void addArg(EntryPtr p);
+
public:
virtual ~CodeGenerator() {};
@@ -435,8 +452,10 @@
*
* @param engine Pointer to the Engine used for the script.
* @param output The std::ostream to output the code to.
+ * @param binOrder Order of arguments for binary operators.
+ * @param callOrder Order of arguments for function calls.
*/
- CodeGenerator(Engine *engine, std::ostream &output);
+ CodeGenerator(Engine *engine, std::ostream &output, ArgOrder binOrder, ArgOrder callOrder);
/**
* Generates code from the provided graph and outputs it to stdout.
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp 2010-07-23 01:38:34 UTC (rev 51189)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp 2010-07-23 02:42:09 UTC (rev 51190)
@@ -429,7 +429,7 @@
switch (c) {
// All of these meanings are taken from descumm.
case 'l':
- _argList.push_front(createListEntry());
+ addArg(createListEntry());
break;
// No SCUMMv6 opcodes using these types have more than one parameter, so it's safe to assume it's the first parameter we want.
case 'w':
@@ -438,11 +438,11 @@
switch (inst._params[0]._type) {
case kSByte:
case kShort:
- _argList.push_front(new IntEntry(inst._params[0].getSigned(), false));
+ addArg(new IntEntry(inst._params[0].getSigned(), false));
break;
case kByte:
case kUShort:
- _argList.push_front(new IntEntry(inst._params[0].getUnsigned(), false));
+ addArg(new IntEntry(inst._params[0].getUnsigned(), false));
break;
default:
std::cerr << boost::format("Unexpected type for parameter 0 @ %08X while processing metadata character %c") % inst._address % c;
@@ -450,14 +450,14 @@
}
break;
case 'v':
- _argList.push_front(new VarEntry(decodeVarName(inst._params[0].getUnsigned())));
+ addArg(new VarEntry(decodeVarName(inst._params[0].getUnsigned())));
break;
case 's':
- _argList.push_front(new StringEntry(inst._params[0].getString()));
+ addArg(new StringEntry(inst._params[0].getString()));
break;
case 'z':
- _argList.push_front(_stack.pop());
- _argList.push_front(_stack.pop());
+ addArg(_stack.pop());
+ addArg(_stack.pop());
break;
default:
::CodeGenerator::processSpecialMetadata(inst, c);
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.h 2010-07-23 01:38:34 UTC (rev 51189)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.h 2010-07-23 02:42:09 UTC (rev 51190)
@@ -71,7 +71,7 @@
* @param engine Pointer to the Engine used for the script.
* @param output The std::ostream to output the code to.
*/
- CodeGenerator(Engine *engine, std::ostream &output) : ::CodeGenerator(engine, output) {}
+ CodeGenerator(Engine *engine, std::ostream &output) : ::CodeGenerator(engine, output, kFIFO, kFIFO) {}
protected:
void processInst(const Instruction inst);
virtual void processSpecialMetadata(const Instruction inst, char c);
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