Skip to content

Commit 8665e83

Browse files
committed
MC: handle ParseDirective properly
Target specific parsers should return false if the target AsmParser wishes to handle the directive, true otherwise. Many of the target specific directive parsers would 'return Error' which does not follow these semantics. The result was noisy diagnostics which would also be slightly misleading. This change simply changes the target specific routine to conform to the semantics of ParseDirective properly.
1 parent 6a4207d commit 8665e83

File tree

6 files changed

+123
-117
lines changed

6 files changed

+123
-117
lines changed

lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,15 +2273,16 @@ bool AArch64AsmParser::ParseInstruction(ParseInstructionInfo &Info,
22732273
bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) {
22742274
StringRef IDVal = DirectiveID.getIdentifier();
22752275
if (IDVal == ".hword")
2276-
return ParseDirectiveWord(2, DirectiveID.getLoc());
2276+
ParseDirectiveWord(2, DirectiveID.getLoc());
22772277
else if (IDVal == ".word")
2278-
return ParseDirectiveWord(4, DirectiveID.getLoc());
2278+
ParseDirectiveWord(4, DirectiveID.getLoc());
22792279
else if (IDVal == ".xword")
2280-
return ParseDirectiveWord(8, DirectiveID.getLoc());
2280+
ParseDirectiveWord(8, DirectiveID.getLoc());
22812281
else if (IDVal == ".tlsdesccall")
2282-
return ParseDirectiveTLSDescCall(DirectiveID.getLoc());
2283-
2284-
return true;
2282+
ParseDirectiveTLSDescCall(DirectiveID.getLoc());
2283+
else
2284+
return true;
2285+
return false;
22852286
}
22862287

22872288
/// parseDirectiveWord

lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7954,56 +7954,58 @@ MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
79547954
bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
79557955
StringRef IDVal = DirectiveID.getIdentifier();
79567956
if (IDVal == ".word")
7957-
return parseDirectiveWord(4, DirectiveID.getLoc());
7957+
parseDirectiveWord(4, DirectiveID.getLoc());
79587958
else if (IDVal == ".thumb")
7959-
return parseDirectiveThumb(DirectiveID.getLoc());
7959+
parseDirectiveThumb(DirectiveID.getLoc());
79607960
else if (IDVal == ".arm")
7961-
return parseDirectiveARM(DirectiveID.getLoc());
7961+
parseDirectiveARM(DirectiveID.getLoc());
79627962
else if (IDVal == ".thumb_func")
7963-
return parseDirectiveThumbFunc(DirectiveID.getLoc());
7963+
parseDirectiveThumbFunc(DirectiveID.getLoc());
79647964
else if (IDVal == ".code")
7965-
return parseDirectiveCode(DirectiveID.getLoc());
7965+
parseDirectiveCode(DirectiveID.getLoc());
79667966
else if (IDVal == ".syntax")
7967-
return parseDirectiveSyntax(DirectiveID.getLoc());
7967+
parseDirectiveSyntax(DirectiveID.getLoc());
79687968
else if (IDVal == ".unreq")
7969-
return parseDirectiveUnreq(DirectiveID.getLoc());
7969+
parseDirectiveUnreq(DirectiveID.getLoc());
79707970
else if (IDVal == ".arch")
7971-
return parseDirectiveArch(DirectiveID.getLoc());
7971+
parseDirectiveArch(DirectiveID.getLoc());
79727972
else if (IDVal == ".eabi_attribute")
7973-
return parseDirectiveEabiAttr(DirectiveID.getLoc());
7973+
parseDirectiveEabiAttr(DirectiveID.getLoc());
79747974
else if (IDVal == ".cpu")
7975-
return parseDirectiveCPU(DirectiveID.getLoc());
7975+
parseDirectiveCPU(DirectiveID.getLoc());
79767976
else if (IDVal == ".fpu")
7977-
return parseDirectiveFPU(DirectiveID.getLoc());
7977+
parseDirectiveFPU(DirectiveID.getLoc());
79787978
else if (IDVal == ".fnstart")
7979-
return parseDirectiveFnStart(DirectiveID.getLoc());
7979+
parseDirectiveFnStart(DirectiveID.getLoc());
79807980
else if (IDVal == ".fnend")
7981-
return parseDirectiveFnEnd(DirectiveID.getLoc());
7981+
parseDirectiveFnEnd(DirectiveID.getLoc());
79827982
else if (IDVal == ".cantunwind")
7983-
return parseDirectiveCantUnwind(DirectiveID.getLoc());
7983+
parseDirectiveCantUnwind(DirectiveID.getLoc());
79847984
else if (IDVal == ".personality")
7985-
return parseDirectivePersonality(DirectiveID.getLoc());
7985+
parseDirectivePersonality(DirectiveID.getLoc());
79867986
else if (IDVal == ".handlerdata")
7987-
return parseDirectiveHandlerData(DirectiveID.getLoc());
7987+
parseDirectiveHandlerData(DirectiveID.getLoc());
79887988
else if (IDVal == ".setfp")
7989-
return parseDirectiveSetFP(DirectiveID.getLoc());
7989+
parseDirectiveSetFP(DirectiveID.getLoc());
79907990
else if (IDVal == ".pad")
7991-
return parseDirectivePad(DirectiveID.getLoc());
7991+
parseDirectivePad(DirectiveID.getLoc());
79927992
else if (IDVal == ".save")
7993-
return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7993+
parseDirectiveRegSave(DirectiveID.getLoc(), false);
79947994
else if (IDVal == ".vsave")
7995-
return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7995+
parseDirectiveRegSave(DirectiveID.getLoc(), true);
79967996
else if (IDVal == ".inst")
7997-
return parseDirectiveInst(DirectiveID.getLoc());
7997+
parseDirectiveInst(DirectiveID.getLoc());
79987998
else if (IDVal == ".inst.n")
7999-
return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7999+
parseDirectiveInst(DirectiveID.getLoc(), 'n');
80008000
else if (IDVal == ".inst.w")
8001-
return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8001+
parseDirectiveInst(DirectiveID.getLoc(), 'w');
80028002
else if (IDVal == ".ltorg" || IDVal == ".pool")
8003-
return parseDirectiveLtorg(DirectiveID.getLoc());
8003+
parseDirectiveLtorg(DirectiveID.getLoc());
80048004
else if (IDVal == ".even")
8005-
return parseDirectiveEven(DirectiveID.getLoc());
8006-
return true;
8005+
parseDirectiveEven(DirectiveID.getLoc());
8006+
else
8007+
return true;
8008+
return false;
80078009
}
80088010

80098011
/// parseDirectiveWord
@@ -8013,16 +8015,18 @@ bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
80138015
for (;;) {
80148016
const MCExpr *Value;
80158017
if (getParser().parseExpression(Value))
8016-
return true;
8018+
return false;
80178019

80188020
getParser().getStreamer().EmitValue(Value, Size);
80198021

80208022
if (getLexer().is(AsmToken::EndOfStatement))
80218023
break;
80228024

80238025
// FIXME: Improve diagnostic.
8024-
if (getLexer().isNot(AsmToken::Comma))
8025-
return Error(L, "unexpected token in directive");
8026+
if (getLexer().isNot(AsmToken::Comma)) {
8027+
Error(L, "unexpected token in directive");
8028+
return false;
8029+
}
80268030
Parser.Lex();
80278031
}
80288032
}
@@ -8034,12 +8038,16 @@ bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
80348038
/// parseDirectiveThumb
80358039
/// ::= .thumb
80368040
bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
8037-
if (getLexer().isNot(AsmToken::EndOfStatement))
8038-
return Error(L, "unexpected token in directive");
8041+
if (getLexer().isNot(AsmToken::EndOfStatement)) {
8042+
Error(L, "unexpected token in directive");
8043+
return false;
8044+
}
80398045
Parser.Lex();
80408046

8041-
if (!hasThumb())
8042-
return Error(L, "target does not support Thumb mode");
8047+
if (!hasThumb()) {
8048+
Error(L, "target does not support Thumb mode");
8049+
return false;
8050+
}
80438051

80448052
if (!isThumb())
80458053
SwitchMode();
@@ -8050,12 +8058,16 @@ bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
80508058
/// parseDirectiveARM
80518059
/// ::= .arm
80528060
bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
8053-
if (getLexer().isNot(AsmToken::EndOfStatement))
8054-
return Error(L, "unexpected token in directive");
8061+
if (getLexer().isNot(AsmToken::EndOfStatement)) {
8062+
Error(L, "unexpected token in directive");
8063+
return false;
8064+
}
80558065
Parser.Lex();
80568066

8057-
if (!hasARM())
8058-
return Error(L, "target does not support ARM mode");
8067+
if (!hasARM()) {
8068+
Error(L, "target does not support ARM mode");
8069+
return false;
8070+
}
80598071

80608072
if (isThumb())
80618073
SwitchMode();
@@ -8081,8 +8093,10 @@ bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
80818093
if (isMachO) {
80828094
const AsmToken &Tok = Parser.getTok();
80838095
if (Tok.isNot(AsmToken::EndOfStatement)) {
8084-
if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
8085-
return Error(L, "unexpected token in .thumb_func directive");
8096+
if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8097+
Error(L, "unexpected token in .thumb_func directive");
8098+
return false;
8099+
}
80868100
MCSymbol *Func =
80878101
getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
80888102
getParser().getStreamer().EmitThumbFunc(Func);
@@ -8091,8 +8105,10 @@ bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
80918105
}
80928106
}
80938107

8094-
if (getLexer().isNot(AsmToken::EndOfStatement))
8095-
return Error(L, "unexpected token in directive");
8108+
if (getLexer().isNot(AsmToken::EndOfStatement)) {
8109+
Error(L, "unexpected token in directive");
8110+
return false;
8111+
}
80968112

80978113
NextSymbolIsThumb = true;
80988114

@@ -8103,15 +8119,21 @@ bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
81038119
/// ::= .syntax unified | divided
81048120
bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
81058121
const AsmToken &Tok = Parser.getTok();
8106-
if (Tok.isNot(AsmToken::Identifier))
8107-
return Error(L, "unexpected token in .syntax directive");
8122+
if (Tok.isNot(AsmToken::Identifier)) {
8123+
Error(L, "unexpected token in .syntax directive");
8124+
return false;
8125+
}
81088126
StringRef Mode = Tok.getString();
81098127
if (Mode == "unified" || Mode == "UNIFIED")
81108128
Parser.Lex();
8111-
else if (Mode == "divided" || Mode == "DIVIDED")
8112-
return Error(L, "'.syntax divided' arm asssembly not supported");
8113-
else
8114-
return Error(L, "unrecognized syntax mode in .syntax directive");
8129+
else if (Mode == "divided" || Mode == "DIVIDED") {
8130+
Error(L, "'.syntax divided' arm asssembly not supported");
8131+
return false;
8132+
}
8133+
else {
8134+
Error(L, "unrecognized syntax mode in .syntax directive");
8135+
return false;
8136+
}
81158137

81168138
if (getLexer().isNot(AsmToken::EndOfStatement)) {
81178139
Error(Parser.getTok().getLoc(), "unexpected token in directive");

lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,74 +2499,48 @@ bool MipsAsmParser::parseDirectiveOption() {
24992499
}
25002500

25012501
bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
2502-
25032502
StringRef IDVal = DirectiveID.getString();
25042503

2505-
if (IDVal == ".ent") {
2504+
if (IDVal == ".ent")
25062505
// Ignore this directive for now.
25072506
Parser.Lex();
2508-
return false;
2509-
}
2510-
2511-
if (IDVal == ".end") {
2507+
else if (IDVal == ".end")
25122508
// Ignore this directive for now.
25132509
Parser.Lex();
2514-
return false;
2515-
}
2516-
2517-
if (IDVal == ".frame") {
2510+
else if (IDVal == ".frame")
25182511
// Ignore this directive for now.
25192512
Parser.eatToEndOfStatement();
2520-
return false;
2521-
}
2522-
2523-
if (IDVal == ".set") {
2524-
return parseDirectiveSet();
2525-
}
2526-
2527-
if (IDVal == ".fmask") {
2513+
else if (IDVal == ".set")
2514+
parseDirectiveSet();
2515+
else if (IDVal == ".fmask")
25282516
// Ignore this directive for now.
25292517
Parser.eatToEndOfStatement();
2530-
return false;
2531-
}
2532-
2533-
if (IDVal == ".mask") {
2518+
else if (IDVal == ".mask")
25342519
// Ignore this directive for now.
25352520
Parser.eatToEndOfStatement();
2536-
return false;
2537-
}
2538-
2539-
if (IDVal == ".gpword") {
2521+
else if (IDVal == ".gpword")
25402522
// Ignore this directive for now.
25412523
parseDirectiveGpWord();
2542-
return false;
2543-
}
2544-
2545-
if (IDVal == ".word") {
2524+
else if (IDVal == ".word")
25462525
parseDirectiveWord(4, DirectiveID.getLoc());
2547-
return false;
2548-
}
2549-
2550-
if (IDVal == ".mips_hack_stocg")
2551-
return parseDirectiveMipsHackStocg();
2552-
2553-
if (IDVal == ".mips_hack_elf_flags")
2554-
return parseDirectiveMipsHackELFFlags();
2555-
2556-
if (IDVal == ".option")
2526+
else if (IDVal == ".mips_hack_stocg")
2527+
parseDirectiveMipsHackStocg();
2528+
else if (IDVal == ".mips_hack_elf_flags")
2529+
parseDirectiveMipsHackELFFlags();
2530+
else if (IDVal == ".option")
25572531
return parseDirectiveOption();
2558-
2559-
if (IDVal == ".abicalls") {
2532+
else if (IDVal == ".abicalls") {
25602533
getTargetStreamer().emitDirectiveAbiCalls();
25612534
if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
25622535
Error(Parser.getTok().getLoc(), "unexpected token in directive");
25632536
// Clear line
25642537
Parser.eatToEndOfStatement();
25652538
}
2566-
return false;
25672539
}
2540+
else
2541+
return true;
25682542

2569-
return true;
2543+
return false;
25702544
}
25712545

25722546
extern "C" void LLVMInitializeMipsAsmParser() {

lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,18 +1352,22 @@ bool PPCAsmParser::ParseDirective(AsmToken DirectiveID) {
13521352
StringRef IDVal = DirectiveID.getIdentifier();
13531353
if (!isDarwin()) {
13541354
if (IDVal == ".word")
1355-
return ParseDirectiveWord(2, DirectiveID.getLoc());
1356-
if (IDVal == ".llong")
1357-
return ParseDirectiveWord(8, DirectiveID.getLoc());
1358-
if (IDVal == ".tc")
1359-
return ParseDirectiveTC(isPPC64()? 8 : 4, DirectiveID.getLoc());
1360-
if (IDVal == ".machine")
1361-
return ParseDirectiveMachine(DirectiveID.getLoc());
1355+
ParseDirectiveWord(2, DirectiveID.getLoc());
1356+
else if (IDVal == ".llong")
1357+
ParseDirectiveWord(8, DirectiveID.getLoc());
1358+
else if (IDVal == ".tc")
1359+
ParseDirectiveTC(isPPC64() ? 8 : 4, DirectiveID.getLoc());
1360+
else if (IDVal == ".machine")
1361+
ParseDirectiveMachine(DirectiveID.getLoc());
1362+
else
1363+
return true;
13621364
} else {
13631365
if (IDVal == ".machine")
1364-
return ParseDarwinDirectiveMachine(DirectiveID.getLoc());
1366+
ParseDarwinDirectiveMachine(DirectiveID.getLoc());
1367+
else
1368+
return true;
13651369
}
1366-
return true;
1370+
return false;
13671371
}
13681372

13691373
/// ParseDirectiveWord

lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,24 +2649,21 @@ MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
26492649
bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
26502650
StringRef IDVal = DirectiveID.getIdentifier();
26512651
if (IDVal == ".word")
2652-
return ParseDirectiveWord(2, DirectiveID.getLoc());
2653-
else if (IDVal.startswith(".code"))
2654-
return ParseDirectiveCode(IDVal, DirectiveID.getLoc());
2652+
ParseDirectiveWord(2, DirectiveID.getLoc());
2653+
else if (IDVal == ".code32" || IDVal == ".code64")
2654+
ParseDirectiveCode(IDVal, DirectiveID.getLoc());
26552655
else if (IDVal.startswith(".att_syntax")) {
26562656
getParser().setAssemblerDialect(0);
2657-
return false;
26582657
} else if (IDVal.startswith(".intel_syntax")) {
26592658
getParser().setAssemblerDialect(1);
26602659
if (getLexer().isNot(AsmToken::EndOfStatement)) {
2661-
if(Parser.getTok().getString() == "noprefix") {
2660+
if (Parser.getTok().getString() == "noprefix")
26622661
// FIXME : Handle noprefix
26632662
Parser.Lex();
2664-
} else
2665-
return true;
26662663
}
2667-
return false;
2668-
}
2669-
return true;
2664+
} else
2665+
return true;
2666+
return false;
26702667
}
26712668

26722669
/// ParseDirectiveWord
@@ -2716,7 +2713,7 @@ bool X86AsmParser::ParseDirectiveCode(StringRef IDVal, SMLoc L) {
27162713
getParser().getStreamer().EmitAssemblerFlag(MCAF_Code64);
27172714
}
27182715
} else {
2719-
return Error(L, "unexpected directive " + IDVal);
2716+
llvm_unreachable(Twine("unexpected directive " + IDVal).str().c_str());
27202717
}
27212718

27222719
return false;

0 commit comments

Comments
 (0)