@@ -193,49 +193,79 @@ CFLGraph* CFLGraphBuilder::buildFromText(std::string fileName, GrammarBase *gram
193193 return cflGraph;
194194}
195195
196- CFLGraph * CFLGraphBuilder::buildFromDot (std::string fileName, GrammarBase *grammar, BuildDirection direction)
196+ CFLGraph *CFLGraphBuilder::buildFromDot (std::string fileName, GrammarBase *grammar, BuildDirection direction)
197197{
198198 buildlabelToKindMap (grammar);
199199 cflGraph = new CFLGraph (grammar->getStartKind ());
200200 std::string lineString;
201201 std::ifstream inputFile (fileName);
202202 std::cout << " Building CFL Graph from dot file: " << fileName << " ..\n " ;
203- std::regex reg (" Node(\\ w+)\\ s*->\\ s*Node(\\ w+)\\ s*\\ [.*label=(.*)\\ ]" );
204203 std::cout << std::boolalpha;
205- u32_t lineNum = 0 ;
204+
205+ u32_t lineNum = 0 ;
206206 current = labelToKindMap.size ();
207207
208208 while (getline (inputFile, lineString))
209209 {
210210 lineNum += 1 ;
211- std::smatch matches;
212- if (std::regex_search (lineString, matches, reg))
211+
212+ // Find "Node" prefixes and "->"
213+ size_t srcStart = lineString.find (" Node" );
214+ if (srcStart == std::string::npos) continue ;
215+
216+ size_t srcEnd = lineString.find (" " , srcStart);
217+ if (srcEnd == std::string::npos) continue ;
218+
219+ size_t arrowPos = lineString.find (" ->" , srcEnd);
220+ if (arrowPos == std::string::npos) continue ;
221+
222+ size_t dstStart = lineString.find (" Node" , arrowPos);
223+ if (dstStart == std::string::npos) continue ;
224+
225+ size_t dstEnd = lineString.find (" " , dstStart);
226+ if (dstEnd == std::string::npos) continue ;
227+
228+ size_t labelStart = lineString.find (" label=" , dstEnd);
229+ if (labelStart == std::string::npos) continue ;
230+
231+ labelStart += 6 ; // Move past "label=" to the start of the label
232+ size_t labelEnd = lineString.find_first_of (" ]" , labelStart);
233+ if (labelEnd == std::string::npos) continue ;
234+
235+ // Extract the source ID, destination ID, and label
236+ std::string srcIDStr = lineString.substr (srcStart + 4 , srcEnd - (srcStart + 4 ));
237+ std::string dstIDStr = lineString.substr (dstStart + 4 , dstEnd - (dstStart + 4 ));
238+ std::string label = lineString.substr (labelStart, labelEnd - labelStart);
239+
240+ // Convert source and destination IDs from hexadecimal
241+ u32_t srcID = std::stoul (srcIDStr, nullptr , 16 );
242+ u32_t dstID = std::stoul (dstIDStr, nullptr , 16 );
243+
244+ CFLNode *src = addGNode (srcID);
245+ CFLNode *dst = addGNode (dstID);
246+
247+ if (labelToKindMap.find (label) != labelToKindMap.end ())
248+ {
249+ cflGraph->addCFLEdge (src, dst, labelToKindMap[label]);
250+ }
251+ else
213252 {
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 ())
253+ if (Options::FlexSymMap () == true )
254+ {
255+ labelToKindMap.insert ({label, current++});
220256 cflGraph->addCFLEdge (src, dst, labelToKindMap[label]);
257+ }
221258 else
222259 {
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- }
260+ std::string msg = " In line " + std::to_string (lineNum) +
261+ " sym cannot be found in grammar. Please correct the input dot or set --flexsymmap." ;
262+ SVFUtil::errMsg (msg);
263+ std::cout << msg;
264+ abort ();
236265 }
237266 }
238267 }
268+
239269 inputFile.close ();
240270 return cflGraph;
241271}
@@ -247,7 +277,6 @@ CFLGraph* CFLGraphBuilder::buildFromJson(std::string fileName, GrammarBase *gram
247277 return cflGraph;
248278}
249279
250-
251280CFLGraph* AliasCFLGraphBuilder::buildBigraph (ConstraintGraph *graph, Kind startKind, GrammarBase *grammar)
252281{
253282 cflGraph = new CFLGraph (startKind);
@@ -543,4 +572,4 @@ CFLGraph* VFCFLGraphBuilder::buildBiPEGgraph(ConstraintGraph *graph, Kind startK
543572}
544573
545574
546- } // end of SVF namespace
575+ } // end of SVF namespace
0 commit comments