ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

decompiler.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef STARK_TOOLS_SCRIPT_H
00024 #define STARK_TOOLS_SCRIPT_H
00025 
00026 #include "common/str.h"
00027 
00028 #include "engines/stark/resources/script.h"
00029 
00030 namespace Stark {
00031 
00032 namespace Resources {
00033 class Script;
00034 }
00035 
00036 namespace Tools {
00037 
00038 class Block;
00039 class CFGCommand;
00040 class DefinitionRegistry;
00041 struct ControlStructure;
00042 struct ASTBlock;
00043 struct ASTNode;
00044 struct ASTCondition;
00045 struct ASTLoop;
00046 
00047 class Decompiler {
00048 public:
00049     Decompiler(Resources::Script *script);
00050     ~Decompiler();
00051 
00052     void printCommands() const;
00053     void printBlocks() const;
00054     void printDecompiled();
00055 
00056     Common::String getError() const;
00057 
00058 private:
00059     // Command control flow graph construction
00060     bool checkCommands();
00061     void linkCommandBranches();
00062     CFGCommand *findEntryPoint();
00063 
00064     // Block control flow graph construction
00065     void buildBlocks();
00066     void buildBlocks(Block *block, CFGCommand *command);
00067     Block *buildBranchBlocks(CFGCommand *command);
00068 
00069     // Control flow analysis
00070     void analyseControlFlow();
00071     void detectInfiniteLoop();
00072     void detectWhile();
00073     void detectIf();
00074 
00075     // AST generation
00076     ASTNode *buildAST();
00077     void buildASTFromBlock(ASTBlock *parent, Block *block, Block *stopBlock);
00078     ASTCondition *buildASTConditionFromBlock(ASTNode *parent, Block *block);
00079     ASTLoop *buildASTLoopFromBlock(ASTNode *parent, Block *block);
00080 
00081     // AST verification
00082     void verifyAST();
00083     bool verifyCommandInAST(CFGCommand *cfgCommand);
00084     bool verifyCommandSuccessorInAST(CFGCommand *cfgCommand, CFGCommand *cfgSuccessor, ASTNode *astSuccessor, const char *successorType);
00085 
00086     Common::String _error;
00087 
00088     Common::Array<CFGCommand *> _commands;
00089     CFGCommand *_entryPoint;
00090 
00091     Common::Array<Block *> _blocks;
00092     Common::Array<ControlStructure *> _controlStructures;
00093 
00094     ASTNode *_astHead;
00095     Common::Array<Block *> _visitedInfiniteLoopStarts;
00096     Common::Array<Block *> _visitedBlocks;
00097 
00098     DefinitionRegistry *_definitionRegistry;
00099 };
00100 
00101 } // End of namespace Tools
00102 } // End of namespace Stark
00103 
00104 #endif // STARK_TOOLS_SCRIPT_H


Generated on Sat Dec 7 2019 05:00:39 for ResidualVM by doxygen 1.7.1
curved edge   curved edge