コード例 #1
0
        private void WriteOperand(CilInstruction instruction)
        {
            switch (instruction.OpCode.OperandType)
            {
            case CilOperandType.InlineNone:
                break;

            case CilOperandType.ShortInlineI:
                _writer.WriteSByte(OperandToSByte(instruction));
                break;

            case CilOperandType.InlineI:
                _writer.WriteInt32(OperandToInt32(instruction));
                break;

            case CilOperandType.InlineI8:
                _writer.WriteInt64(OperandToInt64(instruction));
                break;

            case CilOperandType.ShortInlineR:
                _writer.WriteSingle(OperandToFloat32(instruction));
                break;

            case CilOperandType.InlineR:
                _writer.WriteDouble(OperandToFloat64(instruction));
                break;

            case CilOperandType.ShortInlineVar:
                _writer.WriteByte((byte)OperandToLocalIndex(instruction));
                break;

            case CilOperandType.InlineVar:
                _writer.WriteUInt16(OperandToLocalIndex(instruction));
                break;

            case CilOperandType.ShortInlineArgument:
                _writer.WriteByte((byte)OperandToArgumentIndex(instruction));
                break;

            case CilOperandType.InlineArgument:
                _writer.WriteUInt16(OperandToArgumentIndex(instruction));
                break;

            case CilOperandType.ShortInlineBrTarget:
                _writer.WriteSByte((sbyte)OperandToBranchDelta(instruction));
                break;

            case CilOperandType.InlineBrTarget:
                _writer.WriteInt32(OperandToBranchDelta(instruction));
                break;

            case CilOperandType.InlineSwitch:
                var labels = (IList <ICilLabel>)instruction.Operand;
                _writer.WriteInt32(labels.Count);

                int baseOffset = (int)_writer.Offset + labels.Count * sizeof(int);
                for (int i = 0; i < labels.Count; i++)
                {
                    _writer.WriteInt32(labels[i].Offset - baseOffset);
                }

                break;

            case CilOperandType.InlineString:
                _writer.WriteUInt32(_operandBuilder.GetStringToken(instruction.Operand));
                break;

            case CilOperandType.InlineField:
            case CilOperandType.InlineMethod:
            case CilOperandType.InlineSig:
            case CilOperandType.InlineTok:
            case CilOperandType.InlineType:
                _writer.WriteUInt32(_operandBuilder.GetMemberToken(instruction.Operand).ToUInt32());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #2
0
        private void WriteOperand(CilInstruction instruction)
        {
            switch (instruction.OpCode.OperandType)
            {
            case CilOperandType.InlineNone:
                break;

            case CilOperandType.ShortInlineI:
                _writer.WriteSByte((sbyte)instruction.Operand);
                break;

            case CilOperandType.InlineI:
                _writer.WriteInt32((int)instruction.Operand);
                break;

            case CilOperandType.InlineI8:
                _writer.WriteInt64((long)instruction.Operand);
                break;

            case CilOperandType.ShortInlineR:
                _writer.WriteSingle((float)instruction.Operand);
                break;

            case CilOperandType.InlineR:
                _writer.WriteDouble((double)instruction.Operand);
                break;

            case CilOperandType.ShortInlineVar:
                _writer.WriteSByte((sbyte)_operandBuilder.GetVariableIndex(instruction.Operand));
                break;

            case CilOperandType.InlineVar:
                _writer.WriteUInt16((ushort)_operandBuilder.GetVariableIndex(instruction.Operand));
                break;

            case CilOperandType.ShortInlineArgument:
                _writer.WriteSByte((sbyte)_operandBuilder.GetArgumentIndex(instruction.Operand));
                break;

            case CilOperandType.InlineArgument:
                _writer.WriteUInt16((ushort)_operandBuilder.GetArgumentIndex(instruction.Operand));
                break;

            case CilOperandType.ShortInlineBrTarget:
                sbyte shortOffset = (sbyte)(((ICilLabel)instruction.Operand).Offset - (int)(_writer.Offset + sizeof(sbyte)));
                _writer.WriteSByte(shortOffset);
                break;

            case CilOperandType.InlineBrTarget:
                int longOffset = ((ICilLabel)instruction.Operand).Offset - (int)(_writer.Offset + sizeof(int));
                _writer.WriteInt32(longOffset);
                break;

            case CilOperandType.InlineSwitch:
                var labels = (IList <ICilLabel>)instruction.Operand;
                _writer.WriteInt32(labels.Count);

                int baseOffset = (int)_writer.Offset + labels.Count * sizeof(int);
                for (int i = 0; i < labels.Count; i++)
                {
                    _writer.WriteInt32(labels[i].Offset - baseOffset);
                }

                break;

            case CilOperandType.InlineString:
                _writer.WriteUInt32(_operandBuilder.GetStringToken(instruction.Operand));
                break;

            case CilOperandType.InlineField:
            case CilOperandType.InlineMethod:
            case CilOperandType.InlineSig:
            case CilOperandType.InlineTok:
            case CilOperandType.InlineType:
                _writer.WriteUInt32(_operandBuilder.GetMemberToken(instruction.Operand).ToUInt32());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }