00001 00018 //-------------------------------------------------------------------- 00019 //-------------------------------------------------------------------- 00020 00021 #ifndef ICFGInterface_H 00022 #define ICFGInterface_H 00023 00024 #include <OpenAnalysis/IRInterface/IRHandles.hpp> 00025 #include <OpenAnalysis/Utils/DGraph/DGraphInterface.hpp> 00026 #include <OpenAnalysis/CFG/CFGInterface.hpp> 00027 00028 //-------------------------------------------------------------------- 00029 00030 namespace OA { 00031 namespace ICFG { 00032 00033 // Changes here must be also reflected in edgeTypeToString 00034 // and nodeTypeToString. 00035 enum EdgeType { CFLOW_EDGE, CALL_EDGE, RETURN_EDGE, CALL_RETURN_EDGE }; 00036 enum NodeType { CFLOW_NODE, CALL_NODE, RETURN_NODE, ENTRY_NODE, EXIT_NODE }; 00037 00038 //-------------------------------------------------------------------- 00044 class NodeInterface; 00045 class EdgeInterface; 00046 class ICFGInterface; 00047 class NodesIteratorInterface; 00048 class EdgesIteratorInterface; 00049 00050 00051 //-------------------------------------------------------- 00052 class NodeInterface : public virtual DGraph::NodeInterface { 00053 public: 00054 NodeInterface () {} 00055 ~NodeInterface () { } 00056 00057 //======================================================== 00058 // Info specific to ICFG 00059 //======================================================== 00060 00061 virtual NodeType getType() const = 0; 00062 00063 virtual ProcHandle getProc() const = 0; 00064 00066 virtual unsigned int size () const = 0; 00067 00069 virtual OA_ptr<CFG::NodeStatementsIteratorInterface> 00070 getNodeStatementsIterator() const = 0; 00071 00073 virtual OA_ptr<CFG::NodeStatementsRevIteratorInterface> 00074 getNodeStatementsRevIterator() const = 0; 00075 00076 //======================================================== 00077 // Output 00078 //======================================================== 00079 // virtual void dump(std::ostream& os) = 0; 00080 // virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir) = 0; 00081 // virtual void dumpdot(ICFGStandard&, 00082 // std::ostream& os, OA_ptr<IRHandlesIRInterface> ir) = 0; 00083 // void longdump(ICFGStandard& icfg, std::ostream& os, 00084 // OA_ptr<IRHandlesIRInterface> ir) = 0; 00085 00086 public: 00087 //======================================================== 00088 // These methods shadow the same named methods in 00089 // the DGraph::Interface class and allow us to return 00090 // the more specific subclass 00091 //======================================================== 00092 // Other Iterators 00093 /* 00094 OA_ptr<DGraph::EdgesIteratorInterface> getIncomingEdgesIterator() const { 00095 } 00096 00097 OA_ptr<DGraph::EdgesIteratorInterface> getOutgoingEdgesIterator() const { 00098 } 00099 00100 OA_ptr<DGraph::NodesIteratorInterface> getSourceNodesIterator() const { 00101 } 00102 00103 00104 OA_ptr<DGraph::NodesIteratorInterface> getSinkNodesIterator() const { 00105 } 00106 */ 00107 00108 00109 virtual OA_ptr<EdgesIteratorInterface> getICFGIncomingEdgesIterator() const = 0; 00110 00111 virtual OA_ptr<EdgesIteratorInterface> getICFGOutgoingEdgesIterator() const = 0; 00112 00113 virtual OA_ptr<NodesIteratorInterface> getICFGSourceNodesIterator() const = 0; 00114 00115 virtual OA_ptr<NodesIteratorInterface> getICFGSinkNodesIterator() const = 0; 00116 00117 00118 //------------------------------------------------------------------ 00119 }; 00120 00121 //-------------------------------------------------------- 00122 class EdgeInterface : public virtual DGraph::EdgeInterface { 00123 public: 00124 EdgeInterface () {} 00125 ~EdgeInterface () {} 00126 00127 //======================================================== 00128 // Info specific to ICFG 00129 //======================================================== 00130 00131 virtual EdgeType getType() const = 0; 00132 00133 virtual ProcHandle getSourceProc() const = 0; 00134 virtual ProcHandle getSinkProc() const = 0; 00135 virtual CallHandle getCall() const = 0; 00136 00137 virtual OA_ptr<NodeInterface> getICFGSource() const = 0; 00138 00139 virtual OA_ptr<NodeInterface> getICFGSink() const = 0; 00140 00141 00142 }; 00143 00144 00145 //------------------------------------------------------------------ 00149 class NodesIteratorInterface : public virtual DGraph::NodesIteratorInterface 00150 { 00151 public: 00152 virtual OA_ptr<NodeInterface> currentICFGNode() const = 0; 00153 }; 00154 00155 //------------------------------------------------------------------ 00159 class EdgesIteratorInterface : public virtual DGraph::EdgesIteratorInterface 00160 { 00161 public: 00162 00163 virtual OA_ptr<EdgeInterface> currentICFGEdge() const = 0; 00164 }; 00165 00166 00167 //------------------------------------------------------------------ 00168 00169 class ICFGInterface : public virtual DGraph::DGraphInterface { 00170 00171 public: 00172 00173 //void dump (std::ostream& os, OA_ptr<IRHandlesIRInterface> ir); 00174 //void dumpdot (std::ostream& os, OA_ptr<IRHandlesIRInterface> ir); 00175 //void dumpbase(std::ostream& os) {} 00176 00177 //------------------------------------------------------------------ 00178 // Using trick of imitating covariance when getting all iterators 00179 // so that get an iterator specific to actual subclass 00180 // This is why have these getBlahIterator methods that shadow those 00181 // in DGraph::Interface and also have the protected ones 00182 // that must be defined here which override implementation in 00183 // DGraph::Interface 00184 //------------------------------------------------------------------ 00185 /* 00186 OA_ptr<DGraph::NodesIteratorInterface> getNodesIterator() const { 00187 } 00188 00189 00190 virtual OA_ptr<DGraph::NodesIteratorInterface> getExitNodesIterator() const = 0; 00191 00192 OA_ptr<DGraph::EdgesIteratorInterface> getEdgesIterator() const { 00193 } 00194 00195 OA_ptr<DGraph::NodesIteratorInterface> 00196 getReversePostDFSIterator(DGraph::DGraphEdgeDirection pOrient) { 00197 } 00198 00199 00200 OA_ptr<DGraph::NodesIteratorInterface> getDFSIterator(OA_ptr<NodeInterface> n) { } 00201 */ 00202 00203 virtual OA_ptr<NodesIteratorInterface> getICFGNodesIterator() const = 0; 00204 00205 virtual OA_ptr<EdgesIteratorInterface> getICFGEdgesIterator() const = 0; 00206 00207 virtual OA_ptr<NodesIteratorInterface> getICFGEntryNodesIterator() const = 0; 00208 00209 virtual OA_ptr<NodesIteratorInterface> getICFGExitNodesIterator() const = 0; 00210 00211 virtual OA_ptr<NodesIteratorInterface> 00212 getICFGReversePostDFSIterator(DGraph::DGraphEdgeDirection pOrient) = 0; 00213 00214 00215 virtual OA_ptr<NodesIteratorInterface> getICFGDFSIterator(OA_ptr<NodeInterface> n) = 0; 00216 00217 00218 00219 }; 00220 //-------------------------------------------------------------------- 00221 00222 } // end of ICFG namespace 00223 } // end of OA namespace 00224 00225 #endif
1.7.1