Static Value-Flow Analysis
Loading...
Searching...
No Matches
CFLBase.cpp
Go to the documentation of this file.
1//===----- CFLBase.cpp -- CFL Analysis Client Base--------------//
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 * CFLBase.cpp
25 *
26 * Created on: Oct 13, 2022
27 * Author: Pei Xu
28 */
29
30
31#include "CFL/CFLBase.h"
33#include "CFL/CFGNormalizer.h"
34#include "CFL/GrammarBuilder.h"
35#include "Util/Options.h"
36#include "Util/PTAStat.h"
37#include "Util/SVFUtil.h"
38
39namespace SVF
40{
41
42class CFLStat;
43
47double CFLBase::timeOfSolving = 0;
53double CFLBase::numOfChecks = 1;
54
56{
57 // Check for valid grammar file before parsing other options
58 std::string filename = Options::GrammarFilename();
59 bool pagfile = (filename.rfind("PAGGrammar.txt") == filename.length() - std::string("PAGGrammar.txt").length());
60 bool pegfile = (filename.rfind("PEGGrammar.txt") == filename.length() - std::string("PEGGrammar.txt").length());
61 bool vfgfile = (filename.rfind("VFGGrammar.txt") == filename.length() - std::string("VFGGrammar.txt").length());
62 if (!Options::Customized() && !(pagfile || pegfile || vfgfile))
63 {
64 SVFUtil::errs() << "Invalid alias grammar file: " << Options::GrammarFilename() << "\n"
65 << "Please use a file that ends with either 'CFGrammar.txt' or 'PEGGrammar.txt', "
66 << "or use the -customized flag to allow custom grammar files.\n";
67 assert(false && "grammar loading failed!"); // exit with error
68 }
69}
70
72{
73 // Start building grammar
74 double start = stat->getClk(true);
75
78
79 // Get time of build grammar
80 double end = stat->getClk(true);
82}
83
85{
86 // Start building CFLGraph
87 double start = stat->getClk(true);
88
90 if (Options::CFLGraph().empty()) // built from svfir
91 {
95 graph = cflGraphBuilder.buildBiPEGgraph(consCG, grammarBase->getStartKind(), grammarBase, svfir);
96 else
97 graph = cflGraphBuilder.buildBigraph(consCG, grammarBase->getStartKind(), grammarBase);
98 delete consCG;
99 }
100 else
102 // Check CFL Graph and Grammar are accordance with grammar
105
106 // Get time of build graph
107 double end = stat->getClk(true);
109}
110
112{
113 // Start normalize grammar
114 double start = stat->getClk(true);
115
117 grammar = normalizer.normalize(grammarBase);
118
119 // Get time of normalize grammar
120 double end = stat->getClk(true);
122}
123
125{
126 // Start solving
127 double start = stat->getClk(true);
128
129 solver->solve();
130
131 double end = stat->getClk(true);
132 timeOfSolving += (end - start) / TIMEINTERVAL;
133}
134
141
143{
144 initialize();
145
146 solve();
147
148 finalize();
149}
150
152{
153 return graph;
154}
155
157{
158 numOfStartEdges = 0;
159 for(auto it = getCFLGraph()->getCFLEdges().begin(); it != getCFLGraph()->getCFLEdges().end(); it++ )
160 {
161 if ((*it)->getEdgeKind() == grammar->getStartKind())
163 }
164}
165
166} // End namespace SVF
#define TIMEINTERVAL
Definition SVFType.h:604
AliasCFLGraphBuilder: a CFLGraphBuilder specialized for handling aliasing.
void finalize() override
Finalization of pointer analysis, and normalize points-to information to Bit Vector representation.
static double timeOfBuildCFLGrammar
Statistics.
Definition CFLBase.h:91
virtual void buildCFLGraph()
Build CFLGraph based on Option.
Definition CFLBase.cpp:84
CFLGraph * getCFLGraph()
Get CFL graph.
Definition CFLBase.cpp:151
static double numOfStartEdges
Definition CFLBase.h:98
virtual void analyze()
Perform analyze (main part of CFLR Analysis)
Definition CFLBase.cpp:142
virtual void solve()
Solving CFL Reachability.
Definition CFLBase.cpp:124
CFLSolver * solver
Definition CFLBase.h:110
virtual void normalizeCFLGrammar()
Normalize grammar.
Definition CFLBase.cpp:111
static double numOfChecks
Definition CFLBase.h:101
static double numOfNonterminalEdges
Definition CFLBase.h:97
virtual void checkParameter()
Parameter Checking.
Definition CFLBase.cpp:55
virtual void buildCFLGrammar()
Build Grammar from text file.
Definition CFLBase.cpp:71
virtual void finalize()
Finalize extra stat info passing.
Definition CFLBase.cpp:135
CFLGraph * graph
Definition CFLBase.h:107
virtual void countSumEdges()
Count the num of Nonterminal Edges.
Definition CFLBase.cpp:156
static double timeOfSolving
Definition CFLBase.h:102
CFGrammar * grammar
Definition CFLBase.h:109
static double timeOfBuildCFLGraph
Definition CFLBase.h:94
SVFIR * svfir
Definition CFLBase.h:106
static double numOfIteration
Definition CFLBase.h:100
static double numOfTerminalEdges
Definition CFLBase.h:95
static double numOfTemporaryNonterminalEdges
Definition CFLBase.h:96
static double timeOfNormalizeGrammar
Definition CFLBase.h:92
GrammarBase * grammarBase
Definition CFLBase.h:108
const CFLEdgeSet & getCFLEdges() const
Definition CFLGraph.h:198
virtual void solve()
Start solving.
static double numOfChecks
Definition CFLSolver.h:53
Kind getStartKind()
Definition CFGrammar.h:209
static const Option< bool > Customized
Definition Options.h:229
static const Option< bool > PEGTransfer
Definition Options.h:225
static const Option< std::string > CFLGraph
Definition Options.h:222
static const Option< std::string > GrammarFilename
Definition Options.h:221
virtual void initialize()
Initialization of a pointer analysis, including building symbol table and SVFIR etc.
PTAStat * stat
Statistics.
static double getClk(bool mark=false)
Definition SVFStat.cpp:51
std::ostream & errs()
Overwrite llvm::errs()
Definition SVFUtil.h:58
for isBitcode
Definition BasicTypes.h:70
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76