![]() |
V-Gears 0
Free Final Fantasy VII engine.
|
Class for doing code flow analysis. More...
#include <ControlFlow.h>
Public Member Functions | |
ControlFlow (InstVec &insts, Engine &engine) | |
Constructor for the control flow graph. More... | |
ControlFlow (const ControlFlow &control_flow)=delete | |
Copy constructor disabled. More... | |
ControlFlow & | operator= (const ControlFlow &control_flow)=delete |
Copy constructor disabled. More... | |
const Graph & | GetGraph () const |
Retrieves the current control flow graph. More... | |
void | CreateGroups () |
Creates groups suitable for a stack-based machine. More... | |
const Graph & | Analyze () |
Performs control flow analysis. More... | |
Private Member Functions | |
GraphVertex | Find (const InstPtr inst) |
Finds a graph vertex through an instruction. More... | |
GraphVertex | Find (ConstInstIterator it) |
Finds a graph vertex through an instruction iterator. More... | |
GraphVertex | Find (uint32 address) |
Finds a graph vertex through an address. More... | |
void | Merge (GraphVertex graph_1, GraphVertex graph_2) |
Merges two graph vertices. More... | |
void | SetStackLevel (GraphVertex graph, int level) |
Sets the stack level for all instructions, using depth-first search. More... | |
void | DetectShortCircuit () |
Merged groups that are part of the same short-circuited condition. More... | |
void | DetectWhile () |
Detects while blocks. More... | |
void | DetectDoWhile () |
Detects do-while blocks. More... | |
void | DetectBreak () |
Detects break statements. More... | |
void | DetectContinue () |
Detects continue statements. More... | |
bool | ValidateBreakOrContinue (GroupPtr group, GroupPtr condition_group) |
Checks if a candidate break/continue goes to the closest loop. More... | |
void | DetectIf () |
Detects if blocks. More... | |
void | DetectElse () |
Detects else blocks. More... | |
bool | ValidateElseBlock (GroupPtr if_group, GroupPtr start, GroupPtr end) |
Checks if a candidate else block will cross block boundaries. More... | |
Private Attributes | |
Graph | graph_ |
The control flow graph. More... | |
Engine & | engine_ |
The engine used for the script. More... | |
InstVec & | insts_ |
The instructions being analyzed. More... | |
std::map< uint32, GraphVertex > | addr_map_ |
Map of addresses and vertices. More... | |
Class for doing code flow analysis.
Constructor for the control flow graph.
[in] | insts | The instructions to analyze control flow for. |
[in] | engine | Pointer to the Engine used for the script. |
|
delete |
Copy constructor disabled.
[in] | control_flow | The control flow to copy. |
const Graph & ControlFlow::Analyze | ( | ) |
Performs control flow analysis.
The constructs are detected in the following order: do-while, while, break, continue, if/else.
void ControlFlow::CreateGroups | ( | ) |
Creates groups suitable for a stack-based machine.
Before group creation, the expected stack level for each instruction is determined. After group creation, short-circuit detection is applied to the groups.
|
private |
Detects break statements.
Do-while and while detection must be completed before running this method.
|
private |
Detects continue statements.
Do-while and while detection must be completed before running this method.
|
private |
Detects do-while blocks.
|
private |
Detects else blocks.
Must be performed after if detection.
|
private |
Detects if blocks.
Must be performed after break and continue detection.
|
private |
Merged groups that are part of the same short-circuited condition.
|
private |
Detects while blocks.
Do-while detection must be completed before running this method.
|
private |
Finds a graph vertex through an instruction.
[in] | inst | The instruction to find the vertex for. |
|
private |
Finds a graph vertex through an instruction iterator.
[in] | it | The iterator to find the vertex for. |
|
private |
Finds a graph vertex through an address.
[in] | address | The address to find the vertex for. |
const Graph & ControlFlow::GetGraph | ( | ) | const |
Retrieves the current control flow graph.
|
private |
Merges two graph vertices.
graph_2 will be merged into graph_1.
[in,out] | graph_1 | The first vertex to merge. |
[in] | graph_2 | The second vertex to merge. |
|
delete |
Copy constructor disabled.
[in] | control_flow | The control flow to copy. |
|
private |
Sets the stack level for all instructions, using depth-first search.
[in] | graph | The GraphVertex to search from. |
[in] | level | The stack level when g is reached. |
Checks if a candidate break/continue goes to the closest loop.
[in] | group | The group containing the candidate break/continue. |
[in] | condition_group | The group containing the respective loop condition. |
Checks if a candidate else block will cross block boundaries.
[in] | if_group | The group containing the if this else candidate is associated with. |
[in] | start | The group containing the start of the else. |
[in] | end | The group immediately after the group ending the else. |
|
private |
Map of addresses and vertices.
|
private |
The engine used for the script.
|
private |
The control flow graph.
|
private |
The instructions being analyzed.