protected bool DumpCFG() { using (Operation engineOp = L.Begin("Writing GraphML for control-flow graphs.")) { Dictionary <SourceRoutineSymbol, string> graphs = new Dictionary <SourceRoutineSymbol, string>(SourceRoutinesCompiler.ControlFlowGraphs.Count); XmlWriterSettings settings = new XmlWriterSettings() { Async = false, Encoding = Encoding.UTF32, Indent = true, IndentChars = " ", CloseOutput = false }; SourceRoutinesCompiler.ControlFlowGraphs.AsParallel().WithDegreeOfParallelism(MaxConcurrencyLevel).ForEach(graph => { StringBuilder s = new StringBuilder(1000); using (XmlWriter xw = XmlWriter.Create(s, settings)) { GraphSerializer.SerializeControlFlowGraph(graph.Value, xw); xw.Flush(); graphs.Add(graph.Key, s.ToString()); } }); if (OnlyTime) { engineOp.Complete(); return(true); } int count = 0; foreach (var g in graphs) { FileInfo outputFile = new FileInfo($"{OutputFile}-{++count}.graphml"); if (outputFile.Exists) { L.Warn("Overwriting existing output file {0}.", outputFile.FullName); } try { using (StreamWriter sw = new StreamWriter(outputFile.OpenWrite(), new UnicodeEncoding(false, true))) { sw.Write(g.Value); sw.Flush(); } L.Debug("Wrote GraphML for routine {0} in PHP source file {1} to file {2}.", g.Key.Name, g.Key.ContainingFile.SyntaxTree.FilePath, outputFile.FullName); } catch (IOException ioe) { L.Error(ioe, "I/O exception writing to file {file}", outputFile.FullName); } catch (Exception e) { L.Error(e, "Unknown exception writing to file {file}", outputFile.FullName); } } engineOp.Complete(); } return(true); }