Example #1
0
        void RunCode(StackFrame stack, CodeBody body)
        {
            while (true)
            {
                //var code = stack._pos;
                int _pos  = stack._codepos;
                var _code = body.opCodes[_pos];
                if (DebugLevel >= 9)
                {
                    environment.logger.Log(_code.ToString());
                }
                switch (_code.code)
                {
                ///////////
                //流程控制
                case CodeEx.Nop:
                    stack.Nop();
                    break;

                case CodeEx.Ret:
                    stack.Ret();
                    return;

                case CodeEx.Leave:
                    stack.Leave(_code.tokenAddr_Index);
                    break;

                case CodeEx.Leave_S:
                    stack.Leave(_code.tokenAddr_Index);
                    break;

                //流程控制之goto
                case CodeEx.Br:
                    stack.Br(_code.tokenAddr_Index);
                    break;

                case CodeEx.Br_S:
                    stack.Br(_code.tokenAddr_Index);
                    break;

                case CodeEx.Brtrue:
                    stack.Brtrue(_code.tokenAddr_Index);
                    break;

                case CodeEx.Brtrue_S:
                    stack.Brtrue(_code.tokenAddr_Index);
                    break;

                case CodeEx.Brfalse:
                    stack.Brfalse(_code.tokenAddr_Index);
                    break;

                case CodeEx.Brfalse_S:
                    stack.Brfalse(_code.tokenAddr_Index);
                    break;

                //比较流程控制
                case CodeEx.Beq:
                    stack.Beq(_code.tokenAddr_Index);
                    break;

                case CodeEx.Beq_S:
                    stack.Beq(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bne_Un:
                    stack.Bne_Un(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bne_Un_S:
                    stack.Bne_Un(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bge:
                    stack.Bge(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bge_S:
                    stack.Bge(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bge_Un:
                    stack.Bge_Un(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bge_Un_S:
                    stack.Bge_Un(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bgt:
                    stack.Bgt(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bgt_S:
                    stack.Bgt(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bgt_Un:
                    stack.Bgt_Un(_code.tokenAddr_Index);
                    break;

                case CodeEx.Bgt_Un_S:
                    stack.Bge_Un(_code.tokenAddr_Index);
                    break;

                case CodeEx.Ble:
                    stack.Ble(_code.tokenAddr_Index);
                    break;

                case CodeEx.Ble_S:
                    stack.Ble(_code.tokenAddr_Index);
                    break;

                case CodeEx.Ble_Un:
                    stack.Ble_Un(_code.tokenAddr_Index);
                    break;

                case CodeEx.Ble_Un_S:
                    stack.Ble_Un(_code.tokenAddr_Index);
                    break;

                case CodeEx.Blt:
                    stack.Blt(_code.tokenAddr_Index);
                    break;

                case CodeEx.Blt_S:
                    stack.Blt(_code.tokenAddr_Index);
                    break;

                case CodeEx.Blt_Un:
                    stack.Blt_Un(_code.tokenAddr_Index);
                    break;

                case CodeEx.Blt_Un_S:
                    stack.Ble_Un(_code.tokenAddr_Index);
                    break;

                //逻辑计算
                case CodeEx.Ceq:
                    stack.Ceq();
                    break;

                case CodeEx.Cgt:
                    stack.Cgt();
                    break;

                case CodeEx.Cgt_Un:
                    stack.Cgt_Un();
                    break;

                case CodeEx.Clt:
                    stack.Clt();
                    break;

                case CodeEx.Clt_Un:
                    stack.Clt_Un();
                    break;

                case CodeEx.Ckfinite:
                    stack.Ckfinite();
                    break;

                //常量加载
                case CodeEx.Ldc_I4:
                    stack.Ldc_I4(_code.tokenI32);
                    break;

                case CodeEx.Ldc_I4_S:
                    stack.Ldc_I4(_code.tokenI32);
                    break;

                case CodeEx.Ldc_I4_M1:
                    stack.Ldc_I4(-1);
                    break;

                case CodeEx.Ldc_I4_0:
                    stack.Ldc_I4(0);
                    break;

                case CodeEx.Ldc_I4_1:
                    stack.Ldc_I4(1);
                    break;

                case CodeEx.Ldc_I4_2:
                    stack.Ldc_I4(2);
                    break;

                case CodeEx.Ldc_I4_3:
                    stack.Ldc_I4(3);
                    break;

                case CodeEx.Ldc_I4_4:
                    stack.Ldc_I4(4);
                    break;

                case CodeEx.Ldc_I4_5:
                    stack.Ldc_I4(5);
                    break;

                case CodeEx.Ldc_I4_6:
                    stack.Ldc_I4(6);
                    break;

                case CodeEx.Ldc_I4_7:
                    stack.Ldc_I4(7);
                    break;

                case CodeEx.Ldc_I4_8:
                    stack.Ldc_I4(8);
                    break;

                case CodeEx.Ldc_I8:
                    stack.Ldc_I8(_code.tokenI64);
                    break;

                case CodeEx.Ldc_R4:
                    stack.Ldc_R4(_code.tokenR32);
                    break;

                case CodeEx.Ldc_R8:
                    stack.Ldc_R8(_code.tokenR64);
                    break;

                //定义为临时变量
                case CodeEx.Stloc:
                    stack.Stloc(_code.tokenI32);
                    break;

                case CodeEx.Stloc_S:
                    stack.Stloc(_code.tokenI32);
                    break;

                case CodeEx.Stloc_0:
                    stack.Stloc(0);
                    break;

                case CodeEx.Stloc_1:
                    stack.Stloc(1);
                    break;

                case CodeEx.Stloc_2:
                    stack.Stloc(2);
                    break;

                case CodeEx.Stloc_3:
                    stack.Stloc(3);
                    break;

                //从临时变量加载
                case CodeEx.Ldloc:
                    stack.Ldloc(_code.tokenI32);
                    break;

                case CodeEx.Ldloc_S:
                    stack.Ldloc(_code.tokenI32);
                    break;

                case CodeEx.Ldloc_0:
                    stack.Ldloc(0);
                    break;

                case CodeEx.Ldloc_1:
                    stack.Ldloc(1);
                    break;

                case CodeEx.Ldloc_2:
                    stack.Ldloc(2);
                    break;

                case CodeEx.Ldloc_3:
                    stack.Ldloc(3);
                    break;

                case CodeEx.Ldloca:
                    stack.Ldloca(_code.tokenI32);
                    break;

                case CodeEx.Ldloca_S:
                    stack.Ldloca(_code.tokenI32);
                    break;

                //加载字符串
                case CodeEx.Ldstr:
                    stack.Ldstr(_code.tokenStr);
                    break;

                //呼叫函数
                case CodeEx.Call:
                    stack.Call(this, _code.tokenMethod, false);
                    break;

                case CodeEx.Callvirt:
                    stack.Call(this, _code.tokenMethod, true);
                    break;

                //算术指令
                case CodeEx.Add:
                    stack.Add();
                    break;

                case CodeEx.Sub:
                    stack.Sub();
                    break;

                case CodeEx.Mul:
                    stack.Mul();
                    break;

                case CodeEx.Div:
                    stack.Div();
                    break;

                case CodeEx.Div_Un:
                    stack.Div_Un();
                    break;

                case CodeEx.Rem:
                    stack.Rem();
                    break;

                case CodeEx.Rem_Un:
                    stack.Rem_Un();
                    break;

                case CodeEx.Neg:
                    stack.Neg();
                    break;

                //装箱
                case CodeEx.Box:
                    stack.Box(_code.tokenType);
                    break;

                case CodeEx.Unbox:
                    stack.Unbox();
                    break;

                case CodeEx.Unbox_Any:
                    stack.Unbox_Any();
                    break;

                //加载参数
                case CodeEx.Ldarg:
                    if (body.bodyNative.Method.IsStatic)
                    {
                        stack.Ldarg(_code.tokenI32);
                    }
                    else
                    {
                        stack.Ldarg(_code.tokenI32 + 1);
                    }

                    break;

                case CodeEx.Ldarg_S:
                    if (body.bodyNative.Method.IsStatic)
                    {
                        stack.Ldarg(_code.tokenI32);
                    }
                    else
                    {
                        stack.Ldarg(_code.tokenI32 + 1);
                    }
                    break;

                case CodeEx.Ldarg_0:
                    stack.Ldarg(0);
                    break;

                case CodeEx.Ldarg_1:
                    stack.Ldarg(1);
                    break;

                case CodeEx.Ldarg_2:
                    stack.Ldarg(2);
                    break;

                case CodeEx.Ldarg_3:
                    stack.Ldarg(3);
                    break;

                case CodeEx.Ldarga:
                    if (body.bodyNative.Method.IsStatic)
                    {
                        stack.Ldarga(_code.tokenI32);
                    }
                    else
                    {
                        stack.Ldarga(_code.tokenI32 + 1);
                    }

                    break;

                case CodeEx.Ldarga_S:
                    if (body.bodyNative.Method.IsStatic)
                    {
                        stack.Ldarga(_code.tokenI32);
                    }
                    else
                    {
                        stack.Ldarga(_code.tokenI32 + 1);
                    }

                    break;

                //转换
                case CodeEx.Conv_I1:
                    stack.Conv_I1();
                    break;

                case CodeEx.Conv_U1:
                    stack.Conv_U1();
                    break;

                case CodeEx.Conv_I2:
                    stack.Conv_I2();
                    break;

                case CodeEx.Conv_U2:
                    stack.Conv_U2();
                    break;

                case CodeEx.Conv_I4:
                    stack.Conv_I4();
                    break;

                case CodeEx.Conv_U4:
                    stack.Conv_U4();
                    break;

                case CodeEx.Conv_I8:
                    stack.Conv_I8();
                    break;

                case CodeEx.Conv_U8:
                    stack.Conv_U8();
                    break;

                case CodeEx.Conv_I:
                    stack.Conv_I();
                    break;

                case CodeEx.Conv_U:
                    stack.Conv_U();
                    break;

                case CodeEx.Conv_R4:
                    stack.Conv_R4();
                    break;

                case CodeEx.Conv_R8:
                    stack.Conv_R8();
                    break;

                case CodeEx.Conv_R_Un:
                    stack.Conv_R_Un();
                    break;

                case CodeEx.Conv_Ovf_I1:
                    stack.Conv_Ovf_I1();
                    break;

                case CodeEx.Conv_Ovf_U1:
                    stack.Conv_Ovf_U1();
                    break;

                case CodeEx.Conv_Ovf_I2:
                    stack.Conv_Ovf_I2();
                    break;

                case CodeEx.Conv_Ovf_U2:
                    stack.Conv_Ovf_U2();
                    break;

                case CodeEx.Conv_Ovf_I4:
                    stack.Conv_Ovf_I4();
                    break;

                case CodeEx.Conv_Ovf_U4:
                    stack.Conv_Ovf_U4();
                    break;

                case CodeEx.Conv_Ovf_I8:
                    stack.Conv_Ovf_I8();
                    break;

                case CodeEx.Conv_Ovf_U8:
                    stack.Conv_Ovf_U8();
                    break;

                case CodeEx.Conv_Ovf_I:
                    stack.Conv_Ovf_I();
                    break;

                case CodeEx.Conv_Ovf_U:
                    stack.Conv_Ovf_U();
                    break;

                case CodeEx.Conv_Ovf_I1_Un:
                    stack.Conv_Ovf_I1_Un();
                    break;

                case CodeEx.Conv_Ovf_U1_Un:
                    stack.Conv_Ovf_U1_Un();
                    break;

                case CodeEx.Conv_Ovf_I2_Un:
                    stack.Conv_Ovf_I2_Un();
                    break;

                case CodeEx.Conv_Ovf_U2_Un:
                    stack.Conv_Ovf_U2_Un();
                    break;

                case CodeEx.Conv_Ovf_I4_Un:
                    stack.Conv_Ovf_I4_Un();
                    break;

                case CodeEx.Conv_Ovf_U4_Un:
                    stack.Conv_Ovf_U4_Un();
                    break;

                case CodeEx.Conv_Ovf_I8_Un:
                    stack.Conv_Ovf_I8_Un();
                    break;

                case CodeEx.Conv_Ovf_U8_Un:
                    stack.Conv_Ovf_U8_Un();
                    break;

                case CodeEx.Conv_Ovf_I_Un:
                    stack.Conv_Ovf_I_Un();
                    break;

                case CodeEx.Conv_Ovf_U_Un:
                    stack.Conv_Ovf_U_Un();
                    break;

                //数组
                case CodeEx.Newarr:
                    stack.NewArr(this, GetNewForArray(_code.tokenUnknown));
                    break;

                case CodeEx.Ldlen:
                    stack.LdLen();
                    break;

                case CodeEx.Ldelema:
                    stack.Ldelema(_code.tokenUnknown);
                    break;

                case CodeEx.Ldelem_I1:
                    stack.Ldelem_I1();
                    break;

                case CodeEx.Ldelem_U1:
                    stack.Ldelem_U1();
                    break;

                case CodeEx.Ldelem_I2:
                    stack.Ldelem_I2();
                    break;

                case CodeEx.Ldelem_U2:
                    stack.Ldelem_U2();
                    break;

                case CodeEx.Ldelem_I4:
                    stack.Ldelem_I4();
                    break;

                case CodeEx.Ldelem_U4:
                    stack.Ldelem_U4();
                    break;

                case CodeEx.Ldelem_I8:
                    stack.Ldelem_I8();
                    break;

                case CodeEx.Ldelem_I:
                    stack.Ldelem_I();
                    break;

                case CodeEx.Ldelem_R4:
                    stack.Ldelem_R4();
                    break;

                case CodeEx.Ldelem_R8:
                    stack.Ldelem_R8();
                    break;

                case CodeEx.Ldelem_Ref:
                    stack.Ldelem_Ref();
                    break;

                case CodeEx.Ldelem_Any:
                    stack.Ldelem_Any(_code.tokenUnknown);
                    break;

                case CodeEx.Stelem_I:
                    stack.Stelem_I();
                    break;

                case CodeEx.Stelem_I1:
                    stack.Stelem_I1();
                    break;

                case CodeEx.Stelem_I2:
                    stack.Stelem_I2();
                    break;

                case CodeEx.Stelem_I4:
                    stack.Stelem_I4();
                    break;

                case CodeEx.Stelem_I8:
                    stack.Stelem_I8();
                    break;

                case CodeEx.Stelem_R4:
                    stack.Stelem_R4();
                    break;

                case CodeEx.Stelem_R8:
                    stack.Stelem_R8();
                    break;

                case CodeEx.Stelem_Ref:
                    stack.Stelem_Ref();
                    break;

                case CodeEx.Stelem_Any:
                    stack.Stelem_Any();
                    break;

                case CodeEx.Newobj:
                    stack.NewObj(this, _code.tokenMethod);
                    break;

                case CodeEx.Dup:
                    stack.Dup();
                    break;

                case CodeEx.Pop:
                    stack.Pop();
                    break;

                case CodeEx.Ldfld:
                    stack.Ldfld(this, _code.tokenField);
                    break;

                case CodeEx.Ldflda:
                    stack.Ldflda(this, _code.tokenField);
                    break;

                case CodeEx.Ldsfld:
                    stack.Ldsfld(this, _code.tokenField);
                    break;

                case CodeEx.Ldsflda:
                    stack.Ldsflda(this, _code.tokenField);
                    break;

                case CodeEx.Stfld:
                    stack.Stfld(this, _code.tokenField);
                    break;

                case CodeEx.Stsfld:
                    stack.Stsfld(this, _code.tokenField);
                    break;


                case CodeEx.Constrained:
                    stack.Constrained(this, _code.tokenType);
                    break;

                case CodeEx.Isinst:
                    stack.Isinst(this, _code.tokenType);
                    break;

                case CodeEx.Ldtoken:
                    stack.Ldtoken(this, GetToken(_code.tokenUnknown));
                    break;

                case CodeEx.Ldftn:
                    stack.Ldftn(this, _code.tokenMethod);
                    break;

                case CodeEx.Ldvirtftn:
                    stack.Ldvirtftn(this, _code.tokenMethod);
                    break;

                case CodeEx.Calli:
                    stack.Calli(this, _code.tokenUnknown);
                    break;

                ///下面是还没有处理的指令
                case CodeEx.Break:
                    stack.Break(this, _code.tokenUnknown);
                    break;

                case CodeEx.Starg_S:
                    stack.Starg_S(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldnull:
                    stack.Ldnull();
                    break;

                case CodeEx.Jmp:
                    stack.Jmp(this, _code.tokenUnknown);
                    break;

                case CodeEx.Switch:
                    stack.Switch(this, _code.tokenAddr_Switch);
                    break;

                case CodeEx.Ldind_I1:
                    stack.Ldind_I1(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_U1:
                    stack.Ldind_U1(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_I2:
                    stack.Ldind_I2(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_U2:
                    stack.Ldind_U2(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_I4:
                    stack.Ldind_I4(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_U4:
                    stack.Ldind_U4(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_I8:
                    stack.Ldind_I8(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_I:
                    stack.Ldind_I(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_R4:
                    stack.Ldind_R4(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_R8:
                    stack.Ldind_R8(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldind_Ref:
                    stack.Ldind_Ref(this, _code.tokenUnknown);
                    break;

                case CodeEx.Stind_Ref:
                    stack.Stind_Ref(this, _code.tokenUnknown);
                    break;

                case CodeEx.Stind_I1:
                    stack.Stind_I1(this, _code.tokenUnknown);
                    break;

                case CodeEx.Stind_I2:
                    stack.Stind_I2(this, _code.tokenUnknown);
                    break;

                case CodeEx.Stind_I4:
                    stack.Stind_I4(this, _code.tokenUnknown);
                    break;

                case CodeEx.Stind_I8:
                    stack.Stind_I8(this, _code.tokenUnknown);
                    break;

                case CodeEx.Stind_R4:
                    stack.Stind_R4(this, _code.tokenUnknown);
                    break;

                case CodeEx.Stind_R8:
                    stack.Stind_R8(this, _code.tokenUnknown);
                    break;

                case CodeEx.And:
                    stack.And();
                    break;

                case CodeEx.Or:
                    stack.Or();
                    break;

                case CodeEx.Xor:
                    stack.Xor();
                    break;

                case CodeEx.Shl:
                    stack.Shl(this, _code.tokenUnknown);
                    break;

                case CodeEx.Shr:
                    stack.Shr(this, _code.tokenUnknown);
                    break;

                case CodeEx.Shr_Un:
                    stack.Shr_Un(this, _code.tokenUnknown);
                    break;

                case CodeEx.Not:
                    stack.Not();
                    break;

                case CodeEx.Cpobj:
                    stack.Cpobj(this, _code.tokenUnknown);
                    break;

                case CodeEx.Ldobj:
                    stack.Ldobj(this, _code.tokenUnknown);
                    break;

                case CodeEx.Castclass:
                    stack.Castclass(this, _code.tokenType);
                    break;

                case CodeEx.Throw:
                    stack.Throw(this, _code.tokenUnknown);
                    break;

                case CodeEx.Stobj:
                    stack.Stobj(this, _code.tokenUnknown);
                    break;

                case CodeEx.Refanyval:
                    stack.Refanyval(this, _code.tokenUnknown);
                    break;

                case CodeEx.Mkrefany:
                    stack.Mkrefany(this, _code.tokenUnknown);
                    break;

                case CodeEx.Add_Ovf:
                    stack.Add_Ovf(this, _code.tokenUnknown);
                    break;

                case CodeEx.Add_Ovf_Un:
                    stack.Add_Ovf_Un(this, _code.tokenUnknown);
                    break;

                case CodeEx.Mul_Ovf:
                    stack.Mul_Ovf(this, _code.tokenUnknown);
                    break;

                case CodeEx.Mul_Ovf_Un:
                    stack.Mul_Ovf_Un(this, _code.tokenUnknown);
                    break;

                case CodeEx.Sub_Ovf:
                    stack.Sub_Ovf(this, _code.tokenUnknown);
                    break;

                case CodeEx.Sub_Ovf_Un:
                    stack.Sub_Ovf_Un(this, _code.tokenUnknown);
                    break;

                case CodeEx.Endfinally:
                    stack.Endfinally(this, _code.tokenUnknown);
                    break;

                case CodeEx.Stind_I:
                    stack.Stind_I(this, _code.tokenUnknown);
                    break;

                case CodeEx.Arglist:
                    stack.Arglist(this, _code.tokenUnknown);
                    break;

                case CodeEx.Starg:
                    stack.Starg(this, _code.tokenUnknown);
                    break;

                case CodeEx.Localloc:
                    stack.Localloc(this, _code.tokenUnknown);
                    break;

                case CodeEx.Endfilter:
                    stack.Endfilter(this, _code.tokenUnknown);
                    break;

                case CodeEx.Unaligned:
                    stack.Unaligned(this, _code.tokenUnknown);
                    break;

                case CodeEx.Volatile:
                    stack.Volatile(this, _code.tokenUnknown);
                    break;

                case CodeEx.Tail:
                    stack.Tail(this, _code.tokenUnknown);
                    break;

                case CodeEx.Initobj:
                    stack.Initobj(this, _code.tokenType);
                    break;

                case CodeEx.Cpblk:
                    stack.Cpblk(this, _code.tokenUnknown);
                    break;

                case CodeEx.Initblk:
                    stack.Initblk(this, _code.tokenUnknown);
                    break;

                case CodeEx.No:
                    stack.No(this, _code.tokenUnknown);
                    break;

                case CodeEx.Rethrow:
                    stack.Rethrow(this, _code.tokenUnknown);
                    break;

                case CodeEx.Sizeof:
                    stack.Sizeof(this, _code.tokenUnknown);
                    break;

                case CodeEx.Refanytype:
                    stack.Refanytype(this, _code.tokenUnknown);
                    break;

                case CodeEx.Readonly:
                    stack.Readonly(this, _code.tokenUnknown);
                    break;

                default:
                    throw new Exception("未实现的OpCode:" + _code.code);
                }
            }
        }
Example #2
0
        private void RunCode(StackFrame stack, CodeBody body)
        {
            CodeBody.OpCode opCode;
            while (true)
            {
                int codepos = stack._codepos;
                opCode = body.opCodes[codepos];
                bool flag = this.DebugLevel >= 9;
                if (flag)
                {
                    this.environment.logger.Log(opCode.ToString());
                }
                switch (opCode.code)
                {
                case CodeEx.Nop:
                    stack.Nop();
                    continue;

                case CodeEx.Break:
                    stack.Break(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Ldarg_0:
                    stack.Ldarg(0);
                    continue;

                case CodeEx.Ldarg_1:
                    stack.Ldarg(1);
                    continue;

                case CodeEx.Ldarg_2:
                    stack.Ldarg(2);
                    continue;

                case CodeEx.Ldarg_3:
                    stack.Ldarg(3);
                    continue;

                case CodeEx.Ldloc_0:
                    stack.Ldloc(0);
                    continue;

                case CodeEx.Ldloc_1:
                    stack.Ldloc(1);
                    continue;

                case CodeEx.Ldloc_2:
                    stack.Ldloc(2);
                    continue;

                case CodeEx.Ldloc_3:
                    stack.Ldloc(3);
                    continue;

                case CodeEx.Stloc_0:
                    stack.Stloc(0);
                    continue;

                case CodeEx.Stloc_1:
                    stack.Stloc(1);
                    continue;

                case CodeEx.Stloc_2:
                    stack.Stloc(2);
                    continue;

                case CodeEx.Stloc_3:
                    stack.Stloc(3);
                    continue;

                case CodeEx.Ldarg_S:
                {
                    bool isStatic = body.bodyNative.Method.IsStatic;
                    if (isStatic)
                    {
                        stack.Ldarg(opCode.tokenI32);
                    }
                    else
                    {
                        stack.Ldarg(opCode.tokenI32 + 1);
                    }
                    continue;
                }

                case CodeEx.Ldarga_S:
                {
                    bool isStatic2 = body.bodyNative.Method.IsStatic;
                    if (isStatic2)
                    {
                        stack.Ldarga(opCode.tokenI32);
                    }
                    else
                    {
                        stack.Ldarga(opCode.tokenI32 + 1);
                    }
                    continue;
                }

                case CodeEx.Starg_S:
                {
                    bool isStatic3 = body.bodyNative.Method.IsStatic;
                    if (isStatic3)
                    {
                        stack.Starg(this, opCode.tokenI32);
                    }
                    else
                    {
                        stack.Starg(this, opCode.tokenI32 + 1);
                    }
                    continue;
                }

                case CodeEx.Ldloc_S:
                    stack.Ldloc(opCode.tokenI32);
                    continue;

                case CodeEx.Ldloca_S:
                    stack.Ldloca(opCode.tokenI32);
                    continue;

                case CodeEx.Stloc_S:
                    stack.Stloc(opCode.tokenI32);
                    continue;

                case CodeEx.Ldnull:
                    stack.Ldnull();
                    continue;

                case CodeEx.Ldc_I4_M1:
                    stack.Ldc_I4(-1);
                    continue;

                case CodeEx.Ldc_I4_0:
                    stack.Ldc_I4(0);
                    continue;

                case CodeEx.Ldc_I4_1:
                    stack.Ldc_I4(1);
                    continue;

                case CodeEx.Ldc_I4_2:
                    stack.Ldc_I4(2);
                    continue;

                case CodeEx.Ldc_I4_3:
                    stack.Ldc_I4(3);
                    continue;

                case CodeEx.Ldc_I4_4:
                    stack.Ldc_I4(4);
                    continue;

                case CodeEx.Ldc_I4_5:
                    stack.Ldc_I4(5);
                    continue;

                case CodeEx.Ldc_I4_6:
                    stack.Ldc_I4(6);
                    continue;

                case CodeEx.Ldc_I4_7:
                    stack.Ldc_I4(7);
                    continue;

                case CodeEx.Ldc_I4_8:
                    stack.Ldc_I4(8);
                    continue;

                case CodeEx.Ldc_I4_S:
                    stack.Ldc_I4(opCode.tokenI32);
                    continue;

                case CodeEx.Ldc_I4:
                    stack.Ldc_I4(opCode.tokenI32);
                    continue;

                case CodeEx.Ldc_I8:
                    stack.Ldc_I8(opCode.tokenI64);
                    continue;

                case CodeEx.Ldc_R4:
                    stack.Ldc_R4(opCode.tokenR32);
                    continue;

                case CodeEx.Ldc_R8:
                    stack.Ldc_R8(opCode.tokenR64);
                    continue;

                case CodeEx.Dup:
                    stack.Dup();
                    continue;

                case CodeEx.Pop:
                    stack.Pop();
                    continue;

                case CodeEx.Jmp:
                    stack.Jmp(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Call:
                    stack.Call(this, opCode.tokenMethod, false);
                    continue;

                case CodeEx.Calli:
                    stack.Calli(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Ret:
                    goto IL_3CF;

                case CodeEx.Br_S:
                    stack.Br(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Brfalse_S:
                    stack.Brfalse(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Brtrue_S:
                    stack.Brtrue(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Beq_S:
                    stack.Beq(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bge_S:
                    stack.Bge(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bgt_S:
                    stack.Bgt(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Ble_S:
                    stack.Ble(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Blt_S:
                    stack.Blt(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bne_Un_S:
                    stack.Bne_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bge_Un_S:
                    stack.Bge_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bgt_Un_S:
                    stack.Bgt_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Ble_Un_S:
                    stack.Ble_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Blt_Un_S:
                    stack.Blt_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Br:
                    stack.Br(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Brfalse:
                    stack.Brfalse(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Brtrue:
                    stack.Brtrue(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Beq:
                    stack.Beq(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bge:
                    stack.Bge(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bgt:
                    stack.Bgt(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Ble:
                    stack.Ble(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Blt:
                    stack.Blt(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bne_Un:
                    stack.Bne_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bge_Un:
                    stack.Bge_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Bgt_Un:
                    stack.Bgt_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Ble_Un:
                    stack.Ble_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Blt_Un:
                    stack.Blt_Un(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Switch:
                    stack.Switch(this, opCode.tokenAddr_Switch);
                    continue;

                case CodeEx.Ldind_I1:
                    stack.Ldind_I1();
                    continue;

                case CodeEx.Ldind_U1:
                    stack.Ldind_U1();
                    continue;

                case CodeEx.Ldind_I2:
                    stack.Ldind_I2();
                    continue;

                case CodeEx.Ldind_U2:
                    stack.Ldind_U2();
                    continue;

                case CodeEx.Ldind_I4:
                    stack.Ldind_I4();
                    continue;

                case CodeEx.Ldind_U4:
                    stack.Ldind_U4();
                    continue;

                case CodeEx.Ldind_I8:
                    stack.Ldind_I8();
                    continue;

                case CodeEx.Ldind_I:
                    stack.Ldind_I();
                    continue;

                case CodeEx.Ldind_R4:
                    stack.Ldind_R4();
                    continue;

                case CodeEx.Ldind_R8:
                    stack.Ldind_R8();
                    continue;

                case CodeEx.Ldind_Ref:
                    stack.Ldind_Ref();
                    continue;

                case CodeEx.Stind_Ref:
                    stack.Stind_Ref(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Stind_I1:
                    stack.Stind_I1(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Stind_I2:
                    stack.Stind_I2(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Stind_I4:
                    stack.Stind_I4(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Stind_I8:
                    stack.Stind_I8(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Stind_R4:
                    stack.Stind_R4(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Stind_R8:
                    stack.Stind_R8(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Add:
                    stack.Add();
                    continue;

                case CodeEx.Sub:
                    stack.Sub();
                    continue;

                case CodeEx.Mul:
                    stack.Mul();
                    continue;

                case CodeEx.Div:
                    stack.Div();
                    continue;

                case CodeEx.Div_Un:
                    stack.Div_Un();
                    continue;

                case CodeEx.Rem:
                    stack.Rem();
                    continue;

                case CodeEx.Rem_Un:
                    stack.Rem_Un();
                    continue;

                case CodeEx.And:
                    stack.And();
                    continue;

                case CodeEx.Or:
                    stack.Or();
                    continue;

                case CodeEx.Xor:
                    stack.Xor();
                    continue;

                case CodeEx.Shl:
                    stack.Shl(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Shr:
                    stack.Shr(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Shr_Un:
                    stack.Shr_Un(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Neg:
                    stack.Neg();
                    continue;

                case CodeEx.Not:
                    stack.Not();
                    continue;

                case CodeEx.Conv_I1:
                    stack.Conv_I1();
                    continue;

                case CodeEx.Conv_I2:
                    stack.Conv_I2();
                    continue;

                case CodeEx.Conv_I4:
                    stack.Conv_I4();
                    continue;

                case CodeEx.Conv_I8:
                    stack.Conv_I8();
                    continue;

                case CodeEx.Conv_R4:
                    stack.Conv_R4();
                    continue;

                case CodeEx.Conv_R8:
                    stack.Conv_R8();
                    continue;

                case CodeEx.Conv_U4:
                    stack.Conv_U4();
                    continue;

                case CodeEx.Conv_U8:
                    stack.Conv_U8();
                    continue;

                case CodeEx.Callvirt:
                    stack.Call(this, opCode.tokenMethod, true);
                    continue;

                case CodeEx.Cpobj:
                    stack.Cpobj(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Ldobj:
                    stack.Ldobj(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Ldstr:
                    stack.Ldstr(opCode.tokenStr);
                    continue;

                case CodeEx.Newobj:
                    stack.NewObj(this, opCode.tokenMethod);
                    continue;

                case CodeEx.Castclass:
                    stack.Castclass(this, opCode.tokenType);
                    continue;

                case CodeEx.Isinst:
                    stack.Isinst(this, opCode.tokenType);
                    continue;

                case CodeEx.Conv_R_Un:
                    stack.Conv_R_Un();
                    continue;

                case CodeEx.Unbox:
                    stack.Unbox();
                    continue;

                case CodeEx.Throw:
                    stack.Throw(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Ldfld:
                    stack.Ldfld(this, opCode.tokenField);
                    continue;

                case CodeEx.Ldflda:
                    stack.Ldflda(this, opCode.tokenField);
                    continue;

                case CodeEx.Stfld:
                    stack.Stfld(this, opCode.tokenField);
                    continue;

                case CodeEx.Ldsfld:
                    stack.Ldsfld(this, opCode.tokenField);
                    continue;

                case CodeEx.Ldsflda:
                    stack.Ldsflda(this, opCode.tokenField);
                    continue;

                case CodeEx.Stsfld:
                    stack.Stsfld(this, opCode.tokenField);
                    continue;

                case CodeEx.Stobj:
                    stack.Stobj(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Conv_Ovf_I1_Un:
                    stack.Conv_Ovf_I1_Un();
                    continue;

                case CodeEx.Conv_Ovf_I2_Un:
                    stack.Conv_Ovf_I2_Un();
                    continue;

                case CodeEx.Conv_Ovf_I4_Un:
                    stack.Conv_Ovf_I4_Un();
                    continue;

                case CodeEx.Conv_Ovf_I8_Un:
                    stack.Conv_Ovf_I8_Un();
                    continue;

                case CodeEx.Conv_Ovf_U1_Un:
                    stack.Conv_Ovf_U1_Un();
                    continue;

                case CodeEx.Conv_Ovf_U2_Un:
                    stack.Conv_Ovf_U2_Un();
                    continue;

                case CodeEx.Conv_Ovf_U4_Un:
                    stack.Conv_Ovf_U4_Un();
                    continue;

                case CodeEx.Conv_Ovf_U8_Un:
                    stack.Conv_Ovf_U8_Un();
                    continue;

                case CodeEx.Conv_Ovf_I_Un:
                    stack.Conv_Ovf_I_Un();
                    continue;

                case CodeEx.Conv_Ovf_U_Un:
                    stack.Conv_Ovf_U_Un();
                    continue;

                case CodeEx.Box:
                    stack.Box(opCode.tokenType);
                    continue;

                case CodeEx.Newarr:
                    stack.NewArr(this, opCode.tokenType.TypeForSystem);
                    continue;

                case CodeEx.Ldlen:
                    stack.LdLen();
                    continue;

                case CodeEx.Ldelema:
                    stack.Ldelema(opCode.tokenUnknown);
                    continue;

                case CodeEx.Ldelem_I1:
                    stack.Ldelem_I1();
                    continue;

                case CodeEx.Ldelem_U1:
                    stack.Ldelem_U1();
                    continue;

                case CodeEx.Ldelem_I2:
                    stack.Ldelem_I2();
                    continue;

                case CodeEx.Ldelem_U2:
                    stack.Ldelem_U2();
                    continue;

                case CodeEx.Ldelem_I4:
                    stack.Ldelem_I4();
                    continue;

                case CodeEx.Ldelem_U4:
                    stack.Ldelem_U4();
                    continue;

                case CodeEx.Ldelem_I8:
                    stack.Ldelem_I8();
                    continue;

                case CodeEx.Ldelem_I:
                    stack.Ldelem_I();
                    continue;

                case CodeEx.Ldelem_R4:
                    stack.Ldelem_R4();
                    continue;

                case CodeEx.Ldelem_R8:
                    stack.Ldelem_R8();
                    continue;

                case CodeEx.Ldelem_Ref:
                    stack.Ldelem_Ref();
                    continue;

                case CodeEx.Stelem_I:
                    stack.Stelem_I();
                    continue;

                case CodeEx.Stelem_I1:
                    stack.Stelem_I1();
                    continue;

                case CodeEx.Stelem_I2:
                    stack.Stelem_I2();
                    continue;

                case CodeEx.Stelem_I4:
                    stack.Stelem_I4();
                    continue;

                case CodeEx.Stelem_I8:
                    stack.Stelem_I8();
                    continue;

                case CodeEx.Stelem_R4:
                    stack.Stelem_R4();
                    continue;

                case CodeEx.Stelem_R8:
                    stack.Stelem_R8();
                    continue;

                case CodeEx.Stelem_Ref:
                    stack.Stelem_Ref();
                    continue;

                case CodeEx.Ldelem_Any:
                    stack.Ldelem_Any(opCode.tokenUnknown);
                    continue;

                case CodeEx.Stelem_Any:
                    stack.Stelem_Any();
                    continue;

                case CodeEx.Unbox_Any:
                    stack.Unbox_Any();
                    continue;

                case CodeEx.Conv_Ovf_I1:
                    stack.Conv_Ovf_I1();
                    continue;

                case CodeEx.Conv_Ovf_U1:
                    stack.Conv_Ovf_U1();
                    continue;

                case CodeEx.Conv_Ovf_I2:
                    stack.Conv_Ovf_I2();
                    continue;

                case CodeEx.Conv_Ovf_U2:
                    stack.Conv_Ovf_U2();
                    continue;

                case CodeEx.Conv_Ovf_I4:
                    stack.Conv_Ovf_I4();
                    continue;

                case CodeEx.Conv_Ovf_U4:
                    stack.Conv_Ovf_U4();
                    continue;

                case CodeEx.Conv_Ovf_I8:
                    stack.Conv_Ovf_I8();
                    continue;

                case CodeEx.Conv_Ovf_U8:
                    stack.Conv_Ovf_U8();
                    continue;

                case CodeEx.Refanyval:
                    stack.Refanyval(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Ckfinite:
                    stack.Ckfinite();
                    continue;

                case CodeEx.Mkrefany:
                    stack.Mkrefany(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Ldtoken:
                    stack.Ldtoken(this, this.GetToken(opCode.tokenUnknown));
                    continue;

                case CodeEx.Conv_U2:
                    stack.Conv_U2();
                    continue;

                case CodeEx.Conv_U1:
                    stack.Conv_U1();
                    continue;

                case CodeEx.Conv_I:
                    stack.Conv_I();
                    continue;

                case CodeEx.Conv_Ovf_I:
                    stack.Conv_Ovf_I();
                    continue;

                case CodeEx.Conv_Ovf_U:
                    stack.Conv_Ovf_U();
                    continue;

                case CodeEx.Add_Ovf:
                    stack.Add_Ovf(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Add_Ovf_Un:
                    stack.Add_Ovf_Un(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Mul_Ovf:
                    stack.Mul_Ovf(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Mul_Ovf_Un:
                    stack.Mul_Ovf_Un(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Sub_Ovf:
                    stack.Sub_Ovf(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Sub_Ovf_Un:
                    stack.Sub_Ovf_Un(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Endfinally:
                    stack.Endfinally(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Leave:
                    stack.Leave(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Leave_S:
                    stack.Leave(opCode.tokenAddr_Index);
                    continue;

                case CodeEx.Stind_I:
                    stack.Stind_I(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Conv_U:
                    stack.Conv_U();
                    continue;

                case CodeEx.Arglist:
                    stack.Arglist(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Ceq:
                    stack.Ceq();
                    continue;

                case CodeEx.Cgt:
                    stack.Cgt();
                    continue;

                case CodeEx.Cgt_Un:
                    stack.Cgt_Un();
                    continue;

                case CodeEx.Clt:
                    stack.Clt();
                    continue;

                case CodeEx.Clt_Un:
                    stack.Clt_Un();
                    continue;

                case CodeEx.Ldftn:
                    stack.Ldftn(this, opCode.tokenMethod);
                    continue;

                case CodeEx.Ldvirtftn:
                    stack.Ldvirtftn(this, opCode.tokenMethod);
                    continue;

                case CodeEx.Ldarg:
                {
                    bool isStatic4 = body.bodyNative.Method.IsStatic;
                    if (isStatic4)
                    {
                        stack.Ldarg(opCode.tokenI32);
                    }
                    else
                    {
                        stack.Ldarg(opCode.tokenI32 + 1);
                    }
                    continue;
                }

                case CodeEx.Ldarga:
                {
                    bool isStatic5 = body.bodyNative.Method.IsStatic;
                    if (isStatic5)
                    {
                        stack.Ldarga(opCode.tokenI32);
                    }
                    else
                    {
                        stack.Ldarga(opCode.tokenI32 + 1);
                    }
                    continue;
                }

                case CodeEx.Starg:
                {
                    bool isStatic6 = body.bodyNative.Method.IsStatic;
                    if (isStatic6)
                    {
                        stack.Starg(this, opCode.tokenI32);
                    }
                    else
                    {
                        stack.Starg(this, opCode.tokenI32 + 1);
                    }
                    continue;
                }

                case CodeEx.Ldloc:
                    stack.Ldloc(opCode.tokenI32);
                    continue;

                case CodeEx.Ldloca:
                    stack.Ldloca(opCode.tokenI32);
                    continue;

                case CodeEx.Stloc:
                    stack.Stloc(opCode.tokenI32);
                    continue;

                case CodeEx.Localloc:
                    stack.Localloc(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Endfilter:
                    stack.Endfilter(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Unaligned:
                    stack.Unaligned(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Volatile:
                    stack.Volatile();
                    continue;

                case CodeEx.Tail:
                    stack.Tail(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Initobj:
                    stack.Initobj(this, opCode.tokenType);
                    continue;

                case CodeEx.Constrained:
                    stack.Constrained(this, opCode.tokenType);
                    continue;

                case CodeEx.Cpblk:
                    stack.Cpblk(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Initblk:
                    stack.Initblk(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.No:
                    stack.No(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Rethrow:
                    stack.Rethrow(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Sizeof:
                    stack.Sizeof(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Refanytype:
                    stack.Refanytype(this, opCode.tokenUnknown);
                    continue;

                case CodeEx.Readonly:
                    stack.Readonly(this, opCode.tokenUnknown);
                    continue;
                }
                break;
            }
            throw new Exception("未实现的OpCode:" + opCode.code);
IL_3CF:
            stack.Ret();
        }
Example #3
0
        void RunCode(StackFrame stack, Mono.Collections.Generic.Collection <Mono.Cecil.Cil.Instruction> codes)
        {
            while (true)
            {
                var code = stack._pos;
                if (DebugLevel >= 9)
                {
                    environment.logger.Log(code.ToString());
                }
                switch (code.OpCode.Code)
                {
                ///////////
                //流程控制

                case Code.Nop:
                    stack.Nop();
                    break;

                case Code.Ret:
                    stack.Ret();
                    return;

                case Code.Leave:
                    stack.Leave(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Leave_S:
                    //stack.Ret();
                    stack.Leave(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                //流程控制之goto
                case Code.Br:
                    stack.Br(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Br_S:
                    stack.Br(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Brtrue:
                    stack.Brtrue(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Brtrue_S:
                    stack.Brtrue(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Brfalse:
                    stack.Brfalse(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Brfalse_S:
                    stack.Brfalse(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                //比较流程控制
                case Code.Beq:
                    stack.Beq(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Beq_S:
                    stack.Beq(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bne_Un:
                    stack.Bne_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bne_Un_S:
                    stack.Bne_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bge:
                    stack.Bge(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bge_S:
                    stack.Bge(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bge_Un:
                    stack.Bge_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bge_Un_S:
                    stack.Bge_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bgt:
                    stack.Bgt(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bgt_S:
                    stack.Bgt(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bgt_Un:
                    stack.Bgt_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Bgt_Un_S:
                    stack.Bge_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Ble:
                    stack.Ble(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Ble_S:
                    stack.Ble(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Ble_Un:
                    stack.Ble_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Ble_Un_S:
                    stack.Ble_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Blt:
                    stack.Blt(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Blt_S:
                    stack.Blt(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Blt_Un:
                    stack.Blt_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                case Code.Blt_Un_S:
                    stack.Ble_Un(code.Operand as Mono.Cecil.Cil.Instruction);
                    break;

                //逻辑计算
                case Code.Ceq:
                    stack.Ceq();
                    break;

                case Code.Cgt:
                    stack.Cgt();
                    break;

                case Code.Cgt_Un:
                    stack.Cgt_Un();
                    break;

                case Code.Clt:
                    stack.Clt();
                    break;

                case Code.Clt_Un:
                    stack.Clt_Un();
                    break;

                case Code.Ckfinite:
                    stack.Ckfinite();
                    break;

                //常量加载
                case Code.Ldc_I4:
                    stack.Ldc_I4(code.Operand);
                    break;

                case Code.Ldc_I4_S:
                    stack.Ldc_I4_S(code.Operand);
                    break;

                case Code.Ldc_I4_M1:
                    stack.Ldc_I4(-1);
                    break;

                case Code.Ldc_I4_0:
                    stack.Ldc_I4(0);
                    break;

                case Code.Ldc_I4_1:
                    stack.Ldc_I4(1);
                    break;

                case Code.Ldc_I4_2:
                    stack.Ldc_I4(2);
                    break;

                case Code.Ldc_I4_3:
                    stack.Ldc_I4(3);
                    break;

                case Code.Ldc_I4_4:
                    stack.Ldc_I4(4);
                    break;

                case Code.Ldc_I4_5:
                    stack.Ldc_I4(5);
                    break;

                case Code.Ldc_I4_6:
                    stack.Ldc_I4(6);
                    break;

                case Code.Ldc_I4_7:
                    stack.Ldc_I4(7);
                    break;

                case Code.Ldc_I4_8:
                    stack.Ldc_I4(8);
                    break;

                case Code.Ldc_I8:
                    stack.Ldc_I8(code.Operand);
                    break;

                case Code.Ldc_R4:
                    stack.Ldc_R4(code.Operand);
                    break;

                case Code.Ldc_R8:
                    stack.Ldc_R8(code.Operand);
                    break;

                //定义为临时变量
                case Code.Stloc:
                    stack.Stloc((int)code.Operand);
                    break;

                case Code.Stloc_S:
                    stack.Stloc(((VariableDefinition)code.Operand).Index);
                    break;

                case Code.Stloc_0:
                    stack.Stloc(0);
                    break;

                case Code.Stloc_1:
                    stack.Stloc(1);
                    break;

                case Code.Stloc_2:
                    stack.Stloc(2);
                    break;

                case Code.Stloc_3:
                    stack.Stloc(3);
                    break;

                //从临时变量加载
                case Code.Ldloc:
                    stack.Ldloc((int)code.Operand);
                    break;

                case Code.Ldloc_S:
                    stack.Ldloc(((VariableDefinition)code.Operand).Index);
                    break;

                case Code.Ldloc_0:
                    stack.Ldloc(0);
                    break;

                case Code.Ldloc_1:
                    stack.Ldloc(1);
                    break;

                case Code.Ldloc_2:
                    stack.Ldloc(2);
                    break;

                case Code.Ldloc_3:
                    stack.Ldloc(3);
                    break;

                case Code.Ldloca:
                    stack.Ldloca(((VariableDefinition)code.Operand).Index);
                    break;

                case Code.Ldloca_S:
                    stack.Ldloca(((VariableDefinition)code.Operand).Index);
                    break;

                //加载字符串
                case Code.Ldstr:
                    stack.Ldstr(code.Operand as string);
                    break;

                //呼叫函数
                case Code.Call:
                    stack.Call(this, GetMethod(code.Operand));
                    break;

                case Code.Callvirt:
                    stack.Call(this, GetMethod(code.Operand));
                    break;

                //算术指令
                case Code.Add:
                    stack.Add();
                    break;

                case Code.Sub:
                    stack.Sub();
                    break;

                case Code.Mul:
                    stack.Mul();
                    break;

                case Code.Div:
                    stack.Div();
                    break;

                case Code.Div_Un:
                    stack.Div_Un();
                    break;

                case Code.Rem:
                    stack.Rem();
                    break;

                case Code.Rem_Un:
                    stack.Rem_Un();
                    break;

                case Code.Neg:
                    stack.Neg();
                    break;

                //装箱
                case Code.Box:
                    stack.Box();
                    break;

                case Code.Unbox:
                    stack.Unbox();
                    break;

                case Code.Unbox_Any:
                    stack.Unbox_Any();
                    break;

                //加载参数
                case Code.Ldarg:
                    stack.Ldarg((int)code.Operand);
                    break;

                case Code.Ldarg_S:
                    stack.Ldarg(GetParamPos(code.Operand));
                    break;

                case Code.Ldarg_0:
                    stack.Ldarg(0);
                    break;

                case Code.Ldarg_1:
                    stack.Ldarg(1);
                    break;

                case Code.Ldarg_2:
                    stack.Ldarg(2);
                    break;

                case Code.Ldarg_3:
                    stack.Ldarg(3);
                    break;

                //转换
                case Code.Conv_I1:
                    stack.Conv_I1();
                    break;

                case Code.Conv_U1:
                    stack.Conv_U1();
                    break;

                case Code.Conv_I2:
                    stack.Conv_I2();
                    break;

                case Code.Conv_U2:
                    stack.Conv_U2();
                    break;

                case Code.Conv_I4:
                    stack.Conv_I4();
                    break;

                case Code.Conv_U4:
                    stack.Conv_U4();
                    break;

                case Code.Conv_I8:
                    stack.Conv_I8();
                    break;

                case Code.Conv_U8:
                    stack.Conv_U8();
                    break;

                case Code.Conv_I:
                    stack.Conv_I();
                    break;

                case Code.Conv_U:
                    stack.Conv_U();
                    break;

                case Code.Conv_R4:
                    stack.Conv_R4();
                    break;

                case Code.Conv_R8:
                    stack.Conv_R8();
                    break;

                case Code.Conv_R_Un:
                    stack.Conv_R_Un();
                    break;

                case Code.Conv_Ovf_I1:
                    stack.Conv_Ovf_I1();
                    break;

                case Code.Conv_Ovf_U1:
                    stack.Conv_Ovf_U1();
                    break;

                case Code.Conv_Ovf_I2:
                    stack.Conv_Ovf_I2();
                    break;

                case Code.Conv_Ovf_U2:
                    stack.Conv_Ovf_U2();
                    break;

                case Code.Conv_Ovf_I4:
                    stack.Conv_Ovf_I4();
                    break;

                case Code.Conv_Ovf_U4:
                    stack.Conv_Ovf_U4();
                    break;

                case Code.Conv_Ovf_I8:
                    stack.Conv_Ovf_I8();
                    break;

                case Code.Conv_Ovf_U8:
                    stack.Conv_Ovf_U8();
                    break;

                case Code.Conv_Ovf_I:
                    stack.Conv_Ovf_I();
                    break;

                case Code.Conv_Ovf_U:
                    stack.Conv_Ovf_U();
                    break;

                case Code.Conv_Ovf_I1_Un:
                    stack.Conv_Ovf_I1_Un();
                    break;

                case Code.Conv_Ovf_U1_Un:
                    stack.Conv_Ovf_U1_Un();
                    break;

                case Code.Conv_Ovf_I2_Un:
                    stack.Conv_Ovf_I2_Un();
                    break;

                case Code.Conv_Ovf_U2_Un:
                    stack.Conv_Ovf_U2_Un();
                    break;

                case Code.Conv_Ovf_I4_Un:
                    stack.Conv_Ovf_I4_Un();
                    break;

                case Code.Conv_Ovf_U4_Un:
                    stack.Conv_Ovf_U4_Un();
                    break;

                case Code.Conv_Ovf_I8_Un:
                    stack.Conv_Ovf_I8_Un();
                    break;

                case Code.Conv_Ovf_U8_Un:
                    stack.Conv_Ovf_U8_Un();
                    break;

                case Code.Conv_Ovf_I_Un:
                    stack.Conv_Ovf_I_Un();
                    break;

                case Code.Conv_Ovf_U_Un:
                    stack.Conv_Ovf_U_Un();
                    break;

                //数组
                case Code.Newarr:
                    stack.NewArr(this, GetNewForArray(code.Operand));
                    break;

                case Code.Ldlen:
                    stack.LdLen();
                    break;

                case Code.Ldelema:
                    stack.Ldelema((Mono.Cecil.TypeReference)code.Operand);
                    break;

                case Code.Ldelem_I1:
                    stack.Ldelem_I1();
                    break;

                case Code.Ldelem_U1:
                    stack.Ldelem_U1();
                    break;

                case Code.Ldelem_I2:
                    stack.Ldelem_I2();
                    break;

                case Code.Ldelem_U2:
                    stack.Ldelem_U2();
                    break;

                case Code.Ldelem_I4:
                    stack.Ldelem_I4();
                    break;

                case Code.Ldelem_U4:
                    stack.Ldelem_U4();
                    break;

                case Code.Ldelem_I8:
                    stack.Ldelem_I8();
                    break;

                case Code.Ldelem_I:
                    stack.Ldelem_I();
                    break;

                case Code.Ldelem_R4:
                    stack.Ldelem_R4();
                    break;

                case Code.Ldelem_R8:
                    stack.Ldelem_R8();
                    break;

                case Code.Ldelem_Ref:
                    stack.Ldelem_Ref();
                    break;

                case Code.Ldelem_Any:
                    stack.Ldelem_Any((Mono.Cecil.TypeReference)code.Operand);
                    break;

                case Code.Stelem_I:
                    stack.Stelem_I();
                    break;

                case Code.Stelem_I1:
                    stack.Stelem_I1();
                    break;

                case Code.Stelem_I2:
                    stack.Stelem_I2();
                    break;

                case Code.Stelem_I4:
                    stack.Stelem_I4();
                    break;

                case Code.Stelem_I8:
                    stack.Stelem_I8();
                    break;

                case Code.Stelem_R4:
                    stack.Stelem_R4();
                    break;

                case Code.Stelem_R8:
                    stack.Stelem_R8();
                    break;

                case Code.Stelem_Ref:
                    stack.Stelem_Ref();
                    break;

                case Code.Stelem_Any:
                    stack.Stelem_Any((Mono.Cecil.TypeReference)code.Operand);
                    break;

                case Code.Newobj:
                    stack.NewObj(this, GetMethod(code.Operand));
                    break;

                case Code.Dup:
                    stack.Dup();
                    break;

                case Code.Pop:
                    stack.Pop();
                    break;

                case Code.Ldfld:
                    stack.Ldfld(this, GetField(code.Operand));
                    break;

                case Code.Ldflda:
                    stack.Ldflda(this, GetField(code.Operand));
                    break;

                case Code.Ldsfld:
                    stack.Ldsfld(this, GetField(code.Operand));
                    break;

                case Code.Ldsflda:
                    stack.Ldsflda(this, GetField(code.Operand));
                    break;

                case Code.Stfld:
                    stack.Stfld(this, GetField(code.Operand));
                    break;

                case Code.Stsfld:
                    stack.Stsfld(this, GetField(code.Operand));
                    break;


                case Code.Constrained:
                    stack.Constrained(this, code.Operand as Mono.Cecil.TypeReference);
                    break;

                case Code.Isinst:
                    stack.Isinst(this, GetType(code.Operand));
                    break;

                case Code.Ldtoken:
                    stack.Ldtoken(this, GetToken(code.Operand));
                    break;

                case Code.Ldftn:
                    stack.Ldftn(this, GetMethod(code.Operand));
                    break;

                case Code.Ldvirtftn:
                    stack.Ldvirtftn(this, GetMethod(code.Operand));
                    break;

                case Code.Ldarga:
                    stack.Ldarga(this, code.Operand);
                    break;

                case Code.Ldarga_S:
                    stack.Ldarga(this, code.Operand);
                    break;

                case Code.Calli:
                    stack.Calli(this, code.Operand);
                    break;

                ///下面是还没有处理的指令
                case Code.Break:
                    stack.Break(this, code.Operand);
                    break;

                case Code.Starg_S:
                    stack.Starg_S(this, code.Operand);
                    break;

                case Code.Ldnull:
                    stack.Ldnull();
                    break;

                case Code.Jmp:
                    stack.Jmp(this, code.Operand);
                    break;

                case Code.Switch:
                    stack.Switch(this, code.Operand);
                    break;

                case Code.Ldind_I1:
                    stack.Ldind_I1(this, code.Operand);
                    break;

                case Code.Ldind_U1:
                    stack.Ldind_U1(this, code.Operand);
                    break;

                case Code.Ldind_I2:
                    stack.Ldind_I2(this, code.Operand);
                    break;

                case Code.Ldind_U2:
                    stack.Ldind_U2(this, code.Operand);
                    break;

                case Code.Ldind_I4:
                    stack.Ldind_I4(this, code.Operand);
                    break;

                case Code.Ldind_U4:
                    stack.Ldind_U4(this, code.Operand);
                    break;

                case Code.Ldind_I8:
                    stack.Ldind_I8(this, code.Operand);
                    break;

                case Code.Ldind_I:
                    stack.Ldind_I(this, code.Operand);
                    break;

                case Code.Ldind_R4:
                    stack.Ldind_R4(this, code.Operand);
                    break;

                case Code.Ldind_R8:
                    stack.Ldind_R8(this, code.Operand);
                    break;

                case Code.Ldind_Ref:
                    stack.Ldind_Ref(this, code.Operand);
                    break;

                case Code.Stind_Ref:
                    stack.Stind_Ref(this, code.Operand);
                    break;

                case Code.Stind_I1:
                    stack.Stind_I1(this, code.Operand);
                    break;

                case Code.Stind_I2:
                    stack.Stind_I2(this, code.Operand);
                    break;

                case Code.Stind_I4:
                    stack.Stind_I4(this, code.Operand);
                    break;

                case Code.Stind_I8:
                    stack.Stind_I8(this, code.Operand);
                    break;

                case Code.Stind_R4:
                    stack.Stind_R4(this, code.Operand);
                    break;

                case Code.Stind_R8:
                    stack.Stind_R8(this, code.Operand);
                    break;

                case Code.And:
                    stack.And(this, code.Operand);
                    break;

                case Code.Or:
                    stack.Or(this, code.Operand);
                    break;

                case Code.Xor:
                    stack.Xor(this, code.Operand);
                    break;

                case Code.Shl:
                    stack.Shl(this, code.Operand);
                    break;

                case Code.Shr:
                    stack.Shr(this, code.Operand);
                    break;

                case Code.Shr_Un:
                    stack.Shr_Un(this, code.Operand);
                    break;

                case Code.Not:
                    stack.Not(this, code.Operand);
                    break;

                case Code.Cpobj:
                    stack.Cpobj(this, code.Operand);
                    break;

                case Code.Ldobj:
                    stack.Ldobj(this, code.Operand);
                    break;

                case Code.Castclass:
                    stack.Castclass(this, code.Operand);
                    break;

                case Code.Throw:
                    stack.Throw(this, code.Operand);
                    break;

                case Code.Stobj:
                    stack.Stobj(this, code.Operand);
                    break;

                case Code.Refanyval:
                    stack.Refanyval(this, code.Operand);
                    break;

                case Code.Mkrefany:
                    stack.Mkrefany(this, code.Operand);
                    break;

                case Code.Add_Ovf:
                    stack.Add_Ovf(this, code.Operand);
                    break;

                case Code.Add_Ovf_Un:
                    stack.Add_Ovf_Un(this, code.Operand);
                    break;

                case Code.Mul_Ovf:
                    stack.Mul_Ovf(this, code.Operand);
                    break;

                case Code.Mul_Ovf_Un:
                    stack.Mul_Ovf_Un(this, code.Operand);
                    break;

                case Code.Sub_Ovf:
                    stack.Sub_Ovf(this, code.Operand);
                    break;

                case Code.Sub_Ovf_Un:
                    stack.Sub_Ovf_Un(this, code.Operand);
                    break;

                case Code.Endfinally:
                    stack.Endfinally(this, code.Operand);
                    break;

                case Code.Stind_I:
                    stack.Stind_I(this, code.Operand);
                    break;

                case Code.Arglist:
                    stack.Arglist(this, code.Operand);
                    break;

                case Code.Starg:
                    stack.Starg(this, code.Operand);
                    break;

                case Code.Localloc:
                    stack.Localloc(this, code.Operand);
                    break;

                case Code.Endfilter:
                    stack.Endfilter(this, code.Operand);
                    break;

                case Code.Unaligned:
                    stack.Unaligned(this, code.Operand);
                    break;

                case Code.Volatile:
                    stack.Volatile(this, code.Operand);
                    break;

                case Code.Tail:
                    stack.Tail(this, code.Operand);
                    break;

                case Code.Initobj:
                    stack.Initobj(this, code.Operand);
                    break;

                case Code.Cpblk:
                    stack.Cpblk(this, code.Operand);
                    break;

                case Code.Initblk:
                    stack.Initblk(this, code.Operand);
                    break;

                case Code.No:
                    stack.No(this, code.Operand);
                    break;

                case Code.Rethrow:
                    stack.Rethrow(this, code.Operand);
                    break;

                case Code.Sizeof:
                    stack.Sizeof(this, code.Operand);
                    break;

                case Code.Refanytype:
                    stack.Refanytype(this, code.Operand);
                    break;

                case Code.Readonly:
                    stack.Readonly(this, code.Operand);
                    break;

                default:
                    throw new Exception("未实现的OpCode:" + code.OpCode.Code);
                }
            }
        }