svf-lib 1.0.1681 → 1.0.1683

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -492,11 +492,12 @@ protected:
492
492
  NodeRefToCycleDepthNumber _nodeToCDN;
493
493
  CycleDepthNumber _num;
494
494
  CFBasicBlockNodes _stack;
495
+ CFBasicBlockGraph* _graph;
495
496
 
496
497
  public:
497
498
  explicit CFBasicBlockGWTO() : _num(0) {}
498
499
 
499
- explicit CFBasicBlockGWTO(const CFBasicBlockNode *entry) : _num(0)
500
+ explicit CFBasicBlockGWTO(CFBasicBlockGraph* graph, const CFBasicBlockNode *entry) : _num(0), _graph(graph)
500
501
  {
501
502
  build(entry);
502
503
  }
@@ -652,12 +653,13 @@ protected:
652
653
  const CFBasicBlockGWTOCycleDepth &_headWTOCycleDepth;
653
654
  const CFBasicBlockNode *_head;
654
655
  NodeRefToWTOCycleDepthPtr &_nodeToWTOCycleDepth;
656
+ CFBasicBlockGraph* _graph;
655
657
 
656
658
  public:
657
659
 
658
- explicit TailBuilder(NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth, NodeRefSet &tails, const CFBasicBlockNode *head,
660
+ explicit TailBuilder(CFBasicBlockGraph* graph, NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth, NodeRefSet &tails, const CFBasicBlockNode *head,
659
661
  const CFBasicBlockGWTOCycleDepth &headWTOCycleDepth) : _tails(tails), _headWTOCycleDepth(headWTOCycleDepth), _head(head), _nodeToWTOCycleDepth(
660
- nodeToWTOCycleDepth)
662
+ nodeToWTOCycleDepth), _graph(graph)
661
663
  {
662
664
  }
663
665
 
@@ -671,15 +673,27 @@ protected:
671
673
 
672
674
  virtual void visit(const CFBasicBlockGWTONode &node) override
673
675
  {
674
- for (const auto &edge: node.node()->getOutEdges())
676
+ if(const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node.node()->getICFGNodes().front()))
675
677
  {
676
- const CFBasicBlockNode *succ = edge->getDstNode();
678
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
677
679
  const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
678
680
  if (succ != _head && succNesting <= _headWTOCycleDepth)
679
681
  {
680
682
  _tails.insert(node.node());
681
683
  }
682
684
  }
685
+ else
686
+ {
687
+ for (const auto &edge: node.node()->getOutEdges())
688
+ {
689
+ const CFBasicBlockNode *succ = edge->getDstNode();
690
+ const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
691
+ if (succ != _head && succNesting <= _headWTOCycleDepth)
692
+ {
693
+ _tails.insert(node.node());
694
+ }
695
+ }
696
+ }
683
697
  }
684
698
 
685
699
  protected:
@@ -751,14 +765,25 @@ protected:
751
765
  const CFBasicBlockGWTOCycle *component(const CFBasicBlockNode *node)
752
766
  {
753
767
  WTOCompRefList partition;
754
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
768
+ if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
755
769
  {
756
- const CFBasicBlockNode *succ = (*it)->getDstNode();
770
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
757
771
  if (getCDN(succ) == 0)
758
772
  {
759
773
  visit(succ, partition);
760
774
  }
761
775
  }
776
+ else
777
+ {
778
+ for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
779
+ {
780
+ const CFBasicBlockNode *succ = (*it)->getDstNode();
781
+ if (getCDN(succ) == 0)
782
+ {
783
+ visit(succ, partition);
784
+ }
785
+ }
786
+ }
762
787
  const CFBasicBlockGWTOCycle *ptr = newCycle(node, partition);
763
788
  _headToCycle.emplace(node, ptr);
764
789
  return ptr;
@@ -776,9 +801,9 @@ protected:
776
801
  head = _num;
777
802
  setCDN(node, head);
778
803
  loop = false;
779
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
804
+ if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
780
805
  {
781
- const CFBasicBlockNode *succ = (*it)->getDstNode();
806
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
782
807
  CycleDepthNumber succ_dfn = getCDN(succ);
783
808
  if (succ_dfn == CycleDepthNumber(0))
784
809
  {
@@ -794,6 +819,27 @@ protected:
794
819
  loop = true;
795
820
  }
796
821
  }
822
+ else
823
+ {
824
+ for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
825
+ {
826
+ const CFBasicBlockNode *succ = (*it)->getDstNode();
827
+ CycleDepthNumber succ_dfn = getCDN(succ);
828
+ if (succ_dfn == CycleDepthNumber(0))
829
+ {
830
+ min = visit(succ, partition);
831
+ }
832
+ else
833
+ {
834
+ min = succ_dfn;
835
+ }
836
+ if (min <= head)
837
+ {
838
+ head = min;
839
+ loop = true;
840
+ }
841
+ }
842
+ }
797
843
  if (head == getCDN(node))
798
844
  {
799
845
  setCDN(node, UINT_MAX);
@@ -831,7 +877,7 @@ protected:
831
877
  for (const auto &head: _headToCycle)
832
878
  {
833
879
  NodeRefSet tails;
834
- TailBuilder builder(_nodeToDepth, tails, head.first, getWTOCycleDepth(head.first));
880
+ TailBuilder builder(_graph, _nodeToDepth, tails, head.first, getWTOCycleDepth(head.first));
835
881
  for (auto it = head.second->begin(), eit = head.second->end(); it != eit; ++it)
836
882
  {
837
883
  (*it)->accept(&builder);
@@ -127,8 +127,6 @@ public:
127
127
  {
128
128
  }
129
129
 
130
- CFBasicBlockNode(const SVFBasicBlock* bb);
131
-
132
130
  friend std::ostream &operator<<(std::ostream &o, const CFBasicBlockNode &node)
133
131
  {
134
132
  o << node.toString();
@@ -143,10 +141,9 @@ public:
143
141
  return (*_icfgNodes.begin())->getBB()->getName();
144
142
  }
145
143
 
146
- inline const SVFBasicBlock *getSVFBasicBlock() const
144
+ inline const std::vector<const ICFGNode*>& getICFGNodes() const
147
145
  {
148
- assert(!_icfgNodes.empty() && "no ICFG nodes in CFBB");
149
- return (*_icfgNodes.begin())->getBB();
146
+ return _icfgNodes;
150
147
  }
151
148
 
152
149
  inline const SVFFunction *getFunction() const
@@ -355,7 +352,6 @@ class CFBasicBlockGraph : public GenericCFBasicBlockGTy
355
352
  private:
356
353
  u32_t _totalCFBasicBlockNode{0};
357
354
  u32_t _totalCFBasicBlockEdge{0};
358
- Map<const SVFFunction*, CFBasicBlockNode*> _funToFirstNode;
359
355
  public:
360
356
 
361
357
  CFBasicBlockGraph() = default;
@@ -379,27 +375,6 @@ public:
379
375
  return hasGNode(id);
380
376
  }
381
377
 
382
- inline CFBasicBlockNode* getFirstCFBasicBlockNode(const SVFFunction* fun) const
383
- {
384
- if (fun && _funToFirstNode.find(fun) != _funToFirstNode.end())
385
- {
386
- return _funToFirstNode.at(fun);
387
- }
388
- else
389
- {
390
- return nullptr;
391
- }
392
- }
393
- inline bool hasFirstCFBasicBlockNode(const SVFFunction* fun) const
394
- {
395
- return fun && _funToFirstNode.find(fun) != _funToFirstNode.end();
396
- }
397
-
398
- inline void setFirstCFBasicBlockNode(const Map<const SVFFunction*, CFBasicBlockNode*>& svfNodeMap)
399
- {
400
- _funToFirstNode = svfNodeMap;
401
- }
402
-
403
378
 
404
379
  bool hasCFBasicBlockEdge(CFBasicBlockNode *src, CFBasicBlockNode *dst, ICFGEdge *icfgEdge)
405
380
  {
@@ -490,24 +465,6 @@ public:
490
465
  }
491
466
  };
492
467
 
493
- class CFBasicBlockGBuilder
494
- {
495
-
496
- private:
497
- CFBasicBlockGraph* _CFBasicBlockG;
498
-
499
- public:
500
- CFBasicBlockGBuilder() : _CFBasicBlockG() {}
501
-
502
- virtual void build(SVFModule* module);
503
-
504
- virtual void build(ICFG* icfg);
505
-
506
- inline CFBasicBlockGraph* getCFBasicBlockGraph()
507
- {
508
- return _CFBasicBlockG;
509
- }
510
- };
511
468
  }
512
469
 
513
470
 
@@ -537,6 +494,10 @@ struct GenericGraphTraits<SVF::CFBasicBlockGraph *>
537
494
  typedef SVF::CFBasicBlockNode *NodeRef;
538
495
  };
539
496
 
497
+ } // End namespace SVF
498
+
499
+ namespace SVF
500
+ {
540
501
  template<>
541
502
  struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVFIR *>
542
503
  {
@@ -574,22 +535,73 @@ struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVF
574
535
  {
575
536
  std::string str;
576
537
  std::stringstream rawstr(str);
577
- rawstr << "color=black";
538
+ if(node->getICFGNodes().size() == 1)
539
+ {
540
+ const ICFGNode* n = node->getICFGNodes()[0];
541
+ if(SVFUtil::isa<IntraICFGNode>(n))
542
+ {
543
+ rawstr << "color=black";
544
+ }
545
+ else if(SVFUtil::isa<FunEntryICFGNode>(n))
546
+ {
547
+ rawstr << "color=yellow";
548
+ }
549
+ else if(SVFUtil::isa<FunExitICFGNode>(n))
550
+ {
551
+ rawstr << "color=green";
552
+ }
553
+ else if(SVFUtil::isa<CallICFGNode>(n))
554
+ {
555
+ rawstr << "color=red";
556
+ }
557
+ else if(SVFUtil::isa<RetICFGNode>(n))
558
+ {
559
+ rawstr << "color=blue";
560
+ }
561
+ else if(SVFUtil::isa<GlobalICFGNode>(n))
562
+ {
563
+ rawstr << "color=purple";
564
+ }
565
+ else
566
+ assert(false && "no such kind of node!!");
567
+ }
568
+ else
569
+ {
570
+ rawstr << "color=black";
571
+ }
572
+ rawstr << "";
578
573
  return rawstr.str();
579
574
  }
580
575
 
581
576
  template<class EdgeIter>
582
577
  static std::string getEdgeAttributes(NodeType *, EdgeIter EI, SVF::CFBasicBlockGraph *)
583
578
  {
584
- return "style=solid";
579
+ CFBasicBlockEdge* edge = *(EI.getCurrent());
580
+ assert(edge && "No edge found!!");
581
+ if (SVFUtil::isa<CallCFGEdge>(edge->getICFGEdge()))
582
+ return "style=solid,color=red";
583
+ else if (SVFUtil::isa<RetCFGEdge>(edge->getICFGEdge()))
584
+ return "style=solid,color=blue";
585
+ else
586
+ return "style=solid";
587
+ return "";
585
588
  }
586
589
 
587
590
  template<class EdgeIter>
588
591
  static std::string getEdgeSourceLabel(NodeType *, EdgeIter EI)
589
592
  {
590
- return "";
593
+ CFBasicBlockEdge* edge = *(EI.getCurrent());
594
+ assert(edge && "No edge found!!");
595
+
596
+ std::string str;
597
+ std::stringstream rawstr(str);
598
+ if (const CallCFGEdge* dirCall = SVFUtil::dyn_cast<CallCFGEdge>(edge->getICFGEdge()))
599
+ rawstr << dirCall->getCallSite();
600
+ else if (const RetCFGEdge* dirRet = SVFUtil::dyn_cast<RetCFGEdge>(edge->getICFGEdge()))
601
+ rawstr << dirRet->getCallSite();
602
+
603
+ return rawstr.str();
591
604
  }
592
605
  };
593
-
594
- } // End namespace SVF
606
+ }
595
607
  #endif //SVF_CFBASICBLOCKG_H
@@ -0,0 +1,59 @@
1
+ //===- CFBasicBlockGBuilder.h ----------------------------------------------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU Affero General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+
13
+ // This program is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU Affero General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU Affero General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * CFBasicBlockGBuilder.h
25
+ *
26
+ * Created on: 17 Oct. 2023
27
+ * Author: Xiao, Jiawei
28
+ */
29
+
30
+ #include "Graphs/CFBasicBlockG.h"
31
+
32
+ namespace SVF
33
+ {
34
+
35
+ class CFBasicBlockGBuilder
36
+ {
37
+
38
+ private:
39
+ CFBasicBlockGraph* _CFBasicBlockG;
40
+
41
+ public:
42
+ CFBasicBlockGBuilder() : _CFBasicBlockG() {}
43
+
44
+ virtual void build(ICFG* icfg);
45
+
46
+ inline CFBasicBlockGraph* getCFBasicBlockGraph()
47
+ {
48
+ return _CFBasicBlockG;
49
+ }
50
+ private:
51
+ void initCFBasicBlockGNodes(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
52
+
53
+ void addInterBBEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
54
+
55
+ void addIntraBBEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
56
+
57
+ void addInterProceduralEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
58
+ };
59
+ }
@@ -488,11 +488,12 @@ protected:
488
488
  NodeRefToCycleDepthNumber _nodeToCDN;
489
489
  CycleDepthNumber _num;
490
490
  CFBasicBlockNodes _stack;
491
+ CFBasicBlockGraph* _graph;
491
492
 
492
493
  public:
493
494
  explicit CFBasicBlockGWTO() : _num(0) {}
494
495
 
495
- explicit CFBasicBlockGWTO(const CFBasicBlockNode *entry) : _num(0)
496
+ explicit CFBasicBlockGWTO(CFBasicBlockGraph* graph, const CFBasicBlockNode *entry) : _num(0), _graph(graph)
496
497
  {
497
498
  build(entry);
498
499
  }
@@ -647,12 +648,13 @@ protected:
647
648
  const CFBasicBlockGWTOCycleDepth &_headWTOCycleDepth;
648
649
  const CFBasicBlockNode *_head;
649
650
  NodeRefToWTOCycleDepthPtr &_nodeToWTOCycleDepth;
651
+ CFBasicBlockGraph* _graph;
650
652
 
651
653
  public:
652
654
 
653
- explicit TailBuilder(NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth, NodeRefSet &tails, const CFBasicBlockNode *head,
655
+ explicit TailBuilder(CFBasicBlockGraph* graph, NodeRefToWTOCycleDepthPtr &nodeToWTOCycleDepth, NodeRefSet &tails, const CFBasicBlockNode *head,
654
656
  const CFBasicBlockGWTOCycleDepth &headWTOCycleDepth) : _tails(tails), _headWTOCycleDepth(headWTOCycleDepth), _head(head), _nodeToWTOCycleDepth(
655
- nodeToWTOCycleDepth)
657
+ nodeToWTOCycleDepth), _graph(graph)
656
658
  {
657
659
  }
658
660
 
@@ -666,15 +668,27 @@ protected:
666
668
 
667
669
  virtual void visit(const CFBasicBlockGWTONode &node) override
668
670
  {
669
- for (const auto &edge: node.node()->getOutEdges())
671
+ if(const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node.node()->getICFGNodes().front()))
670
672
  {
671
- const CFBasicBlockNode *succ = edge->getDstNode();
673
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
672
674
  const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
673
675
  if (succ != _head && succNesting <= _headWTOCycleDepth)
674
676
  {
675
677
  _tails.insert(node.node());
676
678
  }
677
679
  }
680
+ else
681
+ {
682
+ for (const auto &edge: node.node()->getOutEdges())
683
+ {
684
+ const CFBasicBlockNode *succ = edge->getDstNode();
685
+ const CFBasicBlockGWTOCycleDepth &succNesting = getWTOCycleDepth(succ);
686
+ if (succ != _head && succNesting <= _headWTOCycleDepth)
687
+ {
688
+ _tails.insert(node.node());
689
+ }
690
+ }
691
+ }
678
692
  }
679
693
 
680
694
  protected:
@@ -746,14 +760,25 @@ protected:
746
760
  const CFBasicBlockGWTOCycle *component(const CFBasicBlockNode *node)
747
761
  {
748
762
  WTOCompRefList partition;
749
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
763
+ if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
750
764
  {
751
- const CFBasicBlockNode *succ = (*it)->getDstNode();
765
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
752
766
  if (getCDN(succ) == 0)
753
767
  {
754
768
  visit(succ, partition);
755
769
  }
756
770
  }
771
+ else
772
+ {
773
+ for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
774
+ {
775
+ const CFBasicBlockNode *succ = (*it)->getDstNode();
776
+ if (getCDN(succ) == 0)
777
+ {
778
+ visit(succ, partition);
779
+ }
780
+ }
781
+ }
757
782
  const CFBasicBlockGWTOCycle *ptr = newCycle(node, partition);
758
783
  _headToCycle.emplace(node, ptr);
759
784
  return ptr;
@@ -771,9 +796,9 @@ protected:
771
796
  head = _num;
772
797
  setCDN(node, head);
773
798
  loop = false;
774
- for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
799
+ if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node->getICFGNodes().front()))
775
800
  {
776
- const CFBasicBlockNode *succ = (*it)->getDstNode();
801
+ const CFBasicBlockNode *succ = _graph->getCFBasicBlockNode(callNode->getRetICFGNode()->getId());
777
802
  CycleDepthNumber succ_dfn = getCDN(succ);
778
803
  if (succ_dfn == CycleDepthNumber(0))
779
804
  {
@@ -789,6 +814,27 @@ protected:
789
814
  loop = true;
790
815
  }
791
816
  }
817
+ else
818
+ {
819
+ for (auto it = node->getOutEdges().begin(), et = node->getOutEdges().end(); it != et; ++it)
820
+ {
821
+ const CFBasicBlockNode *succ = (*it)->getDstNode();
822
+ CycleDepthNumber succ_dfn = getCDN(succ);
823
+ if (succ_dfn == CycleDepthNumber(0))
824
+ {
825
+ min = visit(succ, partition);
826
+ }
827
+ else
828
+ {
829
+ min = succ_dfn;
830
+ }
831
+ if (min <= head)
832
+ {
833
+ head = min;
834
+ loop = true;
835
+ }
836
+ }
837
+ }
792
838
  if (head == getCDN(node))
793
839
  {
794
840
  setCDN(node, UINT_MAX);
@@ -826,7 +872,7 @@ protected:
826
872
  for (const auto &head: _headToCycle)
827
873
  {
828
874
  NodeRefSet tails;
829
- TailBuilder builder(_nodeToDepth, tails, head.first, getWTOCycleDepth(head.first));
875
+ TailBuilder builder(_graph, _nodeToDepth, tails, head.first, getWTOCycleDepth(head.first));
830
876
  for (auto it = head.second->begin(), eit = head.second->end(); it != eit; ++it)
831
877
  {
832
878
  (*it)->accept(&builder);
@@ -127,8 +127,6 @@ public:
127
127
  {
128
128
  }
129
129
 
130
- CFBasicBlockNode(const SVFBasicBlock* bb);
131
-
132
130
  friend std::ostream &operator<<(std::ostream &o, const CFBasicBlockNode &node)
133
131
  {
134
132
  o << node.toString();
@@ -143,10 +141,9 @@ public:
143
141
  return (*_icfgNodes.begin())->getBB()->getName();
144
142
  }
145
143
 
146
- inline const SVFBasicBlock *getSVFBasicBlock() const
144
+ inline const std::vector<const ICFGNode*>& getICFGNodes() const
147
145
  {
148
- assert(!_icfgNodes.empty() && "no ICFG nodes in CFBB");
149
- return (*_icfgNodes.begin())->getBB();
146
+ return _icfgNodes;
150
147
  }
151
148
 
152
149
  inline const SVFFunction *getFunction() const
@@ -355,7 +352,6 @@ class CFBasicBlockGraph : public GenericCFBasicBlockGTy
355
352
  private:
356
353
  u32_t _totalCFBasicBlockNode{0};
357
354
  u32_t _totalCFBasicBlockEdge{0};
358
- Map<const SVFFunction*, CFBasicBlockNode*> _funToFirstNode;
359
355
  public:
360
356
 
361
357
  CFBasicBlockGraph() = default;
@@ -379,27 +375,6 @@ public:
379
375
  return hasGNode(id);
380
376
  }
381
377
 
382
- inline CFBasicBlockNode* getFirstCFBasicBlockNode(const SVFFunction* fun) const
383
- {
384
- if (fun && _funToFirstNode.find(fun) != _funToFirstNode.end())
385
- {
386
- return _funToFirstNode.at(fun);
387
- }
388
- else
389
- {
390
- return nullptr;
391
- }
392
- }
393
- inline bool hasFirstCFBasicBlockNode(const SVFFunction* fun) const
394
- {
395
- return fun && _funToFirstNode.find(fun) != _funToFirstNode.end();
396
- }
397
-
398
- inline void setFirstCFBasicBlockNode(const Map<const SVFFunction*, CFBasicBlockNode*>& svfNodeMap)
399
- {
400
- _funToFirstNode = svfNodeMap;
401
- }
402
-
403
378
  bool hasCFBasicBlockEdge(CFBasicBlockNode *src, CFBasicBlockNode *dst, ICFGEdge *icfgEdge)
404
379
  {
405
380
  CFBasicBlockEdge edge(src, dst, icfgEdge);
@@ -488,24 +463,6 @@ public:
488
463
  }
489
464
  };
490
465
 
491
- class CFBasicBlockGBuilder
492
- {
493
-
494
- private:
495
- CFBasicBlockGraph* _CFBasicBlockG;
496
-
497
- public:
498
- CFBasicBlockGBuilder() : _CFBasicBlockG() {}
499
-
500
- virtual void build(SVFModule* module);
501
-
502
- virtual void build(ICFG* icfg);
503
-
504
- inline CFBasicBlockGraph* getCFBasicBlockGraph()
505
- {
506
- return _CFBasicBlockG;
507
- }
508
- };
509
466
  }
510
467
 
511
468
  namespace SVF
@@ -534,6 +491,10 @@ struct GenericGraphTraits<SVF::CFBasicBlockGraph *>
534
491
  typedef SVF::CFBasicBlockNode *NodeRef;
535
492
  };
536
493
 
494
+ } // End namespace SVF
495
+
496
+ namespace SVF
497
+ {
537
498
  template<>
538
499
  struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVFIR *>
539
500
  {
@@ -571,22 +532,73 @@ struct DOTGraphTraits<SVF::CFBasicBlockGraph *> : public DOTGraphTraits<SVF::SVF
571
532
  {
572
533
  std::string str;
573
534
  std::stringstream rawstr(str);
574
- rawstr << "color=black";
535
+ if(node->getICFGNodes().size() == 1)
536
+ {
537
+ const ICFGNode* n = node->getICFGNodes()[0];
538
+ if(SVFUtil::isa<IntraICFGNode>(n))
539
+ {
540
+ rawstr << "color=black";
541
+ }
542
+ else if(SVFUtil::isa<FunEntryICFGNode>(n))
543
+ {
544
+ rawstr << "color=yellow";
545
+ }
546
+ else if(SVFUtil::isa<FunExitICFGNode>(n))
547
+ {
548
+ rawstr << "color=green";
549
+ }
550
+ else if(SVFUtil::isa<CallICFGNode>(n))
551
+ {
552
+ rawstr << "color=red";
553
+ }
554
+ else if(SVFUtil::isa<RetICFGNode>(n))
555
+ {
556
+ rawstr << "color=blue";
557
+ }
558
+ else if(SVFUtil::isa<GlobalICFGNode>(n))
559
+ {
560
+ rawstr << "color=purple";
561
+ }
562
+ else
563
+ assert(false && "no such kind of node!!");
564
+ }
565
+ else
566
+ {
567
+ rawstr << "color=black";
568
+ }
569
+ rawstr << "";
575
570
  return rawstr.str();
576
571
  }
577
572
 
578
573
  template<class EdgeIter>
579
574
  static std::string getEdgeAttributes(NodeType *, EdgeIter EI, SVF::CFBasicBlockGraph *)
580
575
  {
581
- return "style=solid";
576
+ CFBasicBlockEdge* edge = *(EI.getCurrent());
577
+ assert(edge && "No edge found!!");
578
+ if (SVFUtil::isa<CallCFGEdge>(edge->getICFGEdge()))
579
+ return "style=solid,color=red";
580
+ else if (SVFUtil::isa<RetCFGEdge>(edge->getICFGEdge()))
581
+ return "style=solid,color=blue";
582
+ else
583
+ return "style=solid";
584
+ return "";
582
585
  }
583
586
 
584
587
  template<class EdgeIter>
585
588
  static std::string getEdgeSourceLabel(NodeType *, EdgeIter EI)
586
589
  {
587
- return "";
590
+ CFBasicBlockEdge* edge = *(EI.getCurrent());
591
+ assert(edge && "No edge found!!");
592
+
593
+ std::string str;
594
+ std::stringstream rawstr(str);
595
+ if (const CallCFGEdge* dirCall = SVFUtil::dyn_cast<CallCFGEdge>(edge->getICFGEdge()))
596
+ rawstr << dirCall->getCallSite();
597
+ else if (const RetCFGEdge* dirRet = SVFUtil::dyn_cast<RetCFGEdge>(edge->getICFGEdge()))
598
+ rawstr << dirRet->getCallSite();
599
+
600
+ return rawstr.str();
588
601
  }
589
602
  };
590
-
591
- } // End namespace SVF
603
+ }
592
604
  #endif //SVF_CFBASICBLOCKG_H
@@ -0,0 +1,59 @@
1
+ //===- CFBasicBlockGBuilder.h ----------------------------------------------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU Affero General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+
13
+ // This program is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU Affero General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU Affero General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * CFBasicBlockGBuilder.h
25
+ *
26
+ * Created on: 17 Oct. 2023
27
+ * Author: Xiao, Jiawei
28
+ */
29
+
30
+ #include "Graphs/CFBasicBlockG.h"
31
+
32
+ namespace SVF
33
+ {
34
+
35
+ class CFBasicBlockGBuilder
36
+ {
37
+
38
+ private:
39
+ CFBasicBlockGraph* _CFBasicBlockG;
40
+
41
+ public:
42
+ CFBasicBlockGBuilder() : _CFBasicBlockG() {}
43
+
44
+ virtual void build(ICFG* icfg);
45
+
46
+ inline CFBasicBlockGraph* getCFBasicBlockGraph()
47
+ {
48
+ return _CFBasicBlockG;
49
+ }
50
+ private:
51
+ void initCFBasicBlockGNodes(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
52
+
53
+ void addInterBBEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
54
+
55
+ void addIntraBBEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
56
+
57
+ void addInterProceduralEdge(ICFG *icfg, Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes);
58
+ };
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1681",
3
+ "version": "1.0.1683",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {