[PATCH] D154202: [MC/AsmLexer] Add '?' (Question) token
Sergei Barannikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 13 17:46:26 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG682fe17e08c5: [MC/AsmLexer] Add '?' (Question) token (authored by barannikov88).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154202/new/
https://reviews.llvm.org/D154202
Files:
llvm/include/llvm/MC/MCAsmMacro.h
llvm/lib/MC/MCParser/AsmLexer.cpp
llvm/lib/MC/MCParser/MCAsmLexer.cpp
llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
Index: llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
===================================================================
--- llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
+++ llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
@@ -358,7 +358,7 @@
Parser->getLexer().Lex();
SmallVector<AsmToken::TokenKind> ExpectedTokens(
- {AsmToken::Error, AsmToken::Identifier, AsmToken::EndOfStatement,
+ {AsmToken::Question, AsmToken::Identifier, AsmToken::EndOfStatement,
AsmToken::Eof});
lexAndCheckTokens(AsmStr, ExpectedTokens);
}
Index: llvm/lib/MC/MCParser/MCAsmLexer.cpp
===================================================================
--- llvm/lib/MC/MCParser/MCAsmLexer.cpp
+++ llvm/lib/MC/MCParser/MCAsmLexer.cpp
@@ -88,6 +88,7 @@
case AsmToken::Pipe: OS << "Pipe"; break;
case AsmToken::PipePipe: OS << "PipePipe"; break;
case AsmToken::Plus: OS << "Plus"; break;
+ case AsmToken::Question: OS << "Question"; break;
case AsmToken::RBrac: OS << "RBrac"; break;
case AsmToken::RCurly: OS << "RCurly"; break;
case AsmToken::RParen: OS << "RParen"; break;
Index: llvm/lib/MC/MCParser/AsmLexer.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmLexer.cpp
+++ llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -776,9 +776,11 @@
IsAtStartOfStatement = false;
switch (CurChar) {
default:
- // Handle identifier: [a-zA-Z_.?][a-zA-Z0-9_$.@#?]*
- if (isalpha(CurChar) || CurChar == '_' || CurChar == '.' ||
- (MAI.doesAllowQuestionAtStartOfIdentifier() && CurChar == '?'))
+ // Handle identifier: [a-zA-Z_.$@#?][a-zA-Z0-9_.$@#?]*
+ // Whether or not the lexer accepts '$', '@', '#' and '?' at the start of
+ // an identifier is target-dependent. These characters are handled in the
+ // respective switch cases.
+ if (isalpha(CurChar) || CurChar == '_' || CurChar == '.')
return LexIdentifier();
// Unknown character, emit an error.
@@ -830,11 +832,18 @@
return LexIdentifier();
return AsmToken(AsmToken::Dollar, StringRef(TokStart, 1));
}
- case '@': {
+ case '@':
if (MAI.doesAllowAtAtStartOfIdentifier())
return LexIdentifier();
return AsmToken(AsmToken::At, StringRef(TokStart, 1));
- }
+ case '#':
+ if (MAI.doesAllowHashAtStartOfIdentifier())
+ return LexIdentifier();
+ return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
+ case '?':
+ if (MAI.doesAllowQuestionAtStartOfIdentifier())
+ return LexIdentifier();
+ return AsmToken(AsmToken::Question, StringRef(TokStart, 1));
case '\\': return AsmToken(AsmToken::BackSlash, StringRef(TokStart, 1));
case '=':
if (*CurPtr == '=') {
@@ -914,11 +923,6 @@
case '/':
IsAtStartOfStatement = OldIsAtStartOfStatement;
return LexSlash();
- case '#': {
- if (MAI.doesAllowHashAtStartOfIdentifier())
- return LexIdentifier();
- return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
- }
case '\'': return LexSingleQuote();
case '"': return LexQuote();
case '0': case '1': case '2': case '3': case '4':
Index: llvm/include/llvm/MC/MCAsmMacro.h
===================================================================
--- llvm/include/llvm/MC/MCAsmMacro.h
+++ llvm/include/llvm/MC/MCAsmMacro.h
@@ -46,7 +46,7 @@
Slash, // '/'
BackSlash, // '\'
LParen, RParen, LBrac, RBrac, LCurly, RCurly,
- Star, Dot, Comma, Dollar, Equal, EqualEqual,
+ Question, Star, Dot, Comma, Dollar, Equal, EqualEqual,
Pipe, PipePipe, Caret,
Amp, AmpAmp, Exclaim, ExclaimEqual, Percent, Hash,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154202.540241.patch
Type: text/x-patch
Size: 3671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230714/ae21f8e0/attachment.bin>
More information about the llvm-commits
mailing list