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], FormatterTextKind.Text); count -= n; } }
public static void AddTabs(FormatterOutput output, int column, int firstOperandCharIndex, int tabSize) { #if DEBUG for (int i = 0; i < spaceStrings.Length; i++) { Debug.Assert(spaceStrings[i].Length == i + 1); } for (int i = 0; i < tabStrings.Length; i++) { 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 endColRoundedDown = endCol / tabSize * tabSize; bool addedTabs = endColRoundedDown > column; if (addedTabs) { int tabs = (endColRoundedDown - (column / tabSize * tabSize)) / tabSize; AddStrings(output, tabStrings, tabs); column = endColRoundedDown; } int spaces = firstOperandCharIndex - column; if (spaces > 0) { AddStrings(output, spaceStrings, spaces); } else if (!addedTabs) { AddStrings(output, spaceStrings, 1); } } }
/// <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);
/// <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);
/// <summary> /// Formats all operands /// </summary> /// <param name="instruction">Instruction</param> /// <param name="output">Output</param> public abstract void FormatAllOperands(ref Instruction instruction, FormatterOutput output);
/// <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);
/// <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);
/// <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);
/// <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);