internal static void VisualizeGraph(this IClrMethodBody body, NodeList list, bool translatedCode) { DebugHooks.LogInfo("Flow graph constructed"); DotService.NameService = null; bool filter = DebugHooks.EvalFilter(body.Method); var after = translatedCode; var before = !translatedCode; if (filter || (before && DebugHooks.VisualizeGraphBefore) || (after && DebugHooks.VisualizeGraphAfter)) { DotService.Write(list, DotService.MakePath(body, before ? "before" : "after"), true, translatedCode); } if (filter || DebugHooks.DumpILCode) { DumpService.Dump(list, body, CommonLanguageInfrastructure.TestCaseDirectory); DebugHooks.LogInfo("IL code dumped"); } }
public static void Dump(IClrMethodBody body, TranslatorResult result, string format, string filename) { if (!(DebugHooks.EvalFilter(body.Method) || DebugHooks.DumpILMap)) { return; } DebugHooks.LogInfo("DumpILMap started. Format = {0}. FileName = {1}.", format, filename); string dir = body.GetTestDirectory(); Directory.CreateDirectory(dir); using (var writer = new StreamWriter(Path.Combine(dir, filename))) { DumpService.DumpLocalVariables(writer, body); writer.WriteLine(Separator); if (result.Begin != null && result.Begin.Length > 0) { writer.WriteLine("#BEGIN CODE"); writer.WriteLine(Separator); for (int i = 0; i < result.Begin.Length; ++i) { writer.WriteLine(result.Output[i].ToString(format, null)); } writer.WriteLine(Separator); } foreach (var bb in body.ControlFlowGraph.Blocks) { writer.WriteLine("#BASIC BLOCK {0}", bb.Index); DumpStackState(writer, bb); writer.WriteLine(Separator); writer.WriteLine("#ORIGINAL CODE"); foreach (var instruction in bb.Code) { writer.WriteLine(instruction.ToString(format, null)); } writer.WriteLine(); var code = bb.TranslatedCode; writer.WriteLine("#TRANSLATED CODE"); foreach (var instruction in code) { writer.WriteLine(instruction.ToString(format, null)); } writer.WriteLine(Separator); } if (result.End != null && result.End.Length > 0) { writer.WriteLine("#END CODE"); writer.WriteLine(Separator); foreach (var instruction in result.End) { writer.WriteLine(instruction.ToString(format, null)); } } } DebugHooks.LogInfo("DumpILMap succeded"); }