Static Value-Flow Analysis
CFLGraphBuilder.cpp
Go to the documentation of this file.
1 //===----- CFLGraphBuilder.h -- CFL Graph Builder--------------//
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  * CFLGraphBuilder.h
25  *
26  * Created on: May 22, 2022
27  * Author: Pei Xu
28  */
29 
30 #include "CFL/CFLGraphBuilder.h"
31 #include "Util/Options.h"
32 #include "SVFIR/SVFValue.h"
33 
34 namespace SVF
35 {
38 {
39  if (kindToAttrsMap.find(kind) == kindToAttrsMap.end())
40  {
41  Set<CFGrammar::Attribute> attrs{attribute};
42  kindToAttrsMap.insert(make_pair(kind, attrs));
43  }
44  else
45  {
46  if (kindToAttrsMap[kind].find(attribute) == kindToAttrsMap[kind].end())
47  {
48  kindToAttrsMap[kind].insert(attribute);
49  }
50  }
51 }
52 
55 {
56  for(auto pairV : grammar->getTerminals())
57  {
58  if(labelToKindMap.find(pairV.first) == labelToKindMap.end())
59  {
60  labelToKindMap.insert(pairV);
61  }
62  if(kindToLabelMap.find(pairV.second) == kindToLabelMap.end())
63  {
64  kindToLabelMap.insert(make_pair(pairV.second, pairV.first));
65  }
66  }
67 
68  for(auto pairV : grammar->getNonterminals())
69  {
70  if(labelToKindMap.find(pairV.first) == labelToKindMap.end())
71  {
72  labelToKindMap.insert(pairV);
73  }
74  if(kindToLabelMap.find(pairV.second) == kindToLabelMap.end())
75  {
76  kindToLabelMap.insert(make_pair(pairV.second, pairV.first));
77  }
78  }
79 }
80 
83 {
84  CFLNode* cflNode;
85  if (cflGraph->hasGNode(NodeID)==false)
86  {
87  cflNode = new CFLNode(NodeID);
88  cflGraph->addCFLNode(NodeID, cflNode);
89  }
90  else
91  {
92  cflNode = cflGraph->getGNode(NodeID);
93  }
94  return cflNode;
95 }
96 
97 
100 template<class N, class E>
102 {
103  cflGraph = new CFLGraph(grammar->getStartKind());
104  // buildlabelToKindMap(grammar);
105  for(auto it = graph->begin(); it!= graph->end(); it++)
106  {
107  CFLNode* node = new CFLNode((*it).first);
108  cflGraph->addCFLNode((*it).first, node);
109  }
110  for(auto it = graph->begin(); it!= graph->end(); it++)
111  {
112  N* node = (*it).second;
113  for(E* edge : node->getOutEdges())
114  {
115  CFGrammar::Kind edgeLabel = edge->getEdgeKind();
116  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
117  if (direction == BuildDirection::bidirection)
118  {
119  std::string label = grammar->kindToStr(edge);
120  label.append("bar");
121  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), grammar->strToKind(label));
122  }
123  }
124  }
125  return cflGraph;
126 }
127 
129 {
130  bool isDot = (fileName.rfind(".dot") == fileName.length() - std::string(".dot").length());
131  if (isDot)
132  return buildFromDot(fileName, grammar, direction);
133 
134  bool isJson = (fileName.rfind(".json") == fileName.length() - std::string(".json").length());
135  if (isJson)
136  return buildFromJson(fileName, grammar, direction);
137 
138  return buildFromText(fileName, grammar, direction);
139 }
140 
143 {
144  buildlabelToKindMap(grammar);
145  cflGraph = new CFLGraph(grammar->getStartKind());
146 
147  std::cout << "Building CFL Graph from text file: " << fileName << "..\n";
148  std::string lineString;
149  std::ifstream inputFile(fileName);
150 
151  if (!inputFile.is_open())
152  {
153  SVFUtil::errs() << "Error opening " << fileName << std::endl;
154  abort();
155  }
156 
157  std::string line;
158  current = labelToKindMap.size();
159  u32_t lineNum = 0 ;
160 
161  while (getline(inputFile, line))
162  {
163  std::vector<std::string> vec = SVFUtil::split(line, '\t');
164  if (vec.empty())
165  continue;
166  lineNum += 1;
167  NodeID srcID = std::stoi(vec[0]);
168  NodeID dstID = std::stoi(vec[1]);
169  CFLNode *src = addGNode(srcID);
170  CFLNode *dst = addGNode(dstID);
171  std::string label = vec[2];
172  if (labelToKindMap.find(label) != labelToKindMap.end())
173  cflGraph->addCFLEdge(src, dst, labelToKindMap[label]);
174  else
175  {
176  if(Options::FlexSymMap() == true)
177  {
178  labelToKindMap.insert({label, current++});
179  cflGraph->addCFLEdge(src, dst, labelToKindMap[label]);
180  }
181  else
182  {
183  std::string msg = "In line " + std::to_string(lineNum) +
184  " sym can not find in grammar, please correct the input dot or set --flexsymmap.";
185  SVFUtil::errMsg(msg);
186  std::cout << msg;
187  abort();
188  }
189  }
190  }
191 
192  inputFile.close();
193  return cflGraph;
194 }
195 
197 {
198  buildlabelToKindMap(grammar);
199  cflGraph = new CFLGraph(grammar->getStartKind());
200  std::string lineString;
201  std::ifstream inputFile(fileName);
202  std::cout << "Building CFL Graph from dot file: " << fileName << "..\n";
203  std::regex reg("Node(\\w+)\\s*->\\s*Node(\\w+)\\s*\\[.*label=(.*)\\]");
204  std::cout << std::boolalpha;
205  u32_t lineNum = 0 ;
206  current = labelToKindMap.size();
207 
208  while (getline(inputFile, lineString))
209  {
210  lineNum += 1;
211  std::smatch matches;
212  if (std::regex_search(lineString, matches, reg))
213  {
214  u32_t srcID = std::stoul(matches.str(1), nullptr, 16);
215  u32_t dstID = std::stoul(matches.str(2), nullptr, 16);
216  std::string label = matches.str(3);
217  CFLNode *src = addGNode(srcID);
218  CFLNode *dst = addGNode(dstID);
219  if (labelToKindMap.find(label) != labelToKindMap.end())
220  cflGraph->addCFLEdge(src, dst, labelToKindMap[label]);
221  else
222  {
223  if(Options::FlexSymMap() == true)
224  {
225  labelToKindMap.insert({label, current++});
226  cflGraph->addCFLEdge(src, dst, labelToKindMap[label]);
227  }
228  else
229  {
230  std::string msg = "In line " + std::to_string(lineNum) +
231  " sym can not find in grammar, please correct the input dot or set --flexsymmap.";
232  SVFUtil::errMsg(msg);
233  std::cout << msg;
234  abort();
235  }
236  }
237  }
238  }
239  inputFile.close();
240  return cflGraph;
241 }
242 
245 {
246  cflGraph = new CFLGraph(grammar->getStartKind());
247  return cflGraph;
248 }
249 
250 
252 {
253  cflGraph = new CFLGraph(startKind);
254 
255  buildlabelToKindMap(grammar);
256  for(auto it = graph->begin(); it!= graph->end(); it++)
257  {
258  CFLNode* node = new CFLNode((*it).first);
259  cflGraph->addCFLNode((*it).first, node);
260  }
261  for(auto it = graph->begin(); it!= graph->end(); it++)
262  {
263  ConstraintNode* node = (*it).second;
264  for(ConstraintEdge* edge : node->getOutEdges())
265  {
266  CFGrammar::Kind edgeLabel = edge->getEdgeKind();
267  // Need to get the offset from the Const Edge
268  // The offset present edge is only from Normal Gep CG at moment
269  if(NormalGepCGEdge::classof(edge))
270  {
271  NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
272  CFGrammar::Attribute attr = nGepEdge->getConstantFieldIdx();
273  addAttribute(edgeLabel, attr);
274  edgeLabel = CFGrammar::getAttributedKind(attr, edgeLabel);
275  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
276  std::string label = kindToLabelMap[edge->getEdgeKind()];
277  label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
278  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFGrammar::getAttributedKind(attr, labelToKindMap[label]));
279  addAttribute(labelToKindMap[label], attr);
280  }
281  else
282  {
283  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
284  std::string label = kindToLabelMap[edge->getEdgeKind()];
285  label.append("bar");
286  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[label]);
287  }
288  }
289  }
290  return cflGraph;
291 }
292 
294 {
295  cflGraph = new CFLGraph(startKind);
296 
297  buildlabelToKindMap(grammar);
298  for(auto it = graph->begin(); it!= graph->end(); it++)
299  {
300  CFLNode* node = new CFLNode((*it).first);
301  cflGraph->addCFLNode((*it).first, node);
302  }
303  for(auto it = graph->begin(); it!= graph->end(); it++)
304  {
305  ConstraintNode* node = (*it).second;
306  for(ConstraintEdge* edge : node->getOutEdges())
307  {
309  if (edge->getEdgeKind() == ConstraintEdge::Store)
310  {
311  if (pag->isNullPtr(edge->getSrcID()))
312  continue;
314  ConstraintNode* Dst = edge->getDstNode();
315  ConstraintNode* DerefNode = nullptr;
316  CFLNode* CFLDerefNode = nullptr;
317  for (ConstraintEdge* DstInEdge : Dst->getInEdges())
318  {
319  if (DstInEdge->getEdgeKind() == ConstraintEdge::Addr)
320  {
321  DerefNode = DstInEdge->getSrcNode();
322  CFLDerefNode = cflGraph->getGNode(DstInEdge->getSrcID());
323  break;
324  }
325  }
326  if (DerefNode == nullptr)
327  {
328 
329  NodeID refId = pag->addDummyValNode();
330  CFLDerefNode = new CFLNode(refId);
331  cflGraph->addCFLNode(refId, CFLDerefNode);
333  cflGraph->addCFLEdge(CFLDerefNode, cflGraph->getGNode(edge->getDstID()), ConstraintEdge::Addr);
335  label.append("bar");
336  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), CFLDerefNode, labelToKindMap[label]);
337  }
339  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(CFLDerefNode->getId()), ConstraintEdge::Copy);
341  label.append("bar");
342  cflGraph->addCFLEdge(cflGraph->getGNode(CFLDerefNode->getId()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[label]);
343  }
345  else if ( edge->getEdgeKind() == ConstraintEdge::Load)
346  {
348  ConstraintNode* Src = edge->getSrcNode();
349  ConstraintNode* DerefNode = nullptr;
350  CFLNode* CFLDerefNode = nullptr;
351  for (ConstraintEdge* SrcInEdge : Src->getInEdges())
352  {
353  if (SrcInEdge->getEdgeKind() == ConstraintEdge::Addr)
354  {
355  DerefNode = SrcInEdge->getSrcNode();
356  CFLDerefNode = cflGraph->getGNode(SrcInEdge->getSrcID());
357  }
358  }
359  if (DerefNode == nullptr)
360  {
361  NodeID refId = pag->addDummyValNode();
362  CFLDerefNode = new CFLNode(refId);
363  cflGraph->addCFLNode(refId, CFLDerefNode);
365  cflGraph->addCFLEdge(CFLDerefNode, cflGraph->getGNode(edge->getSrcID()), ConstraintEdge::Addr);
367  label.append("bar");
368  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), CFLDerefNode, labelToKindMap[label]);
369  }
371  cflGraph->addCFLEdge(cflGraph->getGNode(CFLDerefNode->getId()), cflGraph->getGNode(edge->getDstID()), ConstraintEdge::Copy);
373  label.append("bar");
374  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(CFLDerefNode->getId()), labelToKindMap[label]);
375  }
376  else if ( edge->getEdgeKind() == ConstraintEdge::VariantGep)
377  {
382  connectVGep(cflGraph, graph, edge->getSrcNode(), edge->getDstNode(), 8, pag);
383  }
384  else
385  {
386  CFGrammar::Kind edgeLabel = edge->getEdgeKind();
387  // Need to get the offset from the Const Edge
388  // The offset present edge is only from Normal Gep CG at moment
389  if(NormalGepCGEdge::classof(edge))
390  {
391  NormalGepCGEdge *nGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge);
392  CFGrammar::Attribute attr = nGepEdge->getConstantFieldIdx();
393  addAttribute(edgeLabel, attr);
394  edgeLabel = CFGrammar::getAttributedKind(attr, edgeLabel);
395  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
396  std::string label = kindToLabelMap[edge->getEdgeKind()];
397  label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
398  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFGrammar::getAttributedKind(attr, labelToKindMap[label]));
399  addAttribute(labelToKindMap[label], attr);
400  }
401  else
402  {
403  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
404  std::string label = kindToLabelMap[edge->getEdgeKind()];
405  label.append("bar");
406  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[label]);
407  }
408  }
409  }
410  }
411  return cflGraph;
412 }
413 
414 void AliasCFLGraphBuilder::AliasCFLGraphBuilder::connectVGep(CFLGraph *cflGraph, ConstraintGraph *graph, ConstraintNode *src, ConstraintNode *dst, u32_t level, SVFIR* pag)
415 {
416  if (level == 0) return;
417  level -= 1;
418  for (auto eit = src->getAddrInEdges().begin(); eit != src->getAddrInEdges().end(); eit++)
419  {
420  const MemObj* mem = pag->getBaseObj((*eit)->getSrcID());
421  for (u32_t maxField = 0 ; maxField < mem->getNumOfElements(); maxField++)
422  {
423  addBiGepCFLEdge(cflGraph, (*eit)->getDstNode(), dst, maxField);
424  }
425  }
426  for (auto eit = src->getInEdges().begin(); eit != src->getInEdges().end() && level != 0; eit++)
427  {
428  connectVGep(cflGraph, graph, (*eit)->getSrcNode(), dst, level, pag);
429  }
430  return;
431 }
432 
434 {
435  cflGraph->addCFLEdge(cflGraph->getGNode(src->getId()), cflGraph->getGNode(dst->getId()), kind);
436  std::string label = kindToLabelMap[kind];
437  label.append("bar");
439  return;
440 }
441 
443 {
445  cflGraph->addCFLEdge(cflGraph->getGNode(src->getId()), cflGraph->getGNode(dst->getId()), edgeLabel);
447  label.append("bar");
449  return;
450 }
451 
453 {
454  cflGraph = new CFLGraph(startKind);
455 
456  buildlabelToKindMap(grammar);
457  for(auto it = graph->begin(); it!= graph->end(); it++)
458  {
459  CFLNode* node = new CFLNode((*it).first);
460  cflGraph->addCFLNode((*it).first, node);
461  }
462  for(auto it = graph->begin(); it!= graph->end(); it++)
463  {
464  VFGNode* node = (*it).second;
465  for(VFGEdge* edge : node->getOutEdges())
466  {
467  CFGrammar::Kind edgeLabel;
468  // Get 'a' edge : IntraDirectVF || IntraIndirectVF
469  if (edge->getEdgeKind() == VFGEdge::IntraDirectVF || edge->getEdgeKind() == VFGEdge::IntraIndirectVF || edge->getEdgeKind() == VFGEdge::TheadMHPIndirectVF )
470  {
471  edgeLabel = 0;
472  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
473  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
474  std::string label = kindToLabelMap[edge->getEdgeKind()];
475  label.append("bar");
476  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), labelToKindMap[label]);
477  }
478  // Get 'call' edge : CallDirVF || CallIndVF
479  else if ( edge->getEdgeKind() == VFGEdge::CallDirVF )
480  {
481  edgeLabel = 1;
482  CallDirSVFGEdge *attributedEdge = SVFUtil::dyn_cast<CallDirSVFGEdge>(edge);
483  CFGrammar::Attribute attr = attributedEdge->getCallSiteId();
484  addAttribute(edgeLabel, attr);
485  edgeLabel = CFGrammar::getAttributedKind(attr, edgeLabel);
486  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
487  std::string label = kindToLabelMap[edgeLabel];
488  label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
489  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFGrammar::getAttributedKind(attr, labelToKindMap[label]));
490  addAttribute(labelToKindMap[label], attr);
491  }
492  // Get 'call' edge : CallIndVF
493  else if ( edge->getEdgeKind() == VFGEdge::CallIndVF )
494  {
495  edgeLabel = 1;
496  CallIndSVFGEdge *attributedEdge = SVFUtil::dyn_cast<CallIndSVFGEdge>(edge);
497  CFGrammar::Attribute attr = attributedEdge->getCallSiteId();
498  addAttribute(edgeLabel, attr);
499  edgeLabel = CFGrammar::getAttributedKind(attr, edgeLabel);
500  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
501  std::string label = kindToLabelMap[edgeLabel];
502  label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
503  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFGrammar::getAttributedKind(attr, labelToKindMap[label]));
504  addAttribute(labelToKindMap[label], attr);
505  }
506  // Get 'ret' edge : RetDirVF
507  else if ( edge->getEdgeKind() == VFGEdge::RetDirVF )
508  {
509  edgeLabel = 2;
510  RetDirSVFGEdge *attributedEdge = SVFUtil::dyn_cast<RetDirSVFGEdge>(edge);
511  CFGrammar::Attribute attr = attributedEdge->getCallSiteId();
512  addAttribute(edgeLabel, attr);
513  edgeLabel = CFGrammar::getAttributedKind(attr, edgeLabel);
514  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
515  std::string label = kindToLabelMap[edgeLabel];
516  label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
517  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFGrammar::getAttributedKind(attr, labelToKindMap[label]));
518  addAttribute(labelToKindMap[label], attr);
519  }
520  // Get 'ret' edge : RetIndVF
521  else if ( edge->getEdgeKind() == VFGEdge::RetIndVF )
522  {
523  edgeLabel = 2;
524  RetIndSVFGEdge *attributedEdge = SVFUtil::dyn_cast<RetIndSVFGEdge>(edge);
525  CFGrammar::Attribute attr = attributedEdge->getCallSiteId();
526  addAttribute(edgeLabel, attr);
527  edgeLabel = CFGrammar::getAttributedKind(attr, edgeLabel);
528  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getSrcID()), cflGraph->getGNode(edge->getDstID()), edgeLabel);
529  std::string label = kindToLabelMap[edgeLabel];
530  label.append("bar"); // for example Gep_i should be Gepbar_i, not Gep_ibar
531  cflGraph->addCFLEdge(cflGraph->getGNode(edge->getDstID()), cflGraph->getGNode(edge->getSrcID()), CFGrammar::getAttributedKind(attr, labelToKindMap[label]));
532  addAttribute(labelToKindMap[label], attr);
533  }
534  }
535  }
536  return cflGraph;
537 }
538 
540 {
541  CFLGraph *cflGraph = new CFLGraph(startKind);
542  return cflGraph;
543 }
544 
545 
546 } // end of SVF namespace
const char *const string
Definition: cJSON.h:172
void addBiCFLEdge(CFLGraph *cflGraph, ConstraintNode *src, ConstraintNode *dst, CFGrammar::Kind label)
Handles edges, with the exception of the GEP.
void connectVGep(CFLGraph *cflGraph, ConstraintGraph *graph, ConstraintNode *src, ConstraintNode *dst, u32_t level, SVFIR *pag)
Connects VGep (Variable GEP)
void addBiGepCFLEdge(CFLGraph *cflGraph, ConstraintNode *src, ConstraintNode *dst, CFGrammar::Attribute attri)
Adds bidirectional GEP edges with attributes.
CFLGraph * buildBigraph(ConstraintGraph *graph, Kind startKind, GrammarBase *grammar)
Builds a bidirectional CFL graph by copying nodes and edges from a const graph that inherits from Gen...
CFLGraph * buildBiPEGgraph(ConstraintGraph *graph, Kind startKind, GrammarBase *grammar, SVFIR *pag)
void buildlabelToKindMap(GrammarBase *grammar)
build label and kind connect from the grammar
CFLGraph * buildFromDot(std::string filename, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
Method to build a CFL graph from a Dot file.
Map< std::string, Kind > labelToKindMap
Maps to maintain mapping between labels and kinds.
CFLGraph * build(GenericGraph< N, E > *graph, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
CFGrammar::Kind Kind
Map< Kind, std::string > kindToLabelMap
CFLGraph * buildFromJson(std::string filename, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
Method to build a CFL graph from a Json file.
CFLGraph * buildFromText(std::string fileName, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
Method to build a CFL graph from a Text file.
CFLNode * addGNode(u32_t NodeID)
add src and dst node from file
void addAttribute(CFGrammar::Kind kind, CFGrammar::Attribute attribute)
Method to add an attribute to a specific kind.
Map< CFGrammar::Kind, Set< CFGrammar::Attribute > > kindToAttrsMap
Map to maintain attributes associated with each kind.
virtual void addCFLNode(NodeID id, CFLNode *node)
Definition: CFLGraph.cpp:42
virtual const CFLEdge * addCFLEdge(CFLNode *src, CFLNode *dst, CFLEdge::GEdgeFlag label)
Definition: CFLGraph.cpp:47
CallSiteID getCallSiteId() const
Return callsite ID.
Definition: VFGEdge.h:223
CallSiteID getCallSiteId() const
Definition: SVFGEdge.h:136
const ConstraintEdge::ConstraintEdgeSetTy & getAddrInEdges() const
Definition: ConsGNode.h:143
iterator begin()
Iterators.
Definition: GenericGraph.h:627
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
bool hasGNode(NodeID id) const
Has a node.
Definition: GenericGraph.h:661
const GEdgeSetTy & getOutEdges() const
Definition: GenericGraph.h:430
const GEdgeSetTy & getInEdges() const
Definition: GenericGraph.h:434
Map< std::string, Kind > & getNonterminals()
Definition: CFGrammar.h:160
Kind strToKind(std::string str) const
Definition: CFGrammar.cpp:55
Map< std::string, Kind > & getTerminals()
Definition: CFGrammar.h:170
Kind getStartKind()
Definition: CFGrammar.h:205
std::string kindToStr(Kind kind) const
Definition: CFGrammar.cpp:103
static Kind getAttributedKind(Attribute attribute, Kind kind)
Definition: CFGrammar.h:265
u32_t getNumOfElements() const
Get the number of elements of this object.
static bool classof(const NormalGepCGEdge *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: ConsGEdge.h:277
APOffset getConstantFieldIdx() const
Get location set of the gep edge.
Definition: ConsGEdge.h:309
static const Option< bool > FlexSymMap
Definition: Options.h:234
CallSiteID getCallSiteId() const
Return callsite ID.
Definition: VFGEdge.h:266
CallSiteID getCallSiteId() const
Definition: SVFGEdge.h:175
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
Definition: SVFG.h:66
bool isNullPtr(NodeID id) const
Definition: SVFIR.h:431
NodeID addDummyValNode()
Definition: SVFIR.h:474
const MemObj * getBaseObj(NodeID id) const
Definition: SVFIR.h:459
CFLGraph * buildBiPEGgraph(ConstraintGraph *graph, Kind startKind, GrammarBase *grammar, SVFIR *pag)
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...
@ IntraDirectVF
Definition: VFGEdge.h:53
@ IntraIndirectVF
Definition: VFGEdge.h:54
@ TheadMHPIndirectVF
Definition: VFGEdge.h:59
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
Definition: SVFUtil.cpp:76
std::ostream & errs()
Overwrite llvm::errs()
Definition: SVFUtil.h:56
std::vector< std::string > split(const std::string &s, char separator)
Split into two substrings around the first occurrence of a separator string.
Definition: SVFUtil.h:203
for isBitcode
Definition: BasicTypes.h:68
BuildDirection
u32_t NodeID
Definition: GeneralType.h:55
unsigned u32_t
Definition: GeneralType.h:46
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96