Esempio n. 1
0
        public static void Emit(this SRE::ILGenerator gen, OpCodeEx opcode, int arg)
        {
            if (gen == null)
            {
                throw new ArgumentNullException("gen");
            }

            if (opcode == OpCodes.Ldloc_Opt)
            {
                gen.Emit_Ldloc(arg);
            }
            else if (opcode == OpCodes.Ldloca_Opt)
            {
                gen.Emit_Ldloca(arg);
            }
            else if (opcode == OpCodes.Stloc_Opt)
            {
                gen.Emit_Stloc(arg);
            }
            else if (opcode == OpCodes.Ldc_I4_Opt)
            {
                gen.Emit_Ldc_I4(arg);
            }
            else if (opcode == OpCodes.Ldarg_Opt)
            {
                gen.Emit_Ldarg(arg);
            }
        }
Esempio n. 2
0
        static void Emit_Ldarg(this SRE::ILGenerator gen, int arg)
        {
            Debug.Assert(gen != null);

            switch (arg)
            {
            case 0: gen.Emit(SRE::OpCodes.Ldarg_0); break;

            case 1: gen.Emit(SRE::OpCodes.Ldarg_1); break;

            case 2: gen.Emit(SRE::OpCodes.Ldarg_2); break;

            case 3: gen.Emit(SRE::OpCodes.Ldarg_3); break;

            default:
                if ((int)byte.MinValue <= arg && arg <= (int)byte.MaxValue)
                {
                    gen.Emit(SRE::OpCodes.Ldarg_S, (byte)arg);
                }
                else if ((int)short.MinValue <= arg && arg <= (int)short.MaxValue)
                {
                    gen.Emit(SRE::OpCodes.Ldarg, (short)arg);
                }
                else
                {
                    throw new NotSupportedException("The ldargXX instruction can be specified to the value within the range of 'System.Int16.MaxValue'.");
                }
                break;
            }
        }
Esempio n. 3
0
        static void Emit_Stloc(this SRE::ILGenerator gen, int arg)
        {
            Debug.Assert(gen != null);

            switch (arg)
            {
            case 0: gen.Emit(SRE::OpCodes.Stloc_0); break;

            case 1: gen.Emit(SRE::OpCodes.Stloc_1); break;

            case 2: gen.Emit(SRE::OpCodes.Stloc_2); break;

            case 3: gen.Emit(SRE::OpCodes.Stloc_3); break;

            default:
                if ((int)byte.MinValue <= arg && arg <= (int)byte.MaxValue)
                {
                    gen.Emit(SRE::OpCodes.Stloc_S, (byte)arg);
                }
                else
                {
                    gen.Emit(SRE::OpCodes.Stloc, arg);
                }
                break;
            }
        }
Esempio n. 4
0
        static void Emit_Box(this SRE::ILGenerator gen, Type cls)
        {
            Debug.Assert(gen != null);

            if (cls.IsValueType)
            {
                gen.Emit(OpCodes.Box, cls);
            }
        }
Esempio n. 5
0
        static void Emit_Unbox(this SRE::ILGenerator gen, Type cls)
        {
            Debug.Assert(gen != null);

            if (cls.IsValueType)
            {
                gen.Emit(OpCodes.Unbox_Any, cls);
            }
            else
            {
                gen.Emit(OpCodes.Castclass, cls);
            }
        }
Esempio n. 6
0
        static void Emit_Ldloca(this SRE::ILGenerator gen, int arg)
        {
            Debug.Assert(gen != null);

            if ((int)byte.MinValue <= arg && arg <= (int)byte.MaxValue)
            {
                gen.Emit(SRE::OpCodes.Ldloca_S, (byte)arg);
            }
            else
            {
                gen.Emit(SRE::OpCodes.Ldloca, arg);
            }
        }
Esempio n. 7
0
        public static void Emit(this SRE::ILGenerator gen, OpCodeEx opcode, Type cls)
        {
            if (gen == null)
            {
                throw new ArgumentNullException("gen");
            }

            if (opcode == OpCodes.Unbox_Opt)
            {
                gen.Emit_Unbox(cls);
            }
            else if (opcode == OpCodes.Box_Opt)
            {
                gen.Emit_Box(cls);
            }
        }
Esempio n. 8
0
        static void Emit_Ldc_I4(this SRE::ILGenerator gen, int arg)
        {
            Debug.Assert(gen != null);

            switch (arg)
            {
            case -1: gen.Emit(SRE::OpCodes.Ldc_I4_M1); break;

            case 0: gen.Emit(SRE::OpCodes.Ldc_I4_0); break;

            case 1: gen.Emit(SRE::OpCodes.Ldc_I4_1); break;

            case 2: gen.Emit(SRE::OpCodes.Ldc_I4_2); break;

            case 3: gen.Emit(SRE::OpCodes.Ldc_I4_3); break;

            case 4: gen.Emit(SRE::OpCodes.Ldc_I4_4); break;

            case 5: gen.Emit(SRE::OpCodes.Ldc_I4_5); break;

            case 6: gen.Emit(SRE::OpCodes.Ldc_I4_6); break;

            case 7: gen.Emit(SRE::OpCodes.Ldc_I4_7); break;

            case 8: gen.Emit(SRE::OpCodes.Ldc_I4_8); break;

            default:
                if ((int)byte.MinValue <= arg && arg <= (int)byte.MaxValue)
                {
                    gen.Emit(SRE::OpCodes.Ldc_I4_S, (byte)arg);
                }
                else
                {
                    gen.Emit(SRE::OpCodes.Ldc_I4, arg);
                }
                break;
            }
        }