diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index b348933c3..ff7543a1d 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -55,7 +55,7 @@ class CallGraphEdge : public GenericCallGraphEdgeTy typedef Set CallInstSet; enum CEDGEK { - CallRetEdge,TDForkEdge,TDJoinEdge,HareParForEdge + CallRetEdge }; @@ -77,21 +77,11 @@ class CallGraphEdge : public GenericCallGraphEdgeTy { return (cs << EdgeKindMaskBits) | k; } - /// Get direct and indirect calls - //@{ + /// Get direct calls inline CallSiteID getCallSiteID() const { return csId; } - inline CallInstSet& getDirectCalls() - { - return directCalls; - } - inline const CallInstSet& getDirectCalls() const - { - return directCalls; - } - //@} /// Add direct callsite //@{ @@ -118,9 +108,7 @@ class CallGraphEdge : public GenericCallGraphEdgeTy } static inline bool classof(const GenericCallGraphEdgeTy *edge) { - return edge->getEdgeKind() == CallGraphEdge::CallRetEdge || - edge->getEdgeKind() == CallGraphEdge::TDForkEdge || - edge->getEdgeKind() == CallGraphEdge::TDJoinEdge; + return edge->getEdgeKind() == CallGraphEdge::CallRetEdge; } //@} @@ -241,6 +229,30 @@ class CallGraph : public GenericCallGraphTy /// Clean up memory void destroy(); + /// Add CallSiteID + inline CallSiteID addCallSite(const CallICFGNode* cs, const SVFFunction* callee) + { + std::pair newCS(std::make_pair(cs, callee)); + CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS); + //assert(it == csToIdMap.end() && "cannot add a callsite twice"); + if(it == csToIdMap.end()) + { + CallSiteID id = totalCallSiteNum++; + csToIdMap.insert(std::make_pair(newCS, id)); + idToCSMap.insert(std::make_pair(id, newCS)); + return id; + } + return it->second; + } + + /// Add call graph edge + inline void addEdge(CallGraphEdge* edge) + { + edge->getDstNode()->addIncomingEdge(edge); + edge->getSrcNode()->addOutgoingEdge(edge); + } + + public: /// Constructor CallGraph(CGEK k = NormCallGraph); @@ -274,42 +286,12 @@ class CallGraph : public GenericCallGraphTy //@} - /// Add/Get CallSiteID - //@{ - inline CallSiteID addCallSite(const CallICFGNode* cs, const SVFFunction* callee) - { - std::pair newCS(std::make_pair(cs, callee)); - CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS); - //assert(it == csToIdMap.end() && "cannot add a callsite twice"); - if(it == csToIdMap.end()) - { - CallSiteID id = totalCallSiteNum++; - csToIdMap.insert(std::make_pair(newCS, id)); - idToCSMap.insert(std::make_pair(id, newCS)); - return id; - } - return it->second; - } - //@} - /// Whether we have already created this call graph edge CallGraphEdge* hasGraphEdge(CallGraphNode* src, CallGraphNode* dst, - CallGraphEdge::CEDGEK kind, CallSiteID csId) const; - - - /// Add call graph edge - inline void addEdge(CallGraphEdge* edge) - { - edge->getDstNode()->addIncomingEdge(edge); - edge->getSrcNode()->addOutgoingEdge(edge); - } + CallGraphEdge::CEDGEK kind, CallSiteID csId) const; - /// Add direct/indirect call edges - //@{ + /// Add direct call edges void addDirectCallGraphEdge(const CallICFGNode* call, const SVFFunction* callerFun, const SVFFunction* calleeFun); - //@} - - /// Dump the graph void dump(const std::string& filename); diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index 918c3c594..0be3937ca 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -279,6 +279,30 @@ class PTACallGraph : public GenericPTACallGraphTy /// Clean up memory void destroy(); +protected: + /// Add CallSiteID + inline CallSiteID addCallSite(const CallICFGNode* cs, const SVFFunction* callee) + { + std::pair newCS(std::make_pair(cs, callee)); + CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS); + //assert(it == csToIdMap.end() && "cannot add a callsite twice"); + if(it == csToIdMap.end()) + { + CallSiteID id = totalCallSiteNum++; + csToIdMap.insert(std::make_pair(newCS, id)); + idToCSMap.insert(std::make_pair(id, newCS)); + return id; + } + return it->second; + } + + /// Add call graph edge + inline void addEdge(PTACallGraphEdge* edge) + { + edge->getDstNode()->addIncomingEdge(edge); + edge->getSrcNode()->addOutgoingEdge(edge); + } + public: /// Constructor PTACallGraph(CGEK k = NormCallGraph); @@ -348,22 +372,8 @@ class PTACallGraph : public GenericPTACallGraphTy //@} - /// Add/Get CallSiteID + /// Get CallSiteID //@{ - inline CallSiteID addCallSite(const CallICFGNode* cs, const SVFFunction* callee) - { - std::pair newCS(std::make_pair(cs, callee)); - CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS); - //assert(it == csToIdMap.end() && "cannot add a callsite twice"); - if(it == csToIdMap.end()) - { - CallSiteID id = totalCallSiteNum++; - csToIdMap.insert(std::make_pair(newCS, id)); - idToCSMap.insert(std::make_pair(id, newCS)); - return id; - } - return it->second; - } inline CallSiteID getCallSiteID(const CallICFGNode* cs, const SVFFunction* callee) const { CallSitePair newCS(std::make_pair(cs, callee)); @@ -438,12 +448,7 @@ class PTACallGraph : public GenericPTACallGraphTy return it->second.end(); } //@} - /// Add call graph edge - inline void addEdge(PTACallGraphEdge* edge) - { - edge->getDstNode()->addIncomingEdge(edge); - edge->getSrcNode()->addOutgoingEdge(edge); - } + /// Add indirect call edges //@{ diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index 2513187a1..c96a4b5ac 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -196,20 +196,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits CallGraphEdge* edge = *(EI.getCurrent()); assert(edge && "No edge found!!"); - std::string color; - - if (edge->getEdgeKind() == CallGraphEdge::TDJoinEdge) - { - color = "color=green"; - } - else if (edge->getEdgeKind() == CallGraphEdge::TDForkEdge) - { - color = "color=blue"; - } - else - { - color = "color=black"; - } + std::string color = "color=black"; return color; }