コード例 #1
0
        public Instruction Create(OpCode opcode, int i)
        {
            if (opcode.OperandType == OperandType.InlineVar)
            {
                return(Create(opcode, m_mbody.Variables [i]));
            }

            if (opcode.OperandType == OperandType.InlineParam)
            {
                return(Create(opcode, CodeReader.GetParameter(m_mbody, i)));
            }

            if (opcode.OperandType != OperandType.InlineI)
            {
                throw new ArgumentException("opcode");
            }

            return(FinalCreate(opcode, i));
        }
コード例 #2
0
        public Instruction Create(OpCode opcode, byte b)
        {
            if (opcode.OperandType == OperandType.ShortInlineVar)
            {
                return(Create(opcode, m_mbody.Variables [b]));
            }

            if (opcode.OperandType == OperandType.ShortInlineParam)
            {
                return(Create(opcode, CodeReader.GetParameter(m_mbody, b)));
            }

            if (opcode.OperandType != OperandType.ShortInlineI ||
                opcode == OpCodes.Ldc_I4_S)
            {
                throw new ArgumentException("opcode");
            }

            return(FinalCreate(opcode, b));
        }
コード例 #3
0
        public void Simplify()
        {
            foreach (Instruction i in this.Instructions)
            {
                if (i.OpCode.OpCodeType != OpCodeType.Macro)
                {
                    continue;
                }

                switch (i.OpCode.Code)
                {
                case Code.Ldarg_0:
                    Modify(i, OpCodes.Ldarg,
                           CodeReader.GetParameter(this, 0));
                    break;

                case Code.Ldarg_1:
                    Modify(i, OpCodes.Ldarg,
                           CodeReader.GetParameter(this, 1));
                    break;

                case Code.Ldarg_2:
                    Modify(i, OpCodes.Ldarg,
                           CodeReader.GetParameter(this, 2));
                    break;

                case Code.Ldarg_3:
                    Modify(i, OpCodes.Ldarg,
                           CodeReader.GetParameter(this, 3));
                    break;

                case Code.Ldloc_0:
                    Modify(i, OpCodes.Ldloc,
                           CodeReader.GetVariable(this, 0));
                    break;

                case Code.Ldloc_1:
                    Modify(i, OpCodes.Ldloc,
                           CodeReader.GetVariable(this, 1));
                    break;

                case Code.Ldloc_2:
                    Modify(i, OpCodes.Ldloc,
                           CodeReader.GetVariable(this, 2));
                    break;

                case Code.Ldloc_3:
                    Modify(i, OpCodes.Ldloc,
                           CodeReader.GetVariable(this, 3));
                    break;

                case Code.Stloc_0:
                    Modify(i, OpCodes.Stloc,
                           CodeReader.GetVariable(this, 0));
                    break;

                case Code.Stloc_1:
                    Modify(i, OpCodes.Stloc,
                           CodeReader.GetVariable(this, 1));
                    break;

                case Code.Stloc_2:
                    Modify(i, OpCodes.Stloc,
                           CodeReader.GetVariable(this, 2));
                    break;

                case Code.Stloc_3:
                    Modify(i, OpCodes.Stloc,
                           CodeReader.GetVariable(this, 3));
                    break;

                case Code.Ldarg_S:
                    i.OpCode = OpCodes.Ldarg;
                    break;

                case Code.Ldarga_S:
                    i.OpCode = OpCodes.Ldarga;
                    break;

                case Code.Starg_S:
                    i.OpCode = OpCodes.Starg;
                    break;

                case Code.Ldloc_S:
                    i.OpCode = OpCodes.Ldloc;
                    break;

                case Code.Ldloca_S:
                    i.OpCode = OpCodes.Ldloca;
                    break;

                case Code.Stloc_S:
                    i.OpCode = OpCodes.Stloc;
                    break;

                case Code.Ldc_I4_M1:
                    Modify(i, OpCodes.Ldc_I4, -1);
                    break;

                case Code.Ldc_I4_0:
                    Modify(i, OpCodes.Ldc_I4, 0);
                    break;

                case Code.Ldc_I4_1:
                    Modify(i, OpCodes.Ldc_I4, 1);
                    break;

                case Code.Ldc_I4_2:
                    Modify(i, OpCodes.Ldc_I4, 2);
                    break;

                case Code.Ldc_I4_3:
                    Modify(i, OpCodes.Ldc_I4, 3);
                    break;

                case Code.Ldc_I4_4:
                    Modify(i, OpCodes.Ldc_I4, 4);
                    break;

                case Code.Ldc_I4_5:
                    Modify(i, OpCodes.Ldc_I4, 5);
                    break;

                case Code.Ldc_I4_6:
                    Modify(i, OpCodes.Ldc_I4, 6);
                    break;

                case Code.Ldc_I4_7:
                    Modify(i, OpCodes.Ldc_I4, 7);
                    break;

                case Code.Ldc_I4_8:
                    Modify(i, OpCodes.Ldc_I4, 8);
                    break;

                case Code.Ldc_I4_S:
                    i.OpCode  = OpCodes.Ldc_I4;
                    i.Operand = (int)(sbyte)i.Operand;
                    break;

                case Code.Br_S:
                    i.OpCode = OpCodes.Br;
                    break;

                case Code.Brfalse_S:
                    i.OpCode = OpCodes.Brfalse;
                    break;

                case Code.Brtrue_S:
                    i.OpCode = OpCodes.Brtrue;
                    break;

                case Code.Beq_S:
                    i.OpCode = OpCodes.Beq;
                    break;

                case Code.Bge_S:
                    i.OpCode = OpCodes.Bge;
                    break;

                case Code.Bgt_S:
                    i.OpCode = OpCodes.Bgt;
                    break;

                case Code.Ble_S:
                    i.OpCode = OpCodes.Ble;
                    break;

                case Code.Blt_S:
                    i.OpCode = OpCodes.Blt;
                    break;

                case Code.Bne_Un_S:
                    i.OpCode = OpCodes.Bne_Un;
                    break;

                case Code.Bge_Un_S:
                    i.OpCode = OpCodes.Bge_Un;
                    break;

                case Code.Bgt_Un_S:
                    i.OpCode = OpCodes.Bgt_Un;
                    break;

                case Code.Ble_Un_S:
                    i.OpCode = OpCodes.Ble_Un;
                    break;

                case Code.Blt_Un_S:
                    i.OpCode = OpCodes.Blt_Un;
                    break;

                case Code.Leave_S:
                    i.OpCode = OpCodes.Leave;
                    break;
                }
            }
        }