private static void ComputeStackDelta(Instruction instruction, ref int stack_size)
{
if (instruction.opcode.FlowControl != FlowControl.Call)
{
CodeWriter.ComputePopDelta(instruction.opcode.StackBehaviourPop, ref stack_size);
CodeWriter.ComputePushDelta(instruction.opcode.StackBehaviourPush, ref stack_size);
}
else
{
IMethodSignature methodSignature = (IMethodSignature)instruction.operand;
if (methodSignature.HasImplicitThis() && instruction.opcode.Code != Code.Newobj)
{
stack_size--;
}
if (methodSignature.HasParameters)
{
stack_size -= methodSignature.Parameters.Count;
}
if (instruction.opcode.Code == Code.Calli)
{
stack_size--;
}
if (methodSignature.ReturnType.etype != ElementType.Void || instruction.opcode.Code == Code.Newobj)
{
stack_size++;
return;
}
}
}