Hi,

I guess MethodBody.Simplify should also transform the leave.s
instruction into a leave instruction.

this could be done by adding this block to the case-split

                case Code.Leave_S:
                    SimplifyFromSByte(i, OpCodes.Leave);
                    break;

and making the OpcodeType of OpCodes.Leave_S a OpCodeType.Macro

Furthermore, I read a considerably large application into an assembly.
I looped through all methods and applied Simplify() on the
MethodBody's. Then I output the assembly again to a file. During this
experiment, I discovered two more cast problems:

1.  When this case in MethodBody.Simplify() is used

                                case Code.Ldc_I4_S :
                                        SimplifyFromSByte (i, OpCodes.Ldc_I4);
                                        break;

I get a cast problem in CodeWriter.cs, more specifically at line 145
(The middle one)

                                case OperandType.InlineI :
                                        m_codeWriter.Write ((int) 
instr.Operand);
                                        break;

When I take a look in the debugger, instr.Operand is of type object
{sbyte}

Commenting the case in MethodBody.Simplify() prevents the problem from
happening. I am not sure how to solve it :)

2. When this case in MethodBody.Simplify() is used

                                case Code.Ldloca_S :
                                        Simplify (i, OpCodes.Ldloca,
                                                CodeReader.GetVariable (this, 
(sbyte) i.Operand));
                                        break;

I get an invalid cast exception. When I look in the debugger,
i.Operand has type object{Mono.Cecil.Cil.VariableDefinition}.

Dries


--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to