Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: GenericGraph: try to fix GraphTraits interface #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions include/Graphs/GenericGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,34 +453,36 @@ template<class NodeTy,class EdgeTy> struct GraphTraits<SVF::GenericNode<NodeTy,E
{
typedef NodeTy NodeType;
typedef EdgeTy EdgeType;
typedef NodeTy* NodeRef;
typedef EdgeTy* EdgeRef;

typedef std::pointer_to_unary_function<EdgeType*, NodeType*> DerefEdge;

// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
typedef mapped_iterator<typename SVF::GenericNode<NodeTy,EdgeTy>::iterator, DerefEdge> ChildIteratorType;

static NodeType* getEntryNode(NodeType* pagN)
static NodeRef getEntryNode(SVF::GenericNode<NodeTy,EdgeTy>& pagN)
{
return pagN;
return static_cast<NodeTy*>(&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();
}
Expand All @@ -495,32 +497,34 @@ struct GraphTraits<Inverse<SVF::GenericNode<NodeTy,EdgeTy>* > >
{
typedef NodeTy NodeType;
typedef EdgeTy EdgeType;
typedef NodeTy* NodeRef;
typedef EdgeTy* EdgeRef;

typedef std::pointer_to_unary_function<EdgeType*, NodeType*> DerefEdge;

// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
typedef mapped_iterator<typename SVF::GenericNode<NodeTy,EdgeTy>::iterator, DerefEdge> ChildIteratorType;

static inline NodeType* getEntryNode(Inverse<NodeType* > G)
static inline NodeRef getEntryNode(Inverse<SVF::GenericNode<NodeTy,EdgeTy>>& 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();
}
Expand All @@ -534,6 +538,8 @@ template<class NodeTy,class EdgeTy> struct GraphTraits<SVF::GenericGraph<NodeTy,
typedef SVF::GenericGraph<NodeTy,EdgeTy> GenericGraphTy;
typedef NodeTy NodeType;
typedef EdgeTy EdgeType;
typedef NodeTy NodeRef;
typedef EdgeTy EdgeRef;

static NodeType* getEntryNode(GenericGraphTy* pag)
{
Expand Down
7 changes: 7 additions & 0 deletions tools/Example/svf-ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void traverseOnVFG(const SVFG* vfg, Value* val)
std::set<const VFGNode*> visited;
worklist.push(vNode);


/// Traverse along VFG
while (!worklist.empty())
{
Expand All @@ -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)
Expand Down