[Scummvm-cvs-logs] SF.net SVN: scummvm:[50915] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Thu Jul 15 16:53:07 CEST 2010
Revision: 50915
http://scummvm.svn.sourceforge.net/scummvm/?rev=50915&view=rev
Author: pidgeot
Date: 2010-07-15 14:53:06 +0000 (Thu, 15 Jul 2010)
Log Message:
-----------
Write DFS to process graph vertices in code generation
Appears buggy, needs valgrind testing
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp
tools/branches/gsoc2010-decompiler/decompiler/graph.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp 2010-07-15 12:37:46 UTC (rev 50914)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp 2010-07-15 14:53:06 UTC (rev 50915)
@@ -23,7 +23,13 @@
#include "codegen.h"
#include <iostream>
+#include <set>
+#include <boost/format.hpp>
+
+#define GET(vertex) (boost::get(boost::vertex_name, _g, vertex))
+#define GET_EDGE(edge) (boost::get(boost::edge_attribute, _g, edge))
+
static int dupindex = 0;
EntryPtr StackEntry::dup(std::ostream &output) {
@@ -39,11 +45,53 @@
_engine = engine;
}
+typedef std::pair<GraphVertex, Stack> DFSEntry;
+
void CodeGenerator::generate(const Graph &g) {
_g = g;
- // TODO
+
+ std::cout << boost::format("Got %d vertices.\n") % boost::num_vertices(_g);
+
+ // Find entry point
+ // FIXME: For simplicity, we simply treat the first group as the entry point, because that's how SCUMM works.
+ // This should be changed later to allow for functions etc.
+ VertexRange vr = boost::vertices(_g);
+ GraphVertex entryPoint = *(vr.first);
+ GroupPtr p = GET(entryPoint);
+ while (p->_prev != NULL)
+ p = p->_prev;
+ entryPoint = p->_vertex;
+
+ // DFS from entry point to process each vertex
+ std::stack<DFSEntry> dfsStack;
+ std::set<GraphVertex> seen;
+ dfsStack.push(DFSEntry(entryPoint, Stack()));
+ seen.insert(entryPoint);
+ while (!dfsStack.empty()) {
+ DFSEntry e = dfsStack.top();
+ GroupPtr tmp = GET(e.first);
+ std::cout << boost::format("Found instruction at 0x%08x\n") % tmp->_start->_address;
+ dfsStack.pop();
+ _stack = e.second;
+ GraphVertex v = e.first;
+ process(v);
+ OutEdgeRange r = boost::out_edges(v, _g);
+ for (OutEdgeIterator i = r.first; i != r.second; i++) {
+ GraphVertex target = boost::target(*i, _g);
+ if (seen.find(target) == seen.end()) {
+ dfsStack.push(DFSEntry(target, _stack));
+ seen.insert(target);
+ }
+ }
+ }
+
+ // TODO: Print output
}
void CodeGenerator::process(GraphVertex v) {
+ GroupPtr p = GET(v);
+ std::cout << boost::format("Processing instruction at 0x%08x\n") % p->_start->_address;
+ std::cout << boost::format("Processing instruction at 0x%08x\n") % p->_end->_address;
+// std::cout << "Processing instruction...\n";
// TODO
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp 2010-07-15 12:37:46 UTC (rev 50914)
+++ tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp 2010-07-15 14:53:06 UTC (rev 50915)
@@ -149,7 +149,11 @@
delete cf;
- // TODO: Code generation
+ // Code generation
+ CodeGenerator *cg = engine->getCodeGenerator(std::cout);
+ cg->generate(g);
+
+ delete cg;
// Free memory
delete engine;
Modified: tools/branches/gsoc2010-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-07-15 12:37:46 UTC (rev 50914)
+++ tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-07-15 14:53:06 UTC (rev 50915)
@@ -55,7 +55,6 @@
*/
typedef boost::intrusive_ptr<Group> GroupPtr;
-
/**
* Type representing properties containing a pointer to a Group.
*/
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