Skip to content

Commit

Permalink
Store original file name in ProgramStatement.
Browse files Browse the repository at this point in the history
The sourceProgram is not correct for statements that come from an
.include, and the assembler depends on the sourceProgram actually
being the "top-level" program, not the actual file.

Fixes TheThirdOne#160.
  • Loading branch information
athas committed Sep 23, 2022
1 parent 27a7c1f commit bba0b97
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/rars/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public ErrorMessage(boolean isWarning, RISCVprogram sourceProgram, int line, int
// Added January 2013
public ErrorMessage(ProgramStatement statement, String message) {
this.isWarning = ERROR;
this.filename = (statement.getSourceProgram() == null)
? "" : statement.getSourceProgram().getFilename();
this.filename = statement.getSourceFile();
this.position = 0;
this.message = message;
// Somewhere along the way we lose the macro history, but can
Expand Down Expand Up @@ -243,4 +242,4 @@ private static String getExpansionHistory(RISCVprogram sourceProgram) {
return sourceProgram.getLocalMacroPool().getExpansionHistory();
}

} // ErrorMessage
} // ErrorMessage
6 changes: 4 additions & 2 deletions src/rars/ProgramStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class ProgramStatement implements Comparable<ProgramStatement> {
private int numOperands;
private Instruction instruction;
private int textAddress;
private String sourceFilename;
private int sourceLine;
private int binaryStatement;
private boolean altered;
Expand All @@ -83,7 +84,7 @@ public class ProgramStatement implements Comparable<ProgramStatement> {
* is stored.
**/
public ProgramStatement(RISCVprogram sourceProgram, String source, TokenList origTokenList, TokenList strippedTokenList,
Instruction inst, int textAddress, int sourceLine) {
Instruction inst, int textAddress, String filename, int sourceLine) {
this.sourceProgram = sourceProgram;
this.source = source;
this.originalTokenList = origTokenList;
Expand All @@ -92,6 +93,7 @@ public ProgramStatement(RISCVprogram sourceProgram, String source, TokenList ori
this.numOperands = 0;
this.instruction = inst;
this.textAddress = textAddress;
this.sourceFilename = filename;
this.sourceLine = sourceLine;
this.basicAssemblyStatement = null;
this.basicStatementList = new BasicStatementList();
Expand Down Expand Up @@ -533,7 +535,7 @@ public RISCVprogram getSourceProgram() {
* @return The file name.
**/
public String getSourceFile() {
return (sourceProgram == null) ? "" : sourceProgram.getFilename();
return sourceFilename;
}


Expand Down
7 changes: 4 additions & 3 deletions src/rars/assembler/Assembler.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public ArrayList<ProgramStatement> assemble(ArrayList<RISCVprogram> tokenizedPro
ProgramStatement ps = new ProgramStatement(
this.fileCurrentlyBeingAssembled,
(instrNumber == 0) ? statement.getSource() : "", newTokenList,
newTokenList, instr, textAddress.get(), statement.getSourceLine());
newTokenList, instr, textAddress.get(), statement.getSourceFile(), statement.getSourceLine());
textAddress.increment(Instruction.INSTRUCTION_LENGTH);
ps.buildBasicStatementFromBasicInstruction(errors);
machineList.add(ps);
Expand Down Expand Up @@ -488,8 +488,9 @@ private ArrayList<ProgramStatement> parseLine(TokenList tokenList, String source
"Extended (pseudo) instruction or format not permitted. See Settings."));
}
if (OperandFormat.tokenOperandMatch(tokens, inst, errors)) {
programStatement = new ProgramStatement(this.fileCurrentlyBeingAssembled, source,
tokenList, tokens, inst, textAddress.get(), sourceLineNumber);
programStatement = new ProgramStatement(this.fileCurrentlyBeingAssembled,
source,
tokenList, tokens, inst, textAddress.get(), token.getOriginalProgram().getFilename(), sourceLineNumber);
// instruction length is 4 for all basic instruction, varies for extended instruction
// Modified to permit use of compact expansion if address fits
// in 15 bits. DPS 4-Aug-2009
Expand Down
2 changes: 1 addition & 1 deletion src/rars/assembler/SourceLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ public int getLineNumber() {
public RISCVprogram getRISCVprogram() {
return program;
}
}
}

0 comments on commit bba0b97

Please sign in to comment.