[Scummvm-cvs-logs] SF.net SVN: scummvm:[50629] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Sat Jul 3 21:53:53 CEST 2010
Revision: 50629
http://scummvm.svn.sourceforge.net/scummvm/?rev=50629&view=rev
Author: pidgeot
Date: 2010-07-03 19:53:52 +0000 (Sat, 03 Jul 2010)
Log Message:
-----------
Add detection of do-while conditions, including a test
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp 2010-07-03 19:51:18 UTC (rev 50628)
+++ tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp 2010-07-03 19:53:52 UTC (rev 50629)
@@ -243,6 +243,20 @@
}
void ControlFlow::detectDoWhile() {
+ VertexRange vr = boost::vertices(_g);
+ for (VertexIterator v = vr.first; v != vr.second; ++v) {
+ Group *gr = GET(*v);
+ // Block has not yet been determined and ends with conditional jump...
+ if (out_degree(*v, _g) == 2 && gr->_type == kNormal) {
+ OutEdgeRange oer = boost::out_edges(*v, _g);
+ for (OutEdgeIterator e = oer.first; e != oer.second; ++e) {
+ Group *targetGr = GET(boost::target(*e, _g));
+ // ...to earlier in code
+ if (targetGr->_start->_address < gr->_start->_address)
+ gr->_type = kDoWhileCond;
+ }
+ }
+ }
}
void ControlFlow::detectIf() {
Modified: tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h 2010-07-03 19:51:18 UTC (rev 50628)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h 2010-07-03 19:53:52 UTC (rev 50629)
@@ -153,4 +153,21 @@
TS_ASSERT(gr->_type == kWhileCond);
}
}
+
+ void testDoWhileDetection() {
+ Scumm::v6::Engine *engine = new Scumm::v6::Engine();
+ Disassembler *d = engine->getDisassembler();
+ d->open("decompiler/test/while.dmp");
+ std::vector<Instruction> insts = d->disassemble();
+ delete d;
+ ControlFlow *c = new ControlFlow(insts, engine);
+ c->createGroups();
+ Graph g = c->analyze();
+ VertexRange range = boost::vertices(g);
+ for (VertexIterator it = range.first; it != range.second; ++it) {
+ Group *gr = GET(*it);
+ if (gr->_start->_address == 3)
+ TS_ASSERT(gr->_type == kDoWhileCond);
+ }
+ }
};
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