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

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Tue Jun 8 23:41:34 CEST 2010


Revision: 49522
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49522&view=rev
Author:   pidgeot
Date:     2010-06-08 21:41:33 +0000 (Tue, 08 Jun 2010)

Log Message:
-----------
Refactored disassemblers

Disassembler::disassemble and Disassembler::dumpDisassembly are no
longer virtual, but perform the minimal functionality and ensure that
disassembly is performed once and only once. This helps to prevent
incorrect usage and implementation.

Modified Paths:
--------------
    tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
    tools/branches/gsoc2010-decompiler/decompiler/disassembler.h
    tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
    tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h
    tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp
    tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h
    tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.cpp
    tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.h

Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp	2010-06-08 21:21:19 UTC (rev 49521)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp	2010-06-08 21:41:33 UTC (rev 49522)
@@ -32,7 +32,7 @@
 	_f.open(filename, "rb");
 }
 
-void Disassembler::dumpDisassembly(std::ostream &output) {
+void Disassembler::doDumpDisassembly(std::ostream &output) {
 	std::vector<Instruction>::iterator inst;
 	for (inst = _insts.begin(); inst != _insts.end(); ++inst) {
 		output << boost::format("%08x: %s ") % inst->_address % inst->_name;
@@ -45,3 +45,15 @@
 		output << "\n";
 	}
 }
+
+const std::vector<Instruction> &Disassembler::disassemble() {
+	if (_insts.empty())
+		doDisassemble();
+	return _insts;
+}
+
+void Disassembler::dumpDisassembly(std::ostream &output) {
+	if (_insts.empty())
+		doDisassemble();
+	doDumpDisassembly(output);
+}

Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.h	2010-06-08 21:21:19 UTC (rev 49521)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.h	2010-06-08 21:41:33 UTC (rev 49522)
@@ -39,6 +39,18 @@
 	std::vector<Instruction> _insts; ///< Container for disassembled instructions.
 	uint32 _addressBase;             ///< Base address where the script starts.
 
+	/**
+	 * Performs disassembly.
+	 */
+	virtual void doDisassemble() = 0;
+
+	/**
+	 * Outputs the disassembled code.
+	 *
+	 * @param output The std::ostream to output to.
+	 */
+	virtual void doDumpDisassembly(std::ostream &output);
+
 public:
 	Disassembler();
 	virtual ~Disassembler() {}
@@ -51,15 +63,17 @@
 	void open(const char *filename);
 
 	/**
-	 * Disassembles a file.
+	 * Request disassembled instructions.
+	 *
+	 * @return An std::vector containing the disassembled instructions.
 	 */
-	virtual std::vector<Instruction> disassemble() = 0;
+	const std::vector<Instruction> &disassemble();
 
 	/**
-	 * Outputs the disassembly to a file.
+	 * Outputs the disassembled code. Disassembles code if this has not already been done.
 	 *
-	 * @param filename The file to output the disassembly to.
+	 * @param output The std::ostream to output to.
 	 */
-	virtual void dumpDisassembly(std::ostream &output);
+	void dumpDisassembly(std::ostream &output);
 };
 #endif

Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp	2010-06-08 21:21:19 UTC (rev 49521)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.cpp	2010-06-08 21:41:33 UTC (rev 49522)
@@ -25,7 +25,7 @@
 
 #include "disassembler.h"
 
-std::vector<Instruction> Scumm::v6::Disassembler::disassemble() {
+void Scumm::v6::Disassembler::doDisassemble() {
 	std::string blockName;
 	for (int i = 0; i < 4; i++) {
 		blockName += _f.readChar();
@@ -418,8 +418,6 @@
 		OPCODE(0xEC, "getActorLayer", kSpecial, 0, "");
 		OPCODE(0xED, "getObjectNewDir", kSpecial, 0, "");
 	END_OPCODES;
-
-	return _insts;
 }
 
 void Scumm::v6::Disassembler::readParameter(Parameter *p, char type) {

Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h	2010-06-08 21:21:19 UTC (rev 49521)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/disassembler.h	2010-06-08 21:41:33 UTC (rev 49522)
@@ -34,7 +34,7 @@
  */
 class Disassembler : public SimpleDisassembler {
 public:
-	std::vector<Instruction> disassemble();
+	void doDisassemble();
 
 	void readParameter(Parameter *p, char type);
 };

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp	2010-06-08 21:21:19 UTC (rev 49521)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.cpp	2010-06-08 21:41:33 UTC (rev 49522)
@@ -22,7 +22,7 @@
 
 #include "pasc.h"
 
-std::vector<Instruction> PasCDisassembler::disassemble() {
+void PasCDisassembler::doDisassemble() {
 	START_OPCODES;
 		//Basic machine operations
 		OPCODE(0x00, "PUSH", kStack, 0, "i");
@@ -126,6 +126,4 @@
 		OPCODE(0xD8, "BLOAD [SB]", kLoad, -5, "");
 		OPCODE(0xD9, "BLOAD", kLoad, -5, "");
 	END_OPCODES;
-
-	return _insts;
 }

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h	2010-06-08 21:21:19 UTC (rev 49521)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/pasc.h	2010-06-08 21:41:33 UTC (rev 49522)
@@ -27,6 +27,6 @@
 
 class PasCDisassembler : public SimpleDisassembler {
 public:
-	virtual std::vector<Instruction> disassemble();
+	virtual void doDisassemble();
 };
 #endif

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.cpp	2010-06-08 21:21:19 UTC (rev 49521)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.cpp	2010-06-08 21:41:33 UTC (rev 49522)
@@ -22,12 +22,10 @@
 
 #include "subopcode.h"
 
-std::vector<Instruction> SubOpcodeDisassembler::disassemble() {
+void SubOpcodeDisassembler::doDisassemble() {
 	START_OPCODES;
 		START_SUBOPCODE(0xFF)
 			OPCODE(0xFF, "FOO", kSpecial, 0, "");
 		END_SUBOPCODE
 	END_OPCODES;
-
-	return _insts;
 }

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.h	2010-06-08 21:21:19 UTC (rev 49521)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler/subopcode.h	2010-06-08 21:41:33 UTC (rev 49522)
@@ -27,6 +27,6 @@
 
 class SubOpcodeDisassembler : public SimpleDisassembler {
 public:
-	virtual std::vector<Instruction> disassemble();
+	virtual void doDisassemble();
 };
 #endif


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