[Scummvm-cvs-logs] SF.net SVN: scummvm:[49381] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Tue Jun 1 23:20:36 CEST 2010
Revision: 49381
http://scummvm.svn.sourceforge.net/scummvm/?rev=49381&view=rev
Author: pidgeot
Date: 2010-06-01 21:20:35 +0000 (Tue, 01 Jun 2010)
Log Message:
-----------
Refactored Parameter struct to use boost::variant
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/instruction.h
tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h
tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp 2010-06-01 20:37:55 UTC (rev 49380)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp 2010-06-01 21:20:35 UTC (rev 49381)
@@ -40,29 +40,7 @@
Parameter p = inst._params[j];
if (j != 0)
output << ", ";
- switch(p._type) {
- case kSByte:
- output << p._sbyte;
- break;
- case kByte:
- output << p._byte;
- break;
- case kShort:
- output << p._short;
- break;
- case kUShort:
- output << p._ushort;
- break;
- case kInt:
- output << p._int;
- break;
- case kUInt:
- output << p._uint;
- break;
- case kFloat:
- output << p._float;
- break;
- }
+ output << p._value;
}
output << "\n";
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-06-01 20:37:55 UTC (rev 49380)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-06-01 21:20:35 UTC (rev 49381)
@@ -25,6 +25,7 @@
#include <string>
#include <vector>
+#include <boost/variant.hpp>
#include "common/scummsys.h"
@@ -55,7 +56,7 @@
kUShort, ///<Unsigned 16-bit integer.
kInt, ///<Signed 32-bit integer.
kUInt, ///<Unsigned 32-bit integer.
- kFloat ///<Single-precision IEEE 754 floating-point value.
+ kString ///<Text string.
};
/**
@@ -63,15 +64,10 @@
*/
struct Parameter {
ParamType _type; ///<Type of the parameter.
- union {
- int8 _sbyte;
- uint8 _byte;
- int16 _short;
- uint16 _ushort;
- int32 _int;
- uint32 _uint;
- float _float;
- }; ///<Value of the parameter.
+ boost::variant<int32, uint32, std::string> _value; ///<Value of the parameter.
+ int32 getSigned() { return boost::get<int32>(_value); }
+ uint32 getUnsigned() { return boost::get<uint32>(_value); }
+ std::string getString() { return boost::get<std::string>(_value); }
};
/**
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp 2010-06-01 20:37:55 UTC (rev 49380)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp 2010-06-01 21:20:35 UTC (rev 49381)
@@ -120,7 +120,21 @@
OPCODE(0xD6, "cursorCmd_Transparent", kSpecial, -1, "");
END_SUBOPCODE;
OPCODE(0x6C, "breakHere", kSpecial, 0, "");
+ OPCODE(0x6D, "ifClassOfIs", kSpecial, 0, ""); //Variable stack arguments
END_OPCODES;
return _insts;
}
+
+void ScummV6Disassembler::readParameter(Parameter *p, char type)
+{
+ switch (type)
+ {
+ case 'c': //Character string
+ //TODO
+ break;
+ default: //Defer handling to parent implementation
+ SimpleDisassembler::readParameter(p, type);
+ break;
+ }
+}
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h 2010-06-01 20:37:55 UTC (rev 49380)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h 2010-06-01 21:20:35 UTC (rev 49381)
@@ -30,7 +30,9 @@
*/
class ScummV6Disassembler : public SimpleDisassembler {
public:
- virtual std::vector<Instruction> disassemble();
+ std::vector<Instruction> disassemble();
+
+ void readParameter(Parameter *p, char type);
};
#endif
Modified: tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp 2010-06-01 20:37:55 UTC (rev 49380)
+++ tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp 2010-06-01 21:20:35 UTC (rev 49381)
@@ -35,64 +35,53 @@
switch (type) {
case 'b': //signed byte
p->_type = kSByte;
- p->_sbyte = _f.readChar();
+ p->_value = _f.readChar();
_address++;
break;
case 'B': //unsigned byte
p->_type = kByte;
- p->_byte = _f.readByte();
+ p->_value = (uint32)_f.readByte();
_address++;
break;
case 's': //16-bit signed integer (short), little-endian
p->_type = kShort;
- p->_short = _f.readSint16LE();
+ p->_value = _f.readSint16LE();
_address += 2;
break;
case 'S': //16-bit signed integer (short), big-endian
p->_type = kShort;
- p->_short = _f.readSint16BE();
+ p->_value = _f.readSint16BE();
_address += 2;
break;
case 'w': //16-bit unsigned integer (word), little-endian
p->_type = kUShort;
- p->_ushort = _f.readUint16LE();
+ p->_value = (uint32)_f.readUint16LE();
_address += 2;
break;
case 'W': //16-bit unsigned integer (word), big-endian
p->_type = kUShort;
- p->_ushort = _f.readUint16BE();
+ p->_value = (uint32)_f.readUint16BE();
_address += 2;
break;
case 'i': //32-bit signed integer (int), little-endian
p->_type = kInt;
- p->_int = _f.readSint32LE();
+ p->_value = _f.readSint32LE();
_address += 4;
break;
case 'I': //32-bit signed integer (int), big-endian
p->_type = kInt;
- p->_int = _f.readSint32BE();
+ p->_value = _f.readSint32BE();
_address += 4;
break;
case 'd': //32-bit unsigned integer (dword), little-endian
p->_type = kUInt;
- p->_uint = _f.readUint32LE();
+ p->_value = _f.readUint32LE();
_address += 4;
break;
case 'D': //32-bit unsigned integer (dword), big-endian
p->_type = kUInt;
- p->_uint = _f.readUint32BE();
+ p->_value = _f.readUint32BE();
_address += 4;
break;
- // Common::File doesn't have readFloat methods, but since the value is stored in a union, we just need to read the right bytes into memory.
- case 'f': //Single-precision float, little-endian
- p->_type = kFloat;
- p->_uint = _f.readUint32LE();
- _address += 4;
- break;
- case 'F': //Single-precision float, big-endian
- p->_type = kFloat;
- p->_uint = _f.readUint32BE();
- _address += 4;
- break;
}
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h 2010-06-01 20:37:55 UTC (rev 49380)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h 2010-06-01 21:20:35 UTC (rev 49381)
@@ -37,7 +37,7 @@
TS_ASSERT(insts[0]._name == "PUSH");
TS_ASSERT(insts[0]._stackChange == 0);
TS_ASSERT(insts[0]._params[0]._type == kInt);
- TS_ASSERT(insts[0]._params[0]._uint == 0x60);
+ TS_ASSERT(insts[0]._params[0].getSigned() == 0x60);
} catch (UnknownOpcodeException &uoe) {
printf("Exception message: %s\n", uoe.what());
TS_ASSERT(false);
@@ -79,15 +79,15 @@
s.open("decompiler/test/script-15.dmp");
std::vector<Instruction> insts = s.disassemble();
TS_ASSERT(insts.size() == 11);
- TS_ASSERT(insts[0]._address == 0 && insts[0]._name == "pushWordVar" && insts[0]._params[0]._ushort == 16384);
- TS_ASSERT(insts[1]._address == 3 && insts[1]._name == "writeWordVar" && insts[1]._params[0]._ushort == 197);
- TS_ASSERT(insts[2]._address == 6 && insts[2]._name == "pushWord" && insts[2]._params[0]._ushort == 0);
- TS_ASSERT(insts[3]._address == 9 && insts[3]._name == "pushWord" && insts[3]._params[0]._ushort == 11);
- TS_ASSERT(insts[4]._address == 12 && insts[4]._name == "pushWord" && insts[4]._params[0]._ushort == 0);
+ TS_ASSERT(insts[0]._address == 0 && insts[0]._name == "pushWordVar" && insts[0]._params[0].getUnsigned() == 16384);
+ TS_ASSERT(insts[1]._address == 3 && insts[1]._name == "writeWordVar" && insts[1]._params[0].getUnsigned() == 197);
+ TS_ASSERT(insts[2]._address == 6 && insts[2]._name == "pushWord" && insts[2]._params[0].getUnsigned() == 0);
+ TS_ASSERT(insts[3]._address == 9 && insts[3]._name == "pushWord" && insts[3]._params[0].getUnsigned() == 11);
+ TS_ASSERT(insts[4]._address == 12 && insts[4]._name == "pushWord" && insts[4]._params[0].getUnsigned() == 0);
TS_ASSERT(insts[5]._address == 15 && insts[5]._name == "startScript");
- TS_ASSERT(insts[6]._address == 16 && insts[6]._name == "pushWord" && insts[6]._params[0]._ushort == 0);
- TS_ASSERT(insts[7]._address == 19 && insts[7]._name == "pushWord" && insts[7]._params[0]._ushort == 14);
- TS_ASSERT(insts[8]._address == 22 && insts[8]._name == "pushWord" && insts[8]._params[0]._ushort == 0);
+ TS_ASSERT(insts[6]._address == 16 && insts[6]._name == "pushWord" && insts[6]._params[0].getUnsigned() == 0);
+ TS_ASSERT(insts[7]._address == 19 && insts[7]._name == "pushWord" && insts[7]._params[0].getUnsigned() == 14);
+ TS_ASSERT(insts[8]._address == 22 && insts[8]._name == "pushWord" && insts[8]._params[0].getUnsigned() == 0);
TS_ASSERT(insts[9]._address == 25 && insts[9]._name == "startScript");
TS_ASSERT(insts[10]._address == 26 && insts[10]._name == "stopObjectCodeB");
} catch (...) {
@@ -103,10 +103,10 @@
s.open("decompiler/test/script-31.dmp");
std::vector<Instruction> insts = s.disassemble();
TS_ASSERT(insts.size() == 5);
- TS_ASSERT(insts[0]._address == 0 && insts[0]._name == "pushWord" && insts[0]._params[0]._ushort == 0);
- TS_ASSERT(insts[1]._address == 3 && insts[1]._name == "writeWordVar" && insts[1]._params[0]._ushort == 180);
- TS_ASSERT(insts[2]._address == 6 && insts[2]._name == "pushWord" && insts[2]._params[0]._ushort == 0);
- TS_ASSERT(insts[3]._address == 9 && insts[3]._name == "writeWordVar" && insts[3]._params[0]._ushort == 181);
+ TS_ASSERT(insts[0]._address == 0 && insts[0]._name == "pushWord" && insts[0]._params[0].getUnsigned() == 0);
+ TS_ASSERT(insts[1]._address == 3 && insts[1]._name == "writeWordVar" && insts[1]._params[0].getUnsigned() == 180);
+ TS_ASSERT(insts[2]._address == 6 && insts[2]._name == "pushWord" && insts[2]._params[0].getUnsigned() == 0);
+ TS_ASSERT(insts[3]._address == 9 && insts[3]._name == "writeWordVar" && insts[3]._params[0].getUnsigned() == 181);
TS_ASSERT(insts[4]._address == 12 && insts[4]._name == "stopObjectCodeB");
} catch (...) {
TS_ASSERT(false);
@@ -121,14 +121,14 @@
s.open("decompiler/test/script-33.dmp");
std::vector<Instruction> insts = s.disassemble();
TS_ASSERT(insts.size() == 10);
- TS_ASSERT(insts[0]._address == 0 && insts[0]._name == "pushWord" && insts[0]._params[0]._ushort == 0);
- TS_ASSERT(insts[1]._address == 3 && insts[1]._name == "writeWordVar" && insts[1]._params[0]._ushort == 71);
- TS_ASSERT(insts[2]._address == 6 && insts[2]._name == "pushWordVar" && insts[2]._params[0]._ushort == 177);
- TS_ASSERT(insts[3]._address == 9 && insts[3]._name == "writeWordVar" && insts[3]._params[0]._ushort == 173);
- TS_ASSERT(insts[4]._address == 12 && insts[4]._name == "pushWord" && insts[4]._params[0]._ushort == 874);
- TS_ASSERT(insts[5]._address == 15 && insts[5]._name == "writeWordVar" && insts[5]._params[0]._ushort == 177);
- TS_ASSERT(insts[6]._address == 18 && insts[6]._name == "pushWordVar" && insts[6]._params[0]._ushort == 177);
- TS_ASSERT(insts[7]._address == 21 && insts[7]._name == "pushWord" && insts[7]._params[0]._ushort == 93);
+ TS_ASSERT(insts[0]._address == 0 && insts[0]._name == "pushWord" && insts[0]._params[0].getUnsigned() == 0);
+ TS_ASSERT(insts[1]._address == 3 && insts[1]._name == "writeWordVar" && insts[1]._params[0].getUnsigned() == 71);
+ TS_ASSERT(insts[2]._address == 6 && insts[2]._name == "pushWordVar" && insts[2]._params[0].getUnsigned() == 177);
+ TS_ASSERT(insts[3]._address == 9 && insts[3]._name == "writeWordVar" && insts[3]._params[0].getUnsigned() == 173);
+ TS_ASSERT(insts[4]._address == 12 && insts[4]._name == "pushWord" && insts[4]._params[0].getUnsigned() == 874);
+ TS_ASSERT(insts[5]._address == 15 && insts[5]._name == "writeWordVar" && insts[5]._params[0].getUnsigned() == 177);
+ TS_ASSERT(insts[6]._address == 18 && insts[6]._name == "pushWordVar" && insts[6]._params[0].getUnsigned() == 177);
+ TS_ASSERT(insts[7]._address == 21 && insts[7]._name == "pushWord" && insts[7]._params[0].getUnsigned() == 93);
TS_ASSERT(insts[8]._address == 24 && insts[8]._name == "cursorCmd_Image");
TS_ASSERT(insts[9]._address == 26 && insts[9]._name == "stopObjectCodeB");
} catch (...) {
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