private ushort OperandToArgumentIndex(CilInstruction instruction) { int variableIndex = _operandBuilder.GetArgumentIndex(instruction.Operand); if (instruction.OpCode.OperandType == CilOperandType.ShortInlineArgument && variableIndex > byte.MaxValue) { throw new OverflowException( $"Argument index at offset IL_{instruction.Offset:X4} is too large for a ShortInlineArgument instruction."); } return(unchecked ((ushort)variableIndex)); }
private ushort OperandToArgumentIndex(CilInstruction instruction) { int variableIndex = _operandBuilder.GetArgumentIndex(instruction.Operand); if (instruction.OpCode.OperandType == CilOperandType.ShortInlineArgument && variableIndex > byte.MaxValue) { _errorListener.RegisterException(new OverflowException( $"{_diagnosticPrefix}Argument index at IL_{instruction.Offset:X4} is too large for a ShortInlineArgument instruction.")); } return(unchecked ((ushort)variableIndex)); }
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(); } }