00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #ifndef SHSTRUCTURAL_HPP
00028 #define SHSTRUCTURAL_HPP
00029
00030 #include <list>
00031 #include <utility>
00032 #include <iosfwd>
00033 #include "ShDllExport.hpp"
00034 #include "ShRefCount.hpp"
00035 #include "ShCtrlGraph.hpp"
00036 #include "ShVariable.hpp"
00037
00038 namespace SH {
00039
00040 class
00041 SH_DLLEXPORT ShStructuralNode : public ShRefCountable {
00042 public:
00043 friend class ShStructural;
00044
00045 enum NodeType {
00046 UNREDUCED,
00047 BLOCK,
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
00066
00067 ShCtrlGraphNodePtr cfg_node;
00068 typedef std::pair<ShVariable, ShPointer<ShStructuralNode> > SuccessorEdge;
00069 typedef std::list<SuccessorEdge> SuccessorList;
00070 SuccessorList succs;
00071 typedef std::pair<ShVariable, ShStructuralNode*> PredecessorEdge;
00072 typedef std::list<PredecessorEdge> PredecessorList;
00073 PredecessorList preds;
00074
00075
00076 ShStructuralNode* parent;
00077 typedef std::list< ShPointer<ShStructuralNode> > ChildList;
00078 ChildList children;
00079
00080 };
00081
00082 typedef ShPointer<ShStructuralNode> ShStructuralNodePtr;
00083 typedef ShPointer<const ShStructuralNode> ShStructuralNodeCPtr;
00084
00085 class
00086 SH_DLLEXPORT ShStructural {
00087 public:
00088 ShStructural(const ShCtrlGraphPtr& graph);
00089
00090
00091 std::ostream& dump(std::ostream& out) const;
00092
00093 const ShStructuralNodePtr& head();
00094
00095 private:
00096 ShCtrlGraphPtr m_graph;
00097 ShStructuralNodePtr m_head;
00098
00099 typedef std::list<ShStructuralNode*> PostorderList;
00100 PostorderList m_postorder;
00101
00102 ShStructuralNodePtr build_tree(const ShCtrlGraphNodePtr& node);
00103 void build_postorder(const ShStructuralNodePtr& node);
00104 };
00105
00106 }
00107
00108 #endif