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

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Wed May 26 00:31:16 CEST 2010


Revision: 49222
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49222&view=rev
Author:   pidgeot
Date:     2010-05-25 22:31:16 +0000 (Tue, 25 May 2010)

Log Message:
-----------
Restructure disassembly framework

- Change existing class to a much more basic one
- Enhance parameter and instruction definitions
- Add generic object factory to create correct class when engine-specific stuff is needed.

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

Added Paths:
-----------
    tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
    tools/branches/gsoc2010-decompiler/decompiler/objectFactory.h

Modified: tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp	2010-05-25 20:47:48 UTC (rev 49221)
+++ tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp	2010-05-25 22:31:16 UTC (rev 49222)
@@ -1,12 +1,34 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
 #include <iostream>
-
 #include <boost/program_options.hpp>
 
+#include "objectFactory.h"
+
 using namespace std;
 using namespace boost::program_options;
 
 int main(int argc, char** argv) {
-
 	options_description visible("Options");
 	visible.add_options()
 		("help", "Produce this help message.")
@@ -35,7 +57,8 @@
 	}
 
 	if (vm.count("list")) {
-		cout << "TODO" << "\n";
+		//TODO
+		cout << "Listing of engines is not yet implemented." << "\n";
 		return 0;
 	}
 
@@ -48,5 +71,7 @@
 
 	cout << "Input file is " << vm["inputfile"].as<string>() << "\n";
 
+	//TODO: Process file
+
 	return 0;
 }

Added: tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp	                        (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp	2010-05-25 22:31:16 UTC (rev 49222)
@@ -0,0 +1,27 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
+#include "disassembler.h"
+
+void Disassembler::open(char *filename) {
+	f.open(filename);
+}


Property changes on: tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.h	2010-05-25 20:47:48 UTC (rev 49221)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.h	2010-05-25 22:31:16 UTC (rev 49222)
@@ -1,25 +1,48 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
 #ifndef DEC_DISASSEMBLER_H
 #define DEC_DISASSEMBLER_H
 
+#include <vector>
+
 #include "instruction.h"
 #include "common/file.h"
 
-struct Opcode {
-	uint32_t _opcode;
-	InstType _type;
-	char* name;
-	char* paramlist;
-};
+class Disassembler {
+protected:
+	Common::File f; ///<Used to perform file I/O.
 
-class Disassembler {
-	protected:
-		Common::File f;
-		
-		void readParams(Instruction* inst, char* paramInfo);
-		virtual void setupOpcodes() = 0;
-	public:
-		void open(char* filename);
-		void disassemble();
+public:
+	/**
+	 * Open a file for disassembly.		
+	 * @param filename 
+	 */
+	void open(char *filename);
+
+	/**
+	 * Disassembles a file.
+	 */
+	virtual std::vector<Instruction> disassemble() = 0;
 };
 
 #endif

Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h	2010-05-25 20:47:48 UTC (rev 49221)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h	2010-05-25 22:31:16 UTC (rev 49222)
@@ -1,30 +1,82 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
 #ifndef DEC_INSTRUCTION_H
 #define DEC_INSTRUCTION_H
 
-#include <stdint.h>
+#include <vector>
 
+#include "common/scummsys.h"
+
 /**
  * Enumeration for categorizing the different kinds of instructions.
  */
 enum InstType { 
-	ARITHMETIC,
-	BOOLEAN,
-	COMPARISON,
-	COND_JUMP,
-	JUMP,
-	LOAD,
-	SPECIAL,
-	STORE
+	kArithmetic,
+	kBoolean,
+	kComparison,
+	kCondJump,
+	kJump,
+	kLoad,
+	kSpecial,
+	kStore
 };
 
 /**
+ * Enumeration for categorizing the different kinds of parameters.
+ */
+enum ParamType {
+	kSByte,
+	kByte,
+	kShort,
+	kUShort,
+	kInt,
+	kUInt
+};
+
+/**
+ * Structure for representing a parameter.
+ */
+struct Parameter {
+  ParamType _type; ///<Type of the parameter.
+	union {
+		int8 _sbyte;
+		uint8 _byte;
+		int16 _short;
+		uint16 _ushort;
+		int32 _int;
+		uint32 _uint;
+	}; ///<Value of the parameter.
+};
+
+/**
  * Structure for representing an instruction.
  */
 struct Instruction {
-	uint32_t _address; ///<The instruction address.
-	uint32_t _opcode; ///<The instruction opcode.
+	uint32 _address; ///<The instruction address.
+	int16 _stackChange; ///<How much this instruction changes the stack pointer by.
+	char *_name; ///<The instruction name (opcode name).
 	InstType _type; ///<The instruction type.
-	void* _params[16]; ///<Array of pointers to point to the parameters used for the instruction.
+	std::vector<Parameter> _params; ///<Array of parameters used for the instruction.
 };
 
 #endif

Added: tools/branches/gsoc2010-decompiler/decompiler/objectFactory.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/objectFactory.h	                        (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/objectFactory.h	2010-05-25 22:31:16 UTC (rev 49222)
@@ -0,0 +1,70 @@
+/* ScummVM Tools
+* Copyright (C) 2010 The ScummVM project
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* $URL$
+* $Id$
+*
+*/
+
+#ifndef DEC_OBJECTFACTORY_H
+#define DEC_OBJECTFACTORY_H
+
+#include <map>
+#include <string>
+
+#include "common/scummsys.h"
+
+/**
+ * Template function for creating an instance of Type.
+ */
+template<typename BaseType, typename Type>
+BaseType *createObject() {
+	return new Type();
+}
+
+/**
+ * Generic factory for a class and its subclasses.
+ */
+template<typename BaseType>
+class ObjectFactory {
+private:
+
+	typedef BaseType *(*CreateFunc)(); ///<Function pointer to the object creation function.
+	std::map<std::string, CreateFunc> _registry; ///<Map from an identifier to a creation function.
+
+	/**
+	 * Register a new entry.
+	 * @param name The name to register the class under.
+	 */
+	template<typename Type>
+	void addEntry(std::string& name)	{
+		_registry[name] = &createObject<BaseType, Type>;
+	}
+
+	/**
+	 * Creates an instance of some registered class.
+	 * @param name The name associated with the desired class.
+	 * @return NULL if the name is not registered, else an instance of the associated class.
+	 */
+	BaseType *create(std::string name) {
+		if (_registry.find(name) == _registry.end())
+			return NULL;
+		return _registry[name]();
+	}
+};
+
+#endif


Property changes on: tools/branches/gsoc2010-decompiler/decompiler/objectFactory.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native


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