svf-lib 1.0.1033 → 1.0.1036

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.
@@ -1,4 +1,4 @@
1
- //===----- CFGNormalizer.h -- CFL Alias Analysis Client--------------//
1
+ //===----- CFGNormalizer.h -- Context Free Grammar Normalizer--------------//
2
2
  //
3
3
  // SVF: Static Value-Flow Analysis
4
4
  //
@@ -43,40 +43,33 @@ class CFGNormalizer
43
43
  {
44
44
 
45
45
  public:
46
- typedef u32_t Symbol;
47
- typedef std::vector<Symbol> Production;
48
- typedef Set<Production> Productions;
49
-
50
46
  CFGNormalizer()
51
47
  {
52
48
  }
53
49
 
54
- /// Start Normalize (BIN Only)
55
- // TODO: Add different Combination Transformation Option
56
-
57
- /// Normalization without attribute expanded
50
+ /// Normalization with attribute expanded
58
51
  CFLGrammar* normalize(GrammarBase *generalGrammar);
59
52
 
60
53
  /// Fill Every attribute in CFL grammar
61
- CFLGrammar* fillAttribute(CFLGrammar *grammar, Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>> *kind2AttrMap);
54
+ CFLGrammar* fillAttribute(CFLGrammar *grammar, const Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>>& kind2AttrsMap);
62
55
 
63
56
  private:
64
57
  /// Add nonterminal to tranfer long rules to binary rules
65
- void ebnf_bin(GrammarBase *generalGrammar, CFLGrammar *grammar);
58
+ void ebnf_bin(CFLGrammar *grammar);
66
59
 
67
- void ebnf_sign_replace(char sign, GrammarBase* generalGrammar, CFLGrammar *grammar);
60
+ void ebnf_sign_replace(char sign, CFLGrammar *grammar);
68
61
 
69
- void insertToCFLGrammar(CFLGrammar *grammar, Production &prod);
62
+ void insertToCFLGrammar(CFLGrammar *grammar, GrammarBase::Production &prod);
70
63
 
71
- int ebnf_bracket_match(Production& prod, int i, CFLGrammar *grammar) ;
64
+ int ebnf_bracket_match(GrammarBase::Production& prod, int i, CFLGrammar *grammar) ;
72
65
 
73
- int check_head(Map<Symbol, Productions>& grammar, Production& rule);
66
+ int check_head(Map<GrammarBase::Symbol, GrammarBase::Productions>& grammar, GrammarBase::Production& rule);
74
67
 
75
- Production strTrans(std::string strPro, CFLGrammar *grammar);
68
+ GrammarBase::Production strTrans(std::string strPro, CFLGrammar *grammar);
76
69
 
77
- Production getFilledProd(Production &prod, CFLGrammar::Attribute attribute, CFLGrammar *grammar);
70
+ GrammarBase::Production getFilledProd(GrammarBase::Production &prod, CFLGrammar::Attribute attribute, CFLGrammar *grammar);
78
71
 
79
- Productions getFilledProductions(Production &prod, Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>> *kind2AttriMap, CFLGrammar *grammar);
72
+ GrammarBase::Productions getFilledProductions(GrammarBase::Production &prod,const Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>>& kind2AttriMap, CFLGrammar *grammar);
80
73
  };
81
74
 
82
75
  } // End namespace SVF
@@ -70,21 +70,22 @@ public:
70
70
  Map<std::string, SVF::CFLGraph::Symbol> ConstMap = {{"Addr",0}, {"Copy", 1},{"Store", 2},{"Load", 3},{"Gep_i", 4},{"Vgep", 5},{"Addrbar",6}, {"Copybar", 7},{"Storebar", 8},{"Loadbar", 9},{"Gepbar_i", 10},{"Vgepbar", 11}};
71
71
  GrammarBase *generalGrammar = gReader.build(ConstMap);
72
72
  ConstraintGraph *consCG = new ConstraintGraph(svfir);
73
- graph = cflGraphBuilder.buildBigraph(consCG);
74
- cflChecker.check(generalGrammar, graph);
73
+ graph = cflGraphBuilder.buildBigraph(consCG, generalGrammar->getStartKind());
74
+ cflChecker.check(generalGrammar, &cflGraphBuilder, graph);
75
75
  grammar = normalizer.normalize(generalGrammar);
76
- cflChecker.check(grammar, graph);
76
+ cflChecker.check(grammar, &cflGraphBuilder, graph);
77
+ svfir->dump("SVFIR");
78
+ grammar->dump();
77
79
  delete consCG;
78
80
  delete generalGrammar;
79
- grammar->dump();
80
81
  }
81
82
  else
82
83
  {
83
84
  GrammarBase *generalGrammar = gReader.build();
84
85
  graph = cflGraphBuilder.buildFromDot(Options::InputFilename, generalGrammar);
85
- cflChecker.check(generalGrammar, graph);
86
+ cflChecker.check(generalGrammar, &cflGraphBuilder, graph);
86
87
  grammar = normalizer.normalize(generalGrammar);
87
- cflChecker.check(grammar, graph);
88
+ cflChecker.check(grammar, &cflGraphBuilder, graph);
88
89
  delete generalGrammar;
89
90
  }
90
91
  solver = new CFLSolver(graph, grammar);
@@ -106,7 +107,7 @@ public:
106
107
  /// Interface exposed to users of our pointer analysis, given PAGNodeID
107
108
  virtual AliasResult alias(NodeID node1, NodeID node2)
108
109
  {
109
- if(graph->hasEdge(graph->getGNode(node1), graph->getGNode(node2), graph->startSymbol))
110
+ if(graph->hasEdge(graph->getGNode(node1), graph->getGNode(node2), graph->startKind))
110
111
  return AliasResult::MayAlias;
111
112
  else
112
113
  return AliasResult::NoAlias;
@@ -1,4 +1,4 @@
1
- //===----- CFLGramGraphChecker.h -- CFL Checker for Grammar and Graph alignment --------------//
1
+ //===----- CFLGramGraphChecker.h -- CFL Checker for Grammar and graphBuilder alignment --------------//
2
2
  //
3
3
  // SVF: Static Value-Flow Analysis
4
4
  //
@@ -35,28 +35,35 @@ namespace SVF
35
35
  class CFLGramGraphChecker
36
36
  {
37
37
  public:
38
- void check(GrammarBase *grammar, CFLGraph *graph)
38
+ void check(GrammarBase *grammar, CFLGraphBuilder *graphBuilder, CFLGraph *graph)
39
39
  {
40
- /// Check all the symbol in grammar in graph With the same label
41
- for(auto pairV : grammar->terminals)
40
+ /// Check all kinds in grammar in graphBuilder with the same label
41
+ for(auto pairV : grammar->getTerminals())
42
42
  {
43
- if (graph->label2SymMap.find(pairV.first) != graph->label2SymMap.end())
43
+ if (graphBuilder->getLabel2KindMap().find(pairV.first) != graphBuilder->getLabel2KindMap().end())
44
44
  {
45
- assert(graph->label2SymMap[pairV.first] == pairV.second);
45
+ assert(graphBuilder->getLabel2KindMap()[pairV.first] == pairV.second);
46
+ assert(graphBuilder->getKind2LabelMap()[pairV.second] == pairV.first);
46
47
  }
47
48
  }
48
49
 
49
- for(auto pairV : grammar->nonterminals)
50
+ for(auto pairV : grammar->getNonterminals())
50
51
  {
51
- if (graph->label2SymMap.find(pairV.first) != graph->label2SymMap.end())
52
+ if (graphBuilder->getLabel2KindMap().find(pairV.first) != graphBuilder->getLabel2KindMap().end())
52
53
  {
53
- assert(graph->label2SymMap[pairV.first] == pairV.second);
54
+ assert(graphBuilder->getLabel2KindMap()[pairV.first] == pairV.second);
55
+ assert(graphBuilder->getKind2LabelMap()[pairV.second] == pairV.first);
56
+ }
57
+ else
58
+ {
59
+ graphBuilder->getLabel2KindMap().insert(std::make_pair (pairV.first,pairV.second));
60
+ graphBuilder->getKind2LabelMap().insert(std::make_pair (pairV.second, pairV.first));
54
61
  }
55
62
  }
56
63
 
57
- /// Get Kind2Attr Map from Graph to Grammar
58
- grammar->kind2AttrMap = graph->kind2AttrMap;
59
- graph->startSymbol = grammar->startSymbol;
64
+ /// Get Kind2Attrs Map from Graph to Grammar
65
+ grammar->setKind2AttrsMap(graphBuilder->getKind2AttrsMap());
66
+ graph->startKind = grammar->getStartKind();
60
67
  }
61
68
  };
62
69
 
@@ -40,17 +40,66 @@ public:
40
40
  typedef Set<Production> Productions;
41
41
  typedef u32_t Attribute;
42
42
  typedef u32_t Kind;
43
- Map<std::string, Symbol> terminals;
44
- Map<std::string, Symbol> nonterminals;
45
- Symbol startSymbol;
46
- Symbol totalSymbol;
47
- Map<Symbol, Productions> rawProductions;
48
- Set<Symbol> attributeSymbol;
49
- Map<Kind, Set<Attribute>> kind2AttrMap;
50
43
 
51
- Symbol str2Sym(std::string str) const;
44
+ inline Map<std::string, Kind>& getNonterminals()
45
+ {
46
+ return this->nonterminals;
47
+ }
48
+
49
+ inline void setNonterminals(Map<std::string, Kind>& nonterminals)
50
+ {
51
+ this->nonterminals = nonterminals;
52
+ }
52
53
 
53
- std::string sym2Str(Symbol sym) const;
54
+ inline Map<std::string, Kind>& getTerminals()
55
+ {
56
+ return this->terminals;
57
+ }
58
+
59
+ inline void setTerminals(Map<std::string, Kind>& terminals)
60
+ {
61
+ this->terminals = terminals;
62
+ }
63
+
64
+ inline Map<Symbol, Productions>& getRawProductions()
65
+ {
66
+ return this->rawProductions;
67
+ }
68
+
69
+ inline const Map<Kind, Set<Attribute>>& getKind2AttrsMap() const
70
+ {
71
+ return this->kind2AttrsMap;
72
+ }
73
+
74
+ inline Kind getTotalKind()
75
+ {
76
+ return this->totalKind;
77
+ }
78
+
79
+ inline Kind getStartKind()
80
+ {
81
+ return this->startKind;
82
+ }
83
+
84
+ inline void setStartKind(Kind startKind)
85
+ {
86
+ this->startKind = startKind;
87
+ }
88
+
89
+ inline void setTotalKind(Kind totalKind)
90
+ {
91
+ this->totalKind = totalKind;
92
+ }
93
+
94
+ void setRawProductions(Map<Symbol, Productions>& rawProductions);
95
+
96
+ void setKind2AttrsMap(const Map<Kind, Set<Attribute>>& kind2AttrsMap);
97
+
98
+ void setAttributeKinds(const Set<Kind>& attributeKind);
99
+
100
+ Kind str2Kind(std::string str) const;
101
+
102
+ std::string kind2Str(Kind kind) const;
54
103
 
55
104
  std::string sym2StrDump(Symbol sym) const;
56
105
 
@@ -59,14 +108,14 @@ public:
59
108
  return prod.at(pos);
60
109
  }
61
110
 
62
- inline Set<Symbol>& getAttrSyms()
111
+ inline const Set<Symbol>& getAttrSyms() const
63
112
  {
64
- return this->attributeSymbol;
113
+ return this->attributeKinds;
65
114
  }
66
115
 
67
- Symbol insertTerminalSymbol(std::string strLit);
68
- Symbol insertNonTerminalSymbol(std::string strLit);
69
- void insertAttribute(Symbol s);
116
+ Kind insertTerminalKind(std::string strLit);
117
+ Kind insertNonTerminalKind(std::string strLit);
118
+ void insertAttribute(Kind kind, Attribute a);
70
119
 
71
120
  inline static Kind getSymKind(Symbol sym)
72
121
  {
@@ -86,7 +135,14 @@ public:
86
135
  protected:
87
136
  static constexpr unsigned char EdgeKindMaskBits = 8; ///< We use the lower 8 bits to denote edge kind
88
137
  static constexpr u64_t EdgeKindMask = (~0ULL) >> (64 - EdgeKindMaskBits);
89
-
138
+ Kind startKind;
139
+ private:
140
+ Set<Kind> attributeKinds;
141
+ Map<Kind, Set<Attribute>> kind2AttrsMap;
142
+ Map<Symbol, Productions> rawProductions;
143
+ Kind totalKind;
144
+ Map<std::string, Kind> nonterminals;
145
+ Map<std::string, Kind> terminals;
90
146
  };
91
147
 
92
148
  class CFLGrammar : public GrammarBase
@@ -127,39 +183,39 @@ public:
127
183
  return secondRHS2Prods;
128
184
  }
129
185
 
130
- const bool hasProdsFromFirstRHS(Symbol sym) const
186
+ const bool hasProdsFromFirstRHS(const Symbol sym) const
131
187
  {
132
188
  auto it = firstRHS2Prods.find(sym);
133
189
  return it!=firstRHS2Prods.end();
134
190
  }
135
191
 
136
- const bool hasProdsFromSingleRHS(Symbol sym) const
192
+ const bool hasProdsFromSingleRHS(const Symbol sym) const
137
193
  {
138
194
  auto it = singleRHS2Prods.find(sym);
139
195
  return it!=singleRHS2Prods.end();
140
196
  }
141
197
 
142
- const bool hasProdsFromSecondRHS(Symbol sym) const
198
+ const bool hasProdsFromSecondRHS(const Symbol sym) const
143
199
  {
144
200
  auto it = secondRHS2Prods.find(sym);
145
201
  return it!=secondRHS2Prods.end();
146
202
  }
147
203
 
148
- const Productions& getProdsFromSingleRHS(Symbol sym) const
204
+ const Productions& getProdsFromSingleRHS(const Symbol sym) const
149
205
  {
150
206
  auto it = singleRHS2Prods.find(sym);
151
207
  assert(it!=singleRHS2Prods.end() && "production (X -> sym) not found for sym!!");
152
208
  return it->second;
153
209
  }
154
210
 
155
- const Productions& getProdsFromFirstRHS(Symbol sym) const
211
+ const Productions& getProdsFromFirstRHS(const Symbol sym) const
156
212
  {
157
213
  auto it = firstRHS2Prods.find(sym);
158
214
  assert(it!=firstRHS2Prods.end() && "production (X -> sym Y ) not found for sym!!");
159
215
  return it->second;
160
216
  }
161
217
 
162
- const Productions& getProdsFromSecondRHS(Symbol sym) const
218
+ const Productions& getProdsFromSecondRHS(const Symbol sym) const
163
219
  {
164
220
  auto it = secondRHS2Prods.find(sym);
165
221
  assert(it!=secondRHS2Prods.end() && "production (X -> Y sym) not found for sym!!");
@@ -167,22 +223,22 @@ public:
167
223
  }
168
224
 
169
225
 
170
- const Symbol& getLHSSymbol(const Production& prod)
226
+ const Symbol& getLHSSymbol(const Production& prod) const
171
227
  {
172
228
  return prod.at(0);
173
229
  }
174
230
 
175
- const Symbol& getFirstRHSSymbol(const Production& prod)
231
+ const Symbol& getFirstRHSSymbol(const Production& prod) const
176
232
  {
177
233
  return prod.at(1);
178
234
  }
179
235
 
180
- const Symbol& getSecondRHSSymbol(const Production& prod)
236
+ const Symbol& getSecondRHSSymbol(const Production& prod) const
181
237
  {
182
238
  return prod.at(2);
183
239
  }
184
240
 
185
- void dump();
241
+ void dump() const;
186
242
 
187
243
  const inline int num_generator()
188
244
  {
@@ -1,11 +1,19 @@
1
1
  Start:
2
2
  V
3
3
  Productions:
4
+ F -> Addr;
5
+ F -> Addr ( Copy ) *;
6
+ F -> Addr ( Store V Load ) *;
4
7
  F -> ( Copy ) *;
5
8
  F -> ( Store V Load ) *;
9
+ Fbar -> Addrbar;
10
+ Fbar -> Addrbar ( Copybar ) *;
11
+ Fbar -> Addrbar ( Loadbar V Storebar ) *;
6
12
  Fbar -> ( Copybar ) *;
7
13
  Fbar -> ( Loadbar V Storebar ) *;
8
14
  V -> Fbar V F;
9
15
  V -> Gepbar_i V Gep_i;
10
16
  V -> Addrbar Addr;
11
- V -> epsilon;
17
+ V -> epsilon;
18
+
19
+
@@ -0,0 +1,16 @@
1
+ Start:
2
+ V
3
+ Productions:
4
+ F -> ( Copy ) *;
5
+ F -> ( Store V Load ) *;
6
+ Fbar -> ( Copybar ) *;
7
+ Fbar -> ( Loadbar Vbar Storebar ) *;
8
+ V -> Fbar V F;
9
+ V -> Gepbar_i V Gep_i;
10
+ V -> Addrbar Addr;
11
+ V -> epsilon;
12
+ Vbar -> Fbar Vbar Fbar;
13
+ Vbar -> Gepbar_i Vbar Gep_i;
14
+ Vbar -> Addrbar Addr;
15
+ Vbar -> epsilon;
16
+
@@ -39,7 +39,19 @@ namespace SVF
39
39
 
40
40
  class CFLGraphBuilder
41
41
  {
42
+ private:
43
+ typedef CFLGrammar::Kind Kind;
44
+ typedef CFLGrammar::Symbol Symbol;
45
+ Map<std::string, Kind> label2KindMap;
46
+ Map<Kind, std::string> kind2LabelMap;
47
+ Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>> kind2AttrsMap;
48
+ bool externMap;
49
+ Symbol current;
50
+
42
51
  public:
52
+ /// add attribute to kind2Attribute Map
53
+ void addAttribute(CFLGrammar::Kind kind, CFLGrammar::Attribute attribute);
54
+
43
55
  /// Build graph by copying nodes and edges from any graph inherited from GenericGraph
44
56
  template<class N, class E>
45
57
  void build(GenericGraph<N,E>* graph, CFLGraph* cflGraph)
@@ -61,11 +73,22 @@ public:
61
73
 
62
74
  /// Build Bidirectional graph by copying nodes and edges from any graph inherited from GenericGraph
63
75
  template<class N, class E>
64
- CFLGraph* buildBigraph(GenericGraph<N,E>* graph)
76
+ CFLGraph* buildBigraph(GenericGraph<N,E>* graph, Kind startKind)
65
77
  {
66
- CFLGraph *cflGraph = new CFLGraph();
78
+ CFLGraph *cflGraph = new CFLGraph(startKind);
67
79
  Map<std::string, SVF::CFLGraph::Symbol> ConstMap = {{"Addr",0}, {"Copy", 1},{"Store", 2},{"Load", 3},{"Gep_i", 4},{"Vgep", 5},{"Addrbar",6}, {"Copybar", 7},{"Storebar", 8},{"Loadbar", 9},{"Gepbar_i", 10},{"Vgepbar", 11}};
68
- cflGraph->setMap(ConstMap);
80
+ externMap = true;
81
+ for(auto pairV : ConstMap)
82
+ {
83
+ if(label2KindMap.find(pairV.first) == label2KindMap.end())
84
+ {
85
+ label2KindMap.insert(pairV);
86
+ }
87
+ if(kind2LabelMap.find(pairV.second) == kind2LabelMap.end())
88
+ {
89
+ kind2LabelMap.insert(make_pair(pairV.second, pairV.first));
90
+ }
91
+ }
69
92
  for(auto it = graph->begin(); it!= graph->end(); it++)
70
93
  {
71
94
  CFLNode* node = new CFLNode((*it).first);
@@ -82,23 +105,23 @@ public:
82
105
  if(NormalGepCGEdge::classof(edge))
83
106
  {
84
107
  NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
85
- CFLGrammar::Attribute offset = nGepEdge->getConstantFieldIdx();
86
- cflGraph->addAttribute(edgeLabel, offset);
87
- edgeLabel = CFLGrammar::getAttributedKind(offset, edgeLabel);
108
+ CFLGrammar::Attribute attr = nGepEdge->getConstantFieldIdx();
109
+ addAttribute(edgeLabel, attr);
110
+ edgeLabel = CFLGrammar::getAttributedKind(attr, edgeLabel);
88
111
  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
89
- std::string key = cflGraph->sym2LabelMap[edge->getEdgeKind()];
112
+ std::string key = kind2LabelMap[edge->getEdgeKind()];
90
113
  key.pop_back();
91
114
  key.pop_back(); // _i standsfor attribute variable should place at last
92
115
  key.append("bar_i"); // for example Gep_i should be Gepbar_i, not Gep_ibar
93
- cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(offset, cflGraph->label2SymMap[key]));
94
- cflGraph->addAttribute(cflGraph->label2SymMap[key], offset);
116
+ cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFLGrammar::getAttributedKind(attr, label2KindMap[key]));
117
+ addAttribute(label2KindMap[key], attr);
95
118
  }
96
119
  else
97
120
  {
98
121
  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
99
- std::string key = cflGraph->sym2LabelMap[edge->getEdgeKind()];
122
+ std::string key = kind2LabelMap[edge->getEdgeKind()];
100
123
  key.append("bar");
101
- cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), cflGraph->label2SymMap[key]);
124
+ cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), label2KindMap[key]);
102
125
  }
103
126
  }
104
127
  }
@@ -109,6 +132,23 @@ public:
109
132
 
110
133
  /// Build graph from Dot
111
134
  CFLGraph *buildFromDot(std::string filename, GrammarBase *grammar);
135
+
136
+ Map<std::string, Kind>& getLabel2KindMap()
137
+ {
138
+ return this->label2KindMap;
139
+ }
140
+
141
+ Map<Kind, std::string>& getKind2LabelMap()
142
+ {
143
+ return this->kind2LabelMap;
144
+ }
145
+
146
+ Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>>& getKind2AttrsMap()
147
+ {
148
+ return this->kind2AttrsMap;
149
+ }
150
+
151
+
112
152
  };
113
153
  }// SVF
114
154
 
@@ -50,6 +50,8 @@ public:
50
50
 
51
51
  ~CFLSolver()
52
52
  {
53
+ delete graph;
54
+ delete grammar;
53
55
  }
54
56
 
55
57
  /// Start solving
@@ -77,16 +77,13 @@ class CFLGraph: public GenericCFLGraphTy
77
77
  {
78
78
  public:
79
79
  typedef CFLGrammar::Symbol Symbol;
80
+ typedef CFLGrammar::Kind Kind;
80
81
  typedef GenericNode<CFLNode,CFLEdge>::GEdgeSetTy CFLEdgeSet;
81
- Map<std::string, Symbol> label2SymMap;
82
- Map<Symbol, std::string> sym2LabelMap;
83
- Symbol startSymbol;
84
- Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>> kind2AttrMap;
85
- bool externMap;
86
- Symbol current;
87
-
88
- CFLGraph()
82
+ Kind startKind;
83
+
84
+ CFLGraph(Kind kind)
89
85
  {
86
+ startKind = kind;
90
87
  }
91
88
  ~CFLGraph() override = default;
92
89
 
@@ -100,27 +97,6 @@ public:
100
97
 
101
98
  void view();
102
99
 
103
- void setMap(Map<std::string, Symbol> &labelMap);
104
- /// Set label2Sym from External
105
- void setMap(GrammarBase *grammar);
106
-
107
- /// add attribute to kind2Attribute Map
108
- void addAttribute(CFLGrammar::Kind kind, CFLGrammar::Attribute attribute)
109
- {
110
- if(kind2AttrMap.find(kind) == kind2AttrMap.end())
111
- {
112
- Set<CFLGrammar::Attribute> attrs {attribute};
113
- kind2AttrMap.insert(make_pair(kind, attrs));
114
- }
115
- else
116
- {
117
- if(kind2AttrMap[kind].find(attribute) == kind2AttrMap[kind].end())
118
- {
119
- kind2AttrMap[kind].insert(attribute);
120
- }
121
- }
122
- }
123
-
124
100
  private:
125
101
  CFLEdgeSet cflEdgeSet;
126
102
 
Binary file
@@ -1,4 +1,4 @@
1
- //===----- CFGNormalizer.h -- CFL Alias Analysis Client--------------//
1
+ //===----- CFGNormalizer.h -- Context Free Grammar Normalizer--------------//
2
2
  //
3
3
  // SVF: Static Value-Flow Analysis
4
4
  //
@@ -43,40 +43,33 @@ class CFGNormalizer
43
43
  {
44
44
 
45
45
  public:
46
- typedef u32_t Symbol;
47
- typedef std::vector<Symbol> Production;
48
- typedef Set<Production> Productions;
49
-
50
46
  CFGNormalizer()
51
47
  {
52
48
  }
53
49
 
54
- /// Start Normalize (BIN Only)
55
- // TODO: Add different Combination Transformation Option
56
-
57
- /// Normalization without attribute expanded
50
+ /// Normalization with attribute expanded
58
51
  CFLGrammar* normalize(GrammarBase *generalGrammar);
59
52
 
60
53
  /// Fill Every attribute in CFL grammar
61
- CFLGrammar* fillAttribute(CFLGrammar *grammar, Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>> *kind2AttrMap);
54
+ CFLGrammar* fillAttribute(CFLGrammar *grammar, const Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>>& kind2AttrsMap);
62
55
 
63
56
  private:
64
57
  /// Add nonterminal to tranfer long rules to binary rules
65
- void ebnf_bin(GrammarBase *generalGrammar, CFLGrammar *grammar);
58
+ void ebnf_bin(CFLGrammar *grammar);
66
59
 
67
- void ebnf_sign_replace(char sign, GrammarBase* generalGrammar, CFLGrammar *grammar);
60
+ void ebnf_sign_replace(char sign, CFLGrammar *grammar);
68
61
 
69
- void insertToCFLGrammar(CFLGrammar *grammar, Production &prod);
62
+ void insertToCFLGrammar(CFLGrammar *grammar, GrammarBase::Production &prod);
70
63
 
71
- int ebnf_bracket_match(Production& prod, int i, CFLGrammar *grammar) ;
64
+ int ebnf_bracket_match(GrammarBase::Production& prod, int i, CFLGrammar *grammar) ;
72
65
 
73
- int check_head(Map<Symbol, Productions>& grammar, Production& rule);
66
+ int check_head(Map<GrammarBase::Symbol, GrammarBase::Productions>& grammar, GrammarBase::Production& rule);
74
67
 
75
- Production strTrans(std::string strPro, CFLGrammar *grammar);
68
+ GrammarBase::Production strTrans(std::string strPro, CFLGrammar *grammar);
76
69
 
77
- Production getFilledProd(Production &prod, CFLGrammar::Attribute attribute, CFLGrammar *grammar);
70
+ GrammarBase::Production getFilledProd(GrammarBase::Production &prod, CFLGrammar::Attribute attribute, CFLGrammar *grammar);
78
71
 
79
- Productions getFilledProductions(Production &prod, Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>> *kind2AttriMap, CFLGrammar *grammar);
72
+ GrammarBase::Productions getFilledProductions(GrammarBase::Production &prod,const Map<CFLGrammar::Kind, Set<CFLGrammar::Attribute>>& kind2AttriMap, CFLGrammar *grammar);
80
73
  };
81
74
 
82
75
  } // End namespace SVF
@@ -70,21 +70,22 @@ public:
70
70
  Map<std::string, SVF::CFLGraph::Symbol> ConstMap = {{"Addr",0}, {"Copy", 1},{"Store", 2},{"Load", 3},{"Gep_i", 4},{"Vgep", 5},{"Addrbar",6}, {"Copybar", 7},{"Storebar", 8},{"Loadbar", 9},{"Gepbar_i", 10},{"Vgepbar", 11}};
71
71
  GrammarBase *generalGrammar = gReader.build(ConstMap);
72
72
  ConstraintGraph *consCG = new ConstraintGraph(svfir);
73
- graph = cflGraphBuilder.buildBigraph(consCG);
74
- cflChecker.check(generalGrammar, graph);
73
+ graph = cflGraphBuilder.buildBigraph(consCG, generalGrammar->getStartKind());
74
+ cflChecker.check(generalGrammar, &cflGraphBuilder, graph);
75
75
  grammar = normalizer.normalize(generalGrammar);
76
- cflChecker.check(grammar, graph);
76
+ cflChecker.check(grammar, &cflGraphBuilder, graph);
77
+ svfir->dump("SVFIR");
78
+ grammar->dump();
77
79
  delete consCG;
78
80
  delete generalGrammar;
79
- grammar->dump();
80
81
  }
81
82
  else
82
83
  {
83
84
  GrammarBase *generalGrammar = gReader.build();
84
85
  graph = cflGraphBuilder.buildFromDot(Options::InputFilename, generalGrammar);
85
- cflChecker.check(generalGrammar, graph);
86
+ cflChecker.check(generalGrammar, &cflGraphBuilder, graph);
86
87
  grammar = normalizer.normalize(generalGrammar);
87
- cflChecker.check(grammar, graph);
88
+ cflChecker.check(grammar, &cflGraphBuilder, graph);
88
89
  delete generalGrammar;
89
90
  }
90
91
  solver = new CFLSolver(graph, grammar);
@@ -106,7 +107,7 @@ public:
106
107
  /// Interface exposed to users of our pointer analysis, given PAGNodeID
107
108
  virtual AliasResult alias(NodeID node1, NodeID node2)
108
109
  {
109
- if(graph->hasEdge(graph->getGNode(node1), graph->getGNode(node2), graph->startSymbol))
110
+ if(graph->hasEdge(graph->getGNode(node1), graph->getGNode(node2), graph->startKind))
110
111
  return AliasResult::MayAlias;
111
112
  else
112
113
  return AliasResult::NoAlias;