00001 #ifndef GRAPH_HELPER_H_INCLUDED_
00002 #define GRAPH_HELPER_H_INCLUDED_
00003
00004 #include<set>
00005 #include<utility>
00006 #include<list>
00007
00008 #include "rose.h"
00009
00010 #include "boost/graph/adjacency_list.hpp"
00011 #include "boost/graph/breadth_first_search.hpp"
00012
00013 #include "segment_graph.h"
00014
00015 namespace risc {
00016
00017 namespace sg {
00018
00019 class LeafNodeVisitor: public boost::default_bfs_visitor {
00020
00021 public:
00022
00023 LeafNodeVisitor(std::set<Graph::vertex_descriptor>& leaf_nodes):
00024 leaf_nodes_(leaf_nodes)
00025 { }
00026
00027 LeafNodeVisitor(const LeafNodeVisitor &other):
00028 leaf_nodes_(other.leaf_nodes_)
00029 { }
00030
00031
00032 void discover_vertex(const Graph::vertex_descriptor vertex,
00033 const Graph &graph)
00034 {
00035 if(boost::out_degree(vertex, graph) == 0) {
00036 leaf_nodes_.insert(vertex);
00037 }
00038 }
00039
00040 std::set<Graph::vertex_descriptor>& leaf_nodes_;
00041 };
00042
00043
00044 class BreakStmtVisitor: public boost::default_bfs_visitor {
00045
00046 public:
00047
00048 BreakStmtVisitor(std::set<Graph::vertex_descriptor>& segment_with_break):
00049 segment_with_break_(segment_with_break)
00050 { }
00051
00052 BreakStmtVisitor(const BreakStmtVisitor &other):
00053 segment_with_break_(other.segment_with_break_)
00054 { }
00055
00056
00057 void discover_vertex(const Graph::vertex_descriptor vertex,
00058 const Graph &graph)
00059 {
00060 for(std::list<NodeWithPath>::const_iterator
00061 iter = graph[vertex].expressions_.begin();
00062 iter != graph[vertex].expressions_.end();
00063 iter++) {
00064
00065 if(isSgBreakStmt(iter->node_)) {
00066 segment_with_break_.insert(vertex);
00067 return;
00068 }
00069 }
00070 }
00071
00072 std::set<Graph::vertex_descriptor>& segment_with_break_;
00073 };
00074
00075
00076 class ContinueStmtVisitor: public boost::default_bfs_visitor {
00077
00078 public:
00079
00080 ContinueStmtVisitor(std::set<Graph::vertex_descriptor>& segment_with_break):
00081 segment_with_break_(segment_with_break)
00082 { }
00083
00084 ContinueStmtVisitor(const ContinueStmtVisitor &other):
00085 segment_with_break_(other.segment_with_break_)
00086 { }
00087
00088
00089 void discover_vertex(const Graph::vertex_descriptor vertex,
00090 const Graph &graph)
00091 {
00092 for(std::list<NodeWithPath>::const_iterator
00093 iter = graph[vertex].expressions_.begin();
00094 iter != graph[vertex].expressions_.end();
00095 iter++) {
00096
00097 if(isSgContinueStmt(iter->node_)) {
00098 segment_with_break_.insert(vertex);
00099 return;
00100 }
00101 }
00102 }
00103
00104 std::set<Graph::vertex_descriptor>& segment_with_break_;
00105 };
00106
00112 std::list<int>
00113 get_all_reachable_segments(SegmentGraph &segment_graph, int starting_id);
00114
00115
00121 std::vector<VertexDescriptor>
00122 get_all_reachable_segments(
00123 SegmentGraph &segment_graph,
00124 VertexDescriptor start_vertex);
00125
00130 std::pair<risc::sg::VertexDescriptor, risc::sg::SegmentGraph::SegmentSet>
00131 clone_graph(risc::sg::VertexDescriptor start_vertex,
00132 risc::sg::SegmentGraph::SegmentSet leaving_vertices,
00133 risc::sg::SegmentGraph &sg,
00134 bool channel_segments);
00135
00136 void
00137 add_pcp_to_graph(
00138 risc::sg::VertexDescriptor start_vertex,
00139 risc::sg::SegmentGraph &sg,
00140 SgFunctionCallExp *func_call_exp);
00141
00142 }
00143
00144 }
00145
00146 #endif
00147
00148