[Scummvm-cvs-logs] SF.net SVN: scummvm:[49272] tools/branches/gsoc2010-decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Fri May 28 00:10:25 CEST 2010
Revision: 49272
http://scummvm.svn.sourceforge.net/scummvm/?rev=49272&view=rev
Author: pidgeot
Date: 2010-05-27 22:10:25 +0000 (Thu, 27 May 2010)
Log Message:
-----------
Tests for SimpleDisassembler
Added cxxtest to project (using svn:externals)
Written test cases for SimpleDisassembler (ticket #2)
Fixed bugs found from tests
Added support for single-precision floating point values as parameters
This completes the last task for Milestone 1: Disassembly framework.
Next milestone: First disassembler (SCUMMv6)
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/Makefile.common
tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/disassembler.h
tools/branches/gsoc2010-decompiler/decompiler/instruction.h
tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h
tools/branches/gsoc2010-decompiler/decompiler/unknown_opcode.h
Added Paths:
-----------
tools/branches/gsoc2010-decompiler/decompiler/test/
tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/
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/subopcode.cpp
tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.h
tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h
tools/branches/gsoc2010-decompiler/decompiler/test/hanoi20.pasb
tools/branches/gsoc2010-decompiler/decompiler/test/module.mk
tools/branches/gsoc2010-decompiler/decompiler/test/subopcode_test.bin
tools/branches/gsoc2010-decompiler/decompiler/test/unknownopcode_test.bin
Modified: tools/branches/gsoc2010-decompiler/Makefile.common
===================================================================
--- tools/branches/gsoc2010-decompiler/Makefile.common 2010-05-27 21:20:07 UTC (rev 49271)
+++ tools/branches/gsoc2010-decompiler/Makefile.common 2010-05-27 22:10:25 UTC (rev 49272)
@@ -42,7 +42,6 @@
engines/touche/ \
engines/tucker/
-
# TODO: This file should be restructured and much of it moved
# to module.mk style files.
@@ -267,6 +266,9 @@
decompile_LIBS := \
-lboost_program_options
+# Decompiler tests
+-include decompiler/test/module.mk
+
# Make base/version.o depend on all other object files. This way if anything is
# changed, it causes version.cpp to be recompiled. This in turn ensures that
# the build date in gScummVMBuildDate is correct.
Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp 2010-05-27 21:20:07 UTC (rev 49271)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp 2010-05-27 22:10:25 UTC (rev 49272)
@@ -30,7 +30,7 @@
Common::File _output;
_output.open(filename, "w");
- char* buf;
+ char buf[1024];
int length;
for (size_t i = 0; i < _insts.size(); i++)
@@ -49,19 +49,22 @@
break;
case kByte:
length += sprintf(&buf[length], "%u", p._byte);
- break;
+ break;
case kShort:
length += sprintf(&buf[length], "%d", p._short);
- break;
+ break;
case kUShort:
length += sprintf(&buf[length], "%u", p._ushort);
- break;
+ break;
case kInt:
length += sprintf(&buf[length], "%d", p._int);
- break;
+ break;
case kUInt:
length += sprintf(&buf[length], "%u", p._uint);
- break;
+ break;
+ case kFloat:
+ length += sprintf(&buf[length], "%f", p._float);
+ break;
}
}
buf[length] = '\n';
Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.h 2010-05-27 21:20:07 UTC (rev 49271)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.h 2010-05-27 22:10:25 UTC (rev 49272)
@@ -29,6 +29,9 @@
#include "common/file.h"
#include "unknown_opcode.h"
+/**
+ * Base class for disassemblers.
+ */
class Disassembler {
protected:
Common::File _f; ///<Used to perform file I/O.
@@ -36,7 +39,7 @@
uint32 _addressBase; ///<Base address where the script starts.
public:
- virtual ~Disassembler() {};
+ virtual ~Disassembler() {}
/**
* Open a file for disassembly.
Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-05-27 21:20:07 UTC (rev 49271)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-05-27 22:10:25 UTC (rev 49272)
@@ -32,26 +32,30 @@
* Enumeration for categorizing the different kinds of instructions.
*/
enum InstType {
- kArithmetic,
- kBoolean,
- kComparison,
- kCondJump,
- kJump,
- kLoad,
- kSpecial,
- kStore
+ kArithmetic, ///<Arithmetic instruction (+, -, *, etc.).
+ kBoolean, ///<Boolean instruction (AND, OR, etc.).
+ kCall, ///<Regular function call.
+ kComparison, ///<Comparison instruction.
+ kCondJump, ///<Conditional jump.
+ kJump, ///<Unconditional jump.
+ kLoad, ///<Load value to stack.
+ kReturn, ///<Return from regular function call.
+ kSpecial, ///<Special functions.
+ kStack, ///<Stack allocation or deallocation (altering stack pointer).
+ kStore ///<Store value from stack in memory.
};
/**
* Enumeration for categorizing the different kinds of parameters.
*/
enum ParamType {
- kSByte,
- kByte,
- kShort,
- kUShort,
- kInt,
- kUInt
+ kSByte, ///<Signed 8-bit integer.
+ kByte, ///<Unsigned 8-bit integer.
+ kShort, ///<Signed 16-bit integer.
+ kUShort, ///<Unsigned 16-bit integer.
+ kInt, ///<Signed 32-bit integer.
+ kUInt, ///<Unsigned 32-bit integer.
+ kFloat ///<Single-precision IEEE 754 floating-point value.
};
/**
@@ -66,6 +70,7 @@
uint16 _ushort;
int32 _int;
uint32 _uint;
+ float _float;
}; ///<Value of the parameter.
};
Modified: tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp 2010-05-27 21:20:07 UTC (rev 49271)
+++ tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.cpp 2010-05-27 22:10:25 UTC (rev 49272)
@@ -22,53 +22,71 @@
#include "simple_disassembler.h"
-void SimpleDisassembler::readParams(Instruction *inst, char *typeString)
-{
- while (*typeString)
- {
+void SimpleDisassembler::readParams(Instruction *inst, char *typeString) {
+ while (*typeString) {
Parameter p;
- switch (*typeString)
- {
+ switch (*typeString) {
case 'b': //signed byte
p._type = kSByte;
p._sbyte = _f.readChar();
+ _address++;
break;
case 'B': //unsigned byte
p._type = kByte;
p._byte = _f.readByte();
+ _address++;
break;
- case 's': //16-bit integer (short), little-endian
+ case 's': //16-bit signed integer (short), little-endian
p._type = kShort;
p._short = _f.readSint16LE();
+ _address += 2;
break;
- case 'S': //16-bit integer (short), big-endian
+ case 'S': //16-bit signed integer (short), big-endian
p._type = kShort;
p._short = _f.readSint16BE();
+ _address += 2;
break;
- case 'w': //16-bit integer (word), little-endian
+ case 'w': //16-bit unsigned integer (word), little-endian
p._type = kUShort;
p._ushort = _f.readUint16LE();
+ _address += 2;
break;
- case 'W': //16-bit integer (word), big-endian
+ case 'W': //16-bit unsigned integer (word), big-endian
p._type = kUShort;
p._ushort = _f.readUint16BE();
+ _address += 2;
break;
- case 'i': //32-bit integer (int), little-endian
+ case 'i': //32-bit signed integer (int), little-endian
p._type = kInt;
p._int = _f.readSint32LE();
+ _address += 4;
break;
- case 'I': //32-bit integer (int), big-endian
+ case 'I': //32-bit signed integer (int), big-endian
p._type = kInt;
p._int = _f.readSint32BE();
+ _address += 4;
break;
- case 'd': //32-bit integer (dword), little-endian
+ case 'd': //32-bit unsigned integer (dword), little-endian
p._type = kUInt;
p._uint = _f.readUint32LE();
+ _address += 4;
break;
- case 'D': //32-bit integer (dword), big-endian
+ case 'D': //32-bit unsigned integer (dword), big-endian
p._type = kUInt;
p._uint = _f.readUint32BE();
+ _address += 4;
break;
+ // Common::File doesn't have readFloat methods, but since the valueis 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;
}
inst->_params.push_back(p);
typeString++;
Modified: tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h 2010-05-27 21:20:07 UTC (rev 49271)
+++ tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h 2010-05-27 22:10:25 UTC (rev 49272)
@@ -28,8 +28,7 @@
/**
* Simple disassembler acting as a base for instruction sets only consisting of simple instructions (opcode params...).
*/
-class SimpleDisassembler : public Disassembler
-{
+class SimpleDisassembler : public Disassembler {
protected:
uint32 _address; ///<Variable to maintain the current address.
@@ -43,10 +42,10 @@
#define INC_ADDR _address++;
#define ADD_INST _insts.push_back(Instruction());
-#define LAST_INST (_insts[insts.size()-1])
+#define LAST_INST (_insts[_insts.size()-1])
#define START_OPCODES \
- while (!_f.eos()) { \
+ while (_f.pos() != _f.size()) { \
uint8 opcode = _f.readByte(); \
switch (opcode) {
#define END_OPCODES \
@@ -65,12 +64,12 @@
LAST_INST._stackChange = stackChange; \
LAST_INST._name = std::string(name); \
LAST_INST._type = category; \
- readParams(LAST_INST, params); \
+ readParams(&LAST_INST, (char*)params); \
break;
#define START_SUBOPCODE(val) \
OPCODE_BASE(val) \
- uint8 opcode = _f.readByte(); \
+ opcode = _f.readByte(); \
switch (opcode) {
#define END_SUBOPCODE \
default: \
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test
___________________________________________________________________
Added: svn:ignore
+ runner
runner.cpp
*.dSYM
Added: svn:externals
+ cxxtest https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/test/cxxtest
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler
___________________________________________________________________
Added: svn:ignore
+ .deps
Added: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp 2010-05-27 22:10:25 UTC (rev 49272)
@@ -0,0 +1,131 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
+#include "pasc.h"
+
+std::vector<Instruction> PasCDisassembler::disassemble() {
+ START_OPCODES;
+ //Basic machine operations
+ OPCODE(0x00, "PUSH", kStack, 0, "i");
+ OPCODE(0x01, "POP", kStack, 0, "i");
+ OPCODE(0x02, "CALL", kCall, 0, "d");
+ OPCODE(0x03, "RETURN", kReturn, 0, "");
+ OPCODE(0x04, "HALT", kSpecial, 0, "");
+
+ //Jumps
+ OPCODE(0x10, "JUMP", kJump, 0, "d");
+ OPCODE(0x11, "JEQ", kCondJump, 0, "d");
+ OPCODE(0x12, "JAEQ", kCondJump, 0, "d");
+ OPCODE(0x13, "JGT", kCondJump, 0, "d");
+ OPCODE(0x14, "JLT", kCondJump, 0, "d");
+ OPCODE(0x15, "JALT", kCondJump, 0, "d");
+ OPCODE(0x16, "JAGT", kCondJump, 0, "d");
+
+ //Boolean operations
+ OPCODE(0x20, "OR", kBoolean, -1, "");
+ OPCODE(0x21, "AND", kBoolean, -1, "");
+ OPCODE(0x22, "XOR", kBoolean, -1, "");
+ OPCODE(0x23, "NOT", kBoolean, -1, "");
+
+ //Padding instructions (smaller integer -> larger integer)
+ OPCODE(0x30, "SPAD", kSpecial, 0, "B");
+ OPCODE(0x31, "UPAD", kSpecial, 0, "B");
+
+ //32-bit operations
+ OPCODE(0x80, "IADD", kArithmetic, -4, "");
+ OPCODE(0x81, "ISUB", kArithmetic, -4, "");
+ OPCODE(0x82, "IMULT", kArithmetic, -4, "");
+ OPCODE(0x83, "IDIV", kArithmetic, -4, "");
+ OPCODE(0x84, "IMOD", kArithmetic, -4, "");
+ OPCODE(0x85, "ISHL", kArithmetic, -4, "");
+ OPCODE(0x86, "ISHR", kArithmetic, -4, "");
+ OPCODE(0x87, "ISTOREA [SB]", kStore, -4, "i");
+ OPCODE(0x88, "ISTOREL [SB]", kStore, 0, "ii");
+ OPCODE(0x89, "ILOADA [SB]", kLoad, 4, "i");
+ OPCODE(0x8A, "ISTOREA", kStore, -4, "d");
+ OPCODE(0x8B, "ISTOREL", kStore, 0, "di");
+ OPCODE(0x8C, "ILOADA", kLoad, 4, "d");
+ OPCODE(0x8D, "ILOADL", kLoad, 0, "i");
+ OPCODE(0x8E, "ICMP", kComparison, -8, "");
+ OPCODE(0x8F, "UICMP", kComparison, -8, "");
+ OPCODE(0x90, "IDUP", kLoad, 4, "");
+ OPCODE(0x91, "IPRINT", kSpecial, -4, "");
+ OPCODE(0x92, "UIPRINT", kSpecial, -4, "");
+ OPCODE(0x96, "ISTORE [SB]", kStore, -8, "");
+ OPCODE(0x97, "ISTORE", kStore, -8, "");
+ OPCODE(0x98, "ILOAD [SB]", kLoad, -8, "");
+ OPCODE(0x99, "ILOAD", kLoad, -8, "");
+
+ //16-bit operations
+ OPCODE(0xA0, "SADD", kArithmetic, -2, "");
+ OPCODE(0xA1, "SSUB", kArithmetic, -2, "");
+ OPCODE(0xA2, "SMULT", kArithmetic, -2, "");
+ OPCODE(0xA3, "SDIV", kArithmetic, -2, "");
+ OPCODE(0xA4, "SMOD", kArithmetic, -2, "");
+ OPCODE(0xA5, "SSHL", kArithmetic, -2, "");
+ OPCODE(0xA6, "SSHR", kArithmetic, -2, "");
+ OPCODE(0xA7, "SSTOREA [SB]", kStore, -2, "i");
+ OPCODE(0xA8, "SSTOREL [SB]", kStore, 0, "is");
+ OPCODE(0xA9, "SLOADA [SB]", kLoad, 2, "i");
+ OPCODE(0xAA, "SSTOREA", kStore, -2, "d");
+ OPCODE(0xAB, "SSTOREL", kStore, 0, "ds");
+ OPCODE(0xAC, "SLOADA", kLoad, 2, "d");
+ OPCODE(0xAD, "SLOADL", kLoad, 0, "s");
+ OPCODE(0xAE, "SCMP", kComparison, -4, "");
+ OPCODE(0xAF, "USCMP", kComparison, -4, "");
+ OPCODE(0xB0, "SDUP", kLoad, 2, "");
+ OPCODE(0xB1, "SPRINT", kSpecial, -2, "");
+ OPCODE(0xB2, "USPRINT", kSpecial, -2, "");
+ OPCODE(0xB6, "SSTORE [SB]", kStore, -6, "");
+ OPCODE(0xB7, "SSTORE", kStore, -6, "");
+ OPCODE(0xB8, "SLOAD [SB]", kLoad, -6, "");
+ OPCODE(0xB9, "SLOAD", kLoad, -6, "");
+
+ //8-bit operations
+ OPCODE(0xC0, "BADD", kArithmetic, -1, "");
+ OPCODE(0xC1, "BSUB", kArithmetic, -1, "");
+ OPCODE(0xC2, "BMULT", kArithmetic, -1, "");
+ OPCODE(0xC3, "BDIV", kArithmetic, -1, "");
+ OPCODE(0xC4, "BMOD", kArithmetic, -1, "");
+ OPCODE(0xC5, "BSHL", kArithmetic, -1, "");
+ OPCODE(0xC6, "BSHR", kArithmetic, -1, "");
+ OPCODE(0xC7, "BSTOREA [SB]", kStore, -1, "i");
+ OPCODE(0xC8, "BSTOREL [SB]", kStore, 0, "iB");
+ OPCODE(0xC9, "BLOADA [SB]", kLoad, 1, "i");
+ OPCODE(0xCA, "BSTOREA", kStore, -1, "d");
+ OPCODE(0xCB, "BSTOREL", kStore, 0, "dB");
+ OPCODE(0xCC, "BLOADA", kLoad, 1, "d");
+ OPCODE(0xCD, "BLOADL", kLoad, 0, "B");
+ OPCODE(0xCE, "SBCMP", kComparison, -2, "");
+ OPCODE(0xCF, "BCMP", kComparison, -2, "");
+ OPCODE(0xD0, "BDUP", kLoad, 1, "");
+ OPCODE(0xD1, "SBPRINT", kSpecial, -1, "");
+ OPCODE(0xD2, "BPRINT", kSpecial, -1, "");
+ OPCODE(0xD3, "CPRINT", kSpecial, -1, "");
+ OPCODE(0xD6, "BSTORE [SB]", kStore, -5, "");
+ OPCODE(0xD7, "BSTORE", kStore, -5, "");
+ OPCODE(0xD8, "BLOAD [SB]", kLoad, -5, "");
+ OPCODE(0xD9, "BLOAD", kLoad, -5, "");
+ END_OPCODES;
+
+ return _insts;
+}
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h 2010-05-27 22:10:25 UTC (rev 49272)
@@ -0,0 +1,32 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
+#ifndef DEC_TEST_DISASM_PASC_H
+#define DEC_TEST_DISASM_PASC_H
+
+#include "decompiler/simple_disassembler.h"
+
+class PasCDisassembler : public SimpleDisassembler {
+public:
+ virtual std::vector<Instruction> disassemble();
+};
+#endif
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.cpp (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.cpp 2010-05-27 22:10:25 UTC (rev 49272)
@@ -0,0 +1,33 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
+#include "subopcode.h"
+
+std::vector<Instruction> SubOpcodeDisassembler::disassemble() {
+ START_OPCODES;
+ START_SUBOPCODE(0xFF)
+ OPCODE(0xFF, "FOO", kSpecial, 0, "");
+ END_SUBOPCODE
+ END_OPCODES;
+
+ return _insts;
+}
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.h (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.h 2010-05-27 22:10:25 UTC (rev 49272)
@@ -0,0 +1,32 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
+#ifndef DEC_TEST_DISASM_SUBOPCODE_H
+#define DEC_TEST_DISASM_SUBOPCODE_H
+
+#include "decompiler/simple_disassembler.h"
+
+class SubOpcodeDisassembler : public SimpleDisassembler {
+public:
+ virtual std::vector<Instruction> disassemble();
+};
+#endif
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h 2010-05-27 22:10:25 UTC (rev 49272)
@@ -0,0 +1,72 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
+#include <cxxtest/TestSuite.h>
+
+#include "disassembler/pasc.h"
+#include "disassembler/subopcode.h"
+
+class DisassemblerTestSuite : public CxxTest::TestSuite {
+public:
+ void testDisassembly() {
+ try {
+ PasCDisassembler p;
+ p.open("decompiler/test/hanoi20.pasb");
+ std::vector<Instruction> insts = p.disassemble();
+ TS_ASSERT(insts[0]._address == 0);
+ 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);
+ } catch (UnknownOpcodeException &uoe) {
+ printf("Exception message: %s\n",uoe.what());
+ TS_ASSERT(false);
+ } catch (std::exception &ex) {
+ printf("Exception message: %s\n",ex.what());
+ TS_ASSERT(false);
+ }
+ }
+
+ void testSubOpcodeDisassembly() {
+ try {
+ SubOpcodeDisassembler s;
+ s.open("decompiler/test/subopcode_test.bin");
+ std::vector<Instruction> insts = s.disassemble();
+ TS_ASSERT(insts[0]._name == "FOO");
+ } catch (...) {
+ TS_ASSERT(false);
+ }
+ }
+
+ void testUnknownOpcodeException() {
+ try {
+ SubOpcodeDisassembler s;
+ s.open("decompiler/test/unknownopcode_test.bin");
+ s.disassemble();
+ TS_ASSERT(false);
+ } catch (UnknownOpcodeException) {
+ TS_ASSERT(true);
+ } catch (...) {
+ TS_ASSERT(false);
+ }
+ }
+};
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/branches/gsoc2010-decompiler/decompiler/test/hanoi20.pasb
===================================================================
(Binary files differ)
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/hanoi20.pasb
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: tools/branches/gsoc2010-decompiler/decompiler/test/module.mk
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/module.mk (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/module.mk 2010-05-27 22:10:25 UTC (rev 49272)
@@ -0,0 +1,48 @@
+######################################################################
+# Unit/regression tests, based on CxxTest.
+# Use the 'test' target to run them.
+# Edit TESTS and TESTLIBS to add more tests.
+#
+######################################################################
+
+TESTS := $(srcdir)/decompiler/test/*.h
+TEST_LIBS := \
+ common/file.o\
+ decompiler/disassembler.o \
+ decompiler/simple_disassembler.o \
+ decompiler/test/disassembler/pasc.o \
+ decompiler/test/disassembler/subopcode.o \
+ decompiler/unknown_opcode.o \
+
+#
+TEST_FLAGS := --runner=StdioPrinter
+TEST_CFLAGS := -I$(srcdir)/decompiler/test/cxxtest
+TEST_LDFLAGS := $(decompile_LIBS)
+
+ifdef HAVE_GCC3
+# In test/common/str.h, we test a zero length format string. This causes GCC
+# to generate a warning which in turn poses a problem when building with -Werror.
+# To work around this, we disable -Wformat here.
+TEST_CFLAGS += -Wno-format
+endif
+
+# Enable this to get an X11 GUI for the error reporter.
+#TEST_FLAGS += --gui=X11Gui
+#TEST_LDFLAGS += -L/usr/X11R6/lib -lX11
+
+
+test: decompiler/test/runner
+ ./decompiler/test/runner
+decompiler/test/runner: decompiler/test/runner.cpp $(TEST_LIBS)
+ $(QUIET_LINK)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TEST_LDFLAGS) $(TEST_CFLAGS) -o $@ $+
+decompiler/test/runner.cpp: $(TESTS)
+ @mkdir -p decompiler
+ @mkdir -p decompiler/test
+ python $(srcdir)/decompiler/test/cxxtest/cxxtestgen.py $(TEST_FLAGS) -o $@ $+
+
+
+clean: clean-test
+clean-test:
+ -$(RM) decompiler/test/runner.cpp decompiler/test/runner
+
+.PHONY: test clean-test
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/module.mk
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: tools/branches/gsoc2010-decompiler/decompiler/test/subopcode_test.bin
===================================================================
(Binary files differ)
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/subopcode_test.bin
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: tools/branches/gsoc2010-decompiler/decompiler/test/unknownopcode_test.bin
===================================================================
(Binary files differ)
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/test/unknownopcode_test.bin
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: tools/branches/gsoc2010-decompiler/decompiler/unknown_opcode.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/unknown_opcode.h 2010-05-27 21:20:07 UTC (rev 49271)
+++ tools/branches/gsoc2010-decompiler/decompiler/unknown_opcode.h 2010-05-27 22:10:25 UTC (rev 49272)
@@ -36,6 +36,7 @@
uint8 _opcode; ///<The value of the invalid opcode.
char _buf[255]; ///<Buffer for formatting the error message.
+public:
/**
* Constructor for UnknownOpcodeException.
* @param address Address where the invalid opcode was found.
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