100 template<
class N,
class E>
105 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
110 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
112 N* node = (*it).second;
113 for(E* edge : node->getOutEdges())
130 bool isDot = (fileName.rfind(
".dot") == fileName.length() -
std::string(
".dot").length());
134 bool isJson = (fileName.rfind(
".json") == fileName.length() -
std::string(
".json").length());
147 std::cout <<
"Building CFL Graph from text file: " << fileName <<
"..\n";
149 std::ifstream inputFile(fileName);
151 if (!inputFile.is_open())
153 SVFUtil::errs() <<
"Error opening " << fileName << std::endl;
161 while (getline(inputFile, line))
167 NodeID srcID = std::stoi(vec[0]);
168 NodeID dstID = std::stoi(vec[1]);
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.";
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;
208 while (getline(inputFile, lineString))
212 if (std::regex_search(lineString, matches, reg))
214 u32_t srcID = std::stoul(matches.str(1),
nullptr, 16);
215 u32_t dstID = std::stoul(matches.str(2),
nullptr, 16);
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.";
256 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
261 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
298 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
303 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
316 CFLNode* CFLDerefNode =
nullptr;
321 DerefNode = DstInEdge->getSrcNode();
326 if (DerefNode ==
nullptr)
330 CFLDerefNode =
new CFLNode(refId);
350 CFLNode* CFLDerefNode =
nullptr;
355 DerefNode = SrcInEdge->getSrcNode();
359 if (DerefNode ==
nullptr)
362 CFLDerefNode =
new CFLNode(refId);
416 if (level == 0)
return;
423 addBiGepCFLEdge(cflGraph, (*eit)->getDstNode(), dst, maxField);
428 connectVGep(cflGraph, graph, (*eit)->getSrcNode(), dst, level, pag);
457 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
462 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
482 CallDirSVFGEdge *attributedEdge = SVFUtil::dyn_cast<CallDirSVFGEdge>(edge);
496 CallIndSVFGEdge *attributedEdge = SVFUtil::dyn_cast<CallIndSVFGEdge>(edge);
510 RetDirSVFGEdge *attributedEdge = SVFUtil::dyn_cast<RetDirSVFGEdge>(edge);
524 RetIndSVFGEdge *attributedEdge = SVFUtil::dyn_cast<RetIndSVFGEdge>(edge);
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)
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)
virtual const CFLEdge * addCFLEdge(CFLNode *src, CFLNode *dst, CFLEdge::GEdgeFlag label)
CallSiteID getCallSiteId() const
Return callsite ID.
CallSiteID getCallSiteId() const
const ConstraintEdge::ConstraintEdgeSetTy & getAddrInEdges() const
iterator begin()
Iterators.
NodeType * getGNode(NodeID id) const
Get a node.
bool hasGNode(NodeID id) const
Has a node.
const GEdgeSetTy & getOutEdges() const
const GEdgeSetTy & getInEdges() const
Map< std::string, Kind > & getNonterminals()
Kind strToKind(std::string str) const
Map< std::string, Kind > & getTerminals()
std::string kindToStr(Kind kind) const
static Kind getAttributedKind(Attribute attribute, Kind kind)
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:
APOffset getConstantFieldIdx() const
Get location set of the gep edge.
static const Option< bool > FlexSymMap
CallSiteID getCallSiteId() const
Return callsite ID.
CallSiteID getCallSiteId() const
NodeID getId() const
Get ID.
bool isNullPtr(NodeID id) const
const MemObj * getBaseObj(NodeID id) const
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...
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
std::ostream & errs()
Overwrite llvm::errs()
std::vector< std::string > split(const std::string &s, char separator)
Split into two substrings around the first occurrence of a separator string.
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set