-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[AsmParser] Replace starIsStartOfStatement with tokenIsStartOfStatement. #137997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Currently `MCTargetAsmParser::starIsStartOfStatement` checks for `*` at the start of the statement. There are other (currently) downstream back-ends that need the same treatment for other tokens. Instead of introducing bespoke APIs for each such token, we generalize (and rename) starIsStartOfStatement as tokenIsStartOfStatement which takes the token of interest as an argument. Update the BPF AsmParser (the only upstream consumer today) to use the new version.
@llvm/pr-subscribers-mc Author: Jason Eckhardt (nvjle) ChangesCurrently Update the BPF AsmParser (the only upstream consumer today) to use the new version. Full diff: https://github.com/llvm/llvm-project/pull/137997.diff 3 Files Affected:
diff --git a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
index c7f098be70945..c94ae9442f028 100644
--- a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
+++ b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
@@ -508,8 +508,10 @@ class MCTargetAsmParser : public MCAsmParserExtension {
virtual bool equalIsAsmAssignment() { return true; };
// Return whether this start of statement identifier is a label
virtual bool isLabel(AsmToken &Token) { return true; };
- // Return whether this parser accept star as start of statement
- virtual bool starIsStartOfStatement() { return false; };
+ // Return whether this parser accepts the given token as start of statement.
+ virtual bool tokenIsStartOfStatement(AsmToken::TokenKind Token) {
+ return false;
+ }
virtual const MCExpr *applySpecifier(const MCExpr *E, uint32_t,
MCContext &Ctx) {
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index aee1259eeb126..f27a27833858a 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -1769,11 +1769,9 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
// Treat '}' as a valid identifier in this context.
Lex();
IDVal = "}";
- } else if (Lexer.is(AsmToken::Star) &&
- getTargetParser().starIsStartOfStatement()) {
- // Accept '*' as a valid start of statement.
+ } else if (getTargetParser().tokenIsStartOfStatement(ID.getKind())) {
Lex();
- IDVal = "*";
+ IDVal = ID.getString();
} else if (parseIdentifier(IDVal)) {
if (!TheCondState.Ignore) {
Lex(); // always eat a token
diff --git a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
index 494445fa89b5e..2e4819e5ede38 100644
--- a/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
+++ b/llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
@@ -49,7 +49,9 @@ class BPFAsmParser : public MCTargetAsmParser {
bool equalIsAsmAssignment() override { return false; }
// "*" is used for dereferencing memory that it will be the start of
// statement.
- bool starIsStartOfStatement() override { return true; }
+ bool tokenIsStartOfStatement(AsmToken::TokenKind Token) override {
+ return Token == AsmToken::Star;
+ }
#define GET_ASSEMBLER_HEADER
#include "BPFGenAsmMatcher.inc"
|
Gentle ping for this tiny patch... |
} else if (Lexer.is(AsmToken::Star) && | ||
getTargetParser().starIsStartOfStatement()) { | ||
// Accept '*' as a valid start of statement. | ||
} else if (getTargetParser().tokenIsStartOfStatement(ID.getKind())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LCurly/RCurly should be pushed into the new method as well, they are invalid at the start of a statement on most targets. In-tree exceptions are Hexagon (curlies are used for bundles) and X86 (used for various prefixes such as {evex}
).
Currently
MCTargetAsmParser::starIsStartOfStatement
checks for*
at the start of the statement. There are other (currently) downstream back-ends that need the same treatment for other tokens. Instead of introducing bespoke APIs for each such token, we generalize (and rename) starIsStartOfStatement as tokenIsStartOfStatement which takes the token of interest as an argument.Update the BPF AsmParser (the only upstream consumer today) to use the new version.