ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dominatorTreesAndDominanceFrontiers/ControlFlowGraph.h
Go to the documentation of this file.
1 #ifndef _CONTROLFLOWGRAPH_H_
2 #define _CONTROLFLOWGRAPH_H_
3 
4 #include "SimpleDirectedGraph.h"
5 #include "CFGImpl.h"
6 #include "GraphDotOutput.h"
7 #include "virtualCFG.h"
8 
9 #include <map>
10 #include <queue>
11 #include <set>
12 
13 // DQ (12/30/2005): This is a Bad Bad thing to do (I can explain)
14 // it hides names in the global namespace and causes errors in
15 // otherwise valid and useful code. Where it is needed it should
16 // appear only in *.C files (and only ones not included for template
17 // instantiation reasons) else they effect user who use ROSE unexpectedly.
18 // using namespace std;
19 
20 
21 // DQ (3/21/2006): Namespace introduced to hide redundent use of
22 // ControlFlowGraph class also found in:
23 // src/midend/programTransformation/partialRedundancyElimination
24 namespace DominatorTreesAndDominanceFrontiers {
25 
26 class ControlNode;
27 
41 
42 public:
43 
52  enum ID_dir // NO_STRINGIFY
53  {
56  };
57 
59  ControlFlowGraph(SgNode * head);
60 
62  void createNode(CFGNodeImpl * node);
63 
65  int getSize() {return _numNodes;}
66 
68  ControlNode * getNode(int id, ID_dir dir) {return (dir == FORWARD)?_forIndex[id]:_backIndex[id];}
69 
71  void outputCFGImpl();
72 
73 private:
74 
75  void _buildCFGImpl(SgNode * head);
76 
77  void _buildCFG();
78  void _buildBranches(ControlNode * from, CFGNodeImpl * curr);
79  void _setupIDs(ID_dir);
80 
81  virtual void _displayData(SimpleDirectedGraphNode * data, std::ostream & os);
82 
83  DefaultCFGImpl * _cfg;
84 
85  int _numNodes;
88 
90  std::map<CFGNodeImpl *, ControlNode *> _cfgnodemap;
92  std::map<SgNode *, ControlNode *> _sgnodemap;
93 
98 };
99 
109 
110 public:
111 
112  enum Type // NO_STRINGIFY
113  {
116  };
117 
118  ControlNode(SgNode * node = NULL) : _node(node) {
119  if (_node)
120  _type = SGNODE;
121  else
122  _type = EMPTY;
123  }
124 
125  SgNode * getNode() {return _node;}
126  Type getType() {return _type;}
127 
129  if (dir == ControlFlowGraph::FORWARD) {
130  return _forID;
131  } else {
132  return _backID;
133  }
134  }
135 
136  void setID(int id, ControlFlowGraph::ID_dir dir) {
137  if (dir == ControlFlowGraph::FORWARD) {
138  _forID = id;
139  } else {
140  _backID = id;
141  }
142  }
143 
144  virtual void writeOut(std::ostream & os) {
145  char buf[sizeof(ControlNode *)*2 + 3];
146  sprintf(buf, "%p", this);
147  os << "(" << _forID << "/" << _backID << ": " << buf << ") ";
148  if (_type == EMPTY) {
149  os << "EMPTY";
150  } else {
151  char buf[sizeof(SgNode *) * 2 + 3];
152  sprintf(buf, "%p", _node);
153  os << buf << ":" << _node->sage_class_name() << " ";
154  os << "[" << escapeString(_node->unparseToString()) << "]";
155  }
156  }
157 
158 private:
159 
162 
163  int _forID;
164  int _backID;
165 
166 };
167 
168 // end of namespace: DominatorTreesAndDominanceFrontiers
169  }
170 
171 #endif