Skip to content

Commit 0050e04

Browse files
MaskRaycuviper
authored andcommitted
[RISCV][MC] Simplify .option and make error messages more conventional
and add line/column information to tests.
1 parent 22897bc commit 0050e04

File tree

2 files changed

+35
-59
lines changed

2 files changed

+35
-59
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

+27-51
Original file line numberDiff line numberDiff line change
@@ -2043,109 +2043,85 @@ bool RISCVAsmParser::parseDirectiveOption() {
20432043
MCAsmParser &Parser = getParser();
20442044
// Get the option token.
20452045
AsmToken Tok = Parser.getTok();
2046+
20462047
// At the moment only identifiers are supported.
2047-
if (Tok.isNot(AsmToken::Identifier))
2048-
return Error(Parser.getTok().getLoc(),
2049-
"unexpected token, expected identifier");
2048+
if (parseToken(AsmToken::Identifier, "expected identifier"))
2049+
return true;
20502050

20512051
StringRef Option = Tok.getIdentifier();
20522052

20532053
if (Option == "push") {
2054-
getTargetStreamer().emitDirectiveOptionPush();
2055-
2056-
Parser.Lex();
2057-
if (Parser.getTok().isNot(AsmToken::EndOfStatement))
2058-
return Error(Parser.getTok().getLoc(),
2059-
"unexpected token, expected end of statement");
2054+
if (Parser.parseEOL())
2055+
return true;
20602056

2057+
getTargetStreamer().emitDirectiveOptionPush();
20612058
pushFeatureBits();
20622059
return false;
20632060
}
20642061

20652062
if (Option == "pop") {
20662063
SMLoc StartLoc = Parser.getTok().getLoc();
2067-
getTargetStreamer().emitDirectiveOptionPop();
2068-
2069-
Parser.Lex();
2070-
if (Parser.getTok().isNot(AsmToken::EndOfStatement))
2071-
return Error(Parser.getTok().getLoc(),
2072-
"unexpected token, expected end of statement");
2064+
if (Parser.parseEOL())
2065+
return true;
20732066

2067+
getTargetStreamer().emitDirectiveOptionPop();
20742068
if (popFeatureBits())
20752069
return Error(StartLoc, ".option pop with no .option push");
20762070

20772071
return false;
20782072
}
20792073

20802074
if (Option == "rvc") {
2081-
getTargetStreamer().emitDirectiveOptionRVC();
2082-
2083-
Parser.Lex();
2084-
if (Parser.getTok().isNot(AsmToken::EndOfStatement))
2085-
return Error(Parser.getTok().getLoc(),
2086-
"unexpected token, expected end of statement");
2075+
if (Parser.parseEOL())
2076+
return true;
20872077

2078+
getTargetStreamer().emitDirectiveOptionRVC();
20882079
setFeatureBits(RISCV::FeatureStdExtC, "c");
20892080
return false;
20902081
}
20912082

20922083
if (Option == "norvc") {
2093-
getTargetStreamer().emitDirectiveOptionNoRVC();
2094-
2095-
Parser.Lex();
2096-
if (Parser.getTok().isNot(AsmToken::EndOfStatement))
2097-
return Error(Parser.getTok().getLoc(),
2098-
"unexpected token, expected end of statement");
2084+
if (Parser.parseEOL())
2085+
return true;
20992086

2087+
getTargetStreamer().emitDirectiveOptionNoRVC();
21002088
clearFeatureBits(RISCV::FeatureStdExtC, "c");
21012089
clearFeatureBits(RISCV::FeatureExtZca, "+experimental-zca");
21022090
return false;
21032091
}
21042092

21052093
if (Option == "pic") {
2106-
getTargetStreamer().emitDirectiveOptionPIC();
2107-
2108-
Parser.Lex();
2109-
if (Parser.getTok().isNot(AsmToken::EndOfStatement))
2110-
return Error(Parser.getTok().getLoc(),
2111-
"unexpected token, expected end of statement");
2094+
if (Parser.parseEOL())
2095+
return true;
21122096

2097+
getTargetStreamer().emitDirectiveOptionPIC();
21132098
ParserOptions.IsPicEnabled = true;
21142099
return false;
21152100
}
21162101

21172102
if (Option == "nopic") {
2118-
getTargetStreamer().emitDirectiveOptionNoPIC();
2119-
2120-
Parser.Lex();
2121-
if (Parser.getTok().isNot(AsmToken::EndOfStatement))
2122-
return Error(Parser.getTok().getLoc(),
2123-
"unexpected token, expected end of statement");
2103+
if (Parser.parseEOL())
2104+
return true;
21242105

2106+
getTargetStreamer().emitDirectiveOptionNoPIC();
21252107
ParserOptions.IsPicEnabled = false;
21262108
return false;
21272109
}
21282110

21292111
if (Option == "relax") {
2130-
getTargetStreamer().emitDirectiveOptionRelax();
2131-
2132-
Parser.Lex();
2133-
if (Parser.getTok().isNot(AsmToken::EndOfStatement))
2134-
return Error(Parser.getTok().getLoc(),
2135-
"unexpected token, expected end of statement");
2112+
if (Parser.parseEOL())
2113+
return true;
21362114

2115+
getTargetStreamer().emitDirectiveOptionRelax();
21372116
setFeatureBits(RISCV::FeatureRelax, "relax");
21382117
return false;
21392118
}
21402119

21412120
if (Option == "norelax") {
2142-
getTargetStreamer().emitDirectiveOptionNoRelax();
2143-
2144-
Parser.Lex();
2145-
if (Parser.getTok().isNot(AsmToken::EndOfStatement))
2146-
return Error(Parser.getTok().getLoc(),
2147-
"unexpected token, expected end of statement");
2121+
if (Parser.parseEOL())
2122+
return true;
21482123

2124+
getTargetStreamer().emitDirectiveOptionNoRelax();
21492125
clearFeatureBits(RISCV::FeatureRelax, "relax");
21502126
return false;
21512127
}

llvm/test/MC/RISCV/option-invalid.s

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
# RUN: not llvm-mc -triple riscv32 < %s 2>&1 \
22
# RUN: | FileCheck -check-prefixes=CHECK %s
33

4-
# CHECK: error: unexpected token, expected identifier
4+
# CHECK: :[[#@LINE+1]]:8: error: expected identifier
55
.option
66

7-
# CHECK: error: unexpected token, expected identifier
7+
# CHECK: :[[#@LINE+1]]:9: error: expected identifier
88
.option 123
99

10-
# CHECK: error: unexpected token, expected identifier
10+
# CHECK: :[[#@LINE+1]]:9: error: expected identifier
1111
.option "str"
1212

13-
# CHECK: error: unexpected token, expected end of statement
13+
# CHECK: :[[#@LINE+1]]:13: error: expected newline
1414
.option rvc foo
1515

16-
# CHECK: warning: unknown option, expected 'push', 'pop', 'rvc', 'norvc', 'relax' or 'norelax'
16+
# CHECK: :[[#@LINE+1]]:12: warning: unknown option, expected 'push', 'pop', 'rvc', 'norvc', 'relax' or 'norelax'
1717
.option bar
1818

19-
# CHECK: error: .option pop with no .option push
19+
# CHECK: :[[#@LINE+1]]:12: error: .option pop with no .option push
2020
.option pop
2121

22-
# CHECK: error: unexpected token, expected end of statement
22+
# CHECK: :[[#@LINE+1]]:14: error: expected newline
2323
.option push 123
2424

25-
# CHECK: error: unexpected token, expected end of statement
25+
# CHECK: :[[#@LINE+1]]:13: error: expected newline
2626
.option pop 123

0 commit comments

Comments
 (0)