All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
graph_helper.h
Go to the documentation of this file.
1 #ifndef GRAPH_HELPER_H_INCLUDED_
2 #define GRAPH_HELPER_H_INCLUDED_
3 
4 #include<set>
5 #include<utility>
6 #include<list>
7 
8 #include "rose.h"
9 
10 #include "boost/graph/adjacency_list.hpp"
11 #include "boost/graph/breadth_first_search.hpp"
12 
13 #include "segment_graph.h" // needed for vertex_descriptor
14 
15 namespace risc {
16 
17 namespace sg {
18 
19 class LeafNodeVisitor: public boost::default_bfs_visitor {
20 
21 public:
22 
23  LeafNodeVisitor(std::set<Graph::vertex_descriptor>& leaf_nodes):
24  leaf_nodes_(leaf_nodes)
25  { }
26 
29  { }
30 
31 
32  void discover_vertex(const Graph::vertex_descriptor vertex,
33  const Graph &graph)
34  {
35  if(boost::out_degree(vertex, graph) == 0) {
36  leaf_nodes_.insert(vertex);
37  }
38  }
39 
43  std::set<Graph::vertex_descriptor>& leaf_nodes_;
44 };
45 
46 
47 class BreakStmtVisitor: public boost::default_bfs_visitor {
48 
49 public:
50 
51  BreakStmtVisitor(std::set<Graph::vertex_descriptor>& segment_with_break):
52  segment_with_break_(segment_with_break)
53  { }
54 
57  { }
58 
64  void discover_vertex(const Graph::vertex_descriptor vertex,
65  const Graph &graph)
66  {
67  for(std::list<NodeWithPath>::const_iterator
68  iter = graph[vertex].expressions_.begin();
69  iter != graph[vertex].expressions_.end();
70  iter++) {
71 
72  if(isSgBreakStmt(iter->node_)) {
73  segment_with_break_.insert(vertex);
74  return;
75  }
76  }
77  }
78 
82  std::set<Graph::vertex_descriptor>& segment_with_break_;
83 };
84 
85 
86 class ContinueStmtVisitor: public boost::default_bfs_visitor {
87 
88 public:
89 
90  ContinueStmtVisitor(std::set<Graph::vertex_descriptor>& segment_with_break):
91  segment_with_break_(segment_with_break)
92  { }
93 
96  { }
97 
103  void discover_vertex(const Graph::vertex_descriptor vertex,
104  const Graph &graph)
105  {
106  for(std::list<NodeWithPath>::const_iterator
107  iter = graph[vertex].expressions_.begin();
108  iter != graph[vertex].expressions_.end();
109  iter++) {
110 
111  if(isSgContinueStmt(iter->node_)) {
112  segment_with_break_.insert(vertex);
113  return;
114  }
115  }
116  }
117 
121  std::set<Graph::vertex_descriptor>& segment_with_break_;
122 };
123 
129 std::list<int>
130 get_all_reachable_segments(SegmentGraph &segment_graph, int starting_id);
131 
132 
140 std::vector<VertexDescriptor>
142  SegmentGraph &segment_graph,
143  VertexDescriptor start_vertex);
144 
152 std::pair<risc::sg::VertexDescriptor, risc::sg::SegmentGraph::SegmentSet>
154  risc::sg::SegmentGraph::SegmentSet leaving_vertices,
156  bool channel_segments);
157 
165 void
167  risc::sg::VertexDescriptor start_vertex,
169  SgFunctionCallExp *func_call_exp);
170 
178 void
180  risc::sg::VertexDescriptor start_vertex,
182  SgVariableDefinition* socket_def);
183 
184 } // end of namespace sg
185 
186 } // end of namespace risc
187 
188 #endif /* GRAPH_HELPER_H_INCLUDED_ */
189 
190 /* ex: set softtabstop=2 tabstop=2 shiftwidth=2 expandtab: */
BreakStmtVisitor(std::set< Graph::vertex_descriptor > &segment_with_break)
Definition: graph_helper.h:51
This class represents a segment graph for a process.
Definition: segment_graph.h:79
boost::graph_traits< Graph >::vertex_descriptor VertexDescriptor
Definition: segment_graph.h:34
std::set< VertexDescriptor, SegmentCmp > SegmentSet
Definition: segment_graph.h:93
Definition: graph_helper.h:86
void add_pcp_to_graph(risc::sg::VertexDescriptor start_vertex, risc::sg::SegmentGraph &sg, SgFunctionCallExp *func_call_exp)
add a style one pcp to all the segments starting from start_vertex
Definition: graph_helper.cpp:224
void discover_vertex(const Graph::vertex_descriptor vertex, const Graph &graph)
This function adds all break segments into segment_with_continue_.
Definition: graph_helper.h:103
void discover_vertex(const Graph::vertex_descriptor vertex, const Graph &graph)
Definition: graph_helper.h:32
std::pair< risc::sg::VertexDescriptor, risc::sg::SegmentGraph::SegmentSet > clone_graph(risc::sg::VertexDescriptor start_vertex, risc::sg::SegmentGraph::SegmentSet leaving_vertices, risc::sg::SegmentGraph &sg, bool channel_segments)
clones a subgraph
Definition: graph_helper.cpp:136
std::set< Graph::vertex_descriptor > & segment_with_break_
A set containing all the segments that contains a continue statement.
Definition: graph_helper.h:121
std::list< int > get_all_reachable_segments(SegmentGraph &segment_graph, int starting_id)
This function returns which segments are reachable from the given segment.
Definition: graph_helper.cpp:6
BreakStmtVisitor(const BreakStmtVisitor &other)
Definition: graph_helper.h:55
std::set< Graph::vertex_descriptor > & segment_with_break_
A set containing all the segments that contains a break statement.
Definition: graph_helper.h:82
ContinueStmtVisitor(std::set< Graph::vertex_descriptor > &segment_with_break)
Definition: graph_helper.h:90
void discover_vertex(const Graph::vertex_descriptor vertex, const Graph &graph)
This function adds all break segments into segment_with_break_.
Definition: graph_helper.h:64
Definition: graph_helper.h:19
ContinueStmtVisitor(const ContinueStmtVisitor &other)
Definition: graph_helper.h:94
std::set< Graph::vertex_descriptor > & leaf_nodes_
A set containing all the leaf nodes.
Definition: graph_helper.h:43
LeafNodeVisitor(std::set< Graph::vertex_descriptor > &leaf_nodes)
Definition: graph_helper.h:23
boost::adjacency_list< boost::listS, boost::listS, boost::bidirectionalS, Segment, Edge, boost::property< boost::vertex_index_t, int > > Graph
Definition: segment_graph.h:29
LeafNodeVisitor(const LeafNodeVisitor &other)
Definition: graph_helper.h:27
Definition: graph_helper.h:47