mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-02 22:32:08 +00:00
Add support for lexing single quotes like 'c'.
This fixed 8615. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122150 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fffa863536
commit
7529b16410
@ -60,6 +60,7 @@ private:
|
||||
AsmToken LexSlash();
|
||||
AsmToken LexLineComment();
|
||||
AsmToken LexDigit();
|
||||
AsmToken LexSingleQuote();
|
||||
AsmToken LexQuote();
|
||||
AsmToken LexFloatLiteral();
|
||||
};
|
||||
|
@ -265,6 +265,42 @@ AsmToken AsmLexer::LexDigit() {
|
||||
return AsmToken(AsmToken::Integer, Result, Value);
|
||||
}
|
||||
|
||||
/// LexSingleQuote: Integer: 'b'
|
||||
AsmToken AsmLexer::LexSingleQuote() {
|
||||
int CurChar = getNextChar();
|
||||
|
||||
if (CurChar == '\\')
|
||||
CurChar = getNextChar();
|
||||
|
||||
if (CurChar == EOF)
|
||||
return ReturnError(TokStart, "unterminated single quote");
|
||||
|
||||
CurChar = getNextChar();
|
||||
|
||||
if (CurChar != '\'')
|
||||
return ReturnError(TokStart, "single quote way too long");
|
||||
|
||||
// The idea here being that 'c' is basically just an integral
|
||||
// constant.
|
||||
StringRef Res = StringRef(TokStart,CurPtr - TokStart);
|
||||
long long Value;
|
||||
|
||||
if (Res.startswith("\'\\")) {
|
||||
char theChar = Res[2];
|
||||
switch (theChar) {
|
||||
default: Value = theChar; break;
|
||||
case '\'': Value = '\''; break;
|
||||
case 't': Value = '\t'; break;
|
||||
case 'n': Value = '\n'; break;
|
||||
case 'b': Value = '\b'; break;
|
||||
}
|
||||
} else
|
||||
Value = TokStart[1];
|
||||
|
||||
return AsmToken(AsmToken::Integer, Res, Value);
|
||||
}
|
||||
|
||||
|
||||
/// LexQuote: String: "..."
|
||||
AsmToken AsmLexer::LexQuote() {
|
||||
int CurChar = getNextChar();
|
||||
@ -361,6 +397,7 @@ AsmToken AsmLexer::LexToken() {
|
||||
case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1));
|
||||
case '/': return LexSlash();
|
||||
case '#': return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
|
||||
case '\'': return LexSingleQuote();
|
||||
case '"': return LexQuote();
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
|
@ -40,3 +40,19 @@ TEST5:
|
||||
.value 8
|
||||
# CHECK: TEST5:
|
||||
# CHECK: .short 8
|
||||
|
||||
TEST6:
|
||||
.byte 'c'
|
||||
.byte '\''
|
||||
.byte '\\'
|
||||
.byte '\#'
|
||||
.byte '\t'
|
||||
.byte '\n'
|
||||
|
||||
# CHECK: TEST6
|
||||
# CHECK: .byte 99
|
||||
# CHECK: .byte 39
|
||||
# CHECK: .byte 92
|
||||
# CHECK: .byte 35
|
||||
# CHECK: .byte 9
|
||||
# CHECK: .byte 10
|
||||
|
Loading…
x
Reference in New Issue
Block a user