retdec
|
A base class of all CFG traversals. More...
#include <cfg_traversal.h>
Protected Member Functions | |
CFGTraversal (ShPtr< CFG > cfg, bool defaultCurrRetVal) | |
Constructs a new traverser. More... | |
~CFGTraversal ()=default | |
bool | getCurrRetVal () const |
Returns the value that should be returned as the result of visiting a statement. More... | |
bool | performTraversal (ShPtr< Statement > startStmt) |
Performs a traversal of the current CFG, starting at startStmt. More... | |
bool | performTraversalFromSuccessors (ShPtr< Statement > stmt) |
Performs a traversal of the current CFG, starting at the successor(s) of stmt. More... | |
bool | performReverseTraversal (ShPtr< Statement > startStmt) |
Performs a reverse traversal of the current CFG, starting at startStmt. More... | |
bool | performReverseTraversalFromPredecessors (ShPtr< Statement > stmt) |
Performs a reverse traversal of the current CFG, starting at the predecessor(s) of stmt. More... | |
virtual bool | visitStmt (ShPtr< Statement > stmt)=0 |
Visits the given statement stmt. More... | |
virtual bool | getEndRetVal () const =0 |
Returns the value that should be returned when an end of the traversal is reached. More... | |
virtual bool | combineRetVals (bool origRetVal, bool newRetVal) const =0 |
Computes a new return value from the original return value (origRetVal) and the new return value (newRetVal). More... | |
Protected Attributes | |
ShPtr< CFG > | cfg |
CFG that is being traversed. More... | |
StmtUSet | checkedStmts |
Statements that have been checked (to prevent looping). More... | |
bool | currRetVal |
Current return value of visitStmt(). More... | |
bool | stopTraversal |
Should the traversal be stopped? More... | |
Private Member Functions | |
bool | performTraversalImpl (ShPtr< CFG::Node > startNode, CFG::stmt_iterator startStmtIter) |
A non-recursive implementation of performTraversal(). More... | |
std::pair< bool, bool > | visitSingleNode (CFG::stmt_iterator startStmtIter, CFG::stmt_iterator endStmtIter) |
Visit a single node during our traversal, and all the statements in it. More... | |
bool | performReverseTraversalImpl (ShPtr< CFG::Node > startNode, CFG::stmt_reverse_iterator startStmtRIter) |
A non-recursive implementation of performReverseTraversal(). More... | |
bool | traverseNodePredecessors (ShPtr< CFG::Node > node) |
Traverses all the predecessors of node. More... | |
![]() | |
NonCopyable (const NonCopyable &)=delete | |
NonCopyable & | operator= (const NonCopyable &)=delete |
NonCopyable ()=default | |
~NonCopyable ()=default | |
A base class of all CFG traversals.
A concrete CFG traverser has to implement all purely abstract member functions.
This class is based on the "Template method" design pattern.
Instances of this class have reference object semantics.
|
protected |
Constructs a new traverser.
[in] | cfg | CFG that should be traversed. |
[in] | defaultCurrRetVal | Default value of currRetVal . |
cfg
is non-null
|
protecteddefault |
|
protectedpure virtual |
Computes a new return value from the original return value (origRetVal) and the new return value (newRetVal).
Implemented in retdec::llvmir2hll::VarUseCFGTraversal, retdec::llvmir2hll::VarDefCFGTraversal, retdec::llvmir2hll::OptimFuncInfoCFGTraversal, retdec::llvmir2hll::NodesOfVarUseCFGTraversal, retdec::llvmir2hll::NoVarDefCFGTraversal, retdec::llvmir2hll::ModifiedBeforeReadCFGTraversal, and retdec::llvmir2hll::LhsRhsUsesCFGTraversal.
|
protected |
Returns the value that should be returned as the result of visiting a statement.
This function can be called only after calling visitStmt().
|
protectedpure virtual |
Returns the value that should be returned when an end of the traversal is reached.
For example, the end may mean the end node of the CFG or a statement that has already been traversed.
Implemented in retdec::llvmir2hll::VarUseCFGTraversal, retdec::llvmir2hll::VarDefCFGTraversal, retdec::llvmir2hll::OptimFuncInfoCFGTraversal, retdec::llvmir2hll::NodesOfVarUseCFGTraversal, retdec::llvmir2hll::NoVarDefCFGTraversal, retdec::llvmir2hll::ModifiedBeforeReadCFGTraversal, and retdec::llvmir2hll::LhsRhsUsesCFGTraversal.
|
private |
A non-recursive implementation of performReverseTraversal().
[in] | node | Node to be traversed. |
[in] | stmtRIter | Reverse iterator to a statement in node to be checked. |
If stmtIter equals node->stmt_rend()
, the function traverses all predecessors of node.
|
private |
A non-recursive implementation of performTraversal().
[in] | node | Node to be traversed. |
[in] | stmtIter | Iterator to a statement in node to be checked. |
This function traverses the entire CFG rooted at node, starting with the statement in stmtIter.
Traverses all the predecessors of node.
This function is meant to be called within functions traversing a CFG in reverse.
|
private |
Visit a single node during our traversal, and all the statements in it.
[in] | stmtIter | Iterator to a statement in node to be checked. |
[in] | endStmt | Iterator to last statement in node to be checked. |
|
protectedpure virtual |
Visits the given statement stmt.
return true
if the traversing should continue, false
otherwise.
Note: checkedStmts
is modified in CFGTraversal, so it is not necessary for the implementation of this function to add stmt to checkedStmts
.
If you want the traversal to end prematurely, set the stopTraversal variable to true
. Otherwise, if you just return false
, the traversal may still continue from other branches because of recursion.
Implemented in retdec::llvmir2hll::VarUseCFGTraversal, retdec::llvmir2hll::VarDefCFGTraversal, retdec::llvmir2hll::OptimFuncInfoCFGTraversal, retdec::llvmir2hll::NodesOfVarUseCFGTraversal, retdec::llvmir2hll::NoVarDefCFGTraversal, retdec::llvmir2hll::ModifiedBeforeReadCFGTraversal, and retdec::llvmir2hll::LhsRhsUsesCFGTraversal.
|
protected |
Statements that have been checked (to prevent looping).
|
protected |
Current return value of visitStmt().
|
protected |
Should the traversal be stopped?