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