Exemplo n.º 1
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], FormatterTextKind.Text);
				count -= n;
			}
		}
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
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);
Exemplo n.º 4
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);
Exemplo n.º 5
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);
Exemplo n.º 6
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);
Exemplo n.º 7
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);
Exemplo n.º 8
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);
Exemplo n.º 9
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);