mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
First step in supporting #line directives in assembler. This step parses the
#line directives with the needed support in the lexer. Next will be to build a simple file/line# table mapping source SMLoc's for later use by diagnostics. And the last step will be to get the diagnostics to use the mapping for file and line numbers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139669 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -334,6 +334,17 @@ StringRef AsmLexer::LexUntilEndOfStatement() {
|
||||
return StringRef(TokStart, CurPtr-TokStart);
|
||||
}
|
||||
|
||||
StringRef AsmLexer::LexUntilEndOfLine() {
|
||||
TokStart = CurPtr;
|
||||
|
||||
while (*CurPtr != '\n' &&
|
||||
*CurPtr != '\r' &&
|
||||
(*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) {
|
||||
++CurPtr;
|
||||
}
|
||||
return StringRef(TokStart, CurPtr-TokStart);
|
||||
}
|
||||
|
||||
bool AsmLexer::isAtStartOfComment(char Char) {
|
||||
// FIXME: This won't work for multi-character comment indicators like "//".
|
||||
return Char == *MAI.getCommentString();
|
||||
@@ -345,17 +356,26 @@ bool AsmLexer::isAtStatementSeparator(const char *Ptr) {
|
||||
}
|
||||
|
||||
AsmToken AsmLexer::LexToken() {
|
||||
static bool isAtStartOfLine = true;
|
||||
TokStart = CurPtr;
|
||||
// This always consumes at least one character.
|
||||
int CurChar = getNextChar();
|
||||
|
||||
if (isAtStartOfComment(CurChar))
|
||||
if (isAtStartOfComment(CurChar)) {
|
||||
// If this comment starts with a '#', then return the Hash token and let
|
||||
// the assembler parser see if it can be parsed as a cpp line filename
|
||||
// comment. We do this only if we are at the start of a line.
|
||||
if (CurChar == '#' && isAtStartOfLine)
|
||||
return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
|
||||
isAtStartOfLine = true;
|
||||
return LexLineComment();
|
||||
}
|
||||
if (isAtStatementSeparator(TokStart)) {
|
||||
CurPtr += strlen(MAI.getSeparatorString()) - 1;
|
||||
return AsmToken(AsmToken::EndOfStatement,
|
||||
StringRef(TokStart, strlen(MAI.getSeparatorString())));
|
||||
}
|
||||
isAtStartOfLine = false;
|
||||
|
||||
switch (CurChar) {
|
||||
default:
|
||||
@@ -373,6 +393,7 @@ AsmToken AsmLexer::LexToken() {
|
||||
return LexToken();
|
||||
case '\n': // FALL THROUGH.
|
||||
case '\r':
|
||||
isAtStartOfLine = true;
|
||||
return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
|
||||
case ':': return AsmToken(AsmToken::Colon, StringRef(TokStart, 1));
|
||||
case '+': return AsmToken(AsmToken::Plus, StringRef(TokStart, 1));
|
||||
|
Reference in New Issue
Block a user