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

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Sat Jul 31 02:56:44 CEST 2010


Revision: 51528
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51528&view=rev
Author:   pidgeot
Date:     2010-07-31 00:56:43 +0000 (Sat, 31 Jul 2010)

Log Message:
-----------
Function detection improvements

Add function information from Kyra disassembler
Change storage to a map instead of a set to allow modification

Modified Paths:
--------------
    tools/branches/gsoc2010-decompiler/decompiler/engine.h
    tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp

Modified: tools/branches/gsoc2010-decompiler/decompiler/engine.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/engine.h	2010-07-31 00:54:32 UTC (rev 51527)
+++ tools/branches/gsoc2010-decompiler/decompiler/engine.h	2010-07-31 00:56:43 UTC (rev 51528)
@@ -38,7 +38,7 @@
 	std::string _name;     ///< Function name.
 	GraphVertex _v;        ///< Graph vertex for the entry point to the function.
 	uint32 _args;          ///< Number of arguments to the function.
-	bool retVal;           ///< Whether or not the function returns a value.
+	bool _retVal;           ///< Whether or not the function returns a value.
 	std::string _metadata; ///< Metadata for code generation.
 
 	/**
@@ -56,16 +56,14 @@
 	 */
 	Function(InstIterator startIt, InstIterator endIt) : _startIt(startIt), _endIt(endIt) {
 	}
-
-	/**
-	 * Operator overload for <. Used for storage in an std::set.
-	 */
-	bool operator<(const Function &f) const {
-		return _startIt->_address < f._startIt->_address;
-	}
 };
 
 /**
+ * Type representing a map of functions, indexed by starting address.
+ */
+typedef std::map<uint32, Function> FuncMap;
+
+/**
  * Base class for engines.
  */
 class Engine {
@@ -109,7 +107,7 @@
 	 */
 	virtual bool supportsCodeGen() { return true; }
 
-	std::set<Function> _functions; ///< Functions in the current script.
+	FuncMap _functions; ///< Map to functions in the current script, indexed by starting address.
 };
 
 #endif

Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp	2010-07-31 00:54:32 UTC (rev 51527)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp	2010-07-31 00:56:43 UTC (rev 51528)
@@ -25,6 +25,7 @@
 
 #include <algorithm>
 #include <iostream>
+#include <sstream>
 #include <boost/format.hpp>
 
 struct FunctionData {
@@ -545,15 +546,6 @@
 #undef ADD_INST
 	}
 
-	std::sort(funcAddrs.begin(), funcAddrs.end());
-	//Create ranges from entry points
-	for (size_t i = 0; i < funcAddrs.size(); i++) {
-		if (i == funcAddrs.size() - 1) // Last function
-			_engine->_functions.insert(Function(addrMap[funcAddrs[i]], _insts.end()));
-		else
-			_engine->_functions.insert(Function(addrMap[funcAddrs[i]], addrMap[funcAddrs[i+1]]));
-	}
-
 	// Function detection
 	uint16 nextFunc = 0;
 	// Process candidate entry points
@@ -572,7 +564,7 @@
 					continue;
 
 			if (lastWasPop && _insts[i]._name.compare("popPos") == 0) {
-				_engine->_functions.insert(Function(addrMap[_insts[*it]._address], addrMap[_insts[i]._address]));
+				_engine->_functions[_insts[*it]._address] = Function(addrMap[_insts[*it]._address], addrMap[_insts[i]._address]);
 				nextFunc = _insts[i]._address;
 				break;
 			}
@@ -580,4 +572,28 @@
 			lastWasPop = (_insts[i]._name.compare("popPos") == 0);
 		}
 	}
+
+	for (FuncMap::iterator it = _engine->_functions.begin(); it != _engine->_functions.end(); ++it) {
+		std::stringstream s;
+		s << boost::format("sub0x%X") % it->second._startIt->_address;
+		int maxArg = 0;
+		for (InstIterator instIt = it->second._startIt; instIt != it->second._endIt; ++instIt) {
+			if (instIt->_name.compare("pushBPAdd") == 0) {
+				if (maxArg < instIt->_params[0].getSigned()) {
+					maxArg = instIt->_params[0].getSigned();
+				}
+			}
+		}
+		it->second._args = maxArg;
+		it->second._retVal = true;
+	}
+
+	std::sort(funcAddrs.begin(), funcAddrs.end());
+	//Create ranges from entry points
+	for (size_t i = 0; i < funcAddrs.size(); i++) {
+		if (i == funcAddrs.size() - 1) // Last function
+			_engine->_functions[funcAddrs[i]] = Function(addrMap[funcAddrs[i]], _insts.end());
+		else
+			_engine->_functions[funcAddrs[i]] = Function(addrMap[funcAddrs[i]], addrMap[funcAddrs[i+1]]);
+	}
 }


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