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 PROPINT
00049 };
00050
00051 ShStructuralNode(const ShCtrlGraphNodePtr& node);
00052 ShStructuralNode(NodeType type);
00053
00054
00055 std::ostream& dump(std::ostream& out, int nodes = -1) const;
00056
00057
00058 NodeType type;
00059 ShStructuralNode* container;
00060 typedef std::list< ShPointer< ShStructuralNode> > StructNodeList;
00061 StructNodeList structnodes;
00062 bool contains(ShCtrlGraphNodePtr node) const;
00063
00064
00065 ShCtrlGraphNodePtr cfg_node;
00066 typedef std::pair<ShVariable, ShPointer<ShStructuralNode> > SuccessorEdge;
00067 typedef std::list<SuccessorEdge> SuccessorList;
00068 SuccessorList succs;
00069 typedef std::pair<ShVariable, ShStructuralNode*> PredecessorEdge;
00070 typedef std::list<PredecessorEdge> PredecessorList;
00071 PredecessorList preds;
00072
00073
00074
00079 ShStatement *secStart, *secEnd;
00080
00081
00086 struct CfgMatch {
00087 ShCtrlGraphNodePtr from, to;
00088 ShCtrlGraphNode::SuccessorList::iterator S;
00089
00090 CfgMatch();
00091 CfgMatch(ShCtrlGraphNodePtr from);
00092 CfgMatch(ShCtrlGraphNodePtr from,
00093 ShCtrlGraphNode::SuccessorList::iterator S);
00094
00095 bool isFollower();
00096 };
00097 typedef std::list<CfgMatch> CfgMatchList;
00098
00099
00100 void getSuccs(CfgMatchList &result, const SuccessorEdge &edge);
00101 void getPreds(CfgMatchList &result, const PredecessorEdge &edge);
00102
00103
00104
00105 void getExits(CfgMatchList &result, ShPointer<ShStructuralNode> node = 0);
00106
00107
00108
00109 void getEntries(CfgMatchList &result, ShPointer<ShStructuralNode> node = 0);
00110
00111
00112
00113 ShStructuralNode* parent;
00114 typedef std::list< ShPointer<ShStructuralNode> > ChildList;
00115 ChildList children;
00116
00117 };
00118
00119 typedef ShPointer<ShStructuralNode> ShStructuralNodePtr;
00120 typedef ShPointer<const ShStructuralNode> ShStructuralNodeCPtr;
00121
00122 class
00123 SH_DLLEXPORT ShStructural {
00124 public:
00125 ShStructural(const ShCtrlGraphPtr& graph);
00126
00127
00128 std::ostream& dump(std::ostream& out) const;
00129
00130 const ShStructuralNodePtr& head();
00131
00132 private:
00133 ShCtrlGraphPtr m_graph;
00134 ShStructuralNodePtr m_head;
00135
00136 typedef std::list<ShStructuralNode*> PostorderList;
00137 PostorderList m_postorder;
00138
00139 ShStructuralNodePtr build_tree(const ShCtrlGraphNodePtr& node);
00140 void build_postorder(const ShStructuralNodePtr& node);
00141 };
00142
00143 }
00144
00145 #endif