ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SDG.h
Go to the documentation of this file.
1 /*
2  * File: SDG.h
3  * Author: Cong Hou [hou_cong@gatech.edu]
4  */
5 
6 #ifndef _______SDG_H_______
7 #define _______SDG_H_______
8 
9 #include "PDG.h"
10 #include <boost/function.hpp>
11 #include <boost/unordered_map.hpp>
12 
13 namespace SDG
14 {
15 
16 typedef std::vector<SgInitializedName*> VarName;
17 typedef std::map<SgNode*, std::set<SgNode*> > DefUseChains;
18 
19 struct SDGNode
20 {
21  enum NodeType
22  {
30  };
31 
32  SDGNode(NodeType t) : type(t), astNode(NULL) {}
33 
35 
36  //CFGNodePtr cfgNode;
37 
39 
41  //SgFunctionDefinition* funcDef;
42 
43 };
44 
45 struct SDGEdge
46 {
48  enum EdgeType
49  {
56  };
57 
59  {
64  };
65 
66  SDGEdge(EdgeType t) : type(t) {}
67 
70 
71  //============================================================================//
72  // Control dependence
73  void setTrue() { condition = cdTrue; }
74  void setFalse() { condition = cdFalse; }
76 
79 
82 
83 
84  //============================================================================//
85  // Data dependence
86 
88  std::set<VarName> varNames;
89 };
90 
91 
92 
93 class SystemDependenceGraph : public boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
94 SDGNode*, SDGEdge*>
95 {
96  public:
97  typedef boost::graph_traits<SystemDependenceGraph>::vertex_descriptor Vertex;
98  typedef boost::graph_traits<SystemDependenceGraph>::edge_descriptor Edge;
99 
100  protected:
104 
105  typedef boost::function<void(SgProject*, DefUseChains&)> DefUseChainsGen;
106  //typedef std::vector<DefUseChain> DefUseChains;
107 
108  protected:
109 
112 
115 
117  std::map<SgFunctionDeclaration*, CFG*> functionsToCFGs_;
118 
120  std::map<SgFunctionDeclaration*, Vertex> functionsToEntries_;
121 
122  boost::function<void(SgProject*, DefUseChains&)> defUseChainGenerator_;
123 
124 
126  {
127  CallSiteInfo() : funcCall(NULL), isVoid(true) {}
129 
132  std::vector<Vertex> inPara;
133  std::vector<Vertex> outPara;
134  // If the called function returns anything.
135  bool isVoid;
137  };
138 
139  public:
141  : project_(project), cfgNodefilter_(filter)
142  {}
143 
145  void build();
146 
148  { cfgNodefilter_ = filter; }
149 
150  void setDefUseChainsGenerator(const DefUseChainsGen& defUseChainsGen)
151  { defUseChainGenerator_ = defUseChainsGen; }
152 
153 
155  void toDot(const std::string& filename) const;
156 
157  protected:
159  {
160  Vertex newVertex = boost::add_vertex(*this);
161  (*this)[newVertex] = sdgNode;
162  return newVertex;
163  }
164 
165  Edge addEdge(Vertex src, Vertex tgt, SDGEdge* sdgEdge)
166  {
167  Edge newEdge = boost::add_edge(src, tgt, *this).first;
168  (*this)[newEdge] = sdgEdge;
169  return newEdge;
170  }
171 
173  void addTrueCDEdge(Vertex src, Vertex tgt);
174 
176  const boost::unordered_map<CFGVertex, Vertex>& cfgVerticesToSdgVertices,
177  const CFG& cfg, Vertex entry);
178 
180  const boost::unordered_map<SgNode*, Vertex>& astNodesToSdgVertices,
181  const std::vector<CallSiteInfo>& callSiteInfo,
182  const std::map<SgNode*, Vertex>& formalOutPara);
183 
185  void writeGraphNode(std::ostream& out, const Vertex& vertex) const;
186 
188  void writeGraphEdge(std::ostream& out, const Edge& edge) const;
189 
191  void writeGraphProperty(std::ostream& out) const;
192 
193 };
194 
195 } // end of Backstroke
196 
197 #endif /* _______SDG_H_______ */
198