5#include "AstAttributeMechanism.h"
46 CFG() : graph_(NULL), start_(NULL), entry_(NULL), exit_(NULL) {}
58 CFG(
SgNode* node,
bool is_filtered =
false)
59 : graph_(NULL), start_(node), entry_(NULL), exit_(NULL), is_filtered_(is_filtered)
70 { clearNodesAndEdges(); }
84 bool isFilteredCFG()
const {
return is_filtered_; }
85 void setFiltered(
bool flag) { is_filtered_ = flag; }
91 if (is_filtered_) buildFilteredCFG();
103 std::vector<SgDirectedGraphEdge*> getOutEdges(
SgNode* node,
int index);
104 std::vector<SgDirectedGraphEdge*> getInEdges(
SgNode* node,
int index);
108 std::vector<SgDirectedGraphEdge*> getOutEdges(
SgGraphNode* node);
109 std::vector<SgDirectedGraphEdge*> getInEdges(
SgGraphNode* node);
123 template <
class NodeT,
class EdgeT>
124 void buildCFG(NodeT n, std::map<NodeT, SgGraphNode*>& all_nodes, std::set<NodeT>& explored);
132 virtual void processNodes(std::ostream & o,
SgGraphNode* n, std::set<SgGraphNode*>& explored);
133 virtual void printNodePlusEdges(std::ostream & o,
SgGraphNode* node);
134 virtual void printNode(std::ostream & o,
SgGraphNode* node);
147 : index_(idx), graph_(graph) {}
149 int getIndex()
const {
return index_; }
151 void setIndex(
int idx) { index_ = idx; }
160template <
class EdgeT>
167 void setEdge(
const EdgeT& e)
170 EdgeT getEdge()
const
175std::vector<SgDirectedGraphEdge*> outEdges(
SgGraphNode* node);
176std::vector<SgDirectedGraphEdge*> inEdges(
SgGraphNode* node);
Base class for all IR node attribute values.
This class represents the base class for all IR nodes within Sage III.
This class stores index of each node as an attribuite of SgGraphNode.
SgNode * start_
The start node to begin CFG build.
SgGraphNode * entry_
The entry node.
SgGraphNode * getExit() const
Get the exit node of the CFG.
SgGraphNode * getEntry() const
Get the entry node of the CFG.
SgIncidenceDirectedGraph * getGraph() const
Get the pointer pointing to the graph used by static CFG.
void clearNodesAndEdges()
Delete all nodes and edges in the graph and release memories.
SgGraphNode * toGraphNode(CFGNode &n)
Turn a CFG node into a GraphNode which is defined in VirtualCFG namespace.
CFGNode toCFGNode(SgGraphNode *node)
Turn a graph node into a CFGNode which is defined in VirtualCFG namespace.
std::map< CFGNode, SgGraphNode * > all_nodes_
A map from CFGNode in virtualCFG to node from staticCFG.
void setStart(SgNode *node)
Set the start node for graph building.
virtual void buildFullCFG()
Build CFG for debugging.
bool is_filtered_
A flag shows whether this CFG is filtered or not.
SgGraphNode * exit_
The exit node.
SgIncidenceDirectedGraph * graph_
The graph data structure holding the CFG.
virtual void buildCFG()
Build CFG according to the 'is_filtered_' flag.
void cfgToDot(SgNode *node, const std::string &file_name)
Output the graph to a DOT file.
CFG(SgNode *node, bool is_filtered=false)
The constructor building the CFG.
static int getIndex(SgGraphNode *node)
Get the index of a CFG node.
virtual void buildFilteredCFG()
Build filtered CFG which only contains interesting nodes.
A control flow edge connecting two CFG nodes, with an edge condition to indicate edge types.
A node in the control flow graph.