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

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Wed Dec 15 00:12:10 CET 2010


Revision: 54915
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54915&view=rev
Author:   pidgeot
Date:     2010-12-14 23:12:10 +0000 (Tue, 14 Dec 2010)

Log Message:
-----------
DECOMPILER: Option to disable stack effect output

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

Modified: tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp	2010-12-14 23:00:42 UTC (rev 54914)
+++ tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp	2010-12-14 23:12:10 UTC (rev 54915)
@@ -24,6 +24,7 @@
 
 #include "disassembler.h"
 #include "engine.h"
+#include "instruction.h"
 
 #include "control_flow.h"
 
@@ -60,7 +61,8 @@
 			("only-disassembly,D", "Stops after disassembly. Implies -d.")
 			("only-graph,G", "Stops after control flow graph has been generated. Implies -g.")
 			("show-unreachable,u", "Show the address and contents of unreachable groups in the script.")
-			("variant,v", po::value<std::string>()->default_value(""), "Tell the engine that the script is from a specific variant. To see a list of variants supported by a specific engine, use the -h option and the -e option together.");
+			("variant,v", po::value<std::string>()->default_value(""), "Tell the engine that the script is from a specific variant. To see a list of variants supported by a specific engine, use the -h option and the -e option together.")
+			("no-stack-effect,s", "Leave out the stack effect when printing raw instructions.");
 
 		po::options_description args("");
 		args.add(visible).add_options()
@@ -118,6 +120,10 @@
 			return 2;
 		}
 
+		if (vm.count("no-stack-effect")) {
+			setOutputStackEffect(false);
+		}
+
 		Engine *engine = engineFactory.create(vm["engine"].as<std::string>());
 		engine->_variant = vm["variant"].as<std::string>();
 		std::string inputFile = vm["input-file"].as<std::string>();

Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp	2010-12-14 23:00:42 UTC (rev 54914)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp	2010-12-14 23:12:10 UTC (rev 54915)
@@ -40,7 +40,7 @@
 void Disassembler::doDumpDisassembly(std::ostream &output) {
 	InstIterator inst;
 	for (inst = _insts.begin(); inst != _insts.end(); ++inst) {
-		output << *inst;
+		output << *inst << "\n";
 	}
 }
 

Modified: tools/branches/gsoc2010-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/graph.h	2010-12-14 23:00:42 UTC (rev 54914)
+++ tools/branches/gsoc2010-decompiler/decompiler/graph.h	2010-12-14 23:12:10 UTC (rev 54915)
@@ -307,30 +307,25 @@
 		output << "|";
 		ConstInstIterator inst = group->_start;
 		do {
-			output << boost::format("%08x: %s") % (*inst)->_address % (*inst)->_name;
-			std::vector<ValuePtr>::const_iterator param;
-			for (param = (*inst)->_params.begin(); param != (*inst)->_params.end(); ++param) {
-				if (param != (*inst)->_params.begin())
-					output << ",";
-				output << " ";
-				if (BOOST_VERSION >= 104500)
-					output << *param;
-				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;
-				}
+			std::stringstream stream;
+			stream << *inst;
+			if (BOOST_VERSION >= 104500)
+				output << stream.str();
+			else {
+				std::string s = stream.str();
+				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";
+			output << "\\n";
 		} while (inst++ != group->_end);
 		output << "}";
 		return output;

Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.cpp	2010-12-14 23:00:42 UTC (rev 54914)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.cpp	2010-12-14 23:12:10 UTC (rev 54915)
@@ -24,6 +24,12 @@
 #include "codegen.h"
 #include "engine.h"
 
+bool outputStackEffect = true;
+
+void setOutputStackEffect(bool value) {
+	outputStackEffect = value;
+}
+
 bool Instruction::isJump() const {
 	return false;
 }
@@ -72,7 +78,8 @@
 			output << ",";
 		output << " " << *param;
 	}
-	output << boost::format(" (%d)") % _stackChange << "\n";
+	if (outputStackEffect)
+		output << boost::format(" (%d)") % _stackChange;
 	return output;
 }
 

Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h	2010-12-14 23:00:42 UTC (rev 54914)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h	2010-12-14 23:12:10 UTC (rev 54915)
@@ -38,6 +38,11 @@
 class Engine;
 
 /**
+ * Changes whether or not to output the stack effect for an instruction.
+ */
+void setOutputStackEffect(bool value);
+
+/**
  * Constants for categorizing the different kinds of instructions.
  */
 const int kBinaryOpInst = 0;     ///< Binary operation (e.g. +, &&, etc.), including comparisons.


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