Skip to content

Commit 45f949e

Browse files
committed
[MC] Migrate some parseToken(AsmToken::EndOfStatement, ...) to parseEOL()
1 parent bb6732c commit 45f949e

File tree

6 files changed

+47
-79
lines changed

6 files changed

+47
-79
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,9 +3059,8 @@ bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
30593059
return Error(ExprLoc, "expression must be relocatable");
30603060
}
30613061

3062-
if (parseToken(AsmToken::EndOfStatement,
3063-
"unexpected token in .reloc directive"))
3064-
return true;
3062+
if (parseEOL())
3063+
return true;
30653064

30663065
const MCTargetAsmParser &MCT = getTargetParser();
30673066
const MCSubtargetInfo &STI = MCT.getSTI();
@@ -3513,11 +3512,7 @@ bool AsmParser::parseDirectiveLine() {
35133512
(void)LineNumber;
35143513
// FIXME: Do something with the .line.
35153514
}
3516-
if (parseToken(AsmToken::EndOfStatement,
3517-
"unexpected token in '.line' directive"))
3518-
return true;
3519-
3520-
return false;
3515+
return parseEOL();
35213516
}
35223517

35233518
/// parseDirectiveLoc
@@ -4355,8 +4350,7 @@ bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
43554350
/// parseDirectiveCFISignalFrame
43564351
/// ::= .cfi_signal_frame
43574352
bool AsmParser::parseDirectiveCFISignalFrame() {
4358-
if (parseToken(AsmToken::EndOfStatement,
4359-
"unexpected token in '.cfi_signal_frame'"))
4353+
if (parseEOL())
43604354
return true;
43614355

43624356
getStreamer().emitCFISignalFrame();
@@ -4667,15 +4661,14 @@ bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
46674661
}
46684662

46694663
/// parseDirectivePurgeMacro
4670-
/// ::= .purgem
4664+
/// ::= .purgem name
46714665
bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
46724666
StringRef Name;
46734667
SMLoc Loc;
46744668
if (parseTokenLoc(Loc) ||
46754669
check(parseIdentifier(Name), Loc,
46764670
"expected identifier in '.purgem' directive") ||
4677-
parseToken(AsmToken::EndOfStatement,
4678-
"unexpected token in '.purgem' directive"))
4671+
parseEOL())
46794672
return true;
46804673

46814674
if (!getContext().lookupMacro(Name))
@@ -4695,9 +4688,7 @@ bool AsmParser::parseDirectiveBundleAlignMode() {
46954688
SMLoc ExprLoc = getLexer().getLoc();
46964689
int64_t AlignSizePow2;
46974690
if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
4698-
parseToken(AsmToken::EndOfStatement, "unexpected token after expression "
4699-
"in '.bundle_align_mode' "
4700-
"directive") ||
4691+
parseEOL() ||
47014692
check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,
47024693
"invalid bundle alignment size (expected between 0 and 30)"))
47034694
return true;
@@ -4722,9 +4713,7 @@ bool AsmParser::parseDirectiveBundleLock() {
47224713

47234714
if (!parseOptionalToken(AsmToken::EndOfStatement)) {
47244715
if (check(parseIdentifier(Option), Loc, kInvalidOptionError) ||
4725-
check(Option != "align_to_end", Loc, kInvalidOptionError) ||
4726-
parseToken(AsmToken::EndOfStatement,
4727-
"unexpected token after '.bundle_lock' directive option"))
4716+
check(Option != "align_to_end", Loc, kInvalidOptionError) || parseEOL())
47284717
return true;
47294718
AlignToEnd = true;
47304719
}
@@ -4799,11 +4788,7 @@ bool AsmParser::parseDirectiveDCB(StringRef IDVal, unsigned Size) {
47994788
getStreamer().emitValue(Value, Size, ExprLoc);
48004789
}
48014790

4802-
if (parseToken(AsmToken::EndOfStatement,
4803-
"unexpected token in '" + Twine(IDVal) + "' directive"))
4804-
return true;
4805-
4806-
return false;
4791+
return parseEOL();
48074792
}
48084793

48094794
/// parseDirectiveRealDCB
@@ -4824,11 +4809,7 @@ bool AsmParser::parseDirectiveRealDCB(StringRef IDVal, const fltSemantics &Seman
48244809
return true;
48254810

48264811
APInt AsInt;
4827-
if (parseRealValue(Semantics, AsInt))
4828-
return true;
4829-
4830-
if (parseToken(AsmToken::EndOfStatement,
4831-
"unexpected token in '" + Twine(IDVal) + "' directive"))
4812+
if (parseRealValue(Semantics, AsInt) || parseEOL())
48324813
return true;
48334814

48344815
for (uint64_t i = 0, e = NumValues; i != e; ++i)
@@ -4843,18 +4824,15 @@ bool AsmParser::parseDirectiveRealDCB(StringRef IDVal, const fltSemantics &Seman
48434824
bool AsmParser::parseDirectiveDS(StringRef IDVal, unsigned Size) {
48444825
SMLoc NumValuesLoc = Lexer.getLoc();
48454826
int64_t NumValues;
4846-
if (checkForValidSection() || parseAbsoluteExpression(NumValues))
4827+
if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
4828+
parseEOL())
48474829
return true;
48484830

48494831
if (NumValues < 0) {
48504832
Warning(NumValuesLoc, "'" + Twine(IDVal) + "' directive with negative repeat count has no effect");
48514833
return false;
48524834
}
48534835

4854-
if (parseToken(AsmToken::EndOfStatement,
4855-
"unexpected token in '" + Twine(IDVal) + "' directive"))
4856-
return true;
4857-
48584836
for (uint64_t i = 0, e = NumValues; i != e; ++i)
48594837
getStreamer().emitFill(Size, 0);
48604838

@@ -5271,8 +5249,7 @@ bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
52715249
/// parseDirectiveEnd
52725250
/// ::= .end
52735251
bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
5274-
if (parseToken(AsmToken::EndOfStatement,
5275-
"unexpected token in '.end' directive"))
5252+
if (parseEOL())
52765253
return true;
52775254

52785255
while (Lexer.isNot(AsmToken::Eof))
@@ -5325,8 +5302,7 @@ bool AsmParser::parseDirectiveWarning(SMLoc L) {
53255302

53265303
Message = getTok().getStringContents();
53275304
Lex();
5328-
if (parseToken(AsmToken::EndOfStatement,
5329-
"expected end of statement in '.warning' directive"))
5305+
if (parseEOL())
53305306
return true;
53315307
}
53325308

@@ -5598,9 +5574,7 @@ bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
55985574
return Error(CountLoc, "unexpected token in '" + Dir + "' directive");
55995575
}
56005576

5601-
if (check(Count < 0, CountLoc, "Count is negative") ||
5602-
parseToken(AsmToken::EndOfStatement,
5603-
"unexpected token in '" + Dir + "' directive"))
5577+
if (check(Count < 0, CountLoc, "Count is negative") || parseEOL())
56045578
return true;
56055579

56065580
// Lex the rept definition.
@@ -5630,8 +5604,7 @@ bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
56305604
if (check(parseIdentifier(Parameter.Name),
56315605
"expected identifier in '.irp' directive") ||
56325606
parseToken(AsmToken::Comma, "expected comma in '.irp' directive") ||
5633-
parseMacroArguments(nullptr, A) ||
5634-
parseToken(AsmToken::EndOfStatement, "expected End of Statement"))
5607+
parseMacroArguments(nullptr, A) || parseEOL())
56355608
return true;
56365609

56375610
// Lex the irp definition.
@@ -5670,9 +5643,7 @@ bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
56705643

56715644
if (A.size() != 1 || A.front().size() != 1)
56725645
return TokError("unexpected token in '.irpc' directive");
5673-
5674-
// Eat the end of statement.
5675-
if (parseToken(AsmToken::EndOfStatement, "expected end of statement"))
5646+
if (parseEOL())
56765647
return true;
56775648

56785649
// Lex the irpc definition.
@@ -5751,7 +5722,7 @@ bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
57515722
Lex();
57525723
if (StrTok.isNot(AsmToken::String) || StrTok.getString().front() != '"')
57535724
return Error(DirectiveLoc, "expected double quoted string after .print");
5754-
if (parseToken(AsmToken::EndOfStatement, "expected end of statement"))
5725+
if (parseEOL())
57555726
return true;
57565727
llvm::outs() << StrTok.getStringContents() << '\n';
57575728
return false;
@@ -5828,8 +5799,7 @@ bool AsmParser::parseDirectivePseudoProbe() {
58285799
InlineStack.push_back(Site);
58295800
}
58305801

5831-
if (parseToken(AsmToken::EndOfStatement,
5832-
"unexpected token in '.pseudoprobe' directive"))
5802+
if (parseEOL())
58335803
return true;
58345804

58355805
getStreamer().emitPseudoProbe(Guid, Index, Type, Attr, InlineStack);

llvm/test/MC/AsmParser/AArch64/directive-parse-err.s

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@
149149
.p2alignl 0 $
150150
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
151151
.p2alignl 0 // EOL COMMENT
152-
// CHECK: [[@LINE+1]]:8: error: unexpected token in '.line' directive
152+
// CHECK: [[#@LINE+1]]:8: error: expected newline
153153
.line $
154154
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
155155
.line // EOL COMMENT
156-
// CHECK: [[@LINE+1]]:10: error: unexpected token in '.line' directive
156+
// CHECK: [[#@LINE+1]]:10: error: expected newline
157157
.line 0 $
158-
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
158+
// CHECK-NOT: [[#@LINE+1]]:{{[0-9]+}}: error:
159159
.line 0 // EOL COMMENT
160160

161161
.file 1 "hello"
@@ -175,9 +175,9 @@
175175
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
176176
.cv_loc 1 1 // EOL COMMENT
177177

178-
// CHECK: [[@LINE+1]]:28: error: unexpected token after '.bundle_lock' directive option
178+
// CHECK: [[#@LINE+1]]:28: error: expected newline
179179
.bundle_lock align_to_end $
180-
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
180+
// CHECK-NOT: [[#@LINE+1]]:{{[0-9]+}}: error:
181181
.bundle_lock align_to_end // EOL COMMENT
182182

183183
// CHECK: [[@LINE+1]]:11: error: invalid token in expression in directive
@@ -237,9 +237,9 @@
237237
.warning $
238238
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
239239
.warning // EOL COMMENT
240-
// CHECK: [[@LINE+1]]:21: error: expected end of statement in '.warning' directive
240+
// CHECK: [[#@LINE+1]]:21: error: expected newline
241241
.warning "warning" $
242-
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
242+
// CHECK-NOT: [[#@LINE+1]]:{{[0-9]+}}: error:
243243
.warning "warning" // EOL COMMENT
244244

245245

llvm/test/MC/AsmParser/directive_dcb.s

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# RUN: not llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
2-
# RUN: not llvm-mc -triple i386-unknown-unknown %s 2>&1 > /dev/null| FileCheck %s --check-prefix=CHECK-ERROR
1+
# RUN: llvm-mc -triple=i386 %s | FileCheck %s
2+
# RUN: not llvm-mc -triple=i386 --defsym ERR=1 %s 2>&1 > /dev/null | FileCheck %s --check-prefix=ERR
33

44
# CHECK: TEST0:
55
# CHECK: .byte 1
@@ -42,18 +42,16 @@ TEST5:
4242
TEST6:
4343
.dcb.d 5, .232
4444

45-
# CHECK-ERROR: error: .dcb.x not currently supported for this target
46-
TEST7:
47-
.dcb.x 3, 1.2e3
45+
.ifdef ERR
46+
# ERR: :[[#@LINE+1]]:8: error: .dcb.x not currently supported for this target
47+
.dcb.x 3, 1.2e3
4848

49-
# CHECK-ERROR: warning: '.dcb' directive with negative repeat count has no effect
50-
TEST8:
51-
.dcb -1, 2
49+
# ERR: :[[#@LINE+1]]:6: warning: '.dcb' directive with negative repeat count has no effect
50+
.dcb -1, 2
5251

53-
# CHECK-ERROR: error: unexpected token in '.dcb' directive
54-
TEST9:
55-
.dcb 1 2
52+
# ERR: :[[#@LINE+1]]:8: error: unexpected token in '.dcb' directive
53+
.dcb 1 2
5654

57-
# CHECK-ERROR: error: unexpected token in '.dcb' directive
58-
TEST10:
59-
.dcb 1, 2 3
55+
# ERR: :[[#@LINE+1]]:11: error: expected newline
56+
.dcb 1, 2 3
57+
.endif

llvm/test/MC/AsmParser/directive_ds.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ TEST7:
5353
TEST8:
5454
.ds -1
5555

56-
# CHECK-ERROR: error: unexpected token in '.ds' directive
56+
# CHECK-ERROR: :[[#@LINE+2]]:9: error: expected newline
5757
TEST9:
58-
.ds 1 2
58+
.ds 1 2
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# RUN: not llvm-mc -triple i386-linux-gnu %s 2> %t.err | FileCheck %s
2-
# RUN: FileCheck < %t.err %s --check-prefix=CHECK-ERR
1+
# RUN: llvm-mc -triple i386 %s | FileCheck %s
2+
# RUN: not llvm-mc -triple i386 --defsym ERR=1 %s 2>&1 | FileCheck %s --check-prefix=ERR
33

44
T1:
55
# CHECK: e
66
# CHECK: 2.718281828459045235
77
.print "e"
88
.print "2.718281828459045235"
99

10-
T2:
11-
# CHECK-ERR: expected double quoted string after .print
10+
.ifdef ERR
11+
# CHECK-ERR: :[[#@LINE+2]]:8: expected double quoted string after .print
1212
.altmacro
1313
.print <pi>
1414
.noaltmacro
1515

16-
T3:
17-
# CHECK-ERR: expected end of statement
16+
# ERR: :[[#@LINE+1]]:12: error: expected newline
1817
.print "a" "misplaced-string"
18+
.endif

llvm/test/MC/AsmParser/directive_rept-diagnostics.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ negative:
3535
trailer:
3636
.rep 0 trailer
3737

38-
# CHECK: error: unexpected token in '.rep' directive
38+
# CHECK: :[[#@LINE-2]]:9: error: expected newline
3939
# CHECK: .rep 0 trailer
4040
# CHECK: ^
4141

0 commit comments

Comments
 (0)