void AddBlock(int index, AsmBlock block) { Span blockSpan = new Span(); AsmBlockDecorator decoratedBlock = new AsmBlockDecorator() { Block = block, Span = blockSpan, Instructions = new List <AsmInstructionDecorator>() }; m_decoratedFunction.Blocks.Add(decoratedBlock); foreach (AsmInstruction instruction in block.Instructions) { AsmInstructionDecorator decoratedInstruction = null; if (instruction.IsLabel) { AddPadding(blockSpan.Inlines, m_viewOptions.LabelPadding); decoratedInstruction = CreateLabel(instruction); } else { AddPadding(blockSpan.Inlines, m_viewOptions.InstructionPadding); decoratedInstruction = CreateInstruction(instruction); } decoratedBlock.Instructions.Add(decoratedInstruction); blockSpan.Inlines.Add(decoratedInstruction.Span); blockSpan.Inlines.Add(new Run(Environment.NewLine)); } m_text.Inlines.Add(blockSpan); }
AsmInstructionDecorator CreateInstruction(AsmInstruction instruction) { AsmInstructionDecorator decorator = new AsmInstructionDecorator() { Instruction = instruction, Span = new Span(), Name = CreateInstructionName(instruction), Args = CreateInstructionArgs(instruction), Comment = CreateInstructionComment(instruction) }; int column = m_viewOptions.InstructionPadding; decorator.Span.Inlines.Add(decorator.Name); column += instruction.Name.Length; if (column < m_viewOptions.InstructionArgsPadding) { Run padding = CreatePadding(m_viewOptions.InstructionArgsPadding - column); decorator.Span.Inlines.Add(padding); column = m_viewOptions.InstructionArgsPadding; } if (decorator.Args != null) { for (int i = 0; i < decorator.Args.Count; ++i) { AsmInstructionArgDecorator arg = decorator.Args[i]; decorator.Span.Inlines.Add(arg.Run); column += arg.Run.Text.Length; if ((i + 1) != decorator.Args.Count) { decorator.Span.Inlines.Add(new Run(", ")); column += 2; } } } if (decorator.Comment != null) { if (column < m_viewOptions.CommentPadding) { Run padding = CreatePadding(m_viewOptions.CommentPadding - column); decorator.Span.Inlines.Add(padding); } decorator.Span.Inlines.Add(decorator.Comment); } return(decorator); }
AsmInstructionDecorator CreateLabel(AsmInstruction label) { AsmInstructionDecorator decorator = new AsmInstructionDecorator() { Instruction = label, Span = new Span(), Name = new Run(label.Name) { Foreground = LabelForeground } }; decorator.Span.Inlines.Add(decorator.Name); return(decorator); }