Exemplo n.º 1
0
        void AddLine(ParsedSourceLine sourceLine)
        {
            int count = mInstructions.Count;

            if (mSourceBox.TextLength != 0)
            {
                mSourceBox.AppendText(Environment.NewLine);
            }

            var lineNumberText = (count + 1).ToString();

            mSourceBox.AppendText(new string(' ', mLineNumberLength - lineNumberText.Length) + lineNumberText + lineNumberSeparator);

            var processedLine = new ProcessedSourceLine(sourceLine, mSourceBox.TextLength);

            mInstructions.Add(processedLine);

            if (sourceLine.IsCommentLine)
            {
                if (sourceLine.Comment.Length > 0)
                {
                    mSourceBox.AppendText(sourceLine.Comment);
                }
            }
            else
            {
                mSourceBox.AppendText(sourceLine.LocationField + new string(' ', (processedLine.LocTextLength - sourceLine.LocationField.Length) + Parser.FieldSpacing));
                mSourceBox.AppendText(sourceLine.OpField + new string(' ', (processedLine.OpTextLength - sourceLine.OpField.Length) + Parser.FieldSpacing));
                mSourceBox.AppendText(sourceLine.AddressField + new string(' ', (processedLine.AddressTextLength - sourceLine.AddressField.Length) + Parser.FieldSpacing));
                if (sourceLine.Comment.Length > 0)
                {
                    mSourceBox.AppendText(sourceLine.Comment);
                }
            }

            ApplySyntaxColoring(processedLine);
        }
Exemplo n.º 2
0
        string GetAssemblyErrorsCaption(ParsedSourceLine line, AssemblyFindingCollection findings)
        {
            string caption       = "";
            int    findingNumber = 1;

            foreach (AssemblyFinding finding in findings)
            {
                string fieldLabel = "";

                if (finding.Severity == Severity.Error)
                {
                    switch (finding.LineSection)
                    {
                    case LineSection.OpField:
                        MarkAssemblyError(finding.StartCharIndex, finding.Length);
                        fieldLabel = "mnemonic";

                        break;

                    case LineSection.AddressField:
                        if (finding.Length != 0)
                        {
                            MarkAssemblyError((line.OpField.Length + finding.StartCharIndex) + 1, finding.Length);
                        }
                        else
                        {
                            MarkAssemblyError(line.OpField.Length + 1, line.AddressField.Length);
                        }
                        fieldLabel = "address";

                        break;

                    case LineSection.CommentField:

                        continue;

                    case LineSection.EntireLine:
                        MarkAssemblyError(0, TextLength);
                        fieldLabel = "instruction";

                        break;
                    }
                }

                if (findingNumber != 1)
                {
                    caption = string.Concat(caption, Environment.NewLine, findingNumber, ". ");
                }

                if (findingNumber == 2)
                {
                    caption = "1. " + caption;
                }

                caption = caption + fieldLabel + ": " + finding.Message;

                findingNumber++;
            }

            return(findingNumber == 2
                ? string.Concat("Instruction error: ", caption)
                : string.Concat("Instruction errors:", Environment.NewLine, caption));
        }
Exemplo n.º 3
0
        public static InstructionInstanceBase Assemble(string instructionLine, int locationCounter, out ParsedSourceLine parsedLine, SymbolCollection symbols, out AssemblyFindingCollection findings)
        {
            var status = new ParsingStatus(symbols)
            {
                LocationCounter = locationCounter,
                LineNumber      = 0
            };

            parsedLine = Parser.ParseInstructionLine(instructionLine, status);
            findings   = status.Findings;

            // if errors were found while parsing, abort assembly
            if (status.Findings.ContainsErrors)
            {
                return(null);
            }

            if (!parsedLine.IsDefined)
            {
                status.Findings.Add(new AssemblyError(0, LineSection.EntireLine, 0, 0, new ValidationError("line is not an instruction")));
                return(null);
            }

            status.LocationCounter = locationCounter;
            status.LineNumber      = 0;
            var instructionInstance = parsedLine.CreateInstance(status);

            // if errors were found while assembling, don't return the instruction instance: it would be useless anyway
            if (status.Findings.ContainsErrors)
            {
                return(null);
            }

            return(instructionInstance);
        }
Exemplo n.º 4
0
 public ProcessedSourceLine(ParsedSourceLine sourceLine, int lineTextIndex)
 {
     SourceLine    = sourceLine;
     LineTextIndex = lineTextIndex;
 }