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

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Thu Jul 15 00:21:13 CEST 2010


Revision: 50898
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50898&view=rev
Author:   pidgeot
Date:     2010-07-14 22:21:12 +0000 (Wed, 14 Jul 2010)

Log Message:
-----------
Store the corresponding GraphVertex in Group

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

Modified: tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp	2010-07-14 22:19:05 UTC (rev 50897)
+++ tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp	2010-07-14 22:21:12 UTC (rev 50898)
@@ -44,7 +44,7 @@
 	for (ConstInstIterator it = insts.begin(); it != insts.end(); ++it) {
 		GraphVertex cur = boost::add_vertex(_g);
 		_addrMap[it->_address] = cur;
-		PUT(cur, new Group(it, it, prev));
+		PUT(cur, new Group(cur, it, it, prev));
 		PUT_ID(cur, id);
 		id++;
 

Modified: tools/branches/gsoc2010-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/graph.h	2010-07-14 22:19:05 UTC (rev 50897)
+++ tools/branches/gsoc2010-decompiler/decompiler/graph.h	2010-07-14 22:21:12 UTC (rev 50898)
@@ -55,140 +55,8 @@
  */
 typedef boost::intrusive_ptr<Group> GroupPtr;
 
-namespace boost {
-inline void intrusive_ptr_add_ref(Group *p);
-inline void intrusive_ptr_release(Group *p);
-} // End of namespace boost
 
 /**
- * Structure representing a group of instructions.
- */
-struct Group {
-private:
-  long _refCount;	///< Reference count used for boost::intrusive_ptr.
-  friend void ::boost::intrusive_ptr_add_ref(Group *p); ///< Allow access by reference counting methods in boost namespace.
-  friend void ::boost::intrusive_ptr_release(Group *p); ///< Allow access by reference counting methods in boost namespace.
-
-public:	
-	ConstInstIterator _start; ///< First instruction in the group.
-	ConstInstIterator _end;   ///< Last instruction in the group.
-	int _stackLevel;          ///< Level of the stack upon entry.
-	GroupType _type;          ///< Type of the group.
-	bool _startElse;          ///< Group is start of an else block.
-	Group *_endElse;          ///< Group is end of an else block.
-	Group *_prev;             ///< Pointer to the previous group, when ordered by address. Used for short-circuit analysis.
-	Group *_next;             ///< Pointer to the next group, when ordered by address.
-
-	/**
-	 * Parameterless constructor for Group. Required for use with STL and Boost, should not be called manually.
-	 */
-	Group() : _refCount(0), _stackLevel(-1), _type(kNormal) { }
-
-	/**
-	 * Constructor for Group.
-	 *
-	 * @param start First instruction in the group.
-	 * @param end   Last instruction in the group.
-	 * @param prev  Pointer to the previous group, when ordered by address.
-	 */
-	Group(ConstInstIterator start, ConstInstIterator end, GroupPtr prev) : _refCount(0) {
-		_start = start;
-		_end = end;
-		_stackLevel = -1;
-		_type = kNormal;
-		_prev = prev.get();
-		_startElse = false;
-		_endElse = NULL;
-		if (_prev != NULL)
-			_prev->_next = this;
-		_next = NULL;
-	}
-
-	/**
-	 * Output a group to an std::ostream as a graphviz label.
-	 *
-	 * @param output The std::ostream to output to.
-	 * @param group  The Group to output.
-	 * @return The std::ostream used for output.
-	 */
-	friend std::ostream &operator<<(std::ostream &output, GroupPtr group) {
-		output << "{Block type: ";
-		switch(group->_type) {
-		case kNormal:
-			output << "Normal";
-			break;
-		case kWhileCond:
-			output << "While condition";
-			break;
-		case kDoWhileCond:
-			output << "Do-while condition";
-			break;
-		case kIfCond:
-			output << "If condition";
-			break;
-		case kBreak:
-			output << "Break";
-			break;
-		case kContinue:
-			output << "Continue";
-			break;
-		}
-		output << "\\n";
-		if (group->_startElse)
-			output << "Start of else\\n";
-		if (group->_endElse)
-			output << boost::format("End of else at %08x\\n") % group->_endElse->_start->_address;
-		output << "|";
-		ConstInstIterator inst = group->_start;
-		do {
-			output << boost::format("%08x: %s") % inst->_address % inst->_name;
-			std::vector<Parameter>::const_iterator param;
-			for (param = inst->_params.begin(); param != inst->_params.end(); ++param) {
-				if (param != inst->_params.begin())
-					output << ",";
-				output << " ";
-				if (param->_type != kString)
-					output << param->_value;
-				else {
-					std::string s = param->getString();
-					for (std::string::iterator it = s.begin(); it != s.end(); ++it)
-						if (*it == '"')
-							output << "\\\"";
-						else if (*it == '|')
-							output << "\\|";
-						else if (*it == '{')
-							output << "\\{";
-						else if (*it == '}')
-							output << "\\}";
-						else
-							output << *it;
-				}
-			}
-			output << boost::format(" (%d)") % inst->_stackChange << "\\n";
-		} while (inst++ != group->_end);
-		output << "}";
-		return output;
-	}
-};
-
-namespace boost {
-/**
- * Add a reference to a pointer.
- */
-inline void intrusive_ptr_add_ref(Group *p) {
-	++(p->_refCount);
-}
-
-/**
- * Remove a reference from a pointer.
- */
-inline void intrusive_ptr_release(Group *p) {
-	if (--(p->_refCount) == 0)
-		delete p;
-}
-}
-
-/**
  * Type representing properties containing a pointer to a Group.
  */
 typedef boost::property<boost::vertex_name_t, GroupPtr> GroupProperty;
@@ -275,7 +143,6 @@
 
 } // End of namespace boost
 
-
 typedef boost::property<boost::edge_attribute_t, IsJump> EdgeProperty;
 
 /**
@@ -323,7 +190,143 @@
  */
 typedef std::pair<InEdgeIterator, InEdgeIterator> InEdgeRange;
 
+namespace boost {
+inline void intrusive_ptr_add_ref(Group *p);
+inline void intrusive_ptr_release(Group *p);
+} // End of namespace boost
+
 /**
+ * Structure representing a group of instructions.
+ */
+struct Group {
+private:
+  long _refCount;	///< Reference count used for boost::intrusive_ptr.
+  friend void ::boost::intrusive_ptr_add_ref(Group *p); ///< Allow access by reference counting methods in boost namespace.
+  friend void ::boost::intrusive_ptr_release(Group *p); ///< Allow access by reference counting methods in boost namespace.
+
+public:
+	GraphVertex _vertex;      ///< Vertex the group belongs to.
+	ConstInstIterator _start; ///< First instruction in the group.
+	ConstInstIterator _end;   ///< Last instruction in the group.
+	int _stackLevel;          ///< Level of the stack upon entry.
+	GroupType _type;          ///< Type of the group.
+	bool _startElse;          ///< Group is start of an else block.
+	Group *_endElse;          ///< Group is end of an else block.
+	Group *_prev;             ///< Pointer to the previous group, when ordered by address. Used for short-circuit analysis.
+	Group *_next;             ///< Pointer to the next group, when ordered by address.
+
+	/**
+	 * Parameterless constructor for Group. Required for use with STL and Boost, should not be called manually.
+	 */
+	Group() : _refCount(0), _stackLevel(-1), _type(kNormal) { }
+
+	/**
+	 * Constructor for Group.
+	 *
+	 * @param v     The vertex the group belongs to.
+	 * @param start First instruction in the group.
+	 * @param end   Last instruction in the group.
+	 * @param prev  Pointer to the previous group, when ordered by address.
+	 */
+	Group(GraphVertex v, ConstInstIterator start, ConstInstIterator end, GroupPtr prev) : _refCount(0) {
+		_vertex = v;
+		_start = start;
+		_end = end;
+		_stackLevel = -1;
+		_type = kNormal;
+		_prev = prev.get();
+		_startElse = false;
+		_endElse = NULL;
+		if (_prev != NULL)
+			_prev->_next = this;
+		_next = NULL;
+	}
+
+	/**
+	 * Output a group to an std::ostream as a graphviz label.
+	 *
+	 * @param output The std::ostream to output to.
+	 * @param group  The Group to output.
+	 * @return The std::ostream used for output.
+	 */
+	friend std::ostream &operator<<(std::ostream &output, GroupPtr group) {
+		output << "{Block type: ";
+		switch(group->_type) {
+		case kNormal:
+			output << "Normal";
+			break;
+		case kWhileCond:
+			output << "While condition";
+			break;
+		case kDoWhileCond:
+			output << "Do-while condition";
+			break;
+		case kIfCond:
+			output << "If condition";
+			break;
+		case kBreak:
+			output << "Break";
+			break;
+		case kContinue:
+			output << "Continue";
+			break;
+		}
+		output << "\\n";
+		if (group->_startElse)
+			output << "Start of else\\n";
+		if (group->_endElse)
+			output << boost::format("End of else at %08x\\n") % group->_endElse->_start->_address;
+		output << "|";
+		ConstInstIterator inst = group->_start;
+		do {
+			output << boost::format("%08x: %s") % inst->_address % inst->_name;
+			std::vector<Parameter>::const_iterator param;
+			for (param = inst->_params.begin(); param != inst->_params.end(); ++param) {
+				if (param != inst->_params.begin())
+					output << ",";
+				output << " ";
+				if (param->_type != kString)
+					output << param->_value;
+				else {
+					std::string s = param->getString();
+					for (std::string::iterator it = s.begin(); it != s.end(); ++it)
+						if (*it == '"')
+							output << "\\\"";
+						else if (*it == '|')
+							output << "\\|";
+						else if (*it == '{')
+							output << "\\{";
+						else if (*it == '}')
+							output << "\\}";
+						else
+							output << *it;
+				}
+			}
+			output << boost::format(" (%d)") % inst->_stackChange << "\\n";
+		} while (inst++ != group->_end);
+		output << "}";
+		return output;
+	}
+};
+
+namespace boost {
+/**
+ * Add a reference to a pointer.
+ */
+inline void intrusive_ptr_add_ref(Group *p) {
+	++(p->_refCount);
+}
+
+/**
+ * Remove a reference from a pointer.
+ */
+inline void intrusive_ptr_release(Group *p) {
+	if (--(p->_refCount) == 0)
+		delete p;
+}
+}
+
+/**
  * Type used to set properties for dot output.
  */
 struct GraphProperties {


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