private int OperandToBranchDelta(CilInstruction instruction) { bool isShort = instruction.OpCode.OperandType == CilOperandType.ShortInlineBrTarget; int delta; switch (instruction.Operand) { case sbyte x: delta = x; break; case int x: delta = x; break; case ICilLabel label: int operandSize = isShort ? sizeof(sbyte) : sizeof(int); delta = label.Offset - (int)(_writer.Offset + (ulong)operandSize); break; default: return(ThrowInvalidOperandType <sbyte>(instruction, typeof(ICilLabel), typeof(sbyte))); } if (isShort && (delta < sbyte.MinValue || delta > sbyte.MaxValue)) { _errorListener.RegisterException(new OverflowException( $"{_diagnosticPrefix}Branch target at IL_{instruction.Offset:X4} is too far away for a ShortInlineBr instruction.")); } return(delta); }
/// <summary> /// Registers an error, and returns a default value for the provided type. /// </summary> /// <param name="self">The error listener.</param> /// <param name="exception">The error.</param> /// <typeparam name="T">The type of value to return.</typeparam> public static T RegisterExceptionAndReturnDefault <T>(this IErrorListener self, Exception exception) { self.RegisterException(exception); return(default);
/// <summary> /// Registers an instance of a <see cref="BadImageFormatException"/> class. /// </summary> /// <param name="self">The error listener.</param> /// <param name="message">The message of the error.</param> public static void BadImage(this IErrorListener self, string message) { self.RegisterException(new BadImageFormatException(message)); }
/// <summary> /// Registers an instance of a <see cref="NotSupportedException"/> class. /// </summary> /// <param name="self">The error listener.</param> /// <param name="message">The message of the error.</param> public static void NotSupported(this IErrorListener self, string message) { self.RegisterException(new NotSupportedException(message)); }
public static void MetadataBuilder(this IErrorListener listener, string message) { listener.RegisterException(new MetadataBuilderException(message)); }