[Scummvm-cvs-logs] SF.net SVN: scummvm:[50855] tools/branches/gsoc2010-decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Wed Jul 14 00:52:11 CEST 2010
Revision: 50855
http://scummvm.svn.sourceforge.net/scummvm/?rev=50855&view=rev
Author: pidgeot
Date: 2010-07-13 22:52:10 +0000 (Tue, 13 Jul 2010)
Log Message:
-----------
Add some metadata to StackEntry to easily tell the various types apart
Add functionality to create a duplicate entry from any entry
Add CodeGenerator creation to Engine
Prepare a SCUMMv6 code generator class
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/Makefile.common
tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
tools/branches/gsoc2010-decompiler/decompiler/codegen.h
tools/branches/gsoc2010-decompiler/decompiler/engine.h
tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h
tools/branches/gsoc2010-decompiler/decompiler/test/module.mk
Added Paths:
-----------
tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.h
Modified: tools/branches/gsoc2010-decompiler/Makefile.common
===================================================================
--- tools/branches/gsoc2010-decompiler/Makefile.common 2010-07-13 20:42:42 UTC (rev 50854)
+++ tools/branches/gsoc2010-decompiler/Makefile.common 2010-07-13 22:52:10 UTC (rev 50855)
@@ -277,7 +277,8 @@
decompiler/control_flow.o \
decompiler/codegen.o \
decompiler/scummv6/disassembler.o \
- decompiler/scummv6/engine.o
+ decompiler/scummv6/engine.o \
+ decompiler/scummv6/codegen.o
decompile_LIBS := \
-lboost_program_options
Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp 2010-07-13 20:42:42 UTC (rev 50854)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp 2010-07-13 22:52:10 UTC (rev 50855)
@@ -24,12 +24,23 @@
#include <iostream>
-CodeGenerator::CodeGenerator(Engine *engine, const Graph &g) {
+static int dupindex = 0;
+
+StackEntry *StackEntry::dup(std::ostream &output) {
+ if (_type == seDup)
+ return new DupEntry(*(DupEntry *)this);
+
+ StackEntry* dupEntry = new DupEntry(++dupindex);
+ output << this << " = " << dupEntry;
+ return dupEntry;
+}
+
+CodeGenerator::CodeGenerator(Engine *engine, std::ostream &output) : _output(output) {
_engine = engine;
- _g = g;
}
-void CodeGenerator::generate() {
+void CodeGenerator::generate(const Graph &g) {
+ _g = g;
// TODO
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.h 2010-07-13 20:42:42 UTC (rev 50854)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.h 2010-07-13 22:52:10 UTC (rev 50855)
@@ -20,7 +20,6 @@
*
*/
-#include "engine.h"
#include "graph.h"
#include <ostream>
@@ -29,11 +28,23 @@
#ifndef DEC_CODEGEN_H
#define DEC_CODEGEN_H
+class Engine;
+
+typedef int StackEntryType;
+
+const StackEntryType seInt = 0;
+const StackEntryType seVar = 1;
+const StackEntryType seBinOp = 2;
+const StackEntryType seUnaryOp = 3;
+const StackEntryType seDup = 4;
+
/**
* Base class for stack entries.
*/
class StackEntry {
public:
+ StackEntryType _type;
+
virtual ~StackEntry() {}
/**
@@ -43,6 +54,14 @@
* @return The std::ostream used for output.
*/
virtual std::ostream &print(std::ostream &output) const = 0;
+
+ /**
+ * Duplicates a stack entry.
+ *
+ * @param output The std::ostream to output to.
+ * @return A StackEntry corresponding to a duplicate of this entry.
+ */
+ virtual StackEntry *dup(std::ostream &output);
/**
* Output a stack entry to an std::ostream.
@@ -71,7 +90,9 @@
* @param val The value contained in the stack entry.
* @param isSigned Whether or not the value is signed. This will affect output.
*/
- IntEntry(int32 val, bool isSigned) : _val(val), _isSigned(isSigned) {}
+ IntEntry(int32 val, bool isSigned) : _val(val), _isSigned(isSigned) {
+ _type = seInt;
+ }
/**
* Constructor for IntEntry.
@@ -81,6 +102,7 @@
*/
IntEntry(uint32 val, bool isSigned) : _isSigned(isSigned) {
_val = (int32)val;
+ _type = seInt;
}
virtual std::ostream &print(std::ostream &output) const {
@@ -89,7 +111,9 @@
else
output << (uint32)_val;
return output;
- };
+ }
+
+ virtual StackEntry *dup() { return new IntEntry(_val, _isSigned); }
};
/**
@@ -105,7 +129,9 @@
*
* @param varName The name of the variable.
*/
- VarEntry(std::string varName) : _varName(varName) {};
+ VarEntry(std::string varName) : _varName(varName) {
+ _type = seVar;
+ };
virtual std::ostream &print(std::ostream &output) const { return output << _varName; }
};
@@ -127,7 +153,9 @@
* @param rhs Stack entry representing the right side of the operator.
* @param op The operator for this entry.
*/
- BinaryOpEntry(StackEntry *lhs, StackEntry *rhs, std::string op) : _lhs(lhs), _rhs(rhs), _op(op) {}
+ BinaryOpEntry(StackEntry *lhs, StackEntry *rhs, std::string op) : _lhs(lhs), _rhs(rhs), _op(op) {
+ _type = seBinOp;
+ }
virtual std::ostream &print(std::ostream &output) const { return output << _lhs << " " << _op << " " << _rhs; }
};
@@ -147,12 +175,33 @@
* @param operand Stack entry representing the operand of the operation.
* @param op The operator for this entry.
*/
- UnaryOpEntry(StackEntry *operand, std::string op) : _operand(operand), _op(op) {}
+ UnaryOpEntry(StackEntry *operand, std::string op) : _operand(operand), _op(op) {
+ _type = seUnaryOp;
+ }
virtual std::ostream &print(std::ostream &output) const { return output << _op << _operand; }
};
/**
+ * Duplicated stack entry.
+ */
+class DupEntry : public StackEntry {
+private:
+ int _idx; ///< Index to distinguish multiple duplicated entries.
+
+public:
+ /**
+ * Constructor for DupEntry.
+ *
+ * @param idx Index to distinguish multiple duplicated entries.
+ */
+ DupEntry(int idx) : _idx(idx) {
+ _type = seDup;
+ }
+ virtual std::ostream &print(std::ostream &output) const { return output << "dup[" << _idx << "]"; }
+};
+
+/**
* Base class for code generators.
*/
class CodeGenerator {
@@ -168,13 +217,14 @@
void process(GraphVertex v);
protected:
- std::stack<StackEntry *> _stack; ///< The stack at the current point of the generation.
+ std::ostream &_output; ///< The std::ostream to output the code to.
+
/**
* Processes an instruction.
*
* @param inst The instruction to process.
*/
- virtual void process(Instruction inst) = 0;
+ virtual void processInst(Instruction inst) = 0;
public:
virtual ~CodeGenerator() {};
@@ -183,14 +233,16 @@
* Constructor for CodeGenerator.
*
* @param engine Pointer to the Engine used for the script.
- * @param g The annotated graph of the script.
+ * @param output The std::ostream to output the code to.
*/
- CodeGenerator(Engine *engine, const Graph &g);
+ CodeGenerator(Engine *engine, std::ostream &output);
/**
* Generates code from the provided graph and outputs it to stdout.
+ *
+ * @param g The annotated graph of the script.
*/
- void generate();
+ void generate(const Graph &g);
};
#endif
Modified: tools/branches/gsoc2010-decompiler/decompiler/engine.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/engine.h 2010-07-13 20:42:42 UTC (rev 50854)
+++ tools/branches/gsoc2010-decompiler/decompiler/engine.h 2010-07-13 22:52:10 UTC (rev 50855)
@@ -24,6 +24,7 @@
#define ENGINE_H
#include "disassembler.h"
+#include "codegen.h"
/**
* Base class for engines.
@@ -40,11 +41,20 @@
virtual Disassembler *getDisassembler() const = 0;
/**
- * Decode a jump-instruction to get the destination address.
+ * Decode a jump instruction to get the destination address.
*
* @param it Iterator pointing to the instruction to decode.
+ * @return The destination address of the jump instruction
*/
virtual uint32 getDestAddress(ConstInstIterator it) const = 0;
+
+ /**
+ * Retrieve the code generator for the engine.
+ *
+ * @param output The std::ostream to output the code to.
+ * @return Pointer to a CodeGenerator for the engine.
+ */
+ virtual CodeGenerator *getCodeGenerator(std::ostream &output) = 0;
};
#endif
Added: tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp 2010-07-13 22:52:10 UTC (rev 50855)
@@ -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 "codegen.h"
+
+void Scumm::v6::CodeGenerator::processInst(Instruction inst) {
+ // TODO
+}
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.h (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.h 2010-07-13 22:52:10 UTC (rev 50855)
@@ -0,0 +1,46 @@
+/* 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 SCUMM_V6_CODEGEN_H
+#define SCUMM_V6_CODEGEN_H
+
+#include "../codegen.h"
+
+namespace Scumm {
+
+namespace v6 {
+
+/**
+ * SCUMMv6 code generator.
+ */
+class CodeGenerator : public ::CodeGenerator {
+public:
+ CodeGenerator(Engine *engine, std::ostream &output) : ::CodeGenerator(engine, output) {}
+protected:
+ void processInst(Instruction inst);
+};
+
+} // End of namespace v6
+
+} // End of namespace Scumm
+
+#endif
Property changes on: tools/branches/gsoc2010-decompiler/decompiler/scummv6/codegen.h
___________________________________________________________________
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/scummv6/engine.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp 2010-07-13 20:42:42 UTC (rev 50854)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp 2010-07-13 22:52:10 UTC (rev 50855)
@@ -22,6 +22,7 @@
#include "engine.h"
#include "disassembler.h"
+#include "codegen.h"
::Disassembler *Scumm::v6::Engine::getDisassembler() const {
return new Disassembler();
@@ -39,3 +40,7 @@
return 0;
}
}
+
+::CodeGenerator *Scumm::v6::Engine::getCodeGenerator(std::ostream &output) {
+ return new CodeGenerator(this, output);
+}
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h 2010-07-13 20:42:42 UTC (rev 50854)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h 2010-07-13 22:52:10 UTC (rev 50855)
@@ -36,6 +36,7 @@
public:
::Disassembler *getDisassembler() const;
uint32 getDestAddress(ConstInstIterator it) const;
+ ::CodeGenerator *getCodeGenerator(std::ostream &output);
};
} // End of namespace v6
Modified: tools/branches/gsoc2010-decompiler/decompiler/test/module.mk
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/module.mk 2010-07-13 20:42:42 UTC (rev 50854)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/module.mk 2010-07-13 22:52:10 UTC (rev 50855)
@@ -8,10 +8,12 @@
TESTS := $(srcdir)/decompiler/test/*.h
TEST_LIBS := \
common/file.o\
+ decompiler/codegen.o \
decompiler/control_flow.o \
decompiler/disassembler.o \
decompiler/simple_disassembler.o \
decompiler/scummv6/disassembler.o \
+ decompiler/scummv6/codegen.o \
decompiler/scummv6/engine.o \
decompiler/test/disassembler/pasc.o \
decompiler/test/disassembler/subopcode.o \
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