00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHSTRUCTURAL_HPP
00025 #define SHSTRUCTURAL_HPP
00026
00027 #include <list>
00028 #include <utility>
00029 #include <iosfwd>
00030 #include "ShDllExport.hpp"
00031 #include "ShRefCount.hpp"
00032 #include "ShInfo.hpp"
00033 #include "ShCtrlGraph.hpp"
00034 #include "ShVariable.hpp"
00035 #include "ShStatement.hpp"
00036
00037 namespace SH {
00038
00039 class
00040 SH_DLLEXPORT ShStructuralNode : public virtual ShRefCountable {
00041 public:
00042 friend class ShStructural;
00043
00044 enum NodeType {
00045 UNREDUCED,
00046 BLOCK,
00047 SECTION,
00048 IF,
00049 IFELSE,
00050 SELFLOOP,
00051 WHILELOOP
00052 };
00053
00054 ShStructuralNode(const ShCtrlGraphNodePtr& node);
00055 ShStructuralNode(NodeType type);
00056
00057
00058 std::ostream& dump(std::ostream& out, int nodes = -1) const;
00059
00060
00061 NodeType type;
00062 ShStructuralNode* container;
00063 typedef std::list< ShPointer< ShStructuralNode> > StructNodeList;
00064 StructNodeList structnodes;
00065 bool contains(ShCtrlGraphNodePtr node) const;
00066
00067
00068 ShCtrlGraphNodePtr cfg_node;
00069 typedef std::pair<ShVariable, ShPointer<ShStructuralNode> > SuccessorEdge;
00070 typedef std::list<SuccessorEdge> SuccessorList;
00071 SuccessorList succs;
00072 typedef std::pair<ShVariable, ShStructuralNode*> PredecessorEdge;
00073 typedef std::list<PredecessorEdge> PredecessorList;
00074 PredecessorList preds;
00075
00076
00077
00082 ShStatement *secStart, *secEnd;
00083
00084
00089 struct CfgMatch {
00090 ShCtrlGraphNodePtr from, to;
00091 ShCtrlGraphNode::SuccessorList::iterator S;
00092
00093 CfgMatch();
00094 CfgMatch(ShCtrlGraphNodePtr from);
00095 CfgMatch(ShCtrlGraphNodePtr from,
00096 ShCtrlGraphNode::SuccessorList::iterator S);
00097
00098 bool isFollower();
00099 };
00100 typedef std::list<CfgMatch> CfgMatchList;
00101
00102
00103 void getSuccs(CfgMatchList &result, const SuccessorEdge &edge);
00104 void getPreds(CfgMatchList &result, const PredecessorEdge &edge);
00105
00106
00107
00108 void getExits(CfgMatchList &result, ShPointer<ShStructuralNode> node = 0);
00109
00110
00111
00112 void getEntries(CfgMatchList &result, ShPointer<ShStructuralNode> node = 0);
00113
00114
00115
00116 ShStructuralNode* parent;
00117 typedef std::list< ShPointer<ShStructuralNode> > ChildList;
00118 ChildList children;
00119
00120 };
00121
00122 typedef ShPointer<ShStructuralNode> ShStructuralNodePtr;
00123 typedef ShPointer<const ShStructuralNode> ShStructuralNodeCPtr;
00124
00125 class
00126 SH_DLLEXPORT ShStructural {
00127 public:
00128 ShStructural(const ShCtrlGraphPtr& graph);
00129
00130
00131 std::ostream& dump(std::ostream& out) const;
00132
00133 const ShStructuralNodePtr& head();
00134
00135 private:
00136 ShCtrlGraphPtr m_graph;
00137 ShStructuralNodePtr m_head;
00138
00139 typedef std::list<ShStructuralNode*> PostorderList;
00140 PostorderList m_postorder;
00141
00142 ShStructuralNodePtr build_tree(const ShCtrlGraphNodePtr& node);
00143 void build_postorder(const ShStructuralNodePtr& node);
00144 };
00145
00146 }
00147
00148 #endif