Browse Source

Support case when more than one function exist need to show cfg. (#3020)

* Support case when more than one function exist need to show cfg.
Xiang Li 5 years ago
parent
commit
316d802e37
1 changed files with 12 additions and 3 deletions
  1. 12 3
      tools/clang/tools/dotnetc/OptEditorForm.cs

+ 12 - 3
tools/clang/tools/dotnetc/OptEditorForm.cs

@@ -179,7 +179,7 @@ namespace MainNs
             var source = EditorForm.CreateBlobForText(this.Library, section.Text);
             source = this.Library.GetBlobAstUf8(source);
 
-            string[] options = new string [1];
+            string[] options = new string[1];
             options[0] = "-view-cfg-only";
             EditorForm.OptimizeResult opt = EditorForm.RunOptimize(this.Library, options, source);
             if (!opt.Succeeded)
@@ -187,9 +187,18 @@ namespace MainNs
                 MessageBox.Show("Failed to optimize: " + opt.ResultText);
                 return;
             }
+            const string dotStart = "digraph";
+            string dotText = opt.ResultText.Substring(opt.ResultText.IndexOf(dotStart));
+            while (dotText.LastIndexOf(dotStart) != -1)
+            {
+                string dot = dotText.Substring(dotText.LastIndexOf(dotStart));
+                dot = dot.Substring(0, dot.LastIndexOf("}") + 1);
+                dot = dot.Replace("\u0001??", "");
+                dot = dot.Replace("\u0001?", "");
+                EditorForm.LogContextMenuHelper.ShowDot(dot);
+                dotText = dotText.Substring(0, dotText.LastIndexOf(dotStart));
+            }
 
-            string dotText = opt.ResultText.Substring(opt.ResultText.IndexOf("digraph"));
-            EditorForm.LogContextMenuHelper.ShowDot(dotText);
         }
     }