Skip to content

Commit d56f23e

Browse files
authored
[AsmParser] Replace starIsStartOfStatement with tokenIsStartOfStatement. (#137997)
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.
1 parent 4ff9db6 commit d56f23e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,10 @@ class MCTargetAsmParser : public MCAsmParserExtension {
508508
virtual bool equalIsAsmAssignment() { return true; };
509509
// Return whether this start of statement identifier is a label
510510
virtual bool isLabel(AsmToken &Token) { return true; };
511-
// Return whether this parser accept star as start of statement
512-
virtual bool starIsStartOfStatement() { return false; };
511+
// Return whether this parser accepts the given token as start of statement.
512+
virtual bool tokenIsStartOfStatement(AsmToken::TokenKind Token) {
513+
return false;
514+
}
513515

514516
virtual const MCExpr *applySpecifier(const MCExpr *E, uint32_t,
515517
MCContext &Ctx) {

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,11 +1769,9 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
17691769
// Treat '}' as a valid identifier in this context.
17701770
Lex();
17711771
IDVal = "}";
1772-
} else if (Lexer.is(AsmToken::Star) &&
1773-
getTargetParser().starIsStartOfStatement()) {
1774-
// Accept '*' as a valid start of statement.
1772+
} else if (getTargetParser().tokenIsStartOfStatement(ID.getKind())) {
17751773
Lex();
1776-
IDVal = "*";
1774+
IDVal = ID.getString();
17771775
} else if (parseIdentifier(IDVal)) {
17781776
if (!TheCondState.Ignore) {
17791777
Lex(); // always eat a token

llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class BPFAsmParser : public MCTargetAsmParser {
4949
bool equalIsAsmAssignment() override { return false; }
5050
// "*" is used for dereferencing memory that it will be the start of
5151
// statement.
52-
bool starIsStartOfStatement() override { return true; }
52+
bool tokenIsStartOfStatement(AsmToken::TokenKind Token) override {
53+
return Token == AsmToken::Star;
54+
}
5355

5456
#define GET_ASSEMBLER_HEADER
5557
#include "BPFGenAsmMatcher.inc"

0 commit comments

Comments
 (0)