1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[MC] Add MCAsmParser::parseComma to improve diagnostics

llvm-mc will error "expected comma" instead of "unexpected token".
This commit is contained in:
Fangrui Song 2021-05-04 14:13:19 -07:00
parent 3389648c5f
commit c70d7b131b
4 changed files with 28 additions and 40 deletions

View File

@ -260,6 +260,7 @@ public:
/// success.
bool parseOptionalToken(AsmToken::TokenKind T);
bool parseComma() { return parseToken(AsmToken::Comma, "expected comma"); }
bool parseEOL();
bool parseEOL(const Twine &ErrMsg);

View File

@ -2942,8 +2942,8 @@ bool AsmParser::parseIdentifier(StringRef &Res) {
/// ::= .set identifier ',' expression
bool AsmParser::parseDirectiveSet(StringRef IDVal, bool allow_redef) {
StringRef Name;
if (check(parseIdentifier(Name), "expected identifier") ||
parseToken(AsmToken::Comma) || parseAssignment(Name, allow_redef, true))
if (check(parseIdentifier(Name), "expected identifier") || parseComma() ||
parseAssignment(Name, allow_redef, true))
return true;
return false;
}
@ -3071,7 +3071,7 @@ bool AsmParser::parseDirectiveReloc(SMLoc DirectiveLoc) {
if (parseExpression(Offset))
return true;
if (parseToken(AsmToken::Comma, "expected comma") ||
if (parseComma() ||
check(getTok().isNot(AsmToken::Identifier), "expected relocation name"))
return true;
@ -3425,9 +3425,7 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
// Usually the directory and filename together, otherwise just the directory.
// Allow the strings to have escaped octal character sequence.
if (check(getTok().isNot(AsmToken::String),
"unexpected token in '.file' directive") ||
parseEscapedString(Path))
if (parseEscapedString(Path))
return true;
StringRef Directory;
@ -3859,14 +3857,12 @@ bool AsmParser::parseDirectiveCVLinetable() {
int64_t FunctionId;
StringRef FnStartName, FnEndName;
SMLoc Loc = getTok().getLoc();
if (parseCVFunctionId(FunctionId, ".cv_linetable") ||
parseToken(AsmToken::Comma,
"unexpected token in '.cv_linetable' directive") ||
parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
if (parseCVFunctionId(FunctionId, ".cv_linetable") || parseComma() ||
parseTokenLoc(Loc) ||
check(parseIdentifier(FnStartName), Loc,
"expected identifier in directive") ||
parseToken(AsmToken::Comma,
"unexpected token in '.cv_linetable' directive") ||
parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
parseComma() || parseTokenLoc(Loc) ||
check(parseIdentifier(FnEndName), Loc,
"expected identifier in directive"))
return true;
@ -4100,7 +4096,7 @@ bool AsmParser::parseDirectiveCFISections() {
Debug = true;
if (parseOptionalToken(AsmToken::EndOfStatement))
break;
if (parseToken(AsmToken::Comma))
if (parseComma())
return true;
}
}
@ -4156,8 +4152,7 @@ bool AsmParser::parseRegisterOrRegisterNumber(int64_t &Register,
/// ::= .cfi_def_cfa register, offset
bool AsmParser::parseDirectiveCFIDefCfa(SMLoc DirectiveLoc) {
int64_t Register = 0, Offset = 0;
if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
parseToken(AsmToken::Comma, "unexpected token in directive") ||
if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) || parseComma() ||
parseAbsoluteExpression(Offset) || parseEOL())
return true;
@ -4180,8 +4175,7 @@ bool AsmParser::parseDirectiveCFIDefCfaOffset() {
/// ::= .cfi_register register, register
bool AsmParser::parseDirectiveCFIRegister(SMLoc DirectiveLoc) {
int64_t Register1 = 0, Register2 = 0;
if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) ||
parseToken(AsmToken::Comma, "unexpected token in directive") ||
if (parseRegisterOrRegisterNumber(Register1, DirectiveLoc) || parseComma() ||
parseRegisterOrRegisterNumber(Register2, DirectiveLoc) || parseEOL())
return true;
@ -4226,8 +4220,7 @@ bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
int64_t Register = 0;
int64_t Offset = 0;
if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
parseToken(AsmToken::Comma, "unexpected token in directive") ||
if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) || parseComma() ||
parseAbsoluteExpression(Offset) || parseEOL())
return true;
@ -4240,8 +4233,7 @@ bool AsmParser::parseDirectiveCFIOffset(SMLoc DirectiveLoc) {
bool AsmParser::parseDirectiveCFIRelOffset(SMLoc DirectiveLoc) {
int64_t Register = 0, Offset = 0;
if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) ||
parseToken(AsmToken::Comma, "unexpected token in directive") ||
if (parseRegisterOrRegisterNumber(Register, DirectiveLoc) || parseComma() ||
parseAbsoluteExpression(Offset) || parseEOL())
return true;
@ -4284,7 +4276,7 @@ bool AsmParser::parseDirectiveCFIPersonalityOrLsda(bool IsPersonality) {
StringRef Name;
if (check(!isValidEncoding(Encoding), "unsupported encoding.") ||
parseToken(AsmToken::Comma, "unexpected token in directive") ||
parseComma() ||
check(parseIdentifier(Name), "expected identifier in directive") ||
parseEOL())
return true;
@ -4791,8 +4783,7 @@ bool AsmParser::parseDirectiveDCB(StringRef IDVal, unsigned Size) {
return false;
}
if (parseToken(AsmToken::Comma,
"unexpected token in '" + Twine(IDVal) + "' directive"))
if (parseComma())
return true;
const MCExpr *Value;
@ -4829,8 +4820,7 @@ bool AsmParser::parseDirectiveRealDCB(StringRef IDVal, const fltSemantics &Seman
return false;
}
if (parseToken(AsmToken::Comma,
"unexpected token in '" + Twine(IDVal) + "' directive"))
if (parseComma())
return true;
APInt AsInt;
@ -4924,9 +4914,8 @@ bool AsmParser::parseDirectiveComm(bool IsLocal) {
// Handle the identifier as the key symbol.
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
if (getLexer().isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
Lex();
if (parseComma())
return true;
int64_t Size;
SMLoc SizeLoc = getLexer().getLoc();
@ -5139,7 +5128,7 @@ bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc, bool ExpectEqual) {
} else {
StringRef Str1 = parseStringToComma();
if (parseToken(AsmToken::Comma, "unexpected token in '.ifc' directive"))
if (parseComma())
return true;
StringRef Str2 = parseStringToEndOfStatement();
@ -5628,8 +5617,7 @@ bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
MCAsmMacroArguments A;
if (check(parseIdentifier(Parameter.Name),
"expected identifier in '.irp' directive") ||
parseToken(AsmToken::Comma, "expected comma in '.irp' directive") ||
parseMacroArguments(nullptr, A) || parseEOL())
parseComma() || parseMacroArguments(nullptr, A) || parseEOL())
return true;
// Lex the irp definition.
@ -5662,8 +5650,7 @@ bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
if (check(parseIdentifier(Parameter.Name),
"expected identifier in '.irpc' directive") ||
parseToken(AsmToken::Comma, "expected comma in '.irpc' directive") ||
parseMacroArguments(nullptr, A))
parseComma() || parseMacroArguments(nullptr, A))
return true;
if (A.size() != 1 || A.front().size() != 1)

View File

@ -49,7 +49,7 @@ TEST6:
# ERR: :[[#@LINE+1]]:6: warning: '.dcb' directive with negative repeat count has no effect
.dcb -1, 2
# ERR: :[[#@LINE+1]]:8: error: unexpected token in '.dcb' directive
# ERR: :[[#@LINE+1]]:8: error: expected comma
.dcb 1 2
# ERR: :[[#@LINE+1]]:11: error: expected newline

View File

@ -446,9 +446,9 @@ f37:
.ifdef ERR
// ERR: [[#@LINE+1]]:15: error: expected .eh_frame or .debug_frame
.cfi_sections $
// ERR: [[#@LINE+1]]:28: error: unexpected token
// ERR: [[#@LINE+1]]:28: error: expected comma
.cfi_sections .debug_frame $
// ERR: [[#@LINE+1]]:39: error: unexpected token
// ERR: [[#@LINE+1]]:39: error: expected comma
.cfi_sections .debug_frame, .eh_frame $
// ERR: [[#@LINE+1]]:16: error: unexpected token