Skip to content

Commit

Permalink
Make unterminated strings error and range warnings better
Browse files Browse the repository at this point in the history
Unterminated strings were mentioned in #29, I decided to make them an
error because it was slightly technically easier. Also I don't know of
any riscv assembler which allows unterminated strings.

The range warnings for .byte and .half were improved to not warn on
values the fit in an unsigned byte/half and to say exactly how the value
is truncated. Now it matches how gcc handles it. This was mentioned in #5
  • Loading branch information
TheThirdOne committed Jun 4, 2019
1 parent 7148112 commit 0765746
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rars/assembler/Assembler.java
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,8 @@ private void storeInteger(Token token, Directives directive, ErrorList errors) {

if (DataTypes.outOfRange(directive, fullvalue)) {
errors.add(new ErrorMessage(ErrorMessage.WARNING, token.getSourceProgram(), token.getSourceLine(),
token.getStartPos(), "\"" + token.getValue()
+ "\" is out-of-range for a signed value and possibly truncated"));
token.getStartPos(), "value " + Binary.intToHexString(fullvalue)
+ " is out-of-range and truncated to " + Binary.intToHexString(value)));
}
if (this.inDataSegment) {
writeToDataSegment(value, lengthInBytes, token, errors);
Expand Down
5 changes: 3 additions & 2 deletions rars/assembler/DataTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ else if (direct == Directives.BYTE)
* by the given directive (.word, .half, .byte), <tt>false</tt> otherwise.
**/
public static boolean outOfRange(Directives direct, int value) {
return (direct == Directives.HALF && (value < MIN_HALF_VALUE || value > MAX_HALF_VALUE)) ||
(direct == Directives.BYTE && (value < MIN_BYTE_VALUE || value > MAX_BYTE_VALUE));
// Hex values used here rather than constants because there aren't constants for unsigned max
return (direct == Directives.HALF && (value < MIN_HALF_VALUE || value > 0xFFFF)) ||
(direct == Directives.BYTE && (value < MIN_BYTE_VALUE || value > 0xFF));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions rars/assembler/Tokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ public TokenList tokenizeLine(RISCVprogram program, int lineNum, String theLine,
linePos++;
} // while
if (tokenPos > 0) {
if(insideQuotedString){
errors.add(new ErrorMessage(program, lineNum, tokenStartPos,
"String is not terminated."));
}
this.processCandidateToken(token, program, lineNum, theLine, tokenPos, tokenStartPos, result);
tokenPos = 0;
}
Expand Down

0 comments on commit 0765746

Please sign in to comment.