http://www.mono-project.com/Cecil mentions a code optimization tool. Was
there ever any work done on it? I have experimented a bit with Cecil and
wrote an IL optimizer that can inline methods.
While doing that, I found that the Cecil ComputeMaxStack implementation
does compute the maximum stack size correctly. Usually it overestimates
because it doesn't see the implicit pop for each parameter in a call
instruction; but attached is a case where it underestimates the stack
size and causes the assembly to get invalid when it is roundtripped.
Daniel
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---
// Metadata version: v2.0.50727
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) //
.z\V.4..
.ver 2:0:0:0
}
.assembly TestApp
{
.custom instance void
[mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00
07 54 65 73 74 41 70 70 00 00 ) // ...TestApp..
.custom instance void
[mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor()
= ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )
// ceptionThrows.
// --- The following custom attribute is added automatically, do not
uncomment -------
// .custom instance void
[mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype
[mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02
00 00 00 00 00 )
.custom instance void
[mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = (
01 00 00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00
00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00
00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = (
01 00 00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01
00 00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00
00 00 00 )
.custom instance void
[mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 07
54 65 73 74 41 70 70 00 00 ) // ...TestApp..
.custom instance void
[mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32)
= ( 01 00 08 00 00 00 00 00 )
.hash algorithm 0x00008004
.ver 1:0:2847:23628
}
.module TestApp.exe
// MVID: {A636178F-332A-4489-9390-6A67CD7930EC}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x00270000
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi sealed beforefieldinit TestApp.Program
extends [mscorlib]System.Object
{
.method private hidebysig static void Test() cil managed noinlining
{
.entrypoint
// Code size 46 (0x2e)
.maxstack 4
.locals init (class TestApp.Program V_0)
ldc.i4.1
ldc.i4.2
ldc.i4.3
brtrue label1
br label2
label1:
pop
br label3
label2:
pop
label3:
ldc.i4.4
ldc.i4.5
ldc.i4.6
pop
pop
pop
pop
ret
} // end of method Program::Test
} // end of class TestApp.Program