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

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Fri Aug 13 01:32:00 CEST 2010


Revision: 52049
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52049&view=rev
Author:   pidgeot
Date:     2010-08-12 23:31:59 +0000 (Thu, 12 Aug 2010)

Log Message:
-----------
DECOMPILER: Split kUnaryOp into pre- and postfix

Modified Paths:
--------------
    tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
    tools/branches/gsoc2010-decompiler/decompiler/codegen.h
    tools/branches/gsoc2010-decompiler/decompiler/doc/codegen.tex
    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/scummv6/codegen.cpp
    tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
    tools/branches/gsoc2010-decompiler/decompiler/test/codegen.h
    tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp

Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp	2010-08-12 23:31:59 UTC (rev 52049)
@@ -59,7 +59,10 @@
 }
 
 std::ostream &UnaryOpEntry::print(std::ostream &output) const {
-	return output << _op << "(" << _operand << ")";
+	if (_isPostfix)
+		return output << "(" << _operand << ")" << _op;
+	else
+		return output << _op << "(" << _operand << ")";
 }
 
 std::ostream &DupEntry::print(std::ostream &output) const {
@@ -254,9 +257,9 @@
 					_stack.push(p);
 					break;
 				}
-			case kUnaryOp:
-				//TODO: Allow operator to be placed on either side of operand
-				_stack.push(new UnaryOpEntry(_stack.pop(), it->_codeGenData));
+			case kUnaryOpPre:
+			case kUnaryOpPost:
+				_stack.push(new UnaryOpEntry(_stack.pop(), it->_codeGenData, it->_type == kUnaryOpPost));
 				break;
 			case kBinaryOp:
 				{

Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.h	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.h	2010-08-12 23:31:59 UTC (rev 52049)
@@ -222,6 +222,7 @@
 private:
 	const EntryPtr _operand; ///< The operand the operation is performed on.
 	const std::string _op;   ///< The operator for this entry.
+	const bool _isPostfix;   ///< Whether or not the operator should be postfixed to the operand.
 
 public:
 	/**
@@ -229,9 +230,10 @@
 	 *
 	 * @param operand Stack entry representing the operand of the operation.
 	 * @param op The operator for this entry.
+	 * @param isPostfix Whether or not the operator should be postfixed to the operand.
 	 */
-	UnaryOpEntry(EntryPtr operand, std::string op) :
-		StackEntry(seUnaryOp), _operand(operand), _op(op) { }
+	UnaryOpEntry(EntryPtr operand, std::string op, bool isPostfix) :
+		StackEntry(seUnaryOp), _operand(operand), _op(op), _isPostfix(isPostfix) { }
 
 	virtual std::ostream &print(std::ostream &output) const;
 };
@@ -377,8 +379,8 @@
 	/**
 	 * Processes an instruction in an engine-specific manner.
 	 * Called by process() to preprocess conditional jumps, process instructions
-	 * where engine-specific handling is explicitly requested, or the type is not
-	 * one of kBinaryOp, kDup, kJump(Rel), kReturn, kSpecial, or kUnaryOp.
+	 * where engine-specific handling is explicitly requested, or the type is not one
+	 * of kBinaryOp, kDup, kJump(Rel), kReturn, kSpecial, kUnaryOpPre, or kUnaryOpPost.
 	 *
 	 * @param inst The instruction to process.
 	 */

Modified: tools/branches/gsoc2010-decompiler/decompiler/doc/codegen.tex
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/doc/codegen.tex	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/doc/codegen.tex	2010-08-12 23:31:59 UTC (rev 52049)
@@ -84,8 +84,8 @@
 \paragraph{kDup}
 The topmost stack entry is popped, and two duplicated copies are pushed to the stack. If the entry being duplicated was not already a duplicate, an assignment will be output to assign the original stack entry to a special dup variable, to show that the original entry is not being recalculated.
 
-\paragraph{kUnaryOp}
-The topmost stack entry is popped, and a \code{UnaryOpEntry} is created and pushed to the stack, using the codegen metadata as the operator, and the previously popped entry as the operand. Note: currently, a \code{UnaryOpEntry} only supports placing the operator on the left side of the operand.
+\paragraph{kUnaryOpPre/kUnaryOpPost}
+The topmost stack entry is popped, and a \code{UnaryOpEntry} is created and pushed to the stack, using the codegen metadata as the operator, and the previously popped entry as the operand. The exact type determines whether the operator is pre- or postfixed to the operand.
 
 \paragraph{kBinaryOp}
 The two topmost stack entries are popped, and a BinaryOpEntry is created and pushed to the stack, using the codegen metadata as the operator and the previously popped entries as the operands. The order of the operands is determined by the value of the field \code{\_binOrder}, as described in Section~\vref{sec:argOrder}.

Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h	2010-08-12 23:31:59 UTC (rev 52049)
@@ -46,7 +46,8 @@
 	kSpecial,     ///< Special functions.
 	kStack,       ///< Stack allocation or deallocation (altering stack pointer).
 	kStore,       ///< Store value from stack in memory.
-	kUnaryOp      ///< Unary operation (e.g. !)
+	kUnaryOpPre,  ///< Unary operation (e.g. !) with operator placed before the operator.
+	kUnaryOpPost  ///< Unary operation with operator placed after the operator.
 };
 
 /**

Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/codegen.cpp	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/codegen.cpp	2010-08-12 23:31:59 UTC (rev 52049)
@@ -125,7 +125,7 @@
 		case kWhileCond:
 			break;
 		case kDoWhileCond:
-			_stack.push(new UnaryOpEntry(_stack.pop(), "!"));
+			_stack.push(new UnaryOpEntry(_stack.pop(), "!", false));
 			break;
 		default:
 			{

Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp	2010-08-12 23:31:59 UTC (rev 52049)
@@ -485,11 +485,11 @@
 			break;
 		case 16:
 			if (parameter == 0) {
-				OPCODE_MD("boolNegate", kUnaryOp, 0, false, false, "!");
+				OPCODE_MD("boolNegate", kUnaryOpPre, 0, false, false, "!");
 			} else if (parameter == 1) {
-				OPCODE_MD("arithmeticNegate", kUnaryOp, 0, false, false,"-");
+				OPCODE_MD("arithmeticNegate", kUnaryOpPre, 0, false, false,"-");
 			} else if (parameter == 2) {
-				OPCODE_MD("bitwiseNegate", kUnaryOp, 0, false, false, "~");
+				OPCODE_MD("bitwiseNegate", kUnaryOpPre, 0, false, false, "~");
 			} else {
 				// Error: invalid parameter halts execution
 				throw UnknownOpcodeException(address, opcode);

Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp	2010-08-12 23:31:59 UTC (rev 52049)
@@ -120,11 +120,11 @@
 		case kIfCond:
 		case kWhileCond:
 			if (inst._opcode == 0x5C) // jumpTrue
-				_stack.push(new UnaryOpEntry(_stack.pop(), "!"));
+				_stack.push(new UnaryOpEntry(_stack.pop(), "!", false));
 			break;
 		case kDoWhileCond:
 			if (inst._opcode == 0x5D) // jumpFalse
-				_stack.push(new UnaryOpEntry(_stack.pop(), "!"));
+				_stack.push(new UnaryOpEntry(_stack.pop(), "!", false));
 			break;
 		default:
 			{
@@ -135,7 +135,7 @@
 			break;
 		}
 		break;
-	case kUnaryOp:
+	case kUnaryOpPost:
 		switch (inst._opcode) {
 		case 0x4E: // byteVarInc
 		case 0x4F: // wordVarInc
@@ -143,7 +143,7 @@
 		case 0x57: // wordVarDec
 			{
 				std::stringstream s;
-				EntryPtr p = new UnaryOpEntry(new VarEntry(decodeVarName(inst._params[0].getUnsigned())), inst._codeGenData.substr(1));
+				EntryPtr p = new UnaryOpEntry(new VarEntry(decodeVarName(inst._params[0].getUnsigned())), inst._codeGenData.substr(1), true);
 				s << p << ";";
 				addOutputLine(s.str());
 			}
@@ -156,7 +156,7 @@
 				std::stringstream s;
 				EntryList idxs;
 				idxs.push_front(_stack.pop());
-				EntryPtr p = new UnaryOpEntry(new ArrayEntry(decodeVarName(inst._params[0].getUnsigned()), idxs), inst._codeGenData.substr(1));
+				EntryPtr p = new UnaryOpEntry(new ArrayEntry(decodeVarName(inst._params[0].getUnsigned()), idxs), inst._codeGenData.substr(1), true);
 				s << p << ";";
 				addOutputLine(s.str());
 			}

Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp	2010-08-12 23:31:59 UTC (rev 52049)
@@ -72,7 +72,7 @@
 		OPCODE(0x0A, "byteArrayIndexedRead", kLoad, -1, "B");
 		OPCODE(0x0B, "wordArrayIndexedRead", kLoad, -1, "w");
 		OPCODE(0x0C, "dup", kDup, 1, "");
-		OPCODE_MD(0x0D, "not", kUnaryOp, 0, "", "!");
+		OPCODE_MD(0x0D, "not", kUnaryOpPre, 0, "", "!");
 		OPCODE_MD(0x0E, "eq", kBinaryOp, -1, "", "==");
 		OPCODE_MD(0x0F, "neq", kBinaryOp, -1, "", "!=");
 		OPCODE_MD(0x10, "gt", kBinaryOp, -1, "", ">");
@@ -92,14 +92,14 @@
 		OPCODE(0x47, "wordArrayWrite", kStore, -2, "w");
 		OPCODE(0x4A, "byteArrayIndexedWrite", kStore, -3, "B");
 		OPCODE(0x4B, "wordArrayIndexedWrite", kStore, -3, "w");
-		OPCODE_MD(0x4E, "byteVarInc", kUnaryOp, 0, "B", "\xC0++");
-		OPCODE_MD(0x4F, "wordVarInc", kUnaryOp, 0, "w", "\xC0++");
-		OPCODE_MD(0x52, "byteArrayInc", kUnaryOp, -1, "B", "\xC0++");
-		OPCODE_MD(0x53, "wordArrayInc", kUnaryOp, -1, "w", "\xC0++");
-		OPCODE_MD(0x56, "byteVarDec", kUnaryOp, 0, "B", "\xC0--");
-		OPCODE_MD(0x57, "wordVarDec", kUnaryOp, 0, "w", "\xC0--");
-		OPCODE_MD(0x5A, "byteArrayDec", kUnaryOp, -1, "B", "\xC0--");
-		OPCODE_MD(0x5B, "wordArrayDec", kUnaryOp, -1, "w", "\xC0--");
+		OPCODE_MD(0x4E, "byteVarInc", kUnaryOpPost, 0, "B", "\xC0++");
+		OPCODE_MD(0x4F, "wordVarInc", kUnaryOpPost, 0, "w", "\xC0++");
+		OPCODE_MD(0x52, "byteArrayInc", kUnaryOpPost, -1, "B", "\xC0++");
+		OPCODE_MD(0x53, "wordArrayInc", kUnaryOpPost, -1, "w", "\xC0++");
+		OPCODE_MD(0x56, "byteVarDec", kUnaryOpPost, 0, "B", "\xC0--");
+		OPCODE_MD(0x57, "wordVarDec", kUnaryOpPost, 0, "w", "\xC0--");
+		OPCODE_MD(0x5A, "byteArrayDec", kUnaryOpPost, -1, "B", "\xC0--");
+		OPCODE_MD(0x5B, "wordArrayDec", kUnaryOpPost, -1, "w", "\xC0--");
 		OPCODE(0x5C, "jumpTrue", kCondJumpRel, -1, "s");
 		OPCODE(0x5D, "jumpFalse", kCondJumpRel, -1, "s");
 		OPCODE_MD(0x5E, "startScript", kSpecial, 0x1020, "", "lpp"); // Variable stack arguments

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/codegen.h	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/codegen.h	2010-08-12 23:31:59 UTC (rev 52049)
@@ -92,7 +92,7 @@
 		expected.push_back("if(!((18 == var321))) {");
 		expected.push_back("continue;");
 		expected.push_back("}");
-		expected.push_back("--(VAR_CHARSET_MASK);");
+		expected.push_back("(VAR_CHARSET_MASK)--;");
 		expected.push_back("} while ((42 == VAR_CHARSET_MASK))");
 		expected.push_back("stopObjectCodeA();");
 		GroupPtr gr = GET(*v);
@@ -136,7 +136,7 @@
 		expected.push_back("if (!((18 == var321))) {");
 		expected.push_back("break;");
 		expected.push_back("}");
-		expected.push_back("--(VAR_CHARSET_MASK);");
+		expected.push_back("(VAR_CHARSET_MASK)--;");
 		expected.push_back("}");
 		expected.push_back("stopObjectCodeA();");
 		GroupPtr gr = GET(*v);
@@ -177,9 +177,9 @@
 		VertexIterator v = boost::vertices(g).first;
 		std::vector<std::string> output, expected;
 		expected.push_back("if (!((42 == VAR_CHARSET_MASK))) {");
-		expected.push_back("--(VAR_CHARSET_MASK);");
+		expected.push_back("(VAR_CHARSET_MASK)--;");
 		expected.push_back("} else {");
-		expected.push_back("++(VAR_CHARSET_MASK);");
+		expected.push_back("(VAR_CHARSET_MASK)++;");
 		expected.push_back("}");
 		expected.push_back("stopObjectCodeA();");
 		GroupPtr gr = GET(*v);

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp	2010-08-12 23:09:38 UTC (rev 52048)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp	2010-08-12 23:31:59 UTC (rev 52049)
@@ -47,7 +47,7 @@
 		OPCODE(0x20, "OR", kBinaryOp, -1, "");
 		OPCODE(0x21, "AND", kBinaryOp, -1, "");
 		OPCODE(0x22, "XOR", kBinaryOp, -1, "");
-		OPCODE(0x23, "NOT", kUnaryOp, -1, "");
+		OPCODE(0x23, "NOT", kUnaryOpPre, -1, "");
 
 		//Padding instructions (smaller integer -> larger integer)
 		OPCODE(0x30, "SPAD", kSpecial, 0, "B");


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