Example #1
0
 Run CreateInstructionName(AsmInstruction instruction)
 {
     return(new Run(instruction.Name)
     {
         Foreground = InstructionNameForeground
     });
 }
Example #2
0
        AsmInstruction ParseInstruction(string line)
        {
            string trimmed = line.Trim();

            string[] tokens = trimmed.Split(InstructionSeparator, StringSplitOptions.RemoveEmptyEntries);

            // First argument is the instruction name.
            // Second argument can be parameters or comment.
            // Third argument, if present, is comment.

            Debug.Assert(tokens.Length > 0);
            Debug.Assert(tokens.Length < 4);

            AsmInstruction instruction = new AsmInstruction()
            {
                Name = tokens[0]
            };

            if (tokens.Length > 1)
            {
                if (tokens[1][0] == InstructionCommentStart)
                {
                    // There are no arguments for the instruction.
                    // The second argument is a comment.
                    instruction.Comment = tokens[1].Substring(2);
                }
                else
                {
                    // There still can be a comment on this line.
                    // Comments are sometimes not separated by tabs, but
                    // simple space.

                    if (tokens[1].IndexOf(InstructionCommentStart) != -1)
                    {
                        string[] argTokens = tokens[1].Split(InstructionCommentStart);
                        instruction.Args    = ParseInstructionArgs(argTokens[0]);
                        instruction.Comment = argTokens[1].TrimStart();
                    }
                    else
                    {
                        instruction.Args = ParseInstructionArgs(tokens[1]);
                    }
                }

                if (tokens.Length > 2)
                {
                    // The last token can be only comment.
                    Debug.Assert(tokens[2][0] == InstructionCommentStart);
                    instruction.Comment = tokens[2].Substring(2);
                }
            }

            return(instruction);
        }
Example #3
0
        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);
        }
Example #4
0
        Run CreateInstructionComment(AsmInstruction instruction)
        {
            Run comment = null;

            if (instruction.Comment != null)
            {
                comment = new Run("; " + instruction.Comment)
                {
                    Foreground = CommentForeground
                };
            }
            return(comment);
        }
Example #5
0
        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);
        }
Example #6
0
        List <AsmInstructionArgDecorator> CreateInstructionArgs(AsmInstruction instruction)
        {
            List <AsmInstructionArgDecorator> args = null;

            if (instruction.Args != null)
            {
                args = new List <AsmInstructionArgDecorator>();

                foreach (IAsmInstructionArg arg in instruction.Args)
                {
                    AsmInstructionArgDecorator decoratedArg = new AsmInstructionArgDecorator()
                    {
                        Arg = arg,
                        Run = CreateInstructionArg(arg)
                    };
                    args.Add(decoratedArg);
                }
            }

            return(args);
        }