[llvm] 45f949e - [MC] Migrate some parseToken(AsmToken::EndOfStatement, ...) to parseEOL()
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 6 19:25:29 PST 2021
Author: Fangrui Song
Date: 2021-03-06T19:25:22-08:00
New Revision: 45f949ee469f3e59d30a88c97aa7c1139069b261
URL: https://github.com/llvm/llvm-project/commit/45f949ee469f3e59d30a88c97aa7c1139069b261
DIFF: https://github.com/llvm/llvm-project/commit/45f949ee469f3e59d30a88c97aa7c1139069b261.diff
LOG: [MC] Migrate some parseToken(AsmToken::EndOfStatement, ...) to parseEOL()
Added:
Modified:
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/test/MC/AsmParser/AArch64/directive-parse-err.s
llvm/test/MC/AsmParser/directive_dcb.s
llvm/test/MC/AsmParser/directive_ds.s
llvm/test/MC/AsmParser/directive_print.s
llvm/test/MC/AsmParser/directive_rept-diagnostics.s
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index aafd68e9c381..3ef51e69ab7e 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3059,9 +3059,8 @@ bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
return Error(ExprLoc, "expression must be relocatable");
}
- if (parseToken(AsmToken::EndOfStatement,
- "unexpected token in .reloc directive"))
- return true;
+ if (parseEOL())
+ return true;
const MCTargetAsmParser &MCT = getTargetParser();
const MCSubtargetInfo &STI = MCT.getSTI();
@@ -3513,11 +3512,7 @@ bool AsmParser::parseDirectiveLine() {
(void)LineNumber;
// FIXME: Do something with the .line.
}
- if (parseToken(AsmToken::EndOfStatement,
- "unexpected token in '.line' directive"))
- return true;
-
- return false;
+ return parseEOL();
}
/// parseDirectiveLoc
@@ -4355,8 +4350,7 @@ bool AsmParser::parseDirectiveCFIReturnColumn(SMLoc DirectiveLoc) {
/// parseDirectiveCFISignalFrame
/// ::= .cfi_signal_frame
bool AsmParser::parseDirectiveCFISignalFrame() {
- if (parseToken(AsmToken::EndOfStatement,
- "unexpected token in '.cfi_signal_frame'"))
+ if (parseEOL())
return true;
getStreamer().emitCFISignalFrame();
@@ -4667,15 +4661,14 @@ bool AsmParser::parseDirectiveEndMacro(StringRef Directive) {
}
/// parseDirectivePurgeMacro
-/// ::= .purgem
+/// ::= .purgem name
bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
StringRef Name;
SMLoc Loc;
if (parseTokenLoc(Loc) ||
check(parseIdentifier(Name), Loc,
"expected identifier in '.purgem' directive") ||
- parseToken(AsmToken::EndOfStatement,
- "unexpected token in '.purgem' directive"))
+ parseEOL())
return true;
if (!getContext().lookupMacro(Name))
@@ -4695,9 +4688,7 @@ bool AsmParser::parseDirectiveBundleAlignMode() {
SMLoc ExprLoc = getLexer().getLoc();
int64_t AlignSizePow2;
if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
- parseToken(AsmToken::EndOfStatement, "unexpected token after expression "
- "in '.bundle_align_mode' "
- "directive") ||
+ parseEOL() ||
check(AlignSizePow2 < 0 || AlignSizePow2 > 30, ExprLoc,
"invalid bundle alignment size (expected between 0 and 30)"))
return true;
@@ -4722,9 +4713,7 @@ bool AsmParser::parseDirectiveBundleLock() {
if (!parseOptionalToken(AsmToken::EndOfStatement)) {
if (check(parseIdentifier(Option), Loc, kInvalidOptionError) ||
- check(Option != "align_to_end", Loc, kInvalidOptionError) ||
- parseToken(AsmToken::EndOfStatement,
- "unexpected token after '.bundle_lock' directive option"))
+ check(Option != "align_to_end", Loc, kInvalidOptionError) || parseEOL())
return true;
AlignToEnd = true;
}
@@ -4799,11 +4788,7 @@ bool AsmParser::parseDirectiveDCB(StringRef IDVal, unsigned Size) {
getStreamer().emitValue(Value, Size, ExprLoc);
}
- if (parseToken(AsmToken::EndOfStatement,
- "unexpected token in '" + Twine(IDVal) + "' directive"))
- return true;
-
- return false;
+ return parseEOL();
}
/// parseDirectiveRealDCB
@@ -4824,11 +4809,7 @@ bool AsmParser::parseDirectiveRealDCB(StringRef IDVal, const fltSemantics &Seman
return true;
APInt AsInt;
- if (parseRealValue(Semantics, AsInt))
- return true;
-
- if (parseToken(AsmToken::EndOfStatement,
- "unexpected token in '" + Twine(IDVal) + "' directive"))
+ if (parseRealValue(Semantics, AsInt) || parseEOL())
return true;
for (uint64_t i = 0, e = NumValues; i != e; ++i)
@@ -4843,7 +4824,8 @@ bool AsmParser::parseDirectiveRealDCB(StringRef IDVal, const fltSemantics &Seman
bool AsmParser::parseDirectiveDS(StringRef IDVal, unsigned Size) {
SMLoc NumValuesLoc = Lexer.getLoc();
int64_t NumValues;
- if (checkForValidSection() || parseAbsoluteExpression(NumValues))
+ if (checkForValidSection() || parseAbsoluteExpression(NumValues) ||
+ parseEOL())
return true;
if (NumValues < 0) {
@@ -4851,10 +4833,6 @@ bool AsmParser::parseDirectiveDS(StringRef IDVal, unsigned Size) {
return false;
}
- if (parseToken(AsmToken::EndOfStatement,
- "unexpected token in '" + Twine(IDVal) + "' directive"))
- return true;
-
for (uint64_t i = 0, e = NumValues; i != e; ++i)
getStreamer().emitFill(Size, 0);
@@ -5271,8 +5249,7 @@ bool AsmParser::parseDirectiveElse(SMLoc DirectiveLoc) {
/// parseDirectiveEnd
/// ::= .end
bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
- if (parseToken(AsmToken::EndOfStatement,
- "unexpected token in '.end' directive"))
+ if (parseEOL())
return true;
while (Lexer.isNot(AsmToken::Eof))
@@ -5325,8 +5302,7 @@ bool AsmParser::parseDirectiveWarning(SMLoc L) {
Message = getTok().getStringContents();
Lex();
- if (parseToken(AsmToken::EndOfStatement,
- "expected end of statement in '.warning' directive"))
+ if (parseEOL())
return true;
}
@@ -5598,9 +5574,7 @@ bool AsmParser::parseDirectiveRept(SMLoc DirectiveLoc, StringRef Dir) {
return Error(CountLoc, "unexpected token in '" + Dir + "' directive");
}
- if (check(Count < 0, CountLoc, "Count is negative") ||
- parseToken(AsmToken::EndOfStatement,
- "unexpected token in '" + Dir + "' directive"))
+ if (check(Count < 0, CountLoc, "Count is negative") || parseEOL())
return true;
// Lex the rept definition.
@@ -5630,8 +5604,7 @@ bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
if (check(parseIdentifier(Parameter.Name),
"expected identifier in '.irp' directive") ||
parseToken(AsmToken::Comma, "expected comma in '.irp' directive") ||
- parseMacroArguments(nullptr, A) ||
- parseToken(AsmToken::EndOfStatement, "expected End of Statement"))
+ parseMacroArguments(nullptr, A) || parseEOL())
return true;
// Lex the irp definition.
@@ -5670,9 +5643,7 @@ bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
if (A.size() != 1 || A.front().size() != 1)
return TokError("unexpected token in '.irpc' directive");
-
- // Eat the end of statement.
- if (parseToken(AsmToken::EndOfStatement, "expected end of statement"))
+ if (parseEOL())
return true;
// Lex the irpc definition.
@@ -5751,7 +5722,7 @@ bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) {
Lex();
if (StrTok.isNot(AsmToken::String) || StrTok.getString().front() != '"')
return Error(DirectiveLoc, "expected double quoted string after .print");
- if (parseToken(AsmToken::EndOfStatement, "expected end of statement"))
+ if (parseEOL())
return true;
llvm::outs() << StrTok.getStringContents() << '\n';
return false;
@@ -5828,8 +5799,7 @@ bool AsmParser::parseDirectivePseudoProbe() {
InlineStack.push_back(Site);
}
- if (parseToken(AsmToken::EndOfStatement,
- "unexpected token in '.pseudoprobe' directive"))
+ if (parseEOL())
return true;
getStreamer().emitPseudoProbe(Guid, Index, Type, Attr, InlineStack);
diff --git a/llvm/test/MC/AsmParser/AArch64/directive-parse-err.s b/llvm/test/MC/AsmParser/AArch64/directive-parse-err.s
index ca806f36ff95..5496da52fa9c 100644
--- a/llvm/test/MC/AsmParser/AArch64/directive-parse-err.s
+++ b/llvm/test/MC/AsmParser/AArch64/directive-parse-err.s
@@ -149,13 +149,13 @@
.p2alignl 0 $
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
.p2alignl 0 // EOL COMMENT
- // CHECK: [[@LINE+1]]:8: error: unexpected token in '.line' directive
+ // CHECK: [[#@LINE+1]]:8: error: expected newline
.line $
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
.line // EOL COMMENT
- // CHECK: [[@LINE+1]]:10: error: unexpected token in '.line' directive
+ // CHECK: [[#@LINE+1]]:10: error: expected newline
.line 0 $
- // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
+ // CHECK-NOT: [[#@LINE+1]]:{{[0-9]+}}: error:
.line 0 // EOL COMMENT
.file 1 "hello"
@@ -175,9 +175,9 @@
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
.cv_loc 1 1 // EOL COMMENT
- // CHECK: [[@LINE+1]]:28: error: unexpected token after '.bundle_lock' directive option
+ // CHECK: [[#@LINE+1]]:28: error: expected newline
.bundle_lock align_to_end $
- // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
+ // CHECK-NOT: [[#@LINE+1]]:{{[0-9]+}}: error:
.bundle_lock align_to_end // EOL COMMENT
// CHECK: [[@LINE+1]]:11: error: invalid token in expression in directive
@@ -237,9 +237,9 @@
.warning $
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
.warning // EOL COMMENT
- // CHECK: [[@LINE+1]]:21: error: expected end of statement in '.warning' directive
+ // CHECK: [[#@LINE+1]]:21: error: expected newline
.warning "warning" $
- // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
+ // CHECK-NOT: [[#@LINE+1]]:{{[0-9]+}}: error:
.warning "warning" // EOL COMMENT
diff --git a/llvm/test/MC/AsmParser/directive_dcb.s b/llvm/test/MC/AsmParser/directive_dcb.s
index 4445ccc76b4f..b569cab22dd7 100644
--- a/llvm/test/MC/AsmParser/directive_dcb.s
+++ b/llvm/test/MC/AsmParser/directive_dcb.s
@@ -1,5 +1,5 @@
-# RUN: not llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
-# RUN: not llvm-mc -triple i386-unknown-unknown %s 2>&1 > /dev/null| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=i386 %s | FileCheck %s
+# RUN: not llvm-mc -triple=i386 --defsym ERR=1 %s 2>&1 > /dev/null | FileCheck %s --check-prefix=ERR
# CHECK: TEST0:
# CHECK: .byte 1
@@ -42,18 +42,16 @@ TEST5:
TEST6:
.dcb.d 5, .232
-# CHECK-ERROR: error: .dcb.x not currently supported for this target
-TEST7:
- .dcb.x 3, 1.2e3
+.ifdef ERR
+# ERR: :[[#@LINE+1]]:8: error: .dcb.x not currently supported for this target
+.dcb.x 3, 1.2e3
-# CHECK-ERROR: warning: '.dcb' directive with negative repeat count has no effect
-TEST8:
- .dcb -1, 2
+# ERR: :[[#@LINE+1]]:6: warning: '.dcb' directive with negative repeat count has no effect
+.dcb -1, 2
-# CHECK-ERROR: error: unexpected token in '.dcb' directive
-TEST9:
- .dcb 1 2
+# ERR: :[[#@LINE+1]]:8: error: unexpected token in '.dcb' directive
+.dcb 1 2
-# CHECK-ERROR: error: unexpected token in '.dcb' directive
-TEST10:
- .dcb 1, 2 3
+# ERR: :[[#@LINE+1]]:11: error: expected newline
+.dcb 1, 2 3
+.endif
diff --git a/llvm/test/MC/AsmParser/directive_ds.s b/llvm/test/MC/AsmParser/directive_ds.s
index ba61fbaa387b..ea66f019e533 100644
--- a/llvm/test/MC/AsmParser/directive_ds.s
+++ b/llvm/test/MC/AsmParser/directive_ds.s
@@ -53,6 +53,6 @@ TEST7:
TEST8:
.ds -1
-# CHECK-ERROR: error: unexpected token in '.ds' directive
+# CHECK-ERROR: :[[#@LINE+2]]:9: error: expected newline
TEST9:
- .ds 1 2
+ .ds 1 2
diff --git a/llvm/test/MC/AsmParser/directive_print.s b/llvm/test/MC/AsmParser/directive_print.s
index 9d2284408852..463a05ff70a3 100644
--- a/llvm/test/MC/AsmParser/directive_print.s
+++ b/llvm/test/MC/AsmParser/directive_print.s
@@ -1,5 +1,5 @@
-# RUN: not llvm-mc -triple i386-linux-gnu %s 2> %t.err | FileCheck %s
-# RUN: FileCheck < %t.err %s --check-prefix=CHECK-ERR
+# RUN: llvm-mc -triple i386 %s | FileCheck %s
+# RUN: not llvm-mc -triple i386 --defsym ERR=1 %s 2>&1 | FileCheck %s --check-prefix=ERR
T1:
# CHECK: e
@@ -7,12 +7,12 @@ T1:
.print "e"
.print "2.718281828459045235"
-T2:
-# CHECK-ERR: expected double quoted string after .print
+.ifdef ERR
+# CHECK-ERR: :[[#@LINE+2]]:8: expected double quoted string after .print
.altmacro
.print <pi>
.noaltmacro
-T3:
-# CHECK-ERR: expected end of statement
+# ERR: :[[#@LINE+1]]:12: error: expected newline
.print "a" "misplaced-string"
+.endif
diff --git a/llvm/test/MC/AsmParser/directive_rept-diagnostics.s b/llvm/test/MC/AsmParser/directive_rept-diagnostics.s
index cbef15869004..40c355514a05 100644
--- a/llvm/test/MC/AsmParser/directive_rept-diagnostics.s
+++ b/llvm/test/MC/AsmParser/directive_rept-diagnostics.s
@@ -35,7 +35,7 @@ negative:
trailer:
.rep 0 trailer
-# CHECK: error: unexpected token in '.rep' directive
+# CHECK: :[[#@LINE-2]]:9: error: expected newline
# CHECK: .rep 0 trailer
# CHECK: ^
More information about the llvm-commits
mailing list