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 <boost/graph/adjacency_list.hpp> 00009 #include <boost/graph/breadth_first_search.hpp> 00010 00011 #include "segment_graph.h" 00012 00013 namespace risc { 00014 00015 namespace sg { 00016 00017 class LeafNodeVisitor: public boost::default_bfs_visitor { 00018 00019 public: 00020 00021 LeafNodeVisitor(std::set<Graph::vertex_descriptor>& leaf_nodes): 00022 leaf_nodes_(leaf_nodes) 00023 { } 00024 00025 LeafNodeVisitor(const LeafNodeVisitor &other): 00026 leaf_nodes_(other.leaf_nodes_) 00027 { } 00028 00029 00030 void discover_vertex(const Graph::vertex_descriptor vertex, 00031 const Graph &graph) 00032 { 00033 if(boost::out_degree(vertex, graph) == 0) { 00034 leaf_nodes_.insert(vertex); 00035 } 00036 } 00037 00038 std::set<Graph::vertex_descriptor>& leaf_nodes_; 00039 }; 00040 00041 00042 class BreakStmtVisitor: public boost::default_bfs_visitor { 00043 00044 public: 00045 00046 BreakStmtVisitor(std::set<Graph::vertex_descriptor>& segment_with_break): 00047 segment_with_break_(segment_with_break) 00048 { } 00049 00050 BreakStmtVisitor(const BreakStmtVisitor &other): 00051 segment_with_break_(other.segment_with_break_) 00052 { } 00053 00054 00055 void discover_vertex(const Graph::vertex_descriptor vertex, 00056 const Graph &graph) 00057 { 00058 for(std::vector<SgNode*>::const_iterator 00059 iter = graph[vertex].expressions_.begin(); 00060 iter != graph[vertex].expressions_.end(); 00061 iter++) { 00062 00063 if(isSgBreakStmt(*iter)) { 00064 segment_with_break_.insert(vertex); 00065 return; 00066 } 00067 } 00068 } 00069 00070 std::set<Graph::vertex_descriptor>& segment_with_break_; 00071 }; 00072 00073 00074 class ContinueStmtVisitor: public boost::default_bfs_visitor { 00075 00076 public: 00077 00078 ContinueStmtVisitor(std::set<Graph::vertex_descriptor>& segment_with_break): 00079 segment_with_break_(segment_with_break) 00080 { } 00081 00082 ContinueStmtVisitor(const ContinueStmtVisitor &other): 00083 segment_with_break_(other.segment_with_break_) 00084 { } 00085 00086 00087 void discover_vertex(const Graph::vertex_descriptor vertex, 00088 const Graph &graph) 00089 { 00090 for(std::vector<SgNode*>::const_iterator 00091 iter = graph[vertex].expressions_.begin(); 00092 iter != graph[vertex].expressions_.end(); 00093 iter++) { 00094 00095 if(isSgContinueStmt(*iter)) { 00096 segment_with_break_.insert(vertex); 00097 return; 00098 } 00099 } 00100 } 00101 00102 std::set<Graph::vertex_descriptor>& segment_with_break_; 00103 }; 00104 00110 std::list<int> 00111 get_all_reachable_segments(SegmentGraph &segment_graph, int starting_id); 00112 00113 } // end of namespace sg 00114 00115 } // end of namespace risc 00116 00117 #endif /* GRAPH_HELPER_H_INCLUDED_ */ 00118 00119 /* ex: set softtabstop=2 tabstop=2 shiftwidth=2 expandtab: */