public void AppendCommentToProgramLine(int commentedLineAddress, string comment) { ProgramLine commentedLine = GetLineFromAddress(commentedLineAddress); string newLineTextWithComment = commentedLine.Text + " ; " + comment; ProgramLine newLineWithComment = Assembler.ParseProgramLine(newLineTextWithComment); commentedLine.CopyTextualRepresentationFrom(newLineWithComment); }
public static void PrefixLabelToProgramLine(string labelName, ProgramLine programLine) { if (programLine.Label == null) { // Parse new line from text ProgramLine newTextLine = Assembler.ParseProgramLine(labelName + ":" + programLine.Text); // Copy textual representation to the original program Line programLine.CopyTextualRepresentationFrom(newTextLine); } else { throw new InvalidOperationException("Program line is already prefixed by a Label"); } }
public static void ReplaceAddressWithSymbolInProgramLine(ProgramLine instructionLine, int addressParameterIndexToReplace, bool addressIsRelative, string symbolName) { if (addressParameterIndexToReplace == 0 || addressParameterIndexToReplace == 1) { if (instructionLine.OpCodeParameters != null && instructionLine.OpCodeParameters.Count > 0) { InstructionLineParam paramToReplace = instructionLine.OpCodeParameters[addressParameterIndexToReplace]; // Find token to replace AsmToken tokenToReplace = paramToReplace.Tokens.FirstOrDefault <AsmToken>(t => t.Type == AsmTokenType.NUMBER); if (tokenToReplace != null) { // Generate new text for the line, replacing only the address token StringBuilder lineText = new StringBuilder(); foreach (AsmToken token in instructionLine.AllTokens) { if ((!addressIsRelative && token != tokenToReplace) || !paramToReplace.Tokens.Contains(token)) { lineText.Append(token.TextWithLeadingWhiteSpace); } else if (token == tokenToReplace) { if (tokenToReplace.LeadingWhiteSpace != null) { lineText.Append(tokenToReplace.LeadingWhiteSpace.Text); } else if (addressIsRelative && (paramToReplace.Tokens[0] != tokenToReplace)) { if (paramToReplace.Tokens[0].LeadingWhiteSpace != null) { lineText.Append(paramToReplace.Tokens[0].LeadingWhiteSpace.Text); } } lineText.Append(symbolName); } } // Parse new line from text ProgramLine newTextLine = Assembler.ParseProgramLine(lineText.ToString()); // Copy textual representation to the original program Line instructionLine.CopyTextualRepresentationFrom(newTextLine); } } } }
public void PrefixLabelToProgramLine(int lineAddress, string labelName, bool extendSearchToAllNumbers) { ProgramLine programLine = GetLineFromAddress(lineAddress); if (programLine.Label == null) { // Parse new line from text ProgramLine newTextLine = Assembler.ParseProgramLine(labelName + ":" + programLine.Text); // Copy textual representation to the original program Line programLine.CopyTextualRepresentationFrom(newTextLine); // Update all references in the program ReplaceAddressWithSymbol(lineAddress, labelName, extendSearchToAllNumbers); } else { throw new InvalidOperationException("Program line is already prefixed by a Label"); } }
public static void ReplaceAddressWithSymbolInProgramLine(ProgramLine instructionLine, int addressParameterIndexToReplace, bool addressIsRelative, string symbolName) { if (addressParameterIndexToReplace == 0 || addressParameterIndexToReplace == 1) { if (instructionLine.OpCodeParameters != null && instructionLine.OpCodeParameters.Count > 0) { InstructionLineParam paramToReplace = instructionLine.OpCodeParameters[addressParameterIndexToReplace]; // Find token to replace AsmToken tokenToReplace = paramToReplace.Tokens.FirstOrDefault<AsmToken>(t => t.Type == AsmTokenType.NUMBER); if (tokenToReplace != null) { // Generate new text for the line, replacing only the address token StringBuilder lineText = new StringBuilder(); foreach (AsmToken token in instructionLine.AllTokens) { if ((!addressIsRelative && token != tokenToReplace) || !paramToReplace.Tokens.Contains(token)) { lineText.Append(token.TextWithLeadingWhiteSpace); } else if (token == tokenToReplace) { if (tokenToReplace.LeadingWhiteSpace != null) { lineText.Append(tokenToReplace.LeadingWhiteSpace.Text); } else if (addressIsRelative && (paramToReplace.Tokens[0] != tokenToReplace)) { if (paramToReplace.Tokens[0].LeadingWhiteSpace != null) { lineText.Append(paramToReplace.Tokens[0].LeadingWhiteSpace.Text); } } lineText.Append(symbolName); } } // Parse new line from text ProgramLine newTextLine = Assembler.ParseProgramLine(lineText.ToString()); // Copy textual representation to the original program Line instructionLine.CopyTextualRepresentationFrom(newTextLine); } } } }