[Scummvm-cvs-logs] SF.net SVN: scummvm:[54899] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Mon Dec 13 03:08:40 CET 2010
Revision: 54899
http://scummvm.svn.sourceforge.net/scummvm/?rev=54899&view=rev
Author: pidgeot
Date: 2010-12-13 02:08:39 +0000 (Mon, 13 Dec 2010)
Log Message:
-----------
DECOMPILER: Replace Parameter with Value
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/graph.h
tools/branches/gsoc2010-decompiler/decompiler/instruction.h
tools/branches/gsoc2010-decompiler/decompiler/kyra/codegen.cpp
tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h
tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h
tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h
tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp
tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h
tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h
tools/branches/gsoc2010-decompiler/decompiler/value.cpp
tools/branches/gsoc2010-decompiler/decompiler/value.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-12-13 02:08:39 UTC (rev 54899)
@@ -307,45 +307,23 @@
ConstInstIterator inst = group->_start;
do {
output << boost::format("%08x: %s") % (*inst)->_address % (*inst)->_name;
- std::vector<Parameter>::const_iterator param;
+ std::vector<ValuePtr>::const_iterator param;
for (param = (*inst)->_params.begin(); param != (*inst)->_params.end(); ++param) {
if (param != (*inst)->_params.begin())
output << ",";
output << " ";
- if (param->_type != kStringParamType) {
- if ((*inst)->_type == kCondJumpInstType || (*inst)->_type == kCondJumpRelInstType || (*inst)->_type == kJumpInstType || (*inst)->_type == kJumpRelInstType || (*inst)->_type == kCallInstType) {
- // Output numerical arguments to jumps in hexadecimal
- switch (param->_type) {
- case kSByteParamType:
- case kShortParamType:
- case kIntParamType:
- output << boost::format(" 0x%X") % param->getSigned();
- break;
- case kByteParamType:
- case kUShortParamType:
- case kUIntParamType:
- output << boost::format(" 0x%X") % param->getUnsigned();
- break;
- default:
- output << " " << param->_value;
- break;
- }
- } else
- output << " " << param->_value;
- } else {
- std::string s = param->getString();
- for (std::string::iterator it = s.begin(); it != s.end(); ++it)
- if (*it == '"')
- output << "\\\"";
- else if (*it == '|')
- output << "\\|";
- else if (*it == '{')
- output << "\\{";
- else if (*it == '}')
- output << "\\}";
- else
- output << *it;
- }
+ std::string s = (*param)->getString();
+ for (std::string::iterator it = s.begin(); it != s.end(); ++it)
+ if (*it == '"')
+ output << "\\\"";
+ else if (*it == '|')
+ output << "\\|";
+ else if (*it == '{')
+ output << "\\{";
+ else if (*it == '}')
+ output << "\\}";
+ else
+ output << *it;
}
output << boost::format(" (%d)") % (*inst)->_stackChange << "\\n";
} while (inst++ != group->_end);
Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-12-13 02:08:39 UTC (rev 54899)
@@ -31,6 +31,7 @@
#include "common/scummsys.h"
#include "refcounted.h"
+#include "value.h"
/**
* Enumeration for categorizing the different kinds of instructions.
@@ -53,55 +54,6 @@
};
/**
- * Enumeration for categorizing the different kinds of parameters.
- */
-enum ParamType {
- kSByteParamType, ///< Signed 8-bit integer.
- kByteParamType, ///< Unsigned 8-bit integer.
- kShortParamType, ///< Signed 16-bit integer.
- kUShortParamType, ///< Unsigned 16-bit integer.
- kIntParamType, ///< Signed 32-bit integer.
- kUIntParamType, ///< Unsigned 32-bit integer.
- kStringParamType ///< Text string.
-};
-
-/**
- * Structure for representing a parameter.
- */
-struct Parameter {
- ParamType _type; ///< Type of the parameter.
- boost::variant<int32, uint32, std::string> _value; ///< Value of the parameter.
-
- Parameter() {}
- Parameter(ParamType type, boost::variant<int32, uint32, std::string> value)
- : _type(type), _value(value) {}
-
- /**
- * Gets an int32 stored in the _value variant.
- *
- * @return The int32 stored in the _value variant.
- * @throws boost::bad_get if the variant is not storing an int32.
- */
- int32 getSigned() const { return boost::get<int32>(_value); }
-
- /**
- * Gets an uint32 stored in the _value variant.
- *
- * @return The uint32 stored in the _value variant.
- * @throws boost::bad_get if the variant is not storing an uint32.
- */
- uint32 getUnsigned() const { return boost::get<uint32>(_value); }
-
- /**
- * Gets an std::string stored in the _value variant.
- *
- * @return The std::string stored in the _value variant.
- * @throws boost::bad_get if the variant is not storing an std::string.
- */
- std::string getString() const { return boost::get<std::string>(_value); }
-};
-
-/**
* Structure for representing an instruction.
*/
struct Instruction : public RefCounted {
@@ -110,7 +62,7 @@
std::string _name; ///< The instruction name (opcode name).
InstType _type; ///< The instruction type.
int16 _stackChange; ///< How much this instruction changes the stack pointer by.
- std::vector<Parameter> _params; ///< Array of parameters used for the instruction.
+ std::vector<ValuePtr> _params; ///< Array of parameters used for the instruction.
std::string _codeGenData; ///< String containing metadata for code generation. See the extended documentation for details.
Instruction(uint32 opcode = 0, uint32 address = 0,
@@ -137,29 +89,11 @@
*/
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;
+ std::vector<ValuePtr>::const_iterator param;
for (param = inst._params.begin(); param != inst._params.end(); ++param) {
if (param != inst._params.begin())
output << ",";
- if (inst._type == kCondJumpInstType || inst._type == kCondJumpRelInstType || inst._type == kJumpInstType || inst._type == kJumpRelInstType || inst._type == kCallInstType) {
- // Output numerical arguments to jumps in hexadecimal
- switch (param->_type) {
- case kSByteParamType:
- case kShortParamType:
- case kIntParamType:
- output << boost::format(" 0x%X") % param->getSigned();
- break;
- case kByteParamType:
- case kUShortParamType:
- case kUIntParamType:
- output << boost::format(" 0x%X") % param->getUnsigned();
- break;
- default:
- output << " " << param->_value;
- break;
- }
- } else
- output << " " << param->_value;
+ output << " " << *param;
}
output << boost::format(" (%d)") % inst._stackChange << "\n";
return output;
Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/codegen.cpp 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/codegen.cpp 2010-12-13 02:08:39 UTC (rev 54899)
@@ -46,26 +46,26 @@
break;
case 3:
case 4:
- _stack.push(new IntValue(inst->_params[0].getSigned(), true));
+ _stack.push(inst->_params[0]);
break;
case 5:
{
std::stringstream s;
- s << boost::format("var%d") % inst->_params[0].getSigned();
+ s << boost::format("var%d") % inst->_params[0]->getSigned();
_stack.push(new VarValue(s.str()));
}
break;
case 6:
{
std::stringstream s;
- s << boost::format("localvar%d") % inst->_params[0].getSigned();
+ s << boost::format("localvar%d") % inst->_params[0]->getSigned();
_stack.push(new VarValue(s.str()));
}
break;
case 7:
{
std::stringstream s;
- s << boost::format("param%d") % inst->_params[0].getSigned();
+ s << boost::format("param%d") % inst->_params[0]->getSigned();
_stack.push(new VarValue(s.str()));
}
break;
@@ -82,7 +82,7 @@
case 9:
{
std::stringstream s;
- s << boost::format("var%d") % inst->_params[0].getSigned();
+ s << boost::format("var%d") % inst->_params[0]->getSigned();
ValuePtr p = new VarValue(s.str());
writeAssignment(p, _stack.pop());
}
@@ -90,7 +90,7 @@
case 10:
{
std::stringstream s;
- s << boost::format("localvar%d") % inst->_params[0].getSigned();
+ s << boost::format("localvar%d") % inst->_params[0]->getSigned();
ValuePtr p = new VarValue(s.str());
writeAssignment(p, _stack.pop());
}
@@ -98,7 +98,7 @@
case 11:
{
std::stringstream s;
- s << boost::format("param%d") % inst->_params[0].getSigned();
+ s << boost::format("param%d") % inst->_params[0]->getSigned();
ValuePtr p = new VarValue(s.str());
writeAssignment(p, _stack.pop());
}
@@ -107,12 +107,12 @@
break;
case kStackInstType:
if (inst->_opcode == 12) {
- for (int i = inst->_params[0].getSigned(); i != 0; --i) {
+ for (int i = inst->_params[0]->getSigned(); i != 0; --i) {
if (!_stack.empty())
_stack.pop();
}
} else if (inst->_opcode == 13) {
- for (int i = 0; i != inst->_params[0].getSigned(); ++i) {
+ for (int i = 0; i != inst->_params[0]->getSigned(); ++i) {
std::stringstream s;
s << boost::format("localvar%d") % i;
_stack.push(new VarValue(s.str()));
@@ -126,7 +126,7 @@
case kCallInstType:
{
_argList.clear();
- Function f = _engine->_functions.find(inst->_params[0].getUnsigned())->second;
+ Function f = _engine->_functions.find(inst->_params[0]->getUnsigned())->second;
for (size_t i = 0; i < f._metadata.length(); i++)
processSpecialMetadata(inst, f._metadata[i], i);
_stack.push(new CallValue(f._name, _argList));
Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp 2010-12-13 02:08:39 UTC (rev 54899)
@@ -390,7 +390,7 @@
#define ADD_INST _insts.insert(_insts.end(), new Instruction());
#define LAST_INST (_insts.back())
-#define OPCODE_MD(name, category, stackChange, hasParam, isSigned, codeGenData) \
+#define OPCODE_MD(name, category, stackChange, hasParam, isSigned, isAddress, codeGenData) \
ADD_INST; \
LAST_INST->_opcode = opcode; \
LAST_INST->_address = address; \
@@ -399,33 +399,33 @@
LAST_INST->_type = category; \
LAST_INST->_codeGenData = codeGenData; \
if (hasParam) { \
- Parameter p; \
- if (isSigned) { \
- p._type = kShortParamType; \
- p._value = parameter; \
+ ValuePtr p; \
+ if (isAddress) { \
+ p = new AddressValue(parameter); \
+ } else if (isSigned) { \
+ p = new IntValue(parameter, true);\
} else { \
- p._type = kUShortParamType; \
- p._value = (uint32)parameter; \
+ p = new IntValue((uint32)parameter, false);\
} \
LAST_INST->_params.push_back(p);\
}
-#define OPCODE(name, category, stackChange, hasParam, isSigned) OPCODE_MD(name, category, stackChange, hasParam, isSigned, "");
+#define OPCODE(name, category, stackChange, hasParam, isSigned, isAddress) OPCODE_MD(name, category, stackChange, hasParam, isSigned, isAddress, "");
switch(opcode) {
case 0:
parameter *= 2;
if (parameter < minFuncAddr)
jumpTargets.insert(_insts.size());
- OPCODE("jumpTo", kJumpInstType, 0, true, false);
+ OPCODE("jumpTo", kJumpInstType, 0, true, false, true);
break;
case 1:
- OPCODE("setRetValue", kStoreInstType, 0, true, true);
+ OPCODE("setRetValue", kStoreInstType, 0, true, true, false);
break;
case 2:
if (parameter == 0) {
- OPCODE("pushRet", kLoadInstType, 1, false, false);
+ OPCODE("pushRet", kLoadInstType, 1, false, false, false);
} else if (parameter == 1) {
- OPCODE("pushPos", kSpecialCallInstType, 0, false, false); // Sets up function call
+ OPCODE("pushPos", kSpecialCallInstType, 0, false, false, false); // Sets up function call
} else {
// Error: invalid parameter halts execution
throw UnknownOpcodeException(address, opcode);
@@ -433,41 +433,41 @@
break;
case 3:
case 4:
- OPCODE("push", kLoadInstType, 1, true, true);
+ OPCODE("push", kLoadInstType, 1, true, true, false);
break;
case 5:
- OPCODE("pushVar", kLoadInstType, 1, true, true);
+ OPCODE("pushVar", kLoadInstType, 1, true, true, false);
break;
case 6:
- OPCODE("pushBPNeg", kLoadInstType, 1, true, true);
+ OPCODE("pushBPNeg", kLoadInstType, 1, true, true, false);
break;
case 7:
- OPCODE("pushBPAdd", kLoadInstType, 1, true, true);
+ OPCODE("pushBPAdd", kLoadInstType, 1, true, true, false);
break;
case 8:
if (parameter == 0) {
- OPCODE("popRet", kStoreInstType, -1, false, false);
+ OPCODE("popRet", kStoreInstType, -1, false, false, false);
} else if (parameter == 1) {
- OPCODE("popPos", kReturnInstType, 0, false, false); // Returns from function call
+ OPCODE("popPos", kReturnInstType, 0, false, false, false); // Returns from function call
} else {
// Error: invalid parameter halts execution
throw UnknownOpcodeException(address, opcode);
}
break;
case 9:
- OPCODE("popVar", kStoreInstType, -1, true, true);
+ OPCODE("popVar", kStoreInstType, -1, true, true, false);
break;
case 10:
- OPCODE("popBPNeg", kStoreInstType, -1, true, true);
+ OPCODE("popBPNeg", kStoreInstType, -1, true, true, false);
break;
case 11:
- OPCODE("popBPAdd", kStoreInstType, -1, true, true);
+ OPCODE("popBPAdd", kStoreInstType, -1, true, true, false);
break;
case 12:
- OPCODE("addSP", kStackInstType, -parameter, true, true);
+ OPCODE("addSP", kStackInstType, -parameter, true, true, false);
break;
case 13:
- OPCODE("subSP", kStackInstType, parameter, true, true);
+ OPCODE("subSP", kStackInstType, parameter, true, true, false);
break;
case 14:
parameter = (uint8)parameter;
@@ -475,21 +475,21 @@
// Error: unknown function
throw UnknownOpcodeException(address, opcode);
}
- OPCODE_MD(_funcs[parameter]._name, kSpecialCallInstType, 0, false, false, _funcs[parameter]._metadata)
+ OPCODE_MD(_funcs[parameter]._name, kSpecialCallInstType, 0, false, false, false, _funcs[parameter]._metadata)
break;
case 15:
parameter *= 2;
if (parameter < minFuncAddr)
jumpTargets.insert(_insts.size());
- OPCODE("ifNotJmp", kCondJumpInstType, -1, true, false);
+ OPCODE("ifNotJmp", kCondJumpInstType, -1, true, false, true);
break;
case 16:
if (parameter == 0) {
- OPCODE_MD("boolNegate", kUnaryOpPreInstType, 0, false, false, "!");
+ OPCODE_MD("boolNegate", kUnaryOpPreInstType, 0, false, false, false, "!");
} else if (parameter == 1) {
- OPCODE_MD("arithmeticNegate", kUnaryOpPreInstType, 0, false, false,"-");
+ OPCODE_MD("arithmeticNegate", kUnaryOpPreInstType, 0, false, false, false,"-");
} else if (parameter == 2) {
- OPCODE_MD("bitwiseNegate", kUnaryOpPreInstType, 0, false, false, "~");
+ OPCODE_MD("bitwiseNegate", kUnaryOpPreInstType, 0, false, false, false, "~");
} else {
// Error: invalid parameter halts execution
throw UnknownOpcodeException(address, opcode);
@@ -498,58 +498,58 @@
case 17:
switch (parameter) {
case 0:
- OPCODE_MD("eval_band", kBinaryOpInstType, -1, false, false, "&&");
+ OPCODE_MD("eval_band", kBinaryOpInstType, -1, false, false, false, "&&");
break;
case 1:
- OPCODE_MD("eval_bor", kBinaryOpInstType, -1, false, false, "||");
+ OPCODE_MD("eval_bor", kBinaryOpInstType, -1, false, false, false, "||");
break;
case 2:
- OPCODE_MD("eval_eq", kBinaryOpInstType, -1, false, false, "==");
+ OPCODE_MD("eval_eq", kBinaryOpInstType, -1, false, false, false, "==");
break;
case 3:
- OPCODE_MD("eval_neq", kBinaryOpInstType, -1, false, false, "!=");
+ OPCODE_MD("eval_neq", kBinaryOpInstType, -1, false, false, false, "!=");
break;
case 4:
- OPCODE_MD("eval_leq", kBinaryOpInstType, -1, false, false, "<=");
+ OPCODE_MD("eval_leq", kBinaryOpInstType, -1, false, false, false, "<=");
break;
case 5:
- OPCODE_MD("eval_lt", kBinaryOpInstType, -1, false, false, "<");
+ OPCODE_MD("eval_lt", kBinaryOpInstType, -1, false, false, false, "<");
break;
case 6:
- OPCODE_MD("eval_geq", kBinaryOpInstType, -1, false, false, ">=");
+ OPCODE_MD("eval_geq", kBinaryOpInstType, -1, false, false, false, ">=");
break;
case 7:
- OPCODE_MD("eval_gt", kBinaryOpInstType, -1, false, false, ">");
+ OPCODE_MD("eval_gt", kBinaryOpInstType, -1, false, false, false, ">");
break;
case 8:
- OPCODE_MD("eval_add", kBinaryOpInstType, -1, false, false, "+");
+ OPCODE_MD("eval_add", kBinaryOpInstType, -1, false, false, false, "+");
break;
case 9:
- OPCODE_MD("eval_sub", kBinaryOpInstType, -1, false, false, "-");
+ OPCODE_MD("eval_sub", kBinaryOpInstType, -1, false, false, false, "-");
break;
case 10:
- OPCODE_MD("eval_mult", kBinaryOpInstType, -1, false, false, "*");
+ OPCODE_MD("eval_mult", kBinaryOpInstType, -1, false, false, false, "*");
break;
case 11:
- OPCODE_MD("eval_div", kBinaryOpInstType, -1, false, false, "/");
+ OPCODE_MD("eval_div", kBinaryOpInstType, -1, false, false, false, "/");
break;
case 12:
- OPCODE_MD("eval_shr", kBinaryOpInstType, -1, false, false, ">>");
+ OPCODE_MD("eval_shr", kBinaryOpInstType, -1, false, false, false, ">>");
break;
case 13:
- OPCODE_MD("eval_shl", kBinaryOpInstType, -1, false, false, "<<");
+ OPCODE_MD("eval_shl", kBinaryOpInstType, -1, false, false, false, "<<");
break;
case 14:
- OPCODE_MD("eval_land", kBinaryOpInstType, -1, false, false, "&");
+ OPCODE_MD("eval_land", kBinaryOpInstType, -1, false, false, false, "&");
break;
case 15:
- OPCODE_MD("eval_lor", kBinaryOpInstType, -1, false, false, "|");
+ OPCODE_MD("eval_lor", kBinaryOpInstType, -1, false, false, false, "|");
break;
case 16:
- OPCODE_MD("eval_mod", kBinaryOpInstType, -1, false, false, "%");
+ OPCODE_MD("eval_mod", kBinaryOpInstType, -1, false, false, false, "%");
break;
case 17:
- OPCODE_MD("eval_xor", kBinaryOpInstType, -1, false, false, "^");
+ OPCODE_MD("eval_xor", kBinaryOpInstType, -1, false, false, false, "^");
break;
default:
// Error: invalid parameter halts execution
@@ -558,7 +558,7 @@
}
break;
case 18:
- OPCODE("setRetAndJmp", kSpecialCallInstType, -2, false, false);
+ OPCODE("setRetAndJmp", kSpecialCallInstType, -2, false, false, false);
break;
default:
throw UnknownOpcodeException(i*2, code);
@@ -586,7 +586,7 @@
bool lastWasPushPos = false;
for (InstIterator it = _insts.begin(); it != _insts.end(); ++it) {
if ((*it)->_type == kJumpInstType || (*it)->_type == kCondJumpInstType) {
- if (lastWasPushPos || _engine->_functions.find((*it)->_params[0].getUnsigned()) != _engine->_functions.end()) {
+ if (lastWasPushPos || _engine->_functions.find((*it)->_params[0]->getUnsigned()) != _engine->_functions.end()) {
(*it)->_type = kCallInstType;
}
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.cpp 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.cpp 2010-12-13 02:08:39 UTC (rev 54899)
@@ -33,7 +33,7 @@
}
uint32 Kyra::Kyra2Engine::getDestAddress(const InstPtr inst) const {
- return inst->_params[0].getUnsigned();
+ return inst->_params[0]->getUnsigned();
}
CodeGenerator *Kyra::Kyra2Engine::getCodeGenerator(std::ostream &output) {
@@ -49,8 +49,8 @@
int maxArg = 0;
for (ConstInstIterator instIt = it->second._startIt; instIt != it->second._endIt; ++instIt) {
if ((*instIt)->_name.compare("pushBPAdd") == 0) {
- if (maxArg < (*instIt)->_params[0].getSigned()) {
- maxArg = (*instIt)->_params[0].getSigned();
+ if (maxArg < (*instIt)->_params[0]->getSigned()) {
+ maxArg = (*instIt)->_params[0]->getSigned();
}
}
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp 2010-12-13 02:08:39 UTC (rev 54899)
@@ -54,21 +54,19 @@
case kLoadInstType:
switch (inst->_opcode) {
case 0x00: // pushByte
- _stack.push(new IntValue(inst->_params[0].getUnsigned(), false));
- break;
case 0x01: // pushWord
- _stack.push(new IntValue(inst->_params[0].getSigned(), true));
+ _stack.push(inst->_params[0]);
break;
case 0x02: // pushByteVar
case 0x03: // pushWordVar
- _stack.push(new VarValue(decodeVarName(inst->_params[0].getUnsigned())));
+ _stack.push(new VarValue(decodeVarName(inst->_params[0]->getUnsigned())));
break;
case 0x06: // byteArrayRead
case 0x07: // wordArrayRead
{
ValueList idxs;
idxs.push_front(_stack.pop());
- _stack.push(new ArrayValue(decodeArrayName(inst->_params[0].getUnsigned()), idxs));
+ _stack.push(new ArrayValue(decodeArrayName(inst->_params[0]->getUnsigned()), idxs));
break;
}
case 0x0A: // byteArrayIndexedRead
@@ -77,7 +75,7 @@
ValueList idxs;
idxs.push_front(_stack.pop());
idxs.push_front(_stack.pop());
- _stack.push(new ArrayValue(decodeArrayName(inst->_params[0].getUnsigned()), idxs));
+ _stack.push(new ArrayValue(decodeArrayName(inst->_params[0]->getUnsigned()), idxs));
break;
}
}
@@ -87,7 +85,7 @@
case 0x42: // writeByteVar
case 0x43: // writeWordVar
{
- ValuePtr p = new VarValue(decodeVarName(inst->_params[0].getUnsigned()));
+ ValuePtr p = new VarValue(decodeVarName(inst->_params[0]->getUnsigned()));
writeAssignment(p, _stack.pop());
}
break;
@@ -97,7 +95,7 @@
ValuePtr value = _stack.pop();
ValueList idxs;
idxs.push_back(_stack.pop());
- ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0].getUnsigned()), idxs);
+ ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0]->getUnsigned()), idxs);
writeAssignment(p, value);
}
break;
@@ -108,7 +106,7 @@
ValueList idxs;
idxs.push_front(_stack.pop());
idxs.push_front(_stack.pop());
- ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0].getUnsigned()), idxs);
+ ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0]->getUnsigned()), idxs);
writeAssignment(p, value);
}
break;
@@ -139,7 +137,7 @@
case 0x57: // wordVarDec
{
std::stringstream s;
- ValuePtr p = new UnaryOpValue(new VarValue(decodeVarName(inst->_params[0].getUnsigned())), inst->_codeGenData, true);
+ ValuePtr p = new UnaryOpValue(new VarValue(decodeVarName(inst->_params[0]->getUnsigned())), inst->_codeGenData, true);
s << p << ";";
addOutputLine(s.str());
}
@@ -152,7 +150,7 @@
std::stringstream s;
ValueList idxs;
idxs.push_front(_stack.pop());
- ValuePtr p = new UnaryOpValue(new ArrayValue(decodeVarName(inst->_params[0].getUnsigned()), idxs), inst->_codeGenData, true);
+ ValuePtr p = new UnaryOpValue(new ArrayValue(decodeVarName(inst->_params[0]->getUnsigned()), idxs), inst->_codeGenData, true);
s << p << ";";
addOutputLine(s.str());
}
@@ -166,10 +164,10 @@
switch (inst->_opcode) {
case 0xA4CD: // arrayOp_assignString
{
- ValuePtr value = new StringValue(inst->_params[1].getString());
+ ValuePtr value = new StringValue(inst->_params[1]->getString());
ValueList idxs;
idxs.push_front(_stack.pop());
- ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0].getUnsigned()), idxs);
+ ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0]->getUnsigned()), idxs);
writeAssignment(p, value);
}
break;
@@ -178,7 +176,7 @@
ValueList idxs;
idxs.push_front(_stack.pop());
ValuePtr value = createListValue();
- ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0].getUnsigned()), idxs);
+ ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0]->getUnsigned()), idxs);
writeAssignment(p, value);
}
@@ -189,7 +187,7 @@
idxs.push_front(_stack.pop());
ValuePtr value = createListValue();
idxs.push_front(_stack.pop());
- ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0].getUnsigned()), idxs);
+ ValuePtr p = new ArrayValue(decodeArrayName(inst->_params[0]->getUnsigned()), idxs);
writeAssignment(p, value);
}
@@ -417,25 +415,12 @@
case 'w':
case 'j':
case 'i':
- switch (inst->_params[0]._type) {
- case kSByteParamType:
- case kShortParamType:
- addArg(new IntValue(inst->_params[0].getSigned(), true));
- break;
- case kByteParamType:
- case kUShortParamType:
- addArg(new IntValue(inst->_params[0].getUnsigned(), false));
- break;
- default:
- std::cerr << boost::format("WARNING: Unexpected type for parameter 0 @ %08X while processing metadata character %c") % inst->_address % c;
- break;
- }
- break;
+ addArg(inst->_params[0]);
case 'v':
- addArg(new VarValue(decodeVarName(inst->_params[0].getUnsigned())));
+ addArg(new VarValue(decodeVarName(inst->_params[0]->getUnsigned())));
break;
case 's':
- addArg(new StringValue(inst->_params[0].getString()));
+ addArg(inst->_params[0]);
break;
case 'z':
addArg(_stack.pop());
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp 2010-12-13 02:08:39 UTC (rev 54899)
@@ -100,8 +100,8 @@
OPCODE_MD(0x57, "wordVarDec", kUnaryOpPostInstType, 0, "w", "--");
OPCODE_MD(0x5A, "byteArrayDec", kUnaryOpPostInstType, -1, "B", "--");
OPCODE_MD(0x5B, "wordArrayDec", kUnaryOpPostInstType, -1, "w", "--");
- OPCODE(0x5C, "jumpTrue", kCondJumpRelInstType, -1, "s");
- OPCODE(0x5D, "jumpFalse", kCondJumpRelInstType, -1, "s");
+ OPCODE(0x5C, "jumpTrue", kCondJumpRelInstType, -1, "a");
+ OPCODE(0x5D, "jumpFalse", kCondJumpRelInstType, -1, "a");
OPCODE_MD(0x5E, "startScript", kSpecialCallInstType, 0x1020, "", "lpp"); // Variable stack arguments
OPCODE_MD(0x5F, "startScriptQuick", kSpecialCallInstType, 0x1010, "", "lp"); // Variable stack arguments
OPCODE_MD(0x60, "startObject", kSpecialCallInstType, 0x1030, "", "lppp"); // Variable stack arguments
@@ -137,7 +137,7 @@
OPCODE_MD(0x70, "setState", kSpecialCallInstType, -2, "", "pp");
OPCODE_MD(0x71, "setOwner", kSpecialCallInstType, -2, "", "pp");
OPCODE_MD(0x72, "getOwner", kSpecialCallInstType, 0, "", "rp");
- OPCODE(0x73, "jump", kJumpRelInstType, 0, "s");
+ OPCODE(0x73, "jump", kJumpRelInstType, 0, "a");
OPCODE_MD(0x74, "startSound", kSpecialCallInstType, -1, "", "p");
OPCODE_MD(0x75, "stopSound", kSpecialCallInstType, -1, "", "p");
OPCODE_MD(0x76, "startMusic", kSpecialCallInstType, -1, "", "p");
@@ -449,11 +449,16 @@
for (--it2; popBefore != 0; --it2)
if ((*it2)->_type == kLoadInstType)
--popBefore;
- (*it)->_stackChange -= (*it2)->_params[0].getSigned() + 1;
+ (*it)->_stackChange -= (*it2)->_params[0]->getSigned() + 1;
}
-void Scumm::v6::Scummv6Disassembler::readParameter(Parameter *p, char type) {
+ValuePtr Scumm::v6::Scummv6Disassembler::readParameter(InstPtr inst, char type) {
+ ValuePtr retval = NULL;
switch (type) {
+ case 'a':
+ retval = new RelAddressValue(inst->_address + 3, _f.readSint16LE());
+ _address += 2;
+ break;
case 'c': { // Character string
byte cmd;
bool inStr = false;
@@ -526,12 +531,12 @@
_address++;
if (inStr)
s << '"';
- p->_type = kStringParamType;
- p->_value = s.str();
+ retval = new Scummv6StringValue(s.str());
}
break;
default: // Defer handling to parent implementation
- SimpleDisassembler::readParameter(p, type);
+ retval = SimpleDisassembler::readParameter(inst, type);
break;
}
+ return retval;
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h 2010-12-13 02:08:39 UTC (rev 54899)
@@ -24,6 +24,7 @@
#define DEC_SCUMMV6_DISASM_H
#include "decompiler/simple_disassembler.h"
+#include "engine.h"
namespace Scumm {
@@ -43,7 +44,7 @@
void doDisassemble() throw(std::exception);
- void readParameter(Parameter *p, char type);
+ ValuePtr readParameter(InstPtr inst, char type);
/**
* Determines the actual stack effect of an opcode with a variable stack effect.
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp 2010-12-13 02:08:39 UTC (rev 54899)
@@ -24,6 +24,10 @@
#include "disassembler.h"
#include "codegen.h"
+std::ostream &Scumm::v6::Scummv6StringValue::print(std::ostream &output) const {
+ return output << _str;
+}
+
Disassembler *Scumm::v6::Scummv6Engine::getDisassembler(InstVec &insts) {
return new Scummv6Disassembler(insts);
}
@@ -32,7 +36,7 @@
switch(inst->_type) {
case kJumpRelInstType:
case kCondJumpRelInstType:
- return inst->_params[0].getSigned() + inst->_address + 3;
+ return inst->_params[0]->getUnsigned();
default:
return 0;
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h 2010-12-13 02:08:39 UTC (rev 54899)
@@ -24,11 +24,24 @@
#define SCUMM_V6_ENGINE_H
#include "../engine.h"
+#include "../value.h"
namespace Scumm {
namespace v6 {
+class Scummv6StringValue : public StringValue {
+public:
+ /**
+ * Constructor for Scummv6StringValue.
+ *
+ * @param str The string value.
+ */
+ Scummv6StringValue(std::string str) : StringValue(str) { }
+
+ virtual std::ostream &print(std::ostream &output) const;
+};
+
/**
* SCUMMv6 engine.
*/
Modified: tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp 2010-12-13 02:08:39 UTC (rev 54899)
@@ -27,64 +27,54 @@
void SimpleDisassembler::readParams(InstPtr inst, const char *typeString) {
while (*typeString) {
- Parameter p;
- readParameter(&p, *typeString);
- inst->_params.push_back(p);
+ inst->_params.push_back(readParameter(inst, *typeString));
typeString++;
}
}
-void SimpleDisassembler::readParameter(Parameter *p, char type) {
+ValuePtr SimpleDisassembler::readParameter(InstPtr inst, char type) {
+ ValuePtr retval = NULL;
switch (type) {
case 'b': // signed byte
- p->_type = kSByteParamType;
- p->_value = _f.readChar();
+ retval = new IntValue(_f.readChar(), true);
_address++;
break;
case 'B': // unsigned byte
- p->_type = kByteParamType;
- p->_value = (uint32)_f.readByte();
+ retval = new IntValue((uint32)_f.readByte(), false);
_address++;
break;
case 's': // 16-bit signed integer (short), little-endian
- p->_type = kShortParamType;
- p->_value = _f.readSint16LE();
+ retval = new IntValue(_f.readSint16LE(), true);
_address += 2;
break;
case 'S': // 16-bit signed integer (short), big-endian
- p->_type = kShortParamType;
- p->_value = _f.readSint16BE();
+ retval = new IntValue(_f.readSint16BE(), true);
_address += 2;
break;
case 'w': // 16-bit unsigned integer (word), little-endian
- p->_type = kUShortParamType;
- p->_value = (uint32)_f.readUint16LE();
+ retval = new IntValue((uint32)_f.readUint16LE(), false);
_address += 2;
break;
case 'W': // 16-bit unsigned integer (word), big-endian
- p->_type = kUShortParamType;
- p->_value = (uint32)_f.readUint16BE();
+ retval = new IntValue((uint32)_f.readUint16BE(), false);
_address += 2;
break;
case 'i': // 32-bit signed integer (int), little-endian
- p->_type = kIntParamType;
- p->_value = _f.readSint32LE();
+ retval = new IntValue(_f.readSint32LE(), true);
_address += 4;
break;
case 'I': // 32-bit signed integer (int), big-endian
- p->_type = kIntParamType;
- p->_value = _f.readSint32BE();
+ retval = new IntValue(_f.readSint32BE(), true);
_address += 4;
break;
case 'd': // 32-bit unsigned integer (dword), little-endian
- p->_type = kUIntParamType;
- p->_value = _f.readUint32LE();
+ retval = new IntValue(_f.readUint32LE(), false);
_address += 4;
break;
case 'D': // 32-bit unsigned integer (dword), big-endian
- p->_type = kUIntParamType;
- p->_value = _f.readUint32BE();
+ retval = new IntValue(_f.readUint32BE(), false);
_address += 4;
break;
}
+ return retval;
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h 2010-12-13 02:08:39 UTC (rev 54899)
@@ -43,10 +43,11 @@
/**
* Reads data for a single parameter.
*
- * @param p Pointer to the destination Parameter structure.
+ * @param inst The instruction the parameter will belong to. Used for reference in parameter reading.
* @param type Character describing the type of the parameter.
+ * @return The read data as a ValuePtr.
*/
- virtual void readParameter(Parameter *p, char type);
+ virtual ValuePtr readParameter(InstPtr inst, char type);
public:
/**
Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp 2010-12-13 02:08:39 UTC (rev 54899)
@@ -35,13 +35,13 @@
OPCODE(0x04, "HALT", kSpecialCallInstType, 0, "");
//Jumps
- OPCODE(0x10, "JUMP", kJumpInstType, 0, "d");
- OPCODE(0x11, "JEQ", kCondJumpInstType, 0, "d");
- OPCODE(0x12, "JAEQ", kCondJumpInstType, 0, "d");
- OPCODE(0x13, "JGT", kCondJumpInstType, 0, "d");
- OPCODE(0x14, "JLT", kCondJumpInstType, 0, "d");
- OPCODE(0x15, "JALT", kCondJumpInstType, 0, "d");
- OPCODE(0x16, "JAGT", kCondJumpInstType, 0, "d");
+ OPCODE(0x10, "JUMP", kJumpInstType, 0, "a");
+ OPCODE(0x11, "JEQ", kCondJumpInstType, 0, "a");
+ OPCODE(0x12, "JAEQ", kCondJumpInstType, 0, "a");
+ OPCODE(0x13, "JGT", kCondJumpInstType, 0, "a");
+ OPCODE(0x14, "JLT", kCondJumpInstType, 0, "a");
+ OPCODE(0x15, "JALT", kCondJumpInstType, 0, "a");
+ OPCODE(0x16, "JAGT", kCondJumpInstType, 0, "a");
//Boolean operations
OPCODE(0x20, "OR", kBinaryOpInstType, -1, "");
@@ -130,3 +130,17 @@
OPCODE(0xD9, "BLOAD", kLoadInstType, -5, "");
END_OPCODES;
}
+
+ValuePtr PasCDisassembler::readParameter(InstPtr inst, char type) {
+ ValuePtr retval = NULL;
+ switch (type) {
+ case 'a':
+ retval = new AddressValue(_f.readUint32LE());
+ _address += 4;
+ break;
+ default: // Defer handling to parent implementation
+ retval = SimpleDisassembler::readParameter(inst, type);
+ break;
+ }
+ return retval;
+}
Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h 2010-12-13 02:08:39 UTC (rev 54899)
@@ -29,5 +29,6 @@
public:
PasCDisassembler(InstVec &insts);
void doDisassemble() throw(std::exception);
+ ValuePtr readParameter(InstPtr inst, char type);
};
#endif
Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h 2010-12-13 02:08:39 UTC (rev 54899)
@@ -39,8 +39,8 @@
TS_ASSERT(insts[0]->_opcode == 0x00);
TS_ASSERT(insts[0]->_name == "PUSH");
TS_ASSERT(insts[0]->_stackChange == 0);
- TS_ASSERT(insts[0]->_params[0]._type == kIntParamType);
- TS_ASSERT(insts[0]->_params[0].getSigned() == 0x60);
+ TS_ASSERT(insts[0]->_params[0]->isInteger());
+ TS_ASSERT(insts[0]->_params[0]->getSigned() == 0x60);
} catch (UnknownOpcodeException &uoe) {
printf("Exception message: %s\n", uoe.what());
TS_ASSERT(false);
@@ -89,38 +89,38 @@
TS_ASSERT(insts[0]->_address == 0);
TS_ASSERT(insts[0]->_opcode == 0x03);
TS_ASSERT(insts[0]->_name == "pushWordVar");
- TS_ASSERT(insts[0]->_params[0].getUnsigned() == 16384);
+ TS_ASSERT(insts[0]->_params[0]->getUnsigned() == 16384);
TS_ASSERT(insts[1]->_address == 3);
TS_ASSERT(insts[1]->_opcode == 0x43);
TS_ASSERT(insts[1]->_name == "writeWordVar");
- TS_ASSERT(insts[1]->_params[0].getUnsigned() == 197);
+ TS_ASSERT(insts[1]->_params[0]->getUnsigned() == 197);
TS_ASSERT(insts[2]->_address == 6);
TS_ASSERT(insts[2]->_opcode == 0x01);
TS_ASSERT(insts[2]->_name == "pushWord");
- TS_ASSERT(insts[2]->_params[0].getSigned() == 0);
+ TS_ASSERT(insts[2]->_params[0]->getSigned() == 0);
TS_ASSERT(insts[3]->_address == 9);
TS_ASSERT(insts[3]->_opcode == 0x01);
TS_ASSERT(insts[3]->_name == "pushWord");
- TS_ASSERT(insts[3]->_params[0].getSigned() == 11);
+ TS_ASSERT(insts[3]->_params[0]->getSigned() == 11);
TS_ASSERT(insts[4]->_address == 12);
TS_ASSERT(insts[4]->_opcode == 0x01);
TS_ASSERT(insts[4]->_name == "pushWord");
- TS_ASSERT(insts[4]->_params[0].getSigned() == 0);
+ TS_ASSERT(insts[4]->_params[0]->getSigned() == 0);
TS_ASSERT(insts[5]->_address == 15);
TS_ASSERT(insts[5]->_opcode == 0x5E);
TS_ASSERT(insts[5]->_name == "startScript");
TS_ASSERT(insts[6]->_address == 16);
TS_ASSERT(insts[6]->_opcode == 0x01);
TS_ASSERT(insts[6]->_name == "pushWord");
- TS_ASSERT(insts[6]->_params[0].getSigned() == 0);
+ TS_ASSERT(insts[6]->_params[0]->getSigned() == 0);
TS_ASSERT(insts[7]->_address == 19);
TS_ASSERT(insts[7]->_opcode == 0x01);
TS_ASSERT(insts[7]->_name == "pushWord");
- TS_ASSERT(insts[7]->_params[0].getSigned() == 14);
+ TS_ASSERT(insts[7]->_params[0]->getSigned() == 14);
TS_ASSERT(insts[8]->_address == 22);
TS_ASSERT(insts[8]->_opcode == 0x01);
TS_ASSERT(insts[8]->_name == "pushWord");
- TS_ASSERT(insts[8]->_params[0].getSigned() == 0);
+ TS_ASSERT(insts[8]->_params[0]->getSigned() == 0);
TS_ASSERT(insts[9]->_address == 25);
TS_ASSERT(insts[9]->_opcode == 0x5E);
TS_ASSERT(insts[9]->_name == "startScript");
@@ -144,19 +144,19 @@
TS_ASSERT(insts[0]->_address == 0);
TS_ASSERT(insts[0]->_opcode == 0x01);
TS_ASSERT(insts[0]->_name == "pushWord");
- TS_ASSERT(insts[0]->_params[0].getSigned() == 0);
+ TS_ASSERT(insts[0]->_params[0]->getSigned() == 0);
TS_ASSERT(insts[1]->_address == 3);
TS_ASSERT(insts[1]->_opcode == 0x43);
TS_ASSERT(insts[1]->_name == "writeWordVar");
- TS_ASSERT(insts[1]->_params[0].getUnsigned() == 180);
+ TS_ASSERT(insts[1]->_params[0]->getUnsigned() == 180);
TS_ASSERT(insts[2]->_address == 6);
TS_ASSERT(insts[2]->_opcode == 0x01);
TS_ASSERT(insts[2]->_name == "pushWord");
- TS_ASSERT(insts[2]->_params[0].getSigned() == 0);
+ TS_ASSERT(insts[2]->_params[0]->getSigned() == 0);
TS_ASSERT(insts[3]->_address == 9);
TS_ASSERT(insts[3]->_opcode == 0x43);
TS_ASSERT(insts[3]->_name == "writeWordVar");
- TS_ASSERT(insts[3]->_params[0].getUnsigned() == 181);
+ TS_ASSERT(insts[3]->_params[0]->getUnsigned() == 181);
TS_ASSERT(insts[4]->_address == 12);
TS_ASSERT(insts[4]->_opcode == 0x66);
TS_ASSERT(insts[4]->_name == "stopObjectCodeB");
@@ -177,35 +177,35 @@
TS_ASSERT(insts[0]->_address == 0);
TS_ASSERT(insts[0]->_opcode == 0x01);
TS_ASSERT(insts[0]->_name == "pushWord");
- TS_ASSERT(insts[0]->_params[0].getSigned() == 0);
+ TS_ASSERT(insts[0]->_params[0]->getSigned() == 0);
TS_ASSERT(insts[1]->_address == 3);
TS_ASSERT(insts[1]->_opcode == 0x43);
TS_ASSERT(insts[1]->_name == "writeWordVar");
- TS_ASSERT(insts[1]->_params[0].getUnsigned() == 71);
+ TS_ASSERT(insts[1]->_params[0]->getUnsigned() == 71);
TS_ASSERT(insts[2]->_address == 6);
TS_ASSERT(insts[2]->_opcode == 0x03);
TS_ASSERT(insts[2]->_name == "pushWordVar");
- TS_ASSERT(insts[2]->_params[0].getUnsigned() == 177);
+ TS_ASSERT(insts[2]->_params[0]->getUnsigned() == 177);
TS_ASSERT(insts[3]->_address == 9);
TS_ASSERT(insts[3]->_opcode == 0x43);
TS_ASSERT(insts[3]->_name == "writeWordVar");
- TS_ASSERT(insts[3]->_params[0].getUnsigned() == 173);
+ TS_ASSERT(insts[3]->_params[0]->getUnsigned() == 173);
TS_ASSERT(insts[4]->_address == 12);
TS_ASSERT(insts[4]->_opcode == 0x01);
TS_ASSERT(insts[4]->_name == "pushWord");
- TS_ASSERT(insts[4]->_params[0].getSigned() == 874);
+ TS_ASSERT(insts[4]->_params[0]->getSigned() == 874);
TS_ASSERT(insts[5]->_address == 15);
TS_ASSERT(insts[5]->_opcode == 0x43);
TS_ASSERT(insts[5]->_name == "writeWordVar");
- TS_ASSERT(insts[5]->_params[0].getUnsigned() == 177);
+ TS_ASSERT(insts[5]->_params[0]->getUnsigned() == 177);
TS_ASSERT(insts[6]->_address == 18);
TS_ASSERT(insts[6]->_opcode == 0x03);
TS_ASSERT(insts[6]->_name == "pushWordVar");
- TS_ASSERT(insts[6]->_params[0].getUnsigned() == 177);
+ TS_ASSERT(insts[6]->_params[0]->getUnsigned() == 177);
TS_ASSERT(insts[7]->_address == 21);
TS_ASSERT(insts[7]->_opcode == 0x01);
TS_ASSERT(insts[7]->_name == "pushWord");
- TS_ASSERT(insts[7]->_params[0].getSigned() == 93);
+ TS_ASSERT(insts[7]->_params[0]->getSigned() == 93);
TS_ASSERT(insts[8]->_address == 24);
TS_ASSERT(insts[8]->_opcode == 0x6B99);
TS_ASSERT(insts[8]->_name == "cursorCommand.setCursorImg");
Modified: tools/branches/gsoc2010-decompiler/decompiler/value.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/value.cpp 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/value.cpp 2010-12-13 02:08:39 UTC (rev 54899)
@@ -23,6 +23,7 @@
#include "value.h"
#include <boost/format.hpp>
+#include <sstream>
static int dupindex = 0;
@@ -56,6 +57,12 @@
return new NegatedValue(this);
}
+std::string Value::getString() const {
+ std::stringstream s;
+ print(s);
+ return s.str();
+}
+
bool IntValue::isInteger() {
return true;
}
@@ -97,7 +104,7 @@
}
std::ostream &AddressValue::print(std::ostream &output) const {
- return output << boost::format("0x%x") % _val;
+ return output << boost::format("0x%X") % _val;
}
bool RelAddressValue::isAddress() {
@@ -114,8 +121,8 @@
std::ostream &RelAddressValue::print(std::ostream &output) const {
if (_val < 0)
- return output << boost::format("-0x%x") % -_val;
- return output << boost::format("+0x%x") % _val;
+ return output << boost::format("-0x%X") % -_val;
+ return output << boost::format("+0x%X") % _val;
}
ValuePtr DupValue::dup(std::ostream &output) {
Modified: tools/branches/gsoc2010-decompiler/decompiler/value.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/value.h 2010-12-13 00:20:45 UTC (rev 54898)
+++ tools/branches/gsoc2010-decompiler/decompiler/value.h 2010-12-13 02:08:39 UTC (rev 54899)
@@ -104,6 +104,13 @@
virtual std::ostream &print(std::ostream &output) const = 0;
/**
+ * Retrieves the string representation of the value.
+ *
+ * @return The string representation of the value.
+ */
+ std::string getString() const;
+
+ /**
* Duplicates a value.
*
* @param output The std::ostream to output any necessary assignment to.
@@ -171,7 +178,7 @@
* Value containing an absolute address.
*/
class AddressValue : public IntValue {
-protected:
+public:
/**
* Constructor for AddressValue.
*/
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