ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
newCDG.h
Go to the documentation of this file.
1 #ifndef ___________CDG_H__________
2 #define ___________CDG_H__________
3 
4 #include "cong_staticCFG.h"
5 using namespace StaticCFG;
6 
7 namespace SDG
8 {
9 
10 
11 struct CDGEdge
12 {
15 
18 
21 
22  std::string toString() const
23  {
24  switch (condition)
25  {
26  case eckTrue:
27  return "T";
28  case eckFalse:
29  return "F";
30  case eckCaseLabel:
31  return "case" + caseLabel->unparseToString();
32  case eckDefault:
33  return "default";
34  default:
35  break;
36  }
37  return "";
38  }
39 };
40 
41 
42 class ControlDependenceGraph : public boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
43  CFGNodePtr, CDGEdge>
44 {
45 public:
46  typedef boost::graph_traits<ControlDependenceGraph> GraphTraits;
47  typedef GraphTraits::vertex_descriptor Vertex;
48  typedef GraphTraits::edge_descriptor Edge;
49 
50 
52  {
53  ControlDependence(const CDGEdge& edge, SgNode* node)
54  : cdEdge(edge), cdNode(node) {}
55 
58 
60  //CDGNode cdNode;
61 
64  };
65 
66  typedef std::vector<ControlDependence> ControlDependences;
67 
70 
73  { build(cfg); }
74 
76  void build(const ControlFlowGraph& cfg);
77 
79  ControlDependences getControlDependences(CFGNodePtr cfgNode);
80 
82  ControlDependences getControlDependences(SgNode* astNode);
83 
87  Vertex getCDGVertex(SgNode* astNode);
88 
90  void toDot(const std::string& filename) const;
91 
94  static void writeGraphEdge(std::ostream& out, const CDGEdge& edge);
95 
96 protected:
97 
102  typedef std::map<
104  std::map<ControlFlowGraph::Vertex,
105  std::vector<ControlFlowGraph::Edge> > >
107 
109  bool checkCycle(const ControlFlowGraph& cfg);
110 
112  void writeGraphNode(std::ostream& out, const Vertex& node) const
113  {
114  writeCFGNode(out, *(*this)[node]);
115  }
116 
118  void writeGraphEdge(std::ostream& out, const Edge& edge) const
119  {
120  writeGraphEdge(out, (*this)[edge]);
121  }
122 
124  void appendSuccessors(
125  Vertex v,
126  std::vector<Vertex>& vertices,
127  const std::map<Vertex, std::set<Vertex> >& iSucc);
128 
131  const std::map<ControlFlowGraph::Vertex, ControlFlowGraph::Vertex>& iDom, const ControlFlowGraph& cfg);
132 };
133 
134 
135 } // end of namespace
136 
137 #endif /* ___________CDG_H__________ */
138