Skip to content

Commit 97ad399

Browse files
authored
MCParser: Move LCurly/RCurly testing into tokenIsStartOfStatement
Commit 8a0453e (2015) added LCurly and RCurly cases for Hexagon instruction bundles. While gas x86 also adopted `{` in 2017 for pseudo prefixes (see `tc_symbol_chars`), `{` remains uncommon among targets. Move `{` and `}` parsing into the newly introduced `tokenIsStartOfStatement` hook (#137997). Pull Request: #140101
1 parent 56aa935 commit 97ad399

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -1760,15 +1760,6 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
17601760
// Treat '.' as a valid identifier in this context.
17611761
Lex();
17621762
IDVal = ".";
1763-
} else if (Lexer.is(AsmToken::LCurly)) {
1764-
// Treat '{' as a valid identifier in this context.
1765-
Lex();
1766-
IDVal = "{";
1767-
1768-
} else if (Lexer.is(AsmToken::RCurly)) {
1769-
// Treat '}' as a valid identifier in this context.
1770-
Lex();
1771-
IDVal = "}";
17721763
} else if (getTargetParser().tokenIsStartOfStatement(ID.getKind())) {
17731764
Lex();
17741765
IDVal = ID.getString();

llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class HexagonAsmParser : public MCTargetAsmParser {
110110

111111
bool equalIsAsmAssignment() override { return false; }
112112
bool isLabel(AsmToken &Token) override;
113+
bool tokenIsStartOfStatement(AsmToken::TokenKind Token) override;
113114

114115
void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
115116
bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
@@ -1007,6 +1008,10 @@ bool HexagonAsmParser::isLabel(AsmToken &Token) {
10071008
return false;
10081009
}
10091010

1011+
bool HexagonAsmParser::tokenIsStartOfStatement(AsmToken::TokenKind Token) {
1012+
return Token == AsmToken::LCurly || Token == AsmToken::RCurly;
1013+
}
1014+
10101015
bool HexagonAsmParser::handleNoncontigiousRegister(bool Contigious,
10111016
SMLoc &Loc) {
10121017
if (!Contigious && ErrorNoncontigiousRegister) {

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ class X86AsmParser : public MCTargetAsmParser {
124124
return Result;
125125
}
126126

127+
bool tokenIsStartOfStatement(AsmToken::TokenKind Token) override {
128+
return Token == AsmToken::LCurly;
129+
}
130+
127131
X86TargetStreamer &getTargetStreamer() {
128132
assert(getParser().getStreamer().getTargetStreamer() &&
129133
"do not have a target streamer");

llvm/test/MC/AsmParser/token.s

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Tested invalid statement start tokens. X86 supports "{". Use a different target.
2+
# REQUIRES: aarch64-registered-target
3+
4+
# RUN: not llvm-mc -triple=aarch64 %s 2>&1 | FileCheck %s
5+
6+
# CHECK: [[#@LINE+1]]:2: error: unexpected token at start of statement
7+
{insn}

0 commit comments

Comments
 (0)