Ejemplo n.º 1
0
        public static void AddTabs(FormatterOutput output, int column, int firstOperandCharIndex, int tabSize)
        {
#if DEBUG
            for (int i = 0; i < spaceStrings.Length; i++)
            {
                System.Diagnostics.Debug.Assert(spaceStrings[i].Length == i + 1);
            }
            for (int i = 0; i < tabStrings.Length; i++)
            {
                System.Diagnostics.Debug.Assert(tabStrings[i].Length == i + 1);
            }
#endif
            const int max_firstOperandCharIndex = 256;
            if (firstOperandCharIndex < 0)
            {
                firstOperandCharIndex = 0;
            }
            else if (firstOperandCharIndex > max_firstOperandCharIndex)
            {
                firstOperandCharIndex = max_firstOperandCharIndex;
            }

            if (tabSize <= 0)
            {
                int charsLeft = firstOperandCharIndex - column;
                if (charsLeft <= 0)
                {
                    charsLeft = 1;
                }
                AddStrings(output, spaceStrings, charsLeft);
            }
            else
            {
                int endCol = firstOperandCharIndex;
                if (endCol <= column)
                {
                    endCol = column + 1;
                }
                int  endColRoundDown = endCol / tabSize * tabSize;
                bool addedTabs       = endColRoundDown > column;
                if (addedTabs)
                {
                    int tabs = (endColRoundDown - (column / tabSize * tabSize)) / tabSize;
                    AddStrings(output, tabStrings, tabs);
                    column = endColRoundDown;
                }
                int spaces = firstOperandCharIndex - column;
                if (spaces > 0)
                {
                    AddStrings(output, spaceStrings, spaces);
                }
                else if (!addedTabs)
                {
                    AddStrings(output, spaceStrings, 1);
                }
            }
        }
Ejemplo n.º 2
0
 static void AddStrings(FormatterOutput output, string[] strings, int count)
 {
     while (count > 0)
     {
         int n = count;
         if (n >= strings.Length)
         {
             n = strings.Length;
         }
         output.Write(strings[n - 1], FormatterOutputTextKind.Text);
         count -= n;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Formats the mnemonic and any prefixes
 /// </summary>
 /// <param name="instruction">Instruction</param>
 /// <param name="output">Output</param>
 public void FormatMnemonic(ref Instruction instruction, FormatterOutput output) =>
 FormatMnemonic(ref instruction, output, FormatMnemonicOptions.None);
Ejemplo n.º 4
0
 /// <summary>
 /// Formats the mnemonic and any prefixes
 /// </summary>
 /// <param name="instruction">Instruction</param>
 /// <param name="output">Output</param>
 /// <param name="options">Options</param>
 public abstract void FormatMnemonic(ref Instruction instruction, FormatterOutput output, FormatMnemonicOptions options);
Ejemplo n.º 5
0
 /// <summary>
 /// Formats the whole instruction: prefixes, mnemonic, operands
 /// </summary>
 /// <param name="instruction">Instruction</param>
 /// <param name="output">Output</param>
 public void Format(Instruction instruction, FormatterOutput output) => Format(ref instruction, output);
Ejemplo n.º 6
0
 /// <summary>
 /// Formats the whole instruction: prefixes, mnemonic, operands
 /// </summary>
 /// <param name="instruction">Instruction</param>
 /// <param name="output">Output</param>
 public abstract void Format(ref Instruction instruction, FormatterOutput output);
Ejemplo n.º 7
0
 /// <summary>
 /// Formats all operands
 /// </summary>
 /// <param name="instruction">Instruction</param>
 /// <param name="output">Output</param>
 public abstract void FormatAllOperands(ref Instruction instruction, FormatterOutput output);
Ejemplo n.º 8
0
 /// <summary>
 /// Formats an operand separator
 /// </summary>
 /// <param name="instruction">Instruction</param>
 /// <param name="output">Output</param>
 public abstract void FormatOperandSeparator(ref Instruction instruction, FormatterOutput output);
Ejemplo n.º 9
0
 /// <summary>
 /// Formats an operand. This is a formatter operand and not necessarily a real instruction operand.
 /// A formatter can add and remove operands.
 /// </summary>
 /// <param name="instruction">Instruction</param>
 /// <param name="output">Output</param>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.
 /// See <see cref="GetOperandCount(ref Instruction)"/></param>
 public abstract void FormatOperand(ref Instruction instruction, FormatterOutput output, int operand);