Beispiel #1
0
 internal MSILOpCode(string name, byte[] bytes, OperandType operandType, StackBehaviour stackBehaviour)
 {
     Name = name;
     Bytes = bytes;
     OperandType = operandType;
     StackBehaviour = stackBehaviour;
 }
Beispiel #2
0
    //verify the opcode fields
    //if not equal,retun the field name which contains error.
    private CompareResult CompareOpCode(
        OpCode opcode,
        String stringname,
        StackBehaviour pop,
        StackBehaviour push,
        OperandType operand,
        OpCodeType type,
        int size,
        byte s1,
        byte s2,
        FlowControl ctrl)
    {
        CompareResult returnValue = CompareResult.Equal;

        if (opcode.Name != stringname)
        {
            returnValue = returnValue | CompareResult.Name;
        }
        if (opcode.StackBehaviourPop != pop)
        {
            returnValue = returnValue | CompareResult.Pop;
        }
        if (opcode.StackBehaviourPush != push)
        {
            returnValue = returnValue | CompareResult.Push;
        }
        if (opcode.OperandType != operand)
        {
            returnValue = returnValue | CompareResult.OpenrandType;
        }
        if (opcode.OpCodeType != type)
        {
            returnValue = returnValue | CompareResult.OpCodeType;
        }
        if (opcode.Size != size)
        {
            returnValue = returnValue | CompareResult.Size;
        }
        if (size == 2)
        {
            if (opcode.Value != ((short)(s1 << 8 | s2)))
            {
                returnValue = returnValue | CompareResult.Value;
            }
        }
        else
        {
            if (opcode.Value != ((short)s2))
            {
                returnValue = returnValue | CompareResult.Value;
            }
        }
        if (opcode.FlowControl != ctrl)
        {
            returnValue = returnValue | CompareResult.FlowControl;
        }
        return(returnValue);
    }
Beispiel #3
0
        private static bool StackCountChangeImpl(this StackBehaviour behaviour, out int count)
        {
            switch (behaviour)
            {
            case StackBehaviour.Pop0:
            case StackBehaviour.Push0:
                count = 0;
                break;

            case StackBehaviour.Pop1:
            case StackBehaviour.Popi:
            case StackBehaviour.Popref:
                count = -1;
                break;

            case StackBehaviour.Popi_pop1:
            case StackBehaviour.Pop1_pop1:
            case StackBehaviour.Popi_popi:
            case StackBehaviour.Popi_popi8:
            case StackBehaviour.Popi_popr4:
            case StackBehaviour.Popi_popr8:
            case StackBehaviour.Popref_pop1:
            case StackBehaviour.Popref_popi:
                count = -2;
                break;

            case StackBehaviour.Popi_popi_popi:
            case StackBehaviour.Popref_popi_popi:
            case StackBehaviour.Popref_popi_popi8:
            case StackBehaviour.Popref_popi_popr4:
            case StackBehaviour.Popref_popi_popr8:
            case StackBehaviour.Popref_popi_popref:
                count = -3;
                break;

            case StackBehaviour.Push1:
            case StackBehaviour.Pushi:
            case StackBehaviour.Pushi8:
            case StackBehaviour.Pushr4:
            case StackBehaviour.Pushr8:
            case StackBehaviour.Pushref:
                count = 1;
                break;

            case StackBehaviour.Push1_push1:
                count = 2;
                break;

            default:
                count = 0;
                return(false);
            }
            return(true);
        }
Beispiel #4
0
 static int Balance(StackBehaviour op)
 {
     if (s_balance.TryGetValue(op, out var balance))
     {
         return(balance);
     }
     else
     {
         throw new Exception("Don't know how to track stack for " + op);
     }
 }
Beispiel #5
0
 internal OpCode(
     Code code, OpCodeType opCodeType, OperandType operandType,
     FlowControl flowControl, StackBehaviour pop, StackBehaviour push)
 {
     Code          = code;
     OpCodeType    = opCodeType;
     OperandType   = operandType;
     FlowControl   = flowControl;
     PopBehaviour  = pop;
     PushBehaviour = push;
 }
        public ModProperty(float baseValue, StackBehaviour behaviour)
        {
            Set(baseValue);
            Behaviour = behaviour;

            BehaviourMethods = new Dictionary <StackBehaviour, Action <ModProperty> > {
                { StackBehaviour.Add, Add },
                { StackBehaviour.AddMinusOne, AddMinusOne },
                { StackBehaviour.Multiply, Multiply },
                { StackBehaviour.Max, Max },
                { StackBehaviour.Min, Min },
            };
        }
Beispiel #7
0
		internal OpCode(string name, Code code, OperandType operandType, FlowControl flowControl, OpCodeType opCodeType, StackBehaviour push, StackBehaviour pop) {
			this.Name = name;
			this.Code = code;
			this.OperandType = operandType;
			this.FlowControl = flowControl;
			this.OpCodeType = opCodeType;
			this.StackBehaviourPush = push;
			this.StackBehaviourPop = pop;
			if (((ushort)code >> 8) == 0)
				OpCodes.OneByteOpCodes[(byte)code] = this;
			else if (((ushort)code >> 8) == 0xFE)
				OpCodes.TwoByteOpCodes[(byte)code] = this;
		}
 internal OpCode(String stringname, StackBehaviour pop, StackBehaviour push, OperandType operand, OpCodeType type, int size, byte s1, byte s2, FlowControl ctrl, bool endsjmpblk, int stack)
 {
     m_stringname       = stringname;
     m_pop              = pop;
     m_push             = push;
     m_operand          = operand;
     m_type             = type;
     m_size             = size;
     m_s1               = s1;
     m_s2               = s2;
     m_ctrl             = ctrl;
     m_endsUncondJmpBlk = endsjmpblk;
     m_stackChange      = stack;
 }
 internal OpCode(string stringname, StackBehaviour pop, StackBehaviour push, System.Reflection.Emit.OperandType operand, System.Reflection.Emit.OpCodeType type, int size, byte s1, byte s2, System.Reflection.Emit.FlowControl ctrl, bool endsjmpblk, int stack)
 {
     this.m_stringname = stringname;
     this.m_pop = pop;
     this.m_push = push;
     this.m_operand = operand;
     this.m_type = type;
     this.m_size = size;
     this.m_s1 = s1;
     this.m_s2 = s2;
     this.m_ctrl = ctrl;
     this.m_endsUncondJmpBlk = endsjmpblk;
     this.m_stackChange = stack;
 }
Beispiel #10
0
 internal OpCode(OpCodeValues value, int flags)
 {
     this.m_stringname       = (string)null;
     this.m_pop              = (StackBehaviour)(flags >> 12 & 31);
     this.m_push             = (StackBehaviour)(flags >> 17 & 31);
     this.m_operand          = (OperandType)(flags & 31);
     this.m_type             = (OpCodeType)(flags >> 9 & 7);
     this.m_size             = flags >> 22 & 3;
     this.m_s1               = (byte)((uint)value >> 8);
     this.m_s2               = (byte)value;
     this.m_ctrl             = (FlowControl)(flags >> 5 & 15);
     this.m_endsUncondJmpBlk = (uint)(flags & 16777216) > 0U;
     this.m_stackChange      = flags >> 28;
 }
Beispiel #11
0
 internal OpCode(string name, byte op1, byte op2, int size, FlowControl flowControl,
     OpCodeType opCodeType, OperandType operandType,
     StackBehaviour pop, StackBehaviour push)
 {
     m_name = name;
     m_op1 = op1;
     m_op2 = op2;
     m_size = size;
     m_flowControl = flowControl;
     m_opCodeType = opCodeType;
     m_operandType = operandType;
     m_stackBehaviourPop = pop;
     m_stackBehaviourPush = push;
 }
Beispiel #12
0
        internal OpCode(int x, int y)
        {
            m_op1 = (byte)((x >> 0) & 0xff);
            m_op2 = (byte)((x >> 8) & 0xff);
            m_code = (Code)((x >> 16) & 0xff);
            m_flowControl = (FlowControl)((x >> 24) & 0xff);
            m_size = 0;
            m_name = "";

            m_opCodeType = (OpCodeType)((y >> 0) & 0xff);
            m_operandType = (OperandType)((y >> 8) & 0xff);
            m_stackBehaviourPop = (StackBehaviour)((y >> 16) & 0xff);
            m_stackBehaviourPush = (StackBehaviour)((y >> 24) & 0xff);
        }
Beispiel #13
0
 internal OpCode(OpCodeValues value, int flags)
 {
     m_stringname       = null; // computed lazily
     m_pop              = (StackBehaviour)((flags >> StackBehaviourPopShift) & StackBehaviourMask);
     m_push             = (StackBehaviour)((flags >> StackBehaviourPushShift) & StackBehaviourMask);
     m_operand          = (OperandType)(flags & OperandTypeMask);
     m_type             = (OpCodeType)((flags >> OpCodeTypeShift) & OpCodeTypeMask);
     m_size             = (flags >> SizeShift) & SizeMask;
     m_s1               = (byte)((int)value >> 8);
     m_s2               = (byte)(int)value;
     m_ctrl             = (FlowControl)((flags >> FlowControlShift) & FlowControlMask);
     m_endsUncondJmpBlk = (flags & EndsUncondJmpBlkFlag) != 0;
     m_stackChange      = (flags >> StackChangeShift);
 }
Beispiel #14
0
        internal OpCode(int x, int y)
        {
            m_op1         = (byte)((x >> 0) & 0xff);
            m_op2         = (byte)((x >> 8) & 0xff);
            m_code        = (Code)((x >> 16) & 0xff);
            m_flowControl = (FlowControl)((x >> 24) & 0xff);
            m_size        = 0;
            m_name        = "";

            m_opCodeType         = (OpCodeType)((y >> 0) & 0xff);
            m_operandType        = (OperandType)((y >> 8) & 0xff);
            m_stackBehaviourPop  = (StackBehaviour)((y >> 16) & 0xff);
            m_stackBehaviourPush = (StackBehaviour)((y >> 24) & 0xff);
        }
 internal OpCode(string name, byte op1, byte op2, int size, FlowControl flowControl,
                 OpCodeType opCodeType, OperandType operandType,
                 StackBehaviour pop, StackBehaviour push)
 {
     m_name               = name;
     m_op1                = op1;
     m_op2                = op2;
     m_size               = size;
     m_flowControl        = flowControl;
     m_opCodeType         = opCodeType;
     m_operandType        = operandType;
     m_stackBehaviourPop  = pop;
     m_stackBehaviourPush = push;
 }
Beispiel #16
0
 internal OpCode(string stringname, StackBehaviour pop, StackBehaviour push, System.Reflection.Emit.OperandType operand, System.Reflection.Emit.OpCodeType type, int size, byte s1, byte s2, System.Reflection.Emit.FlowControl ctrl, bool endsjmpblk, int stack)
 {
     this.m_stringname       = stringname;
     this.m_pop              = pop;
     this.m_push             = push;
     this.m_operand          = operand;
     this.m_type             = type;
     this.m_size             = size;
     this.m_s1               = s1;
     this.m_s2               = s2;
     this.m_ctrl             = ctrl;
     this.m_endsUncondJmpBlk = endsjmpblk;
     this.m_stackChange      = stack;
 }
        /// <summary>
        /// Returns the number of elements being pushed or popped by a specific StackBehavior.
        /// </summary>
        /// <param name="sb">a StackBehavior</param>
        /// <returns>number of elements being pushed (i.e. positive number) or -(number of elements being popped) (i.e. negative number)</returns>
        public static int GetNumOperands(StackBehaviour sb)
        {
            switch (sb)
            {
                case StackBehaviour.Pop0:
                case StackBehaviour.Push0:
                case StackBehaviour.Varpop:
                case StackBehaviour.Varpush:
                    return 0;

                case StackBehaviour.Pop1:
                case StackBehaviour.Popi:
                case StackBehaviour.Popref:
                    return -1;

                case StackBehaviour.Pop1_pop1:
                case StackBehaviour.Popi_pop1:
                case StackBehaviour.Popi_popi:
                case StackBehaviour.Popi_popi8:
                case StackBehaviour.Popi_popr4:
                case StackBehaviour.Popi_popr8:
                case StackBehaviour.Popref_pop1:
                case StackBehaviour.Popref_popi:
                    return -2;

                case StackBehaviour.Popi_popi_popi:
                case StackBehaviour.Popref_popi_pop1:
                case StackBehaviour.Popref_popi_popi:
                case StackBehaviour.Popref_popi_popi8:
                case StackBehaviour.Popref_popi_popr4:
                case StackBehaviour.Popref_popi_popr8:
                case StackBehaviour.Popref_popi_popref:
                    return -3;

                case StackBehaviour.Push1:
                case StackBehaviour.Pushi:
                case StackBehaviour.Pushi8:
                case StackBehaviour.Pushr4:
                case StackBehaviour.Pushr8:
                case StackBehaviour.Pushref:
                    return 1;

                case StackBehaviour.Push1_push1:
                    return 2;

                default:
                    throw new NotImplementedException();
            }
        }
        /// <summary>
        /// Returns the number of elements being pushed or popped by a specific StackBehavior.
        /// </summary>
        /// <param name="sb">a StackBehavior</param>
        /// <returns>number of elements being pushed (i.e. positive number) or -(number of elements being popped) (i.e. negative number)</returns>
        public static int GetNumOperands(StackBehaviour sb)
        {
            switch (sb)
            {
            case StackBehaviour.Pop0:
            case StackBehaviour.Push0:
            case StackBehaviour.Varpop:
            case StackBehaviour.Varpush:
                return(0);

            case StackBehaviour.Pop1:
            case StackBehaviour.Popi:
            case StackBehaviour.Popref:
                return(-1);

            case StackBehaviour.Pop1_pop1:
            case StackBehaviour.Popi_pop1:
            case StackBehaviour.Popi_popi:
            case StackBehaviour.Popi_popi8:
            case StackBehaviour.Popi_popr4:
            case StackBehaviour.Popi_popr8:
            case StackBehaviour.Popref_pop1:
            case StackBehaviour.Popref_popi:
                return(-2);

            case StackBehaviour.Popi_popi_popi:
            case StackBehaviour.Popref_popi_pop1:
            case StackBehaviour.Popref_popi_popi:
            case StackBehaviour.Popref_popi_popi8:
            case StackBehaviour.Popref_popi_popr4:
            case StackBehaviour.Popref_popi_popr8:
            case StackBehaviour.Popref_popi_popref:
                return(-3);

            case StackBehaviour.Push1:
            case StackBehaviour.Pushi:
            case StackBehaviour.Pushi8:
            case StackBehaviour.Pushr4:
            case StackBehaviour.Pushr8:
            case StackBehaviour.Pushref:
                return(1);

            case StackBehaviour.Push1_push1:
                return(2);

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #19
0
            int GetCountAffected(StackBehaviour behaviour)
            {
                switch (behaviour)
                {
                case StackBehaviour.Pop0:
                case StackBehaviour.Push0:
                    return(0);

                case StackBehaviour.Pop1:
                case StackBehaviour.Popi:
                case StackBehaviour.Popref:
                case StackBehaviour.Varpop:
                    return(1);

                case StackBehaviour.Pop1_pop1:
                case StackBehaviour.Popi_pop1:
                case StackBehaviour.Popi_popi:
                case StackBehaviour.Popi_popi8:
                case StackBehaviour.Popi_popr4:
                case StackBehaviour.Popi_popr8:
                case StackBehaviour.Popref_pop1:
                case StackBehaviour.Popref_popi:
                    return(2);

                case StackBehaviour.Popi_popi_popi:
                case StackBehaviour.Popref_popi_pop1:
                case StackBehaviour.Popref_popi_popi:
                case StackBehaviour.Popref_popi_popi8:
                case StackBehaviour.Popref_popi_popr4:
                case StackBehaviour.Popref_popi_popr8:
                case StackBehaviour.Popref_popi_popref:
                    return(3);

                case StackBehaviour.Push1:
                case StackBehaviour.Pushi:
                case StackBehaviour.Pushi8:
                case StackBehaviour.Pushr4:
                case StackBehaviour.Pushr8:
                case StackBehaviour.Pushref:
                case StackBehaviour.Varpush:
                    return(1);

                case StackBehaviour.Push1_push1:
                    return(2);

                default:
                    return(0);
                }
            }
Beispiel #20
0
	internal OpCode(String stringname, StackBehaviour pop, StackBehaviour push, OperandType operand, OpCodeType type, int size, byte s1, byte s2, FlowControl ctrl, bool endsjmpblk, int stack)
	{
		m_stringname = stringname;
		m_pop = pop;
		m_push = push;
		m_operand = operand;
		m_type = type;
		m_size = size;
		m_s1 = s1;
		m_s2 = s2;
		m_ctrl = ctrl;
		m_endsUncondJmpBlk = endsjmpblk;
		m_stackChange = stack;

	}
        private static void ComputePopDelta(StackBehaviour pop_behavior, ref int stack_size)
        {
            switch (pop_behavior)
            {
            case StackBehaviour.Pop1:
            case StackBehaviour.Popi:
            case StackBehaviour.Popref:
            {
                stack_size--;
                return;
            }

            case StackBehaviour.Pop1_pop1:
            case StackBehaviour.Popi_pop1:
            case StackBehaviour.Popi_popi:
            case StackBehaviour.Popi_popi8:
            case StackBehaviour.Popi_popr4:
            case StackBehaviour.Popi_popr8:
            case StackBehaviour.Popref_pop1:
            case StackBehaviour.Popref_popi:
            {
                stack_size -= 2;
                return;
            }

            case StackBehaviour.Popi_popi_popi:
            case StackBehaviour.Popref_popi_popi:
            case StackBehaviour.Popref_popi_popi8:
            case StackBehaviour.Popref_popi_popr4:
            case StackBehaviour.Popref_popi_popr8:
            case StackBehaviour.Popref_popi_popref:
            {
                stack_size -= 3;
                return;
            }

            case StackBehaviour.PopAll:
            {
                stack_size = 0;
                return;
            }

            default:
            {
                return;
            }
            }
        }
        private static int ToArity(StackBehaviour behavior)
        {
            switch (behavior)
            {
            case StackBehaviour.Pop0:
            case StackBehaviour.Push0:
                return(0);

            case StackBehaviour.Pop1:
            case StackBehaviour.Popi:
            case StackBehaviour.Popref:
            case StackBehaviour.Push1:
            case StackBehaviour.Pushi:
            case StackBehaviour.Pushi8:
            case StackBehaviour.Pushr4:
            case StackBehaviour.Pushr8:
            case StackBehaviour.Pushref:
                return(1);

            case StackBehaviour.Pop1_pop1:
            case StackBehaviour.Popi_pop1:
            case StackBehaviour.Popi_popi:
            case StackBehaviour.Popi_popi8:
            case StackBehaviour.Popi_popr4:
            case StackBehaviour.Popi_popr8:
            case StackBehaviour.Popref_pop1:
            case StackBehaviour.Popref_popi:
            case StackBehaviour.Push1_push1:
                return(2);

            case StackBehaviour.Popi_popi_popi:
            case StackBehaviour.Popref_popi_popi:
            case StackBehaviour.Popref_popi_popi8:
            case StackBehaviour.Popref_popi_popr4:
            case StackBehaviour.Popref_popi_popr8:
            case StackBehaviour.Popref_popi_popref:
                return(3);

            case StackBehaviour.PopAll:
            case StackBehaviour.Varpop:
            case StackBehaviour.Varpush:
            default:
                return(-1);
            }
        }
Beispiel #23
0
 internal OpCode(string name, Code code, OperandType operandType, FlowControl flowControl, OpCodeType opCodeType, StackBehaviour push, StackBehaviour pop)
 {
     this.Name               = name;
     this.Code               = code;
     this.OperandType        = operandType;
     this.FlowControl        = flowControl;
     this.OpCodeType         = opCodeType;
     this.StackBehaviourPush = push;
     this.StackBehaviourPop  = pop;
     if (((ushort)code >> 8) == 0)
     {
         OpCodes.OneByteOpCodes[(byte)code] = this;
     }
     else if (((ushort)code >> 8) == 0xFE)
     {
         OpCodes.TwoByteOpCodes[(byte)code] = this;
     }
 }
Beispiel #24
0
        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;
            }
        }
    /// <summary>
    ///   Gets the stack change.
    /// </summary>
    /// <param name="beh">The beh.</param>
    /// <returns>An int.</returns>
    private static int GetStackChange(StackBehaviour beh)
    {
        switch (beh)
        {
        case StackBehaviour.Pop0:
        case StackBehaviour.Push0:
            return(0);

        case StackBehaviour.Pop1:
        case StackBehaviour.Popi:
        case StackBehaviour.Popref:
        case StackBehaviour.Varpop:
            return(-1);

        case StackBehaviour.Push1:
        case StackBehaviour.Pushi:
        case StackBehaviour.Pushref:
        case StackBehaviour.Varpush:
            return(1);

        case StackBehaviour.Pop1_pop1:
        case StackBehaviour.Popi_pop1:
        case StackBehaviour.Popi_popi:
        case StackBehaviour.Popi_popi8:
        case StackBehaviour.Popi_popr4:
        case StackBehaviour.Popi_popr8:
        case StackBehaviour.Popref_pop1:
        case StackBehaviour.Popref_popi:
            return(-2);

        case StackBehaviour.Push1_push1:
            return(2);

        case StackBehaviour.Popref_popi_pop1:
        case StackBehaviour.Popref_popi_popi:
        case StackBehaviour.Popref_popi_popi8:
        case StackBehaviour.Popref_popi_popr4:
        case StackBehaviour.Popref_popi_popr8:
        case StackBehaviour.Popref_popi_popref:
            return(-3);
        }

        return(0);
    }
Beispiel #26
0
        private void EvaluateStackBehavior(StackBehaviour stackBehavior)
        {
            return;
            //switch (stackBehavior)
            //{
            //    case StackBehaviour.Pop0: return;
            //    case StackBehaviour.Popi:
            //    case StackBehaviour.Pop1:
            //    case StackBehaviour.Popref:
            //    case StackBehaviour.Varpop:
            //        this.stackCount -= 1; break;
            //    case StackBehaviour.Pop1_pop1:
            //    case StackBehaviour.Popi_pop1:
            //    case StackBehaviour.Popi_popi:
            //    case StackBehaviour.Popi_popi8:
            //    case StackBehaviour.Popi_popr4:
            //    case StackBehaviour.Popi_popr8:
            //    case StackBehaviour.Popref_pop1:
            //    case StackBehaviour.Popref_popi:
            //        this.stackCount -= 2; break;
            //    case StackBehaviour.Popref_popi_pop1:
            //    case StackBehaviour.Popref_popi_popi:
            //    case StackBehaviour.Popref_popi_popi8:
            //    case StackBehaviour.Popref_popi_popr4:
            //    case StackBehaviour.Popref_popi_popr8:
            //    case StackBehaviour.Popref_popi_popref:
            //    case StackBehaviour.Popi_popi_popi:
            //        this.stackCount -= 3; break;

            //    case StackBehaviour.Push0: return;
            //    case StackBehaviour.Push1:
            //    case StackBehaviour.Pushi:
            //    case StackBehaviour.Pushi8:
            //    case StackBehaviour.Pushr4:
            //    case StackBehaviour.Pushr8:
            //    case StackBehaviour.Pushref:
            //    case StackBehaviour.Varpush:
            //        this.stackCount += 1; break;
            //    case StackBehaviour.Push1_push1:
            //        this.stackCount += 2; break;
            //    default:
            //        throw new ArgumentOutOfRangeException("Received unexpected StackBehavior value");
            //}
        }
Beispiel #27
0
        /// <summary>
        /// Adds the given <paramref name="buff"/> to the system. If addition is successful, will invoke <see cref="Buff.OnApply"/>.
        /// </summary>
        /// <returns>The buff that was applied, or the buff whose stacks were added to.</returns>
        public static Buff Add(Buff buff, StackBehaviour stackBehaviour = StackBehaviour.None)
        {
            if (buffsByUnit.TryGetValue(buff.Target, out var buffs))
            {
                if (stackBehaviour != StackBehaviour.None)
                {
                    var type = buff.GetType();
                    for (var i = 0; i < buffs.Count; i++)
                    {
                        var currentBuff = buffs[i];
                        if (currentBuff.Active && currentBuff.GetType() == type)
                        {
                            if (stackBehaviour == StackBehaviour.Stack ||
                                (stackBehaviour == StackBehaviour.StackCaster && buff.Caster == currentBuff.Caster) ||
                                (buff.CastingPlayer == currentBuff.CastingPlayer))
                            {
                                switch (currentBuff.OnStack(buff))
                                {
                                case StackResult.Stack:
                                    return(currentBuff);

                                case StackResult.Consume:
                                    currentBuff.Active = false;
                                    break;
                                }
                            }
                        }
                    }
                }

                buffs.Add(buff);
            }
            else
            {
                buffsByUnit.Add(buff.Target, new List <Buff>
                {
                    buff
                });
            }

            buff.Apply();
            periodicTrigger.Add(buff);
            return(buff);
        }
    private bool VerifyOpCodeStackBehaviourPush(OpCode op1, StackBehaviour sb, string errNum)
    {
        bool retVal = true;

        try
        {
            if (op1.StackBehaviourPush != sb)
            {
                TestLibrary.TestFramework.LogError(errNum, "Result is not the value as expected,push behaviour is: " + op1.StackBehaviourPush + ",Expected is: " + sb);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError(errNum, "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
Beispiel #29
0
        private static void ComputePushDelta(StackBehaviour pushBehaviour, ref int stackSize)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (pushBehaviour)
            {
            case StackBehaviour.Push1:
            case StackBehaviour.Pushi:
            case StackBehaviour.Pushi8:
            case StackBehaviour.Pushr4:
            case StackBehaviour.Pushr8:
            case StackBehaviour.Pushref:
                stackSize++;
                break;

            case StackBehaviour.Push1_push1:
                stackSize += 2;
                break;
            }
        }
Beispiel #30
0
    private bool VerifyOpCodeStackBehaviourPush(OpCode op1, StackBehaviour sb, string errNum)
    {
        bool retVal = true;

        try
        {
            if (op1.StackBehaviourPush != sb)
            {
                TestLibrary.TestFramework.LogError(errNum, "Result is not the value as expected,push behaviour is: " + op1.StackBehaviourPush + ",Expected is: " + sb);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError(errNum, "Unexpected exception: " + e);
            retVal = false;
        }
        return(retVal);
    }
Beispiel #31
0
	// Construct a new opcode.
	internal OpCode(String name, int value, FlowControl flowControl,
					OpCodeType opcodeType, OperandType operandType,
					StackBehaviour stackPop, StackBehaviour stackPush)
			{
				this.name = name;
				this.value = (short)value;
				this.flowControl = (byte)flowControl;
				this.opcodeType = (byte)opcodeType;
				this.operandType = (byte)operandType;
				if(value < 0x0100)
				{
					this.size = (byte)1;
				}
				else
				{
					this.size = (byte)2;
				}
				this.stackPop = (byte)stackPop;
				this.stackPush = (byte)stackPush;
			}
Beispiel #32
0
 // Construct a new opcode.
 internal OpCode(String name, int value, FlowControl flowControl,
                 OpCodeType opcodeType, OperandType operandType,
                 StackBehaviour stackPop, StackBehaviour stackPush)
 {
     this.name        = name;
     this.value       = (short)value;
     this.flowControl = (byte)flowControl;
     this.opcodeType  = (byte)opcodeType;
     this.operandType = (byte)operandType;
     if (value < 0x0100)
     {
         this.size = (byte)1;
     }
     else
     {
         this.size = (byte)2;
     }
     this.stackPop  = (byte)stackPop;
     this.stackPush = (byte)stackPush;
 }
Beispiel #33
0
 internal OpCode(string name, Code code, OperandType operandType, FlowControl flowControl, OpCodeType opCodeType, StackBehaviour push, StackBehaviour pop, bool experimental = false)
 {
     Name               = name;
     Code               = code;
     OperandType        = operandType;
     FlowControl        = flowControl;
     OpCodeType         = opCodeType;
     StackBehaviourPush = push;
     StackBehaviourPop  = pop;
     if (!experimental)
     {
         if (((ushort)code >> 8) == 0)
         {
             OpCodes.OneByteOpCodes[(byte)code] = this;
         }
         else if (((ushort)code >> 8) == 0xFE)
         {
             OpCodes.TwoByteOpCodes[(byte)code] = this;
         }
     }
 }
Beispiel #34
0
        private 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++;
                return;

            case StackBehaviour.Push1_push1:
                stack_size += 2;
                return;

            default:
                return;
            }
        }
Beispiel #35
0
        internal OpCode(string name, byte op1, byte op2, int size,
			Code code, FlowControl flowControl,
			OpCodeType opCodeType, OperandType operandType,
			StackBehaviour pop, StackBehaviour push)
        {
            m_name = name;
            m_op1 = op1;
            m_op2 = op2;
            m_size = size;
            m_code = code;
            m_flowControl = flowControl;
            m_opCodeType = opCodeType;
            m_operandType = operandType;
            m_stackBehaviourPop = pop;
            m_stackBehaviourPush = push;

            if (op1 == 0xff)
                OpCodes.OneByteOpCode [op2] = this;
            else
                OpCodes.TwoBytesOpCode [op2] = this;
        }
Beispiel #36
0
 //verify the opcode fields
 //if not equal,retun the field name which contains error. 
 private CompareResult CompareOpCode(
     OpCode opcode,
     String stringname,
     StackBehaviour pop,
     StackBehaviour push,
     OperandType operand,
     OpCodeType type,
     int size,
     byte s1,
     byte s2,
     FlowControl ctrl)
 {
     CompareResult returnValue = CompareResult.Equal;
     if (opcode.Name != stringname) returnValue = returnValue | CompareResult.Name;
     if (opcode.StackBehaviourPop != pop) returnValue = returnValue | CompareResult.Pop;
     if (opcode.StackBehaviourPush != push) returnValue = returnValue | CompareResult.Push;
     if (opcode.OperandType != operand) returnValue = returnValue | CompareResult.OpenrandType;
     if (opcode.OpCodeType != type) returnValue = returnValue | CompareResult.OpCodeType;
     if (opcode.Size != size) returnValue = returnValue | CompareResult.Size;
     if (size == 2)
     {
         if (opcode.Value != ((short)(s1 << 8 | s2)))
         {
             returnValue = returnValue | CompareResult.Value;
         }
     }
     else
     {
         if (opcode.Value != ((short)s2))
         {
             returnValue = returnValue | CompareResult.Value;
         }
     }
     if (opcode.FlowControl != ctrl)
     {
         returnValue = returnValue | CompareResult.FlowControl;
     }
     return returnValue;
 }
Beispiel #37
0
        internal OpCode(byte op1, byte op2,
                        Code code, FlowControl flowControl,
                        OpCodeType opCodeType, OperandType operandType,
                        StackBehaviour pop, StackBehaviour push)
        {
            m_value              = (short)((op1 << 8) | op2);
            m_code               = (byte)code;
            m_flowControl        = (byte)flowControl;
            m_opCodeType         = (byte)opCodeType;
            m_operandType        = (byte)operandType;
            m_stackBehaviourPop  = (byte)pop;
            m_stackBehaviourPush = (byte)push;

            if (op1 == 0xff)
            {
                OpCodes.OneByteOpCode [op2] = this;
            }
            else
            {
                OpCodes.TwoBytesOpCode [op2] = this;
            }
        }
Beispiel #38
0
        public static int GetStackPopCount(StackBehaviour stackBehaviour)
        {
            switch (stackBehaviour)
            {
            case StackBehaviour.Pop0:
                return(0);

            case StackBehaviour.Varpop:
            case StackBehaviour.Popi:
            case StackBehaviour.Pop1:
            case StackBehaviour.Popref:
                return(1);

            case StackBehaviour.Popi_pop1:
            case StackBehaviour.Popi_popi:
            case StackBehaviour.Popi_popi8:
            case StackBehaviour.Popi_popr8:
            case StackBehaviour.Popi_popr4:
            case StackBehaviour.Pop1_pop1:
            case StackBehaviour.Popref_popi:
            case StackBehaviour.Popref_pop1:
                return(2);

            case StackBehaviour.Popi_popi_popi:
            case StackBehaviour.Popref_popi_popi:
            case StackBehaviour.Popref_popi_popi8:
            case StackBehaviour.Popref_popi_popr4:
            case StackBehaviour.Popref_popi_popr8:
            case StackBehaviour.Popref_popi_popref:
                return(3);

            case StackBehaviour.PopAll:
                return(9999);
            }
            return(0);
        }
Beispiel #39
0
        private static void ComputePopDelta(StackBehaviour popBehavior, ref int stackSize)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (popBehavior)
            {
            case StackBehaviour.Popi:
            case StackBehaviour.Popref:
            case StackBehaviour.Pop1:
                stackSize--;
                break;

            case StackBehaviour.Pop1_pop1:
            case StackBehaviour.Popi_pop1:
            case StackBehaviour.Popi_popi:
            case StackBehaviour.Popi_popi8:
            case StackBehaviour.Popi_popr4:
            case StackBehaviour.Popi_popr8:
            case StackBehaviour.Popref_pop1:
            case StackBehaviour.Popref_popi:
                stackSize -= 2;
                break;

            case StackBehaviour.Popi_popi_popi:
            case StackBehaviour.Popref_popi_popi:
            case StackBehaviour.Popref_popi_popi8:
            case StackBehaviour.Popref_popi_popr4:
            case StackBehaviour.Popref_popi_popr8:
            case StackBehaviour.Popref_popi_popref:
                stackSize -= 3;
                break;

            case StackBehaviour.PopAll:
                stackSize = 0;
                break;
            }
        }
Beispiel #40
0
		private int DoGetStackCount(TypedInstruction instruction, StackBehaviour behavior)
		{
			int count = 0;
			
			switch (behavior)
			{
				case StackBehaviour.Pop0:
				case StackBehaviour.Push0:
					break;
					
				case StackBehaviour.Pop1:
				case StackBehaviour.Popi:
				case StackBehaviour.Popref:
				case StackBehaviour.Push1:
				case StackBehaviour.Pushi:
				case StackBehaviour.Pushi8:
				case StackBehaviour.Pushr4:
				case StackBehaviour.Pushr8:
				case StackBehaviour.Pushref:
					count = 1;
					break;
					
				case StackBehaviour.Pop1_pop1:
				case StackBehaviour.Popi_pop1:
				case StackBehaviour.Popi_popi:
				case StackBehaviour.Popi_popi8:
				case StackBehaviour.Popi_popr4:
				case StackBehaviour.Popi_popr8:
				case StackBehaviour.Popref_pop1:
				case StackBehaviour.Popref_popi:
				case StackBehaviour.Push1_push1:
					count = 2;
					break;
					
				case StackBehaviour.Popi_popi_popi:
				case StackBehaviour.Popref_popi_popi:
				case StackBehaviour.Popref_popi_popi8:
				case StackBehaviour.Popref_popi_popr4:
				case StackBehaviour.Popref_popi_popr8:
				case StackBehaviour.Popref_popi_popref:
					count = 3;
					break;
					
				case StackBehaviour.PopAll:				// leave
					count = int.MaxValue;
					break;
					
				case StackBehaviour.Varpop:				// call, newobj, ret
					Call call = instruction as Call;
					if (call != null)
					{
						count = call.Target.Parameters.Count + (call.Target.HasThis ? 1 : 0);
					}
					else if (instruction.Untyped.OpCode.Code == Code.Ret)
					{
						count = int.MaxValue;
					}
					else
					{
						NewObj no = instruction as NewObj;
						DBC.Assert(no != null, "Varpop opcode should be call, ret, or newobj");
						
						count = no.Ctor.Parameters.Count;
					}
					break;
				
				case StackBehaviour.Varpush:			// call
					Call call2 = instruction as Call;
					DBC.Assert(call2 != null, "Varpush opcode should be call");
					if (call2.Target.ReturnType.ReturnType.FullName != "System.Void")
						count = 1;
					break;

				default:
					DBC.Fail("Bad stack behavior: {0}", behavior);
					break;
			}
						
			return count;
		}
Beispiel #41
0
    private bool VerificationHelper(OpCode code,
        string name,
        StackBehaviour pop,
        StackBehaviour push,
        OperandType oprandType,
        OpCodeType type,
        int size,
        byte s1,
        byte s2,
        FlowControl ctrl,
        string errorno,
        string errordesp)
    {
        bool retVal = true;

        string actualName = code.Name;
        if (actualName != name)
        {
            TestLibrary.TestFramework.LogError(errorno + ".0", "Name returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualName = " + actualName + ", name = " + name);
            retVal = false;
        }

        StackBehaviour actualPop = code.StackBehaviourPop;
        if (actualPop != pop)
        {
            TestLibrary.TestFramework.LogError(errorno + ".1", "StackBehaviourPop returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualPop = " + actualPop + ", pop = " + pop);
            retVal = false;
        }

        StackBehaviour actualPush = code.StackBehaviourPush;
        if (actualPush != push)
        {
            TestLibrary.TestFramework.LogError(errorno + ".2", "StackBehaviourPush returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualPush = " + actualPush + ", push = " + push);
            retVal = false;
        }

        OperandType actualOperandType = code.OperandType;
        if (actualOperandType != oprandType)
        {
            TestLibrary.TestFramework.LogError(errorno + ".3", "OperandType returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualOperandType = " + actualOperandType + ", oprandType = " + oprandType);
            retVal = false;
        }

        OpCodeType actualOpCodeType = code.OpCodeType;
        if (actualOpCodeType != type)
        {
            TestLibrary.TestFramework.LogError(errorno + ".4", "OpCodeType returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualOpCodeType = " + actualOpCodeType + ", type = " + type);
            retVal = false;
        }

        int actualSize = code.Size;
        if (actualSize != size)
        {
            TestLibrary.TestFramework.LogError(errorno + ".5", "Size returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualSize = " + actualSize + ", size = " + size);
            retVal = false;
        }

        short expectedValue = 0;
        if (size == 2)
            expectedValue = (short)(s1 << 8 | s2);
        else
            expectedValue = (short)s2;

        short actualValue = code.Value;
        if (actualValue != expectedValue)
        {
            TestLibrary.TestFramework.LogError(errorno + ".6", "Value returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualValue = " + actualValue + ", s1 = " + s1 + ", s2 = " + s2 + ", expectedValue = " + expectedValue);
            retVal = false;
        }

        FlowControl actualCtrl = code.FlowControl;
        if (actualCtrl != ctrl)
        {
            TestLibrary.TestFramework.LogError(errorno + ".7", "FlowControl returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualCtrl = " + actualCtrl + ", ctrl = " + ctrl);
            retVal = false;
        }
        return retVal;
    }
Beispiel #42
0
    private bool VerificationHelper(OpCode code,
                                    string name,
                                    StackBehaviour pop,
                                    StackBehaviour push,
                                    OperandType oprandType,
                                    OpCodeType type,
                                    int size,
                                    byte s1,
                                    byte s2,
                                    FlowControl ctrl,
                                    string errorno,
                                    string errordesp)
    {
        bool retVal = true;

        string actualName = code.Name;

        if (actualName != name)
        {
            TestLibrary.TestFramework.LogError(errorno + ".0", "Name returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualName = " + actualName + ", name = " + name);
            retVal = false;
        }

        StackBehaviour actualPop = code.StackBehaviourPop;

        if (actualPop != pop)
        {
            TestLibrary.TestFramework.LogError(errorno + ".1", "StackBehaviourPop returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualPop = " + actualPop + ", pop = " + pop);
            retVal = false;
        }

        StackBehaviour actualPush = code.StackBehaviourPush;

        if (actualPush != push)
        {
            TestLibrary.TestFramework.LogError(errorno + ".2", "StackBehaviourPush returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualPush = " + actualPush + ", push = " + push);
            retVal = false;
        }

        OperandType actualOperandType = code.OperandType;

        if (actualOperandType != oprandType)
        {
            TestLibrary.TestFramework.LogError(errorno + ".3", "OperandType returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualOperandType = " + actualOperandType + ", oprandType = " + oprandType);
            retVal = false;
        }

        OpCodeType actualOpCodeType = code.OpCodeType;

        if (actualOpCodeType != type)
        {
            TestLibrary.TestFramework.LogError(errorno + ".4", "OpCodeType returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualOpCodeType = " + actualOpCodeType + ", type = " + type);
            retVal = false;
        }

        int actualSize = code.Size;

        if (actualSize != size)
        {
            TestLibrary.TestFramework.LogError(errorno + ".5", "Size returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualSize = " + actualSize + ", size = " + size);
            retVal = false;
        }

        short expectedValue = 0;

        if (size == 2)
        {
            expectedValue = (short)(s1 << 8 | s2);
        }
        else
        {
            expectedValue = (short)s2;
        }

        short actualValue = code.Value;

        if (actualValue != expectedValue)
        {
            TestLibrary.TestFramework.LogError(errorno + ".6", "Value returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualValue = " + actualValue + ", s1 = " + s1 + ", s2 = " + s2 + ", expectedValue = " + expectedValue);
            retVal = false;
        }

        FlowControl actualCtrl = code.FlowControl;

        if (actualCtrl != ctrl)
        {
            TestLibrary.TestFramework.LogError(errorno + ".7", "FlowControl returns wrong value for OpCode " + errordesp);
            TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actualCtrl = " + actualCtrl + ", ctrl = " + ctrl);
            retVal = false;
        }
        return(retVal);
    }
		internal OpCode (byte op1, byte op2,
			Code code, FlowControl flowControl,
			OpCodeType opCodeType, OperandType operandType,
			StackBehaviour pop, StackBehaviour push)
		{
			m_value = (short) ((op1 << 8) | op2);
			m_code = (byte) code;
			m_flowControl = (byte) flowControl;
			m_opCodeType = (byte) opCodeType;
			m_operandType = (byte) operandType;
			m_stackBehaviourPop = (byte) pop;
			m_stackBehaviourPush = (byte) push;

			if (op1 == 0xff)
				OpCodes.OneByteOpCode [op2] = this;
			else
				OpCodes.TwoBytesOpCode [op2] = this;
		}
		private static void ComputePopDelta(StackBehaviour popBehavior, ref int stackSize)
		{
		    // ReSharper disable once SwitchStatementMissingSomeCases
			switch (popBehavior)
			{
				case StackBehaviour.Popi:
				case StackBehaviour.Popref:
				case StackBehaviour.Pop1:
					stackSize--;
					break;
				case StackBehaviour.Pop1_pop1:
				case StackBehaviour.Popi_pop1:
				case StackBehaviour.Popi_popi:
				case StackBehaviour.Popi_popi8:
				case StackBehaviour.Popi_popr4:
				case StackBehaviour.Popi_popr8:
				case StackBehaviour.Popref_pop1:
				case StackBehaviour.Popref_popi:
					stackSize -= 2;
					break;
				case StackBehaviour.Popi_popi_popi:
				case StackBehaviour.Popref_popi_popi:
				case StackBehaviour.Popref_popi_popi8:
				case StackBehaviour.Popref_popi_popr4:
				case StackBehaviour.Popref_popi_popr8:
				case StackBehaviour.Popref_popi_popref:
					stackSize -= 3;
					break;
				case StackBehaviour.PopAll:
					stackSize = 0;
					break;
			}
		}
Beispiel #45
0
		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;
			}
		}
Beispiel #46
0
		static void ComputePopDelta (StackBehaviour pop_behavior, ref int stack_size)
		{
			switch (pop_behavior) {
			case StackBehaviour.Popi:
			case StackBehaviour.Popref:
			case StackBehaviour.Pop1:
				stack_size--;
				break;
			case StackBehaviour.Pop1_pop1:
			case StackBehaviour.Popi_pop1:
			case StackBehaviour.Popi_popi:
			case StackBehaviour.Popi_popi8:
			case StackBehaviour.Popi_popr4:
			case StackBehaviour.Popi_popr8:
			case StackBehaviour.Popref_pop1:
			case StackBehaviour.Popref_popi:
				stack_size -= 2;
				break;
			case StackBehaviour.Popi_popi_popi:
			case StackBehaviour.Popref_popi_popi:
			case StackBehaviour.Popref_popi_popi8:
			case StackBehaviour.Popref_popi_popr4:
			case StackBehaviour.Popref_popi_popr8:
			case StackBehaviour.Popref_popi_popref:
				stack_size -= 3;
				break;
			case StackBehaviour.PopAll:
				stack_size = 0;
				break;
			}
		}
		private static void ComputePushDelta(StackBehaviour pushBehaviour, ref int stackSize)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (pushBehaviour)
			{
				case StackBehaviour.Push1:
				case StackBehaviour.Pushi:
				case StackBehaviour.Pushi8:
				case StackBehaviour.Pushr4:
				case StackBehaviour.Pushr8:
				case StackBehaviour.Pushref:
					stackSize++;
					break;
				case StackBehaviour.Push1_push1:
					stackSize += 2;
					break;
			}
		}
Beispiel #48
0
    private bool VerifyAllTheFileds(OpCode opCode,
                                    String opCodeName,
                                    StackBehaviour pop,
                                    StackBehaviour push,
                                    OperandType operandType,
                                    OpCodeType type,
                                    int size,
                                    byte s1, byte s2,
                                    FlowControl ctrl,
                                    string errorNum)
    {
        bool   retVal = true;
        string errorDesc;

        string actualName = opCode.Name;

        if (actualName != opCodeName)
        {
            errorDesc = "Actual name of the specified MSIL instruction: \"" + actualName +
                        "\" does not equal expected name: \"" + opCodeName + "\"";
            TestLibrary.TestFramework.LogError(errorNum + ".1", errorDesc);
            retVal = false;
        }

        StackBehaviour actualStackBehaviourPop = opCode.StackBehaviourPop;

        if (actualStackBehaviourPop != pop)
        {
            errorDesc = "Actual pop statck behaviour of the specified MSIL instruction: (" + actualStackBehaviourPop +
                        ") does not equal expected pop stack behaviour: (" + pop + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".2", errorDesc);
            retVal = false;
        }

        StackBehaviour actualStackBehaviourPush = opCode.StackBehaviourPush;

        if (actualStackBehaviourPush != push)
        {
            errorDesc = "Actual push statck behaviour of the specified MSIL instruction: (" + actualStackBehaviourPush +
                        ") does not equal expected push stack behaviour: (" + push + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".3", errorDesc);
            retVal = false;
        }


        OperandType actualOperandType = opCode.OperandType;

        if (actualOperandType != operandType)
        {
            errorDesc = "Actual operand type of the specified MSIL instruction: (" + actualOperandType +
                        ") does not equal expected operand type: (" + operandType + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".4", errorDesc);
            retVal = false;
        }

        OpCodeType actualOpCodeType = opCode.OpCodeType;

        if (actualOpCodeType != type)
        {
            errorDesc = "Actual OpCode type of the specified MSIL instruction: (" + actualOpCodeType +
                        ") does not equal expected OpCode type: (" + type + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".5", errorDesc);
            retVal = false;
        }

        int actualSize = opCode.Size;

        if (actualSize != size)
        {
            errorDesc = "Actual size of the specified MSIL instruction: (" + actualSize +
                        ") does not equal expected size: (" + size + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".6", errorDesc);
            retVal = false;
        }

        short actualValue   = opCode.Value;
        short expectedValue = (2 == size) ? (short)(s1 << 8 | s2) : s2;

        if (actualValue != expectedValue)
        {
            errorDesc = "Actual immediate operand value of the specified MSIL instruction: (" + actualValue +
                        ") does not equal expected immediate operand value: (" + expectedValue + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".7", errorDesc);
            retVal = false;
        }

        FlowControl actualCtrl = opCode.FlowControl;

        if (actualCtrl != ctrl)
        {
            errorDesc = "Actual flow control of the specified MSIL instruction: (" + actualCtrl +
                        ") does not equal expected flow control: (" + ctrl + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".8", errorDesc);
            retVal = false;
        }

        return(retVal);
    }
		private static int Map(StackBehaviour[] array, System.Reflection.Emit.StackBehaviour stackBehaviour)
		{
			for (int i = 0; i < array.Length; i++)
			{
				if ((int)array[i] == (int)stackBehaviour)
				{
					return i;
				}
			}
			throw new InvalidOperationException();
		}
Beispiel #50
0
    private bool VerifyAllTheFileds(OpCode opCode, 
                                    String opCodeName, 
                                    StackBehaviour pop, 
                                    StackBehaviour push, 
                                    OperandType operandType, 
                                    OpCodeType type, 
                                    int size, 
                                    byte s1, byte s2, 
                                    FlowControl ctrl, 
                                    string errorNum)
    {
        bool retVal = true;
        string errorDesc;

        string actualName = opCode.Name;
        if (actualName != opCodeName)
        {
            errorDesc = "Actual name of the specified MSIL instruction: \"" + actualName +
                        "\" does not equal expected name: \"" + opCodeName + "\"";
            TestLibrary.TestFramework.LogError( errorNum + ".1", errorDesc);
            retVal = false;
        }

        StackBehaviour actualStackBehaviourPop = opCode.StackBehaviourPop;
        if (actualStackBehaviourPop != pop)
        {
            errorDesc = "Actual pop statck behaviour of the specified MSIL instruction: (" + actualStackBehaviourPop +
                        ") does not equal expected pop stack behaviour: (" + pop + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".2", errorDesc);
            retVal = false;
        }

        StackBehaviour actualStackBehaviourPush = opCode.StackBehaviourPush;
        if (actualStackBehaviourPush != push)
        {
            errorDesc = "Actual push statck behaviour of the specified MSIL instruction: (" + actualStackBehaviourPush +
                        ") does not equal expected push stack behaviour: (" + push + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".3", errorDesc);
            retVal = false;
        }


        OperandType actualOperandType = opCode.OperandType;
        if (actualOperandType != operandType)
        {
            errorDesc = "Actual operand type of the specified MSIL instruction: (" + actualOperandType +
                        ") does not equal expected operand type: (" + operandType + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".4", errorDesc);
            retVal = false;
        }

        OpCodeType actualOpCodeType = opCode.OpCodeType;
        if (actualOpCodeType != type)
        {
            errorDesc = "Actual OpCode type of the specified MSIL instruction: (" + actualOpCodeType +
                        ") does not equal expected OpCode type: (" + type + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".5", errorDesc);
            retVal = false;
        }

        int actualSize = opCode.Size;
        if (actualSize != size)
        {
            errorDesc = "Actual size of the specified MSIL instruction: (" + actualSize +
                        ") does not equal expected size: (" + size + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".6", errorDesc);
            retVal = false;
        }

        short actualValue = opCode.Value;
        short expectedValue = (2 == size) ? (short)(s1 << 8 | s2) : s2;
        if (actualValue != expectedValue)
        {
            errorDesc = "Actual immediate operand value of the specified MSIL instruction: (" + actualValue +
                        ") does not equal expected immediate operand value: (" + expectedValue + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".7", errorDesc);
            retVal = false;
        }

        FlowControl actualCtrl = opCode.FlowControl;
        if (actualCtrl != ctrl)
        {
            errorDesc = "Actual flow control of the specified MSIL instruction: (" + actualCtrl +
                        ") does not equal expected flow control: (" + ctrl + ")";
            TestLibrary.TestFramework.LogError(errorNum + ".8", errorDesc);
            retVal = false;
        }

        return retVal;
    }
Beispiel #51
0
 internal OpCode(OpCodeValues value, int flags)
 {
     m_stringname = null; // computed lazily
     m_pop = (StackBehaviour)((flags >> StackBehaviourPopShift) & StackBehaviourMask);
     m_push = (StackBehaviour)((flags >> StackBehaviourPushShift) & StackBehaviourMask);
     m_operand = (OperandType)(flags & OperandTypeMask);
     m_type = (OpCodeType)((flags >> OpCodeTypeShift) & OpCodeTypeMask);
     m_size = (flags >> SizeShift) & SizeMask;
     m_s1 = (byte)((int)value >> 8);
     m_s2 = (byte)(int)value;
     m_ctrl = (FlowControl)((flags >> FlowControlShift) & FlowControlMask);
     m_endsUncondJmpBlk = (flags & EndsUncondJmpBlkFlag) != 0;
     m_stackChange = (flags >> StackChangeShift);
 }
        private int GetStackChange(StackBehaviour beh)
        {
            switch (beh)
            {
                case StackBehaviour.Pop0:
                case StackBehaviour.Push0:
                    return 0;

                case StackBehaviour.Pop1:
                case StackBehaviour.Popi:
                case StackBehaviour.Popref:
                case StackBehaviour.Varpop:
                    return -1;

                case StackBehaviour.Push1:
                case StackBehaviour.Pushi:
                case StackBehaviour.Pushref:
                case StackBehaviour.Varpush:
                    return 1;

                case StackBehaviour.Pop1_pop1:
                case StackBehaviour.Popi_pop1:
                case StackBehaviour.Popi_popi:
                case StackBehaviour.Popi_popi8:
                case StackBehaviour.Popi_popr4:
                case StackBehaviour.Popi_popr8:
                case StackBehaviour.Popref_pop1:
                case StackBehaviour.Popref_popi:
                    return -2;

                case StackBehaviour.Push1_push1:
                    return 2;

                case StackBehaviour.Popref_popi_pop1:
                case StackBehaviour.Popref_popi_popi:
                case StackBehaviour.Popref_popi_popi8:
                case StackBehaviour.Popref_popi_popr4:
                case StackBehaviour.Popref_popi_popr8:
                case StackBehaviour.Popref_popi_popref:
                    return -3;
            }
            return 0;
        }