[Scummvm-cvs-logs] SF.net SVN: scummvm:[51021] tools/branches/gsoc2010-decompiler/decompiler

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Mon Jul 19 11:29:57 CEST 2010


Revision: 51021
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51021&view=rev
Author:   pidgeot
Date:     2010-07-19 09:29:57 +0000 (Mon, 19 Jul 2010)

Log Message:
-----------
Rework InstType
Add storage of corresponding operator to Instruction
Refactor OPCODE macro from SimpleDisassembler

Modified Paths:
--------------
    tools/branches/gsoc2010-decompiler/decompiler/instruction.h
    tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
    tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h
    tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp

Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h	2010-07-19 08:17:09 UTC (rev 51020)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h	2010-07-19 09:29:57 UTC (rev 51021)
@@ -33,19 +33,20 @@
  * Enumeration for categorizing the different kinds of instructions.
  */
 enum InstType {
-	kArithmetic,  ///< Arithmetic instruction (+, -, *, etc.).
-	kBoolean,     ///< Boolean instruction (AND, OR, etc.).
+	kBinaryOp,    ///< Binary operation (e.g. +, &&, etc.), EXCLUDING comparisons.
 	kCall,        ///< Regular function call.
-	kComparison,  ///< Comparison instruction.
+	kComparison,  ///< Comparison instruction (==, !=, etc.)
 	kCondJump,    ///< Conditional jump (absolute address).
 	kCondJumpRel, ///< Conditional jump (relative address).
+	kDup,         ///< Instruction duplicates the most recent stack entry.
 	kJump,        ///< Unconditional jump (absolute address).
 	kJumpRel,     ///< Unconditional jump (relative address).
 	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.
+	kStore,       ///< Store value from stack in memory.
+	kUnaryOp      ///< Unary operation (e.g. !)
 };
 
 /**
@@ -103,6 +104,7 @@
 	std::string _name;              ///< The instruction name (opcode name).
 	InstType _type;                 ///< The instruction type.
 	std::vector<Parameter> _params; ///< Array of parameters used for the instruction.
+	std::string _operator;          ///< If instruction represents an operator, use this to contain the operator in question.
 };
 
 /**

Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp	2010-07-19 08:17:09 UTC (rev 51020)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp	2010-07-19 09:29:57 UTC (rev 51021)
@@ -64,20 +64,20 @@
 		OPCODE(0x07, "wordArrayRead", kLoad, 0, "w");
 		OPCODE(0x0A, "byteArrayIndexedRead", kLoad, -1, "B");
 		OPCODE(0x0B, "wordArrayIndexedRead", kLoad, -1, "w");
-		OPCODE(0x0C, "dup", kLoad, 1, "");
-		OPCODE(0x0D, "not", kBoolean, 0, "");
-		OPCODE(0x0E, "eq", kComparison, -1, "");
-		OPCODE(0x0F, "neq", kComparison, -1, "");
-		OPCODE(0x10, "gt", kComparison, -1, "");
-		OPCODE(0x11, "lt", kComparison, -1, "");
-		OPCODE(0x12, "le", kComparison, -1, "");
-		OPCODE(0x13, "ge", kComparison, -1, "");
-		OPCODE(0x14, "add", kArithmetic, -1, "");
-		OPCODE(0x15, "sub", kArithmetic, -1, "");
-		OPCODE(0x16, "mul", kArithmetic, -1, "");
-		OPCODE(0x17, "div", kArithmetic, -1, "");
-		OPCODE(0x18, "land", kBoolean, -1, "");
-		OPCODE(0x19, "lor", kBoolean, -1, "");
+		OPCODE(0x0C, "dup", kDup, 1, "");
+		OPCODE_OP(0x0D, "not", kUnaryOp, 0, "", "!");
+		OPCODE_OP(0x0E, "eq", kComparison, -1, "", "==");
+		OPCODE_OP(0x0F, "neq", kComparison, -1, "", "!=");
+		OPCODE_OP(0x10, "gt", kComparison, -1, "", ">");
+		OPCODE_OP(0x11, "lt", kComparison, -1, "", "<");
+		OPCODE_OP(0x12, "le", kComparison, -1, "", "<=");
+		OPCODE_OP(0x13, "ge", kComparison, -1, "", ">=");
+		OPCODE_OP(0x14, "add", kBinaryOp, -1, "", "+");
+		OPCODE_OP(0x15, "sub", kBinaryOp, -1, "", "-");
+		OPCODE_OP(0x16, "mul", kBinaryOp, -1, "", "*");
+		OPCODE_OP(0x17, "div", kBinaryOp, -1, "", "/");
+		OPCODE_OP(0x18, "land", kBinaryOp, -1, "", "&");
+		OPCODE_OP(0x19, "lor", kBinaryOp, -1, "", "|");
 		OPCODE(0x1A, "pop", kStack, -1, "");
 		OPCODE(0x42, "writeByteVar", kStore, -1, "B");
 		OPCODE(0x43, "writeWordVar", kStore, -1, "w");
@@ -85,14 +85,14 @@
 		OPCODE(0x47, "wordArrayWrite", kStore, -2, "w");
 		OPCODE(0x4A, "byteArrayIndexedWrite", kStore, -3, "B");
 		OPCODE(0x4B, "wordArrayIndexedWrite", kStore, -3, "w");
-		OPCODE(0x4E, "byteVarInc", kArithmetic, 0, "B");
-		OPCODE(0x4F, "wordVarInc", kArithmetic, 0, "w");
-		OPCODE(0x52, "byteArrayInc", kArithmetic, -1, "B");
-		OPCODE(0x53, "wordArrayInc", kArithmetic, -1, "w");
-		OPCODE(0x56, "byteVarDec", kArithmetic, 0, "B");
-		OPCODE(0x57, "wordVarDec", kArithmetic, 0, "w");
-		OPCODE(0x5A, "byteArrayDec", kArithmetic, -1, "B");
-		OPCODE(0x5B, "wordArrayDec", kArithmetic, -1, "w");
+		OPCODE_OP(0x4E, "byteVarInc", kUnaryOp, 0, "B", "++");
+		OPCODE_OP(0x4F, "wordVarInc", kUnaryOp, 0, "w", "++");
+		OPCODE_OP(0x52, "byteArrayInc", kUnaryOp, -1, "B", "++");
+		OPCODE_OP(0x53, "wordArrayInc", kUnaryOp, -1, "w", "++");
+		OPCODE_OP(0x56, "byteVarDec", kUnaryOp, 0, "B", "--");
+		OPCODE_OP(0x57, "wordVarDec", kUnaryOp, 0, "w", "--");
+		OPCODE_OP(0x5A, "byteArrayDec", kUnaryOp, -1, "B", "--");
+		OPCODE_OP(0x5B, "wordArrayDec", kUnaryOp, -1, "w", "--");
 		OPCODE(0x5C, "jumpTrue", kCondJumpRel, -1, "s");
 		OPCODE(0x5D, "jumpFalse", kCondJumpRel, -1, "s");
 		OPCODE(0x5E, "startScript", kSpecial, 0x1020, ""); // Variable stack arguments
@@ -395,7 +395,7 @@
 			OPCODE(0xCA, "dim2DimArrayByte", kSpecial, -2, "w");
 			OPCODE(0xCB, "dim2DimArrayString", kSpecial, -2, "w");
 		END_SUBOPCODE;
-		OPCODE(0xC4, "abs", kArithmetic, 0, "");
+		OPCODE(0xC4, "abs", kSpecial, 0, "");
 		OPCODE(0xC5, "getDistObjObj", kSpecial, -1, "");
 		OPCODE(0xC6, "getDistObjPt", kSpecial, -2, "");
 		OPCODE(0xC7, "getDistPtPt", kSpecial, -3, "");
@@ -410,8 +410,8 @@
 		OPCODE(0xD2, "getAnimateVariable", kSpecial, -1, "");
 		OPCODE(0xD4, "shuffle", kSpecial, -2, "w");
 		OPCODE(0xD5, "jumpToScript", kSpecial, 0x1020, ""); // Variable stack arguments
-		OPCODE(0xD6, "band", kBoolean, -1, "");
-		OPCODE(0xD7, "bor", kBoolean, -1, "");
+		OPCODE_OP(0xD6, "band", kBinaryOp, -1, "", "&&");
+		OPCODE_OP(0xD7, "bor", kBinaryOp, -1, "", "||");
 		OPCODE(0xD8, "isRoomScriptRunning", kSpecial, 0, "");
 		OPCODE(0xDD, "findAllObjects", kSpecial, 0, "");
 		OPCODE(0xE1, "getPixel", kSpecial, -1, "");

Modified: tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h	2010-07-19 08:17:09 UTC (rev 51020)
+++ tools/branches/gsoc2010-decompiler/decompiler/simple_disassembler.h	2010-07-19 09:29:57 UTC (rev 51021)
@@ -72,17 +72,24 @@
 
 #define OPCODE_END break;
 
-#define OPCODE(val, name, category, stackChange, params) \
-	OPCODE_BASE(val)\
+#define OPCODE_BODY(name, category, stackChange, params, op) \
 		ADD_INST; \
 		LAST_INST._opcode = full_opcode; \
 		LAST_INST._address = _address; \
 		LAST_INST._stackChange = stackChange; \
 		LAST_INST._name = std::string(name); \
 		LAST_INST._type = category; \
+		LAST_INST._operator = op; \
 		readParams(&LAST_INST, (char*)params); \
+
+#define OPCODE_OP(val, name, category, stackChange, params, op) \
+	OPCODE_BASE(val)\
+		OPCODE_BODY(name, category, stackChange, params, op)\
 		OPCODE_END;
 
+#define OPCODE(val, name, category, stackChange, params) \
+	OPCODE_OP(val, name, category, stackChange, params, "")
+
 #define START_SUBOPCODE(val) \
 	OPCODE_BASE(val) \
 		opcode = _f.readByte(); \

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp	2010-07-19 08:17:09 UTC (rev 51020)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp	2010-07-19 09:29:57 UTC (rev 51021)
@@ -41,23 +41,23 @@
 		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, "");
+		OPCODE(0x20, "OR", kBinaryOp, -1, "");
+		OPCODE(0x21, "AND", kBinaryOp, -1, "");
+		OPCODE(0x22, "XOR", kBinaryOp, -1, "");
+		OPCODE(0x23, "NOT", kUnaryOp, -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(0x80, "IADD", kBinaryOp, -4, "");
+		OPCODE(0x81, "ISUB", kBinaryOp, -4, "");
+		OPCODE(0x82, "IMULT", kBinaryOp, -4, "");
+		OPCODE(0x83, "IDIV", kBinaryOp, -4, "");
+		OPCODE(0x84, "IMOD", kBinaryOp, -4, "");
+		OPCODE(0x85, "ISHL", kBinaryOp, -4, "");
+		OPCODE(0x86, "ISHR", kBinaryOp, -4, "");
 		OPCODE(0x87, "ISTOREA [SB]", kStore, -4, "i");
 		OPCODE(0x88, "ISTOREL [SB]", kStore, 0, "ii");
 		OPCODE(0x89, "ILOADA [SB]", kLoad, 4, "i");
@@ -76,13 +76,13 @@
 		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(0xA0, "SADD", kBinaryOp, -2, "");
+		OPCODE(0xA1, "SSUB", kBinaryOp, -2, "");
+		OPCODE(0xA2, "SMULT", kBinaryOp, -2, "");
+		OPCODE(0xA3, "SDIV", kBinaryOp, -2, "");
+		OPCODE(0xA4, "SMOD", kBinaryOp, -2, "");
+		OPCODE(0xA5, "SSHL", kBinaryOp, -2, "");
+		OPCODE(0xA6, "SSHR", kBinaryOp, -2, "");
 		OPCODE(0xA7, "SSTOREA [SB]", kStore, -2, "i");
 		OPCODE(0xA8, "SSTOREL [SB]", kStore, 0, "is");
 		OPCODE(0xA9, "SLOADA [SB]", kLoad, 2, "i");
@@ -101,13 +101,13 @@
 		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(0xC0, "BADD", kBinaryOp, -1, "");
+		OPCODE(0xC1, "BSUB", kBinaryOp, -1, "");
+		OPCODE(0xC2, "BMULT", kBinaryOp, -1, "");
+		OPCODE(0xC3, "BDIV", kBinaryOp, -1, "");
+		OPCODE(0xC4, "BMOD", kBinaryOp, -1, "");
+		OPCODE(0xC5, "BSHL", kBinaryOp, -1, "");
+		OPCODE(0xC6, "BSHR", kBinaryOp, -1, "");
 		OPCODE(0xC7, "BSTOREA [SB]", kStore, -1, "i");
 		OPCODE(0xC8, "BSTOREL [SB]", kStore, 0, "iB");
 		OPCODE(0xC9, "BLOADA [SB]", kLoad, 1, "i");


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