Static Value-Flow Analysis
Public Member Functions | Private Member Functions | List of all members
SVF::VFCFLGraphBuilder Class Reference

VFCFLGraphBuilder: a CFLGraphBuilder specialized for handling value-flow. More...

#include <CFLGraphBuilder.h>

Inheritance diagram for SVF::VFCFLGraphBuilder:
SVF::CFLGraphBuilder

Public Member Functions

CFLGraphbuildBigraph (SVFG *graph, Kind startKind, GrammarBase *grammar)
 Builds a bidirectional CFL graph by copying nodes and edges from a const graph that inherits from SVFG. More...
 
CFLGraphbuildBiPEGgraph (ConstraintGraph *graph, Kind startKind, GrammarBase *grammar, SVFIR *pag)
 
- Public Member Functions inherited from SVF::CFLGraphBuilder
template<class N , class E >
CFLGraphbuild (GenericGraph< N, E > *graph, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 
CFLGraphbuild (std::string fileName, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from external file. More...
 
Map< std::string, Kind > & getLabelToKindMap ()
 Returns a reference to the map that associates string labels with their corresponding Kind. More...
 
Map< Kind, std::string > & getKindToLabelMap ()
 Returns a reference to the map that associates Kinds with their corresponding string labels. More...
 
Map< CFGrammar::Kind, Set< CFGrammar::Attribute > > & getKindToAttrsMap ()
 Returns a reference to the map that associates Kinds with their corresponding attributes. More...
 

Private Member Functions

void connectVGep (CFLGraph *cflGraph, ConstraintGraph *graph, ConstraintNode *src, ConstraintNode *dst, u32_t level, SVFIR *pag)
 Connects VGep (Variable GEP) More...
 
void addBiCFLEdge (CFLGraph *cflGraph, ConstraintNode *src, ConstraintNode *dst, CFGrammar::Kind label)
 Handles edges, with the exception of the GEP. More...
 
void addBiGepCFLEdge (CFLGraph *cflGraph, ConstraintNode *src, ConstraintNode *dst, CFGrammar::Attribute attri)
 Adds bidirectional GEP edges with attributes. More...
 

Additional Inherited Members

- Protected Types inherited from SVF::CFLGraphBuilder
typedef CFGrammar::Kind Kind
 
typedef CFGrammar::Symbol Symbol
 
- Protected Member Functions inherited from SVF::CFLGraphBuilder
void addAttribute (CFGrammar::Kind kind, CFGrammar::Attribute attribute)
 Method to add an attribute to a specific kind. More...
 
void buildlabelToKindMap (GrammarBase *grammar)
 build label and kind connect from the grammar More...
 
CFLNodeaddGNode (u32_t NodeID)
 add src and dst node from file More...
 
CFLGraphbuildFromText (std::string fileName, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from a Text file. More...
 
CFLGraphbuildFromDot (std::string filename, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from a Dot file. More...
 
CFLGraphbuildFromJson (std::string filename, GrammarBase *grammar, BuildDirection direction=BuildDirection::plain)
 Method to build a CFL graph from a Json file. More...
 
- Protected Attributes inherited from SVF::CFLGraphBuilder
Map< std::string, KindlabelToKindMap
 Maps to maintain mapping between labels and kinds. More...
 
Map< Kind, std::stringkindToLabelMap
 
Map< CFGrammar::Kind, Set< CFGrammar::Attribute > > kindToAttrsMap
 Map to maintain attributes associated with each kind. More...
 
Kind current
 
CFLGraphcflGraph
 

Detailed Description

VFCFLGraphBuilder: a CFLGraphBuilder specialized for handling value-flow.

Definition at line 142 of file CFLGraphBuilder.h.

Member Function Documentation

◆ addBiCFLEdge()

void SVF::VFCFLGraphBuilder::addBiCFLEdge ( CFLGraph cflGraph,
ConstraintNode src,
ConstraintNode dst,
CFGrammar::Kind  label 
)
private

Handles edges, with the exception of the GEP.

◆ addBiGepCFLEdge()

void SVF::VFCFLGraphBuilder::addBiGepCFLEdge ( CFLGraph cflGraph,
ConstraintNode src,
ConstraintNode dst,
CFGrammar::Attribute  attri 
)
private

Adds bidirectional GEP edges with attributes.

◆ buildBigraph()

CFLGraph * SVF::VFCFLGraphBuilder::buildBigraph ( SVFG graph,
Kind  startKind,
GrammarBase grammar 
)

Builds a bidirectional CFL graph by copying nodes and edges from a const graph that inherits from SVFG.

Definition at line 452 of file CFLGraphBuilder.cpp.

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 }
const char *const string
Definition: cJSON.h:172
void buildlabelToKindMap(GrammarBase *grammar)
build label and kind connect from the grammar
Map< std::string, Kind > labelToKindMap
Maps to maintain mapping between labels and kinds.
Map< Kind, std::string > kindToLabelMap
void addAttribute(CFGrammar::Kind kind, CFGrammar::Attribute attribute)
Method to add an attribute to a specific 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
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
static Kind getAttributedKind(Attribute attribute, Kind kind)
Definition: CFGrammar.h:265
@ IntraDirectVF
Definition: VFGEdge.h:53
@ IntraIndirectVF
Definition: VFGEdge.h:54
@ TheadMHPIndirectVF
Definition: VFGEdge.h:59

◆ buildBiPEGgraph()

CFLGraph * SVF::VFCFLGraphBuilder::buildBiPEGgraph ( ConstraintGraph graph,
Kind  startKind,
GrammarBase grammar,
SVFIR pag 
)

Builds a bidirectional CFL graph by copying nodes and edges from any graph that inherits from GenericGraph Transfers Load and Store to copy edge and address edge to construct PEG style CFLGraph

Definition at line 539 of file CFLGraphBuilder.cpp.

540 {
541  CFLGraph *cflGraph = new CFLGraph(startKind);
542  return cflGraph;
543 }

◆ connectVGep()

void SVF::VFCFLGraphBuilder::connectVGep ( CFLGraph cflGraph,
ConstraintGraph graph,
ConstraintNode src,
ConstraintNode dst,
u32_t  level,
SVFIR pag 
)
private

Connects VGep (Variable GEP)


The documentation for this class was generated from the following files: