Static Value-Flow Analysis
ICFGStat.h
Go to the documentation of this file.
1 //===- ICFGStat.h ----------------------------------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2018> <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  * ICFGStat.h
24  *
25  * Created on: 12Sep.,2018
26  * Author: yulei
27  */
28 
29 #ifndef INCLUDE_UTIL_ICFGSTAT_H_
30 #define INCLUDE_UTIL_ICFGSTAT_H_
31 
32 #include "Util/PTAStat.h"
33 #include "Graphs/ICFG.h"
34 #include <iomanip>
35 
36 namespace SVF
37 {
38 
39 class ICFGStat : public PTAStat
40 {
41 
42 private:
50 
55 
56 public:
58 
59  ICFGStat(ICFG *cfg) : PTAStat(nullptr), icfg(cfg)
60  {
61  numOfNodes = 0;
62  numOfCallNodes = 0;
63  numOfRetNodes = 0;
64  numOfEntryNodes = 0;
65  numOfExitNodes = 0;
66  numOfIntraNodes = 0;
67 
68  numOfEdges = 0;
69  numOfCallEdges = 0;
70  numOfRetEdges = 0;
71  numOfIntraEdges = 0;
72 
73  }
74 
75  void performStat()
76  {
77 
78  countStat();
79 
80  PTNumStatMap["ICFGNode"] = numOfNodes;
81  PTNumStatMap["IntraICFGNode"] = numOfIntraNodes;
82  PTNumStatMap["CallICFGNode"] = numOfCallNodes;
83  PTNumStatMap["RetICFGNode"] = numOfRetNodes;
84  PTNumStatMap["FunEntryICFGNode"] = numOfEntryNodes;
85  PTNumStatMap["FunExitICFGNode"] = numOfExitNodes;
86 
87  PTNumStatMap["ICFGEdge"] = numOfEdges;
88  PTNumStatMap["CallCFGEdge"] = numOfCallEdges;
89  PTNumStatMap["RetCFGEdge"] = numOfRetEdges;
90  PTNumStatMap["IntraCFGEdge"] = numOfIntraEdges;
91 
92  printStat("ICFG Stat");
93  }
94 
96  {
97 
98  countStat();
99  PTNumStatMap["ICFGNode(N)"] = numOfNodes;
100  PTNumStatMap["CallICFGNode(Call)"] = numOfCallNodes;
101  PTNumStatMap["ICFGEdge(E)"] = numOfEdges;
102  printStat("IFDS Stat");
103  }
104 
105  void countStat()
106  {
107  ICFG::ICFGNodeIDToNodeMapTy::iterator it = icfg->begin();
108  ICFG::ICFGNodeIDToNodeMapTy::iterator eit = icfg->end();
109  for (; it != eit; ++it)
110  {
111  numOfNodes++;
112 
113  ICFGNode *node = it->second;
114 
115  if (SVFUtil::isa<IntraICFGNode>(node))
116  numOfIntraNodes++;
117  else if (SVFUtil::isa<CallICFGNode>(node))
118  numOfCallNodes++;
119  else if (SVFUtil::isa<RetICFGNode>(node))
120  numOfRetNodes++;
121  else if (SVFUtil::isa<FunEntryICFGNode>(node))
122  numOfEntryNodes++;
123  else if (SVFUtil::isa<FunExitICFGNode>(node))
124  numOfExitNodes++;
125 
126 
127  ICFGEdge::ICFGEdgeSetTy::iterator edgeIt =
128  it->second->OutEdgeBegin();
129  ICFGEdge::ICFGEdgeSetTy::iterator edgeEit =
130  it->second->OutEdgeEnd();
131  for (; edgeIt != edgeEit; ++edgeIt)
132  {
133  const ICFGEdge *edge = *edgeIt;
134  numOfEdges++;
135  if (edge->isCallCFGEdge())
136  numOfCallEdges++;
137  else if (edge->isRetCFGEdge())
138  numOfRetEdges++;
139  else if (edge->isIntraCFGEdge())
140  numOfIntraEdges++;
141  }
142  }
143  }
144 
145  void printStat(std::string statname)
146  {
147 
148  SVFUtil::outs() << "\n************ " << statname << " ***************\n";
149  SVFUtil::outs().flags(std::ios::left);
150  unsigned field_width = 20;
151  for(NUMStatMap::iterator it = PTNumStatMap.begin(), eit = PTNumStatMap.end(); it!=eit; ++it)
152  {
153  // format out put with width 20 space
154  SVFUtil::outs() << std::setw(field_width) << it->first << it->second << "\n";
155  }
156  PTNumStatMap.clear();
157  SVFUtil::outs().flush();
158  }
159 };
160 
161 } // End namespace SVF
162 
163 #endif /* INCLUDE_UTIL_ICFGSTAT_H_ */
164 
const char *const string
Definition: cJSON.h:172
iterator begin()
Iterators.
Definition: GenericGraph.h:627
bool isCallCFGEdge() const
Definition: ICFGEdge.h:77
bool isIntraCFGEdge() const
Definition: ICFGEdge.h:85
bool isRetCFGEdge() const
Definition: ICFGEdge.h:81
ICFG * icfg
Definition: ICFGStat.h:43
void performStatforIFDS()
Definition: ICFGStat.h:95
ICFGStat(ICFG *cfg)
Definition: ICFGStat.h:59
int numOfRetEdges
Definition: ICFGStat.h:53
int numOfIntraEdges
Definition: ICFGStat.h:54
int numOfEdges
Definition: ICFGStat.h:51
void countStat()
Definition: ICFGStat.h:105
Set< const ICFGNode * > ICFGNodeSet
Definition: ICFGStat.h:57
int numOfCallNodes
Definition: ICFGStat.h:45
int numOfNodes
Definition: ICFGStat.h:44
void performStat()
Definition: ICFGStat.h:75
int numOfCallEdges
Definition: ICFGStat.h:52
int numOfRetNodes
Definition: ICFGStat.h:46
int numOfEntryNodes
Definition: ICFGStat.h:47
int numOfExitNodes
Definition: ICFGStat.h:48
int numOfIntraNodes
Definition: ICFGStat.h:49
void printStat(std::string statname)
Definition: ICFGStat.h:145
Definition: ICFG.h:48
NUMStatMap PTNumStatMap
Definition: SVFStat.h:77
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50
for isBitcode
Definition: BasicTypes.h:68
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96