internal static void ComputeStackDelta(Instruction instruction, ref int stackSize, bool addpush = true)
{
// ReSharper disable once SwitchStatementMissingSomeCases
switch (instruction.OpCode.FlowControl)
{
case FlowControl.Call:
{
var method = (IMethodSignature)instruction.Operand;
// pop 'this' argument
if (method.HasImplicitThis() && instruction.OpCode.Code != Code.Newobj)
stackSize--;
// pop normal arguments
if (method.HasParameters)
stackSize -= method.Parameters.Count;
// pop function pointer
if (instruction.OpCode.Code == Code.Calli)
stackSize--;
// push return value
if (!method.ReturnType.IsVoid() || instruction.OpCode.Code == Code.Newobj)
if(addpush)
stackSize++;
break;
}
default:
ComputePopDelta(instruction.OpCode.StackBehaviourPop, ref stackSize);
if(addpush)
ComputePushDelta(instruction.OpCode.StackBehaviourPush, ref stackSize);
break;
}
}