[PATCH] D154202: [MC/AsmLexer] Add '?' (Question) token
Sergei Barannikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 30 04:32:19 PDT 2023
barannikov88 updated this revision to Diff 536180.
barannikov88 added a comment.
Rearrange switch cases to match the comment
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
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.536180.patch
Type: text/x-patch
Size: 3112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230630/03b0c6c4/attachment.bin>
More information about the llvm-commits
mailing list