/// <summary> /// If <paramref name="method"/> matches the pattern, the method will be disassembled /// to the output writer. /// </summary> /// <param name="method">The method IR.</param> public void DumpMethod(CompiledMethod method) { if (!ShouldLog(method.FullName)) { return; } Debug.Assert(Writer is object); // Write the full name as a comment Writer.Write("; "); Writer.WriteLine(method.FullName); // Disassemble the method if (method.Body is null) { Writer.WriteLine("; (Method has no body)"); Writer.WriteLine(); } else { var builder = new StringBuilder(); MethodDisassembler.Disassemble(method, builder); Writer.Write(builder); } Writer.WriteLine(); }
/// <summary> /// Verifies that the method has disassembly equal to <paramref name="expected"/>. /// Both the actual and expected strings are trimmed and linefeed normalized. /// </summary> protected void AssertDisassembly(CompiledMethod compiledMethod, string expected) { var builder = new StringBuilder(); MethodDisassembler.Disassemble(compiledMethod, builder); Assert.That(builder.ToString().Trim().Replace("\r\n", "\n"), Is.EqualTo(expected.Trim().Replace("\r\n", "\n"))); }
public void Disassemble_writes_both_values_and_basic_blocks() { var graphBuilder = new BasicBlockGraphBuilder(); graphBuilder.GetInitialBlockBuilder().AppendInstruction(Opcode.Return, 0, 0, 0); var method = new CompiledMethod("Test::Method") { Body = graphBuilder.Build() }; method.AddLocal(SimpleType.Int32, LocalFlags.None); method.AddLocal(SimpleType.Bool, LocalFlags.Parameter); const string expected = "; #0 int32\n" + "; #1 bool param\n" + "BB_0:\n" + " Return #0\n\n"; var builder = new StringBuilder(); MethodDisassembler.Disassemble(method, builder); Assert.That(builder.ToString().Replace("\r\n", "\n"), Is.EqualTo(expected)); }