Mono.Cecil.Cil.CodeWriter.ComputePushDelta C# (CSharp) Method

ComputePushDelta() static private method

static private ComputePushDelta ( StackBehaviour push_behaviour, int &stack_size ) : void
push_behaviour StackBehaviour
stack_size int
return void
        static void ComputePushDelta(StackBehaviour push_behaviour, ref int stack_size)
        {
            switch (push_behaviour) {
            case StackBehaviour.Push1:
            case StackBehaviour.Pushi:
            case StackBehaviour.Pushi8:
            case StackBehaviour.Pushr4:
            case StackBehaviour.Pushr8:
            case StackBehaviour.Pushref:
                stack_size++;
                break;
            case StackBehaviour.Push1_push1:
                stack_size += 2;
                break;
            }
        }

Usage Example

 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;
         }
     }
 }