Static Value-Flow Analysis
CFLVF.cpp
Go to the documentation of this file.
1 //===----- CFLVF.cpp -- CFL Value Flow Client--------------//
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  * CFLAlias.cpp
25  *
26  * Created on: September 7 , 2022
27  * Author: Pei Xu
28  */
29 
30 #include "CFL/CFLVF.h"
31 
32 using namespace SVF;
33 using namespace SVFUtil;
34 
36 {
37  // Build CFL Graph
38  VFCFLGraphBuilder cflGraphBuilder = VFCFLGraphBuilder();
39  if (Options::CFLGraph().empty()) // built from svfir
40  {
43  svfg = memSSA.buildFullSVFG(ander);
44  graph = cflGraphBuilder.buildBigraph(svfg, grammarBase->getStartKind(), grammarBase);
45  }
46  else
47  graph = cflGraphBuilder.build(Options::CFLGraph(), grammarBase);
48 
49  // Check CFL Graph and Grammar are accordance with grammar
51  cflChecker.check(grammarBase, &cflGraphBuilder, graph);
52 }
53 
55 {
56  // Parameter Checking
57  checkParameter();
58 
59  // Build CFL Grammar
60  buildCFLGrammar();
61 
62  // Build CFL Graph
63  buildCFLGraph();
64 
65  // Normalize grammar
66  normalizeCFLGrammar();
67 
68  // Initialize solver
69  solver = new CFLSolver(graph, grammar);
70 }
71 
73 {
74  // Check for valid grammar file before parsing other options
76  bool vfgfile = (filename.rfind("VFGGrammar.txt") == filename.length() - std::string("VFGGrammar.txt").length());
77  if (!Options::Customized() && !vfgfile)
78  {
79  SVFUtil::errs() << "Invalid VFG grammar file: " << Options::GrammarFilename() << "\n"
80  << "Please use a file that ends with 'VFG.txt', "
81  << "or use the -customized flag to allow custom grammar files.\n";
82  assert(false && "grammar loading failed!"); // exit with error
83  }
84 }
85 
86 
88 {
89  if(Options::PrintCFL())
90  {
91  if (Options::CFLGraph().empty())
92  svfir->dump("IR");
93  grammar->dump("Grammar");
94  graph->dump("CFLGraph");
95  }
96 }
const char *const string
Definition: cJSON.h:172
static AndersenWaveDiff * createAndersenWaveDiff(SVFIR *_pag)
Create an singleton instance directly instead of invoking llvm pass manager.
Definition: Andersen.h:408
void check(GrammarBase *grammar, CFLGraphBuilder *graphBuilder, CFLGraph *graph)
CFLGraph * build(GenericGraph< N, E > *graph, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
virtual void checkParameter()
Parameter Checking.
Definition: CFLVF.cpp:72
virtual void finalize()
Print grammar and graph.
Definition: CFLVF.cpp:87
virtual void initialize()
Initialize the grammar, graph, solver.
Definition: CFLVF.cpp:54
void buildCFLGraph()
Build CFLGraph via VFG.
Definition: CFLVF.cpp:35
static const Option< bool > Customized
Definition: Options.h:239
static const Option< std::string > CFLGraph
Definition: Options.h:232
static const Option< bool > PrintCFL
Definition: Options.h:233
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.
VFCFLGraphBuilder: a CFLGraphBuilder specialized for handling value-flow.
CFLGraph * buildBigraph(SVFG *graph, Kind startKind, GrammarBase *grammar)
Builds a bidirectional CFL graph by copying nodes and edges from a const graph that inherits from SVF...
std::ostream & errs()
Overwrite llvm::errs()
Definition: SVFUtil.h:56
for isBitcode
Definition: BasicTypes.h:68