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"
32
33namespace SVF
34{
35
36class CFLStat;
37
41double CFLBase::timeOfSolving = 0;
47double CFLBase::numOfChecks = 1;
48
50{
51 // Check for valid grammar file before parsing other options
52 std::string filename = Options::GrammarFilename();
53 bool pagfile = (filename.rfind("PAGGrammar.txt") == filename.length() - std::string("PAGGrammar.txt").length());
54 bool pegfile = (filename.rfind("PEGGrammar.txt") == filename.length() - std::string("PEGGrammar.txt").length());
55 bool vfgfile = (filename.rfind("VFGGrammar.txt") == filename.length() - std::string("VFGGrammar.txt").length());
56 if (!Options::Customized() && !(pagfile || pegfile || vfgfile))
57 {
58 SVFUtil::errs() << "Invalid alias grammar file: " << Options::GrammarFilename() << "\n"
59 << "Please use a file that ends with either 'CFGrammar.txt' or 'PEGGrammar.txt', "
60 << "or use the -customized flag to allow custom grammar files.\n";
61 assert(false && "grammar loading failed!"); // exit with error
62 }
63}
64
66{
67 // Start building grammar
68 double start = stat->getClk(true);
69
72
73 // Get time of build grammar
74 double end = stat->getClk(true);
76}
77
79{
80 // Start building CFLGraph
81 double start = stat->getClk(true);
82
84 if (Options::CFLGraph().empty()) // built from svfir
85 {
89 graph = cflGraphBuilder.buildBiPEGgraph(consCG, grammarBase->getStartKind(), grammarBase, svfir);
90 else
91 graph = cflGraphBuilder.buildBigraph(consCG, grammarBase->getStartKind(), grammarBase);
92 delete consCG;
93 }
94 else
96 // Check CFL Graph and Grammar are accordance with grammar
99
100 // Get time of build graph
101 double end = stat->getClk(true);
103}
104
106{
107 // Start normalize grammar
108 double start = stat->getClk(true);
109
111 grammar = normalizer.normalize(grammarBase);
112
113 // Get time of normalize grammar
114 double end = stat->getClk(true);
116}
117
119{
120 // Start solving
121 double start = stat->getClk(true);
122
123 solver->solve();
124
125 double end = stat->getClk(true);
126 timeOfSolving += (end - start) / TIMEINTERVAL;
127}
128
135
137{
138 initialize();
139
140 solve();
141
142 finalize();
143}
144
146{
147 return graph;
148}
149
151{
152 numOfStartEdges = 0;
153 for(auto it = getCFLGraph()->getCFLEdges().begin(); it != getCFLGraph()->getCFLEdges().end(); it++ )
154 {
155 if ((*it)->getEdgeKind() == grammar->getStartKind())
157 }
158}
159
160} // End namespace SVF
#define TIMEINTERVAL
Definition SVFType.h:512
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:94
virtual void buildCFLGraph()
Build CFLGraph based on Option.
Definition CFLBase.cpp:78
CFLGraph * getCFLGraph()
Get CFL graph.
Definition CFLBase.cpp:145
static double numOfStartEdges
Definition CFLBase.h:101
virtual void analyze()
Perform analyze (main part of CFLR Analysis)
Definition CFLBase.cpp:136
virtual void solve()
Solving CFL Reachability.
Definition CFLBase.cpp:118
CFLSolver * solver
Definition CFLBase.h:113
virtual void normalizeCFLGrammar()
Normalize grammar.
Definition CFLBase.cpp:105
static double numOfChecks
Definition CFLBase.h:104
static double numOfNonterminalEdges
Definition CFLBase.h:100
virtual void checkParameter()
Parameter Checking.
Definition CFLBase.cpp:49
virtual void buildCFLGrammar()
Build Grammar from text file.
Definition CFLBase.cpp:65
virtual void finalize()
Finalize extra stat info passing.
Definition CFLBase.cpp:129
CFLGraph * graph
Definition CFLBase.h:110
virtual void countSumEdges()
Count the num of Nonterminal Edges.
Definition CFLBase.cpp:150
static double timeOfSolving
Definition CFLBase.h:105
CFGrammar * grammar
Definition CFLBase.h:112
static double timeOfBuildCFLGraph
Definition CFLBase.h:97
SVFIR * svfir
Definition CFLBase.h:109
static double numOfIteration
Definition CFLBase.h:103
static double numOfTerminalEdges
Definition CFLBase.h:98
static double numOfTemporaryNonterminalEdges
Definition CFLBase.h:99
static double timeOfNormalizeGrammar
Definition CFLBase.h:95
GrammarBase * grammarBase
Definition CFLBase.h:111
const CFLEdgeSet & getCFLEdges() const
Definition CFLGraph.h:198
virtual void solve()
Start solving.
static double numOfChecks
Definition CFLSolver.h:52
Kind getStartKind()
Definition CFGrammar.h:205
static const Option< bool > Customized
Definition Options.h:239
static const Option< bool > PEGTransfer
Definition Options.h:235
static const Option< std::string > CFLGraph
Definition Options.h:232
static const Option< std::string > GrammarFilename
Definition Options.h:231
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:48
std::ostream & errs()
Overwrite llvm::errs()
Definition SVFUtil.h:56
for isBitcode
Definition BasicTypes.h:68
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74