99template<
class N,
class E>
104 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
107 cflGraph->addCFLNode((*it).first, node);
109 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
111 N* node = (*it).second;
112 for(E* edge : node->getOutEdges())
118 std::string label = grammar->
kindToStr(edge);
129 bool isDot = (fileName.rfind(
".dot") == fileName.length() - std::string(
".dot").length());
133 bool isJson = (fileName.rfind(
".json") == fileName.length() - std::string(
".json").length());
146 std::cout <<
"Building CFL Graph from text file: " << fileName <<
"..\n";
147 std::string lineString;
148 std::ifstream inputFile(fileName);
150 if (!inputFile.is_open())
152 SVFUtil::errs() <<
"Error opening " << fileName << std::endl;
160 while (getline(inputFile, line))
166 NodeID srcID = std::stoi(vec[0]);
167 NodeID dstID = std::stoi(vec[1]);
170 std::string label = vec[2];
182 std::string msg =
"In line " + std::to_string(lineNum) +
183 " sym can not find in grammar, please correct the input dot or set --flexsymmap.";
199 std::string lineString;
200 std::ifstream inputFile(fileName);
201 std::cout <<
"Building CFL Graph from dot file: " << fileName <<
"..\n";
202 std::cout << std::boolalpha;
207 while (getline(inputFile, lineString))
212 size_t srcStart = lineString.find(
"Node");
213 if (srcStart == std::string::npos)
continue;
215 size_t srcEnd = lineString.find(
" ", srcStart);
216 if (srcEnd == std::string::npos)
continue;
218 size_t arrowPos = lineString.find(
"->", srcEnd);
219 if (arrowPos == std::string::npos)
continue;
221 size_t dstStart = lineString.find(
"Node", arrowPos);
222 if (dstStart == std::string::npos)
continue;
224 size_t dstEnd = lineString.find(
" ", dstStart);
225 if (dstEnd == std::string::npos)
continue;
227 size_t labelStart = lineString.find(
"label=", dstEnd);
228 if (labelStart == std::string::npos)
continue;
231 size_t labelEnd = lineString.find_first_of(
"]", labelStart);
232 if (labelEnd == std::string::npos)
continue;
235 std::string srcIDStr = lineString.substr(srcStart + 4, srcEnd - (srcStart + 4));
236 std::string dstIDStr = lineString.substr(dstStart + 4, dstEnd - (dstStart + 4));
237 std::string label = lineString.substr(labelStart, labelEnd - labelStart);
240 u32_t srcID = std::stoul(srcIDStr,
nullptr, 16);
241 u32_t dstID = std::stoul(dstIDStr,
nullptr, 16);
259 std::string msg =
"In line " + std::to_string(lineNum) +
260 " sym cannot be found in grammar. Please correct the input dot or set --flexsymmap.";
284 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
287 cflGraph->addCFLNode((*it).first, node);
289 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
326 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
329 cflGraph->addCFLNode((*it).first, node);
331 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
344 CFLNode* CFLDerefNode =
nullptr;
349 DerefNode = DstInEdge->getSrcNode();
350 CFLDerefNode =
cflGraph->getGNode(DstInEdge->getSrcID());
354 if (DerefNode ==
nullptr)
357 CFLDerefNode =
new CFLNode(refId);
358 cflGraph->addCFLNode(refId, CFLDerefNode);
377 CFLNode* CFLDerefNode =
nullptr;
382 DerefNode = SrcInEdge->getSrcNode();
383 CFLDerefNode =
cflGraph->getGNode(SrcInEdge->getSrcID());
386 if (DerefNode ==
nullptr)
389 CFLDerefNode =
new CFLNode(refId);
390 cflGraph->addCFLNode(refId, CFLDerefNode);
443 if (level == 0)
return;
450 addBiGepCFLEdge(cflGraph, (*eit)->getDstNode(), dst, maxField);
455 connectVGep(cflGraph, graph, (*eit)->getSrcNode(), dst, level, pag);
484 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
487 cflGraph->addCFLNode((*it).first, node);
489 for(
auto it = graph->
begin(); it!= graph->
end(); it++)
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)
u32_t getNumOfElements() const
Get the number of elements of this object.
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.
CallSiteID getCallSiteId() const
Return callsite ID.
CallSiteID getCallSiteId() const
const ConstraintEdge::ConstraintEdgeSetTy & getAddrInEdges() const
iterator begin()
Iterators.
const GEdgeSetTy & getOutEdges() const
const GEdgeSetTy & getInEdges() const
Kind strToKind(std::string str) const
Map< std::string, Kind > & getNonterminals()
Map< std::string, Kind > & getTerminals()
std::string kindToStr(Kind kind) const
static Kind getAttributedKind(Attribute attribute, Kind kind)
static bool isNullPtr(NodeID id)
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
const BaseObjVar * getBaseObject(NodeID id) const
NodeID getId() const
Get ID.
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().
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
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