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

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Thu Jul 1 23:46:16 CEST 2010


Revision: 50571
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50571&view=rev
Author:   pidgeot
Date:     2010-07-01 21:46:15 +0000 (Thu, 01 Jul 2010)

Log Message:
-----------
Formatting fixes, code cleanup

Modified Paths:
--------------
    tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
    tools/branches/gsoc2010-decompiler/decompiler/control_flow.h
    tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h

Modified: tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp	2010-07-01 21:39:07 UTC (rev 50570)
+++ tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp	2010-07-01 21:46:15 UTC (rev 50571)
@@ -22,8 +22,10 @@
 
 #include "control_flow.h"
 
+#include <algorithm>
 #include <iostream>
 #include <stack>
+
 #include <boost/format.hpp>
 
 #define PUT(vertex, group) boost::put(boost::vertex_name, _g, vertex, group);
@@ -65,7 +67,7 @@
 	}
 }
 
-GraphVertex ControlFlow::find(Instruction inst) {
+GraphVertex ControlFlow::find(const Instruction &inst) {
 	return _addrMap[inst._address];
 }
 
@@ -96,7 +98,7 @@
 
 	// Add outgoing edges from g2
 	EdgeRange r = boost::out_edges(g2, _g);
-	for (OutEdgeIterator e = r.first; e != r.second; e++) {
+	for (OutEdgeIterator e = r.first; e != r.second; ++e) {
 		boost::add_edge(g1, boost::target(*e, _g), _g);
 	}
 
@@ -105,7 +107,6 @@
 	if (gr2->_next != NULL)
 		gr2->_next->_prev = gr2->_prev;
 
-
 	// Remove edges to/from g2
 	boost::clear_vertex(g2, _g);
 	// Remove vertex
@@ -126,7 +127,7 @@
 		return;
 
 	EdgeRange r = boost::out_edges(g, _g);
-	for (OutEdgeIterator e = r.first; e != r.second; e++) {
+	for (OutEdgeIterator e = r.first; e != r.second; ++e) {
 		setStackLevel(boost::target(*e, _g), level + gr->_start->_stackChange);
 	}
 }
@@ -139,7 +140,7 @@
 	int stackLevel = 0;
 	int expectedStackLevel = 0;
 	std::stack<uint32> s;
-	for (curInst = _insts.begin(); nextInst != _insts.end(); curInst++, nextInst++) {
+	for (curInst = _insts.begin(); nextInst != _insts.end(); ++curInst, ++nextInst) {
 		GraphVertex cur = find(curInst);
 		GraphVertex next = find(nextInst);
 
@@ -188,32 +189,26 @@
 	Group *gr = GET(cur);
 	while (gr->_prev != NULL) {
 		bool doMerge = false;
-		if ((gr->_end->_type == kCondJump || gr->_end->_type == kCondJumpRel) && (gr->_prev->_end->_type == kCondJump || gr->_prev->_end->_type == kCondJumpRel)) {
+		cur = find(gr->_start);
+		GraphVertex prev = find(gr->_prev->_start);
+		if (out_degree(cur, _g) == 2 && out_degree(prev, _g) == 2) {
 			doMerge = true;
-			cur = find(gr->_start);
-			GraphVertex prev = find(gr->_prev->_start);
 			EdgeRange rCur = boost::out_edges(cur, _g);
-			GraphVertex gJump, gSeq;			
+			std::vector<GraphVertex> succs;
 
 			//Find possible target vertices
-			for (OutEdgeIterator it = rCur.first; it != rCur.second; it++) {
-				GraphVertex target = boost::target(*it, _g);
-				Group *targetGroup = GET(target);
-				if (_engine->getDestAddress(gr->_end) == targetGroup->_start->_address)
-					gJump = target;
-				else
-					gSeq = target;
+			for (OutEdgeIterator it = rCur.first; it != rCur.second; ++it) {
+				succs.push_back(boost::target(*it, _g));
 			}
 
 			//Check if vertex would add new targets - if yes, don't merge
 			EdgeRange rPrev = boost::out_edges(prev, _g);
-			for (OutEdgeIterator it = rPrev.first; it != rPrev.second; it++) {
+			for (OutEdgeIterator it = rPrev.first; it != rPrev.second; ++it) {
 				GraphVertex target = boost::target(*it, _g);
-				if (target != gJump && target != gSeq && target != cur)
-					doMerge = false;
+				doMerge &= (std::find(succs.begin(), succs.end(), target) != succs.end() || target == cur);
 			}
 			if (doMerge) {
-				gr = gr->_prev;				
+				gr = gr->_prev;
 				merge(prev, cur);
 				continue;
 			}

Modified: tools/branches/gsoc2010-decompiler/decompiler/control_flow.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/control_flow.h	2010-07-01 21:39:07 UTC (rev 50570)
+++ tools/branches/gsoc2010-decompiler/decompiler/control_flow.h	2010-07-01 21:46:15 UTC (rev 50571)
@@ -41,7 +41,7 @@
 	 *
 	 * @param inst The instruction to find the vertex for.
 	 */
-	GraphVertex find(Instruction inst);
+	GraphVertex find(const Instruction &inst);
 
 	/**
 	 * Finds a graph vertex through an instruction iterator.

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h	2010-07-01 21:39:07 UTC (rev 50570)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h	2010-07-01 21:46:15 UTC (rev 50571)
@@ -105,8 +105,7 @@
 		Graph g = c->getGraph();
 		TS_ASSERT(boost::num_vertices(g) == 3);
 		std::pair<VertexIterator, VertexIterator> range = boost::vertices(g);
-		for (VertexIterator it = range.first; it != range.second; ++it)
-		{
+		for (VertexIterator it = range.first; it != range.second; ++it) {
 			Group *gr = GET(*it);
 			switch (gr->_start->_address) {
 			case 0:


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