[Scummvm-cvs-logs] SF.net SVN: scummvm:[50697] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Mon Jul 5 20:02:55 CEST 2010
Revision: 50697
http://scummvm.svn.sourceforge.net/scummvm/?rev=50697&view=rev
Author: pidgeot
Date: 2010-07-05 18:02:54 +0000 (Mon, 05 Jul 2010)
Log Message:
-----------
Constify instruction vector in ControlFlow
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
tools/branches/gsoc2010-decompiler/decompiler/control_flow.h
tools/branches/gsoc2010-decompiler/decompiler/engine.h
tools/branches/gsoc2010-decompiler/decompiler/graph.h
tools/branches/gsoc2010-decompiler/decompiler/instruction.h
tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp 2010-07-05 17:40:32 UTC (rev 50696)
+++ tools/branches/gsoc2010-decompiler/decompiler/control_flow.cpp 2010-07-05 18:02:54 UTC (rev 50697)
@@ -32,14 +32,14 @@
#define PUT_ID(vertex, id) boost::put(boost::vertex_index, _g, vertex, id);
#define GET(vertex) (boost::get(boost::vertex_name, _g, vertex))
-ControlFlow::ControlFlow(std::vector<Instruction> &insts, Engine *engine) : _insts(insts) {
+ControlFlow::ControlFlow(const std::vector<Instruction> &insts, Engine *engine) : _insts(insts) {
_engine = engine;
GraphVertex last;
bool addEdge = false;
int id = 0;
Group *prev = NULL;
- for (InstIterator it = insts.begin(); it != insts.end(); ++it) {
+ for (ConstInstIterator it = insts.begin(); it != insts.end(); ++it) {
GraphVertex cur = boost::add_vertex(_g);
_addrMap[it->_address] = cur;
PUT(cur, new Group(it, it, prev));
@@ -53,7 +53,7 @@
prev = GET(cur);
}
- for (InstIterator it = insts.begin(); it != insts.end(); ++it) {
+ for (ConstInstIterator it = insts.begin(); it != insts.end(); ++it) {
switch(it->_type) {
case kJump:
case kCondJump:
@@ -71,7 +71,7 @@
return _addrMap[inst._address];
}
-GraphVertex ControlFlow::find(InstIterator it) {
+GraphVertex ControlFlow::find(ConstInstIterator it) {
return _addrMap[it->_address];
}
@@ -90,7 +90,7 @@
PUT(g1, gr1);
// Update address map
- InstIterator it = gr2->_start;
+ ConstInstIterator it = gr2->_start;
do {
_addrMap[it->_address] = g1;
++it;
@@ -135,8 +135,10 @@
}
void ControlFlow::createGroups() {
+ if (GET(find(_insts.begin()))->_stackLevel != -1)
+ return;
setStackLevel(find(_insts.begin()), 0);
- InstIterator curInst, nextInst;
+ ConstInstIterator curInst, nextInst;
nextInst = _insts.begin();
nextInst++;
int stackLevel = 0;
@@ -182,7 +184,7 @@
}
void ControlFlow::detectShortCircuit() {
- InstIterator lastInst = _insts.end();
+ ConstInstIterator lastInst = _insts.end();
--lastInst;
GraphVertex cur = find(lastInst);
Group *gr = GET(cur);
Modified: tools/branches/gsoc2010-decompiler/decompiler/control_flow.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/control_flow.h 2010-07-05 17:40:32 UTC (rev 50696)
+++ tools/branches/gsoc2010-decompiler/decompiler/control_flow.h 2010-07-05 18:02:54 UTC (rev 50697)
@@ -33,7 +33,7 @@
private:
Graph _g; ///< The control flow graph.
Engine *_engine; ///< Pointer to the Engine used for the script.
- std::vector<Instruction> &_insts; ///< The instructions being analyzed
+ const std::vector<Instruction> &_insts; ///< The instructions being analyzed
std::map<uint32, GraphVertex> _addrMap; ///< Map between addresses and vertices.
/**
@@ -48,7 +48,7 @@
*
* @param it The iterator to find the vertex for.
*/
- GraphVertex find(InstIterator it);
+ GraphVertex find(ConstInstIterator it);
/**
* Finds a graph vertex through an address.
@@ -126,7 +126,7 @@
* @param insts std::vector containing the instructions to analyze control flow for.
* @param engine Pointer to the Engine used for the script.
*/
- ControlFlow(std::vector<Instruction> &insts, Engine *engine);
+ ControlFlow(const std::vector<Instruction> &insts, Engine *engine);
/**
* Creates groups suitable for a stack-based machine.
Modified: tools/branches/gsoc2010-decompiler/decompiler/engine.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/engine.h 2010-07-05 17:40:32 UTC (rev 50696)
+++ tools/branches/gsoc2010-decompiler/decompiler/engine.h 2010-07-05 18:02:54 UTC (rev 50697)
@@ -44,7 +44,7 @@
*
* @param it Iterator pointing to the instruction to decode.
*/
- virtual uint32 getDestAddress(InstIterator it) const = 0;
+ virtual uint32 getDestAddress(ConstInstIterator it) const = 0;
};
#endif
Modified: tools/branches/gsoc2010-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-07-05 17:40:32 UTC (rev 50696)
+++ tools/branches/gsoc2010-decompiler/decompiler/graph.h 2010-07-05 18:02:54 UTC (rev 50697)
@@ -49,8 +49,8 @@
* Structure representing a group of instructions.
*/
struct Group {
- InstIterator _start; ///< First instruction in the group.
- InstIterator _end; ///< Last instruction in the group.
+ ConstInstIterator _start; ///< First instruction in the group.
+ ConstInstIterator _end; ///< Last instruction in the group.
int _stackLevel; ///< Level of the stack upon entry.
GroupType _type; ///< Type of the group.
bool _startElse; ///< Group is start of an else block.
@@ -73,7 +73,7 @@
* @param end Last instruction in the group.
* @param prev Pointer to the previous group, when ordered by address.
*/
- Group(InstIterator start, InstIterator end, Group *prev) {
+ Group(ConstInstIterator start, ConstInstIterator end, Group *prev) {
_start = start;
_end = end;
_stackLevel = -1;
@@ -120,10 +120,10 @@
output << "Start of else\\n";
if (group->_endElse)
output << "End of else\\n";
- InstIterator inst = group->_start;
+ ConstInstIterator inst = group->_start;
do {
output << boost::format("%08x: %s") % inst->_address % inst->_name;
- std::vector<Parameter>::iterator param;
+ std::vector<Parameter>::const_iterator param;
for (param = inst->_params.begin(); param != inst->_params.end(); ++param) {
if (param != inst->_params.begin())
output << ",";
Modified: tools/branches/gsoc2010-decompiler/decompiler/instruction.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-07-05 17:40:32 UTC (rev 50696)
+++ tools/branches/gsoc2010-decompiler/decompiler/instruction.h 2010-07-05 18:02:54 UTC (rev 50697)
@@ -109,4 +109,9 @@
*/
typedef std::vector<Instruction>::iterator InstIterator;
+/**
+ * Type representing a const_iterator over Instructions.
+ */
+typedef std::vector<Instruction>::const_iterator ConstInstIterator;
+
#endif
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp 2010-07-05 17:40:32 UTC (rev 50696)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp 2010-07-05 18:02:54 UTC (rev 50697)
@@ -27,7 +27,7 @@
return new Disassembler();
}
-uint32 Scumm::v6::Engine::getDestAddress(InstIterator it) const {
+uint32 Scumm::v6::Engine::getDestAddress(ConstInstIterator it) const {
switch(it->_type) {
case kJump:
case kCondJump:
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h 2010-07-05 17:40:32 UTC (rev 50696)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h 2010-07-05 18:02:54 UTC (rev 50697)
@@ -35,7 +35,7 @@
class Engine : public ::Engine {
public:
::Disassembler *getDisassembler() const;
- uint32 getDestAddress(InstIterator it) const;
+ uint32 getDestAddress(ConstInstIterator it) const;
};
} // End of namespace v6
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