diff --git a/include/Graphs/GenericGraph.h b/include/Graphs/GenericGraph.h index d48dadc9c..20a15d757 100644 --- a/include/Graphs/GenericGraph.h +++ b/include/Graphs/GenericGraph.h @@ -453,34 +453,36 @@ template struct GraphTraits DerefEdge; // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef mapped_iterator::iterator, DerefEdge> ChildIteratorType; - static NodeType* getEntryNode(NodeType* pagN) + static NodeRef getEntryNode(SVF::GenericNode& pagN) { - return pagN; + return static_cast(&pagN); } - static inline ChildIteratorType child_begin(const NodeType* N) + static inline ChildIteratorType child_begin(NodeRef N) { return map_iterator(N->OutEdgeBegin(), DerefEdge(edgeDereference)); } - static inline ChildIteratorType child_end(const NodeType* N) + static inline ChildIteratorType child_end(NodeRef N) { return map_iterator(N->OutEdgeEnd(), DerefEdge(edgeDereference)); } - static inline ChildIteratorType direct_child_begin(const NodeType *N) + static inline ChildIteratorType direct_child_begin(NodeRef N) { return map_iterator(N->directOutEdgeBegin(), DerefEdge(edgeDereference)); } - static inline ChildIteratorType direct_child_end(const NodeType *N) + static inline ChildIteratorType direct_child_end(NodeRef N) { return map_iterator(N->directOutEdgeEnd(), DerefEdge(edgeDereference)); } - static NodeType* edgeDereference(EdgeType* edge) + static NodeRef edgeDereference(EdgeRef edge) { return edge->getDstNode(); } @@ -495,32 +497,34 @@ struct GraphTraits* > > { typedef NodeTy NodeType; typedef EdgeTy EdgeType; + typedef NodeTy* NodeRef; + typedef EdgeTy* EdgeRef; typedef std::pointer_to_unary_function DerefEdge; // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef mapped_iterator::iterator, DerefEdge> ChildIteratorType; - static inline NodeType* getEntryNode(Inverse G) + static inline NodeRef getEntryNode(Inverse>& G) { return G.Graph; } - static inline ChildIteratorType child_begin(const NodeType* N) + static inline ChildIteratorType child_begin(NodeRef N) { return map_iterator(N->InEdgeBegin(), DerefEdge(edgeDereference)); } - static inline ChildIteratorType child_end(const NodeType* N) + static inline ChildIteratorType child_end(NodeRef N) { return map_iterator(N->InEdgeEnd(), DerefEdge(edgeDereference)); } - static inline NodeType* edgeDereference(EdgeType* edge) + static inline NodeRef edgeDereference(EdgeRef edge) { return edge->getSrcNode(); } - static inline unsigned getNodeID(const NodeType* N) + static inline unsigned getNodeID(NodeRef N) { return N->getId(); } @@ -534,6 +538,8 @@ template struct GraphTraits GenericGraphTy; typedef NodeTy NodeType; typedef EdgeTy EdgeType; + typedef NodeTy NodeRef; + typedef EdgeTy EdgeRef; static NodeType* getEntryNode(GenericGraphTy* pag) { diff --git a/tools/Example/svf-ex.cpp b/tools/Example/svf-ex.cpp index e52192138..8981f7431 100644 --- a/tools/Example/svf-ex.cpp +++ b/tools/Example/svf-ex.cpp @@ -114,6 +114,7 @@ void traverseOnVFG(const SVFG* vfg, Value* val) std::set visited; worklist.push(vNode); + /// Traverse along VFG while (!worklist.empty()) { @@ -139,6 +140,12 @@ void traverseOnVFG(const SVFG* vfg, Value* val) /// PAGNode* pNode = vfg->getLHSTopLevPtr(node); /// Value* val = pNode->getValue(); } + + + // LLVM graph traversal functions + for (const VFGNode* node : llvm::inverse_depth_first(vNode)) { + llvm::errs() << "Node: " << *node; + } } int main(int argc, char ** argv)