[Scummvm-cvs-logs] SF.net SVN: scummvm:[42078] tools/branches/gsoc2009-decompiler/decompiler/ syntax.h

kjdf at users.sourceforge.net kjdf at users.sourceforge.net
Fri Jul 3 22:56:40 CEST 2009


Revision: 42078
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42078&view=rev
Author:   kjdf
Date:     2009-07-03 20:56:40 +0000 (Fri, 03 Jul 2009)

Log Message:
-----------
decompiler: (ugly and buggy) if printing

Modified Paths:
--------------
    tools/branches/gsoc2009-decompiler/decompiler/syntax.h

Modified: tools/branches/gsoc2009-decompiler/decompiler/syntax.h
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/syntax.h	2009-07-03 20:56:28 UTC (rev 42077)
+++ tools/branches/gsoc2009-decompiler/decompiler/syntax.h	2009-07-03 20:56:40 UTC (rev 42078)
@@ -117,6 +117,16 @@
 void append(Block *block, Block *until, std::list<Statement*> &seq);
 
 
+IfThenElse *buildIfThenElse(Block *head) {
+	IfThenElse *ifte = new IfThenElse;
+	foreach (Instruction *insn, head->_instructions)
+		ifte->_condition.push_back(new InstructionWrapper(insn));
+	append(head->_out.back(), head->_ifFollow, ifte->_consequence);
+	append(head->_out.front(), head->_ifFollow, ifte->_alternative);
+	return ifte;
+}
+
+
 DoWhileLoop *buildDoWhileLoop(Block *head) {
 	DoWhileLoop *loop = new DoWhileLoop;
 	foreach (Instruction *insn, head->_loopLatch->_instructions)
@@ -139,7 +149,7 @@
 		return;
 	if (block->_visited) {
 		// TODO they should be printed more before append() only sometimes
-		// seq.push_back(new Goto(block->_instructions.front()->_addr));
+		seq.push_back(new Goto(block->_instructions.front()->_addr));
 		return;
 	}
 	block->_visited = true;
@@ -152,6 +162,11 @@
 		append(block->_loopFollow, until, seq);
 		return;
 	}
+	if (block->_ifFollow) {
+		seq.push_back(buildIfThenElse(block));
+		append(block->_ifFollow, until, seq);
+		return;
+	}
 	foreach (Instruction *insn, block->_instructions) {
 		// TODO jump targets will be broken (pointing to not printed basic blocks) if the jump was rewired
 		Jump *jump = dynamic_cast<Jump*>(insn);
@@ -181,15 +196,9 @@
 
 
 std::list<Statement*> buildAbstractSyntaxTree(ControlFlowGraph &graph) {
-	foreach (Block *block, graph._blocks) {
-		if (block->_loopLatch && block->_loopType == PRE_TESTED) {
+	foreach (Block *block, graph._blocks)
+		if (dynamic_cast<Jump*>(block->_instructions.back()))
 			block->_instructions.pop_back();
-			if (block->_loopLatch != block)
-				block->_loopLatch->_instructions.pop_back();
-		} else if (block->_loopLatch && block->_loopType == POST_TESTED) {
-			block->_loopLatch->_instructions.pop_back();
-		}
-	}
 	return buildSequence(graph._entry);
 }
 


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