コード例 #1
0
        /// <summary>
        /// Writes a <see cref="OperandType.ShortInlineBrTarget"/> operand
        /// </summary>
        /// <param name="writer">Instruction writer</param>
        /// <param name="instr">Instruction</param>
        protected virtual void WriteShortInlineBrTarget(ref ArrayWriter writer, Instruction instr)
        {
            int displ = (int)(GetOffset(instr.Operand as Instruction) - (ToInstructionOffset(ref writer) + 1));

            if (sbyte.MinValue <= displ && displ <= sbyte.MaxValue)
            {
                writer.WriteSByte((sbyte)displ);
            }
            else
            {
                Error("Target instruction is too far away for a short branch. Use the long branch or call CilBody.SimplifyBranches() and CilBody.OptimizeBranches()");
                writer.WriteByte(0);
            }
        }
コード例 #2
0
 /// <summary>
 /// Writes a <see cref="OperandType.ShortInlineI"/> operand
 /// </summary>
 /// <param name="writer">Instruction writer</param>
 /// <param name="instr">Instruction</param>
 protected virtual void WriteShortInlineI(ref ArrayWriter writer, Instruction instr)
 {
     if (instr.Operand is sbyte)
     {
         writer.WriteSByte((sbyte)instr.Operand);
     }
     else if (instr.Operand is byte)
     {
         writer.WriteByte((byte)instr.Operand);
     }
     else
     {
         Error("Operand is not a Byte or a SByte");
         writer.WriteByte(0);
     }
 }