[llvm] 23691bb - [CSKY] Replace OperandMatchResultTy with ParseStatus (NFC)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 4 12:24:16 PDT 2023
Author: Sergei Barannikov
Date: 2023-07-04T22:24:07+03:00
New Revision: 23691bbea7f521b309a20897d62aba38649d1fe4
URL: https://github.com/llvm/llvm-project/commit/23691bbea7f521b309a20897d62aba38649d1fe4
DIFF: https://github.com/llvm/llvm-project/commit/23691bbea7f521b309a20897d62aba38649d1fe4.diff
LOG: [CSKY] Replace OperandMatchResultTy with ParseStatus (NFC)
ParseStatus is slightly more convenient to use due to implicit
conversion from bool, which allows to do something like:
```
return Error(L, "msg");
```
when with MatchOperandResultTy it had to be:
```
Error(L, "msg");
return MatchOperand_ParseFail;
```
It also has more appropriate name since parse* methods are not only for
parsing operands.
Reviewed By: zixuan-wu
Differential Revision: https://reviews.llvm.org/D154315
Added:
Modified:
llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp b/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
index c4d600757d811e..317a0a301a006c 100644
--- a/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
+++ b/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
@@ -103,15 +103,15 @@ class CSKYAsmParser : public MCTargetAsmParser {
#define GET_ASSEMBLER_HEADER
#include "CSKYGenAsmMatcher.inc"
- OperandMatchResultTy parseImmediate(OperandVector &Operands);
- OperandMatchResultTy parseRegister(OperandVector &Operands);
- OperandMatchResultTy parseBaseRegImm(OperandVector &Operands);
- OperandMatchResultTy parseCSKYSymbol(OperandVector &Operands);
- OperandMatchResultTy parseConstpoolSymbol(OperandVector &Operands);
- OperandMatchResultTy parseDataSymbol(OperandVector &Operands);
- OperandMatchResultTy parsePSRFlag(OperandVector &Operands);
- OperandMatchResultTy parseRegSeq(OperandVector &Operands);
- OperandMatchResultTy parseRegList(OperandVector &Operands);
+ ParseStatus parseImmediate(OperandVector &Operands);
+ ParseStatus parseRegister(OperandVector &Operands);
+ ParseStatus parseBaseRegImm(OperandVector &Operands);
+ ParseStatus parseCSKYSymbol(OperandVector &Operands);
+ ParseStatus parseConstpoolSymbol(OperandVector &Operands);
+ ParseStatus parseDataSymbol(OperandVector &Operands);
+ ParseStatus parsePSRFlag(OperandVector &Operands);
+ ParseStatus parseRegSeq(OperandVector &Operands);
+ ParseStatus parseRegList(OperandVector &Operands);
bool parseOperand(OperandVector &Operands, StringRef Mnemonic);
@@ -1022,93 +1022,84 @@ bool CSKYAsmParser::parseRegister(MCRegister &RegNo, SMLoc &StartLoc,
return false;
}
- return MatchOperand_NoMatch;
+ return true;
}
-OperandMatchResultTy CSKYAsmParser::parseRegister(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseRegister(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
switch (getLexer().getKind()) {
default:
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
case AsmToken::Identifier: {
StringRef Name = getLexer().getTok().getIdentifier();
MCRegister RegNo;
if (matchRegisterNameHelper(getSTI(), (MCRegister &)RegNo, Name))
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
getLexer().Lex();
Operands.push_back(CSKYOperand::createReg(RegNo, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
}
}
-OperandMatchResultTy CSKYAsmParser::parseBaseRegImm(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseBaseRegImm(OperandVector &Operands) {
assert(getLexer().is(AsmToken::LParen));
Operands.push_back(CSKYOperand::createToken("(", getLoc()));
auto Tok = getParser().Lex(); // Eat '('
- if (parseRegister(Operands) != MatchOperand_Success) {
+ if (!parseRegister(Operands).isSuccess()) {
getLexer().UnLex(Tok);
Operands.pop_back();
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
}
if (getLexer().is(AsmToken::RParen)) {
Operands.push_back(CSKYOperand::createToken(")", getLoc()));
getParser().Lex(); // Eat ')'
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
- if (getLexer().isNot(AsmToken::Comma)) {
- Error(getLoc(), "expected ','");
- return MatchOperand_ParseFail;
- }
+ if (getLexer().isNot(AsmToken::Comma))
+ return Error(getLoc(), "expected ','");
getParser().Lex(); // Eat ','
- if (parseRegister(Operands) == MatchOperand_Success) {
- if (getLexer().isNot(AsmToken::LessLess)) {
- Error(getLoc(), "expected '<<'");
- return MatchOperand_ParseFail;
- }
+ if (parseRegister(Operands).isSuccess()) {
+ if (getLexer().isNot(AsmToken::LessLess))
+ return Error(getLoc(), "expected '<<'");
Operands.push_back(CSKYOperand::createToken("<<", getLoc()));
getParser().Lex(); // Eat '<<'
- if (parseImmediate(Operands) != MatchOperand_Success) {
- Error(getLoc(), "expected imm");
- return MatchOperand_ParseFail;
- }
+ if (!parseImmediate(Operands).isSuccess())
+ return Error(getLoc(), "expected imm");
- } else if (parseImmediate(Operands) != MatchOperand_Success) {
- Error(getLoc(), "expected imm");
- return MatchOperand_ParseFail;
+ } else if (!parseImmediate(Operands).isSuccess()) {
+ return Error(getLoc(), "expected imm");
}
- if (getLexer().isNot(AsmToken::RParen)) {
- Error(getLoc(), "expected ')'");
- return MatchOperand_ParseFail;
- }
+ if (getLexer().isNot(AsmToken::RParen))
+ return Error(getLoc(), "expected ')'");
Operands.push_back(CSKYOperand::createToken(")", getLoc()));
getParser().Lex(); // Eat ')'
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parseImmediate(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseImmediate(OperandVector &Operands) {
switch (getLexer().getKind()) {
default:
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
case AsmToken::LParen:
case AsmToken::Minus:
case AsmToken::Plus:
@@ -1119,14 +1110,12 @@ OperandMatchResultTy CSKYAsmParser::parseImmediate(OperandVector &Operands) {
const MCExpr *IdVal;
SMLoc S = getLoc();
- if (getParser().parseExpression(IdVal)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseExpression(IdVal))
+ return Error(getLoc(), "unknown expression");
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
Operands.push_back(CSKYOperand::createImm(IdVal, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
/// Looks at a token type and creates the relevant operand from this
@@ -1135,33 +1124,33 @@ OperandMatchResultTy CSKYAsmParser::parseImmediate(OperandVector &Operands) {
bool CSKYAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
// Check if the current operand has a custom associated parser, if so, try to
// custom parse the operand, or fallback to the general approach.
- OperandMatchResultTy Result =
+ ParseStatus Result =
MatchOperandParserImpl(Operands, Mnemonic, /*ParseForAllFeatures=*/true);
- if (Result == MatchOperand_Success)
+ if (Result.isSuccess())
return false;
- if (Result == MatchOperand_ParseFail)
+ if (Result.isFailure())
return true;
// Attempt to parse token as register
auto Res = parseRegister(Operands);
- if (Res == MatchOperand_Success)
+ if (Res.isSuccess())
return false;
- else if (Res == MatchOperand_ParseFail)
+ if (Res.isFailure())
return true;
// Attempt to parse token as (register, imm)
if (getLexer().is(AsmToken::LParen)) {
Res = parseBaseRegImm(Operands);
- if (Res == MatchOperand_Success)
+ if (Res.isSuccess())
return false;
- else if (Res == MatchOperand_ParseFail)
+ if (Res.isFailure())
return true;
}
Res = parseImmediate(Operands);
- if (Res == MatchOperand_Success)
+ if (Res.isSuccess())
return false;
- else if (Res == MatchOperand_ParseFail)
+ if (Res.isFailure())
return true;
// Finally we have exhausted all options and must declare defeat.
@@ -1169,21 +1158,19 @@ bool CSKYAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
return true;
}
-OperandMatchResultTy CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
const MCExpr *Res;
if (getLexer().getKind() != AsmToken::Identifier)
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
StringRef Identifier;
AsmToken Tok = getLexer().getTok();
- if (getParser().parseIdentifier(Identifier)) {
- Error(getLoc(), "unknown identifier");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseIdentifier(Identifier))
+ return Error(getLoc(), "unknown identifier");
CSKYMCExpr::VariantKind Kind = CSKYMCExpr::VK_CSKY_None;
if (Identifier.consume_back("@GOT"))
@@ -1214,8 +1201,7 @@ OperandMatchResultTy CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
const MCExpr *V = Sym->getVariableValue(/*SetUsed=*/false);
if (!isa<MCSymbolRefExpr>(V)) {
getLexer().UnLex(Tok); // Put back if it's not a bare symbol.
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
}
Res = V;
} else
@@ -1228,7 +1214,7 @@ OperandMatchResultTy CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
Res = CSKYMCExpr::create(Res, Kind, getContext());
Operands.push_back(CSKYOperand::createImm(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
case AsmToken::Plus:
Opcode = MCBinaryExpr::Add;
break;
@@ -1240,43 +1226,37 @@ OperandMatchResultTy CSKYAsmParser::parseCSKYSymbol(OperandVector &Operands) {
getLexer().Lex(); // eat + or -
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
Res = MCBinaryExpr::create(Opcode, Res, Expr, getContext());
Operands.push_back(CSKYOperand::createImm(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
const MCExpr *Res;
if (!parseOptionalToken(AsmToken::LBrac))
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
if (getLexer().getKind() != AsmToken::Identifier) {
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
if (parseToken(AsmToken::RBrac, "expected ']'"))
- return MatchOperand_ParseFail;
+ return ParseStatus::Failure;
Operands.push_back(CSKYOperand::createConstpoolOp(Expr, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
AsmToken Tok = getLexer().getTok();
StringRef Identifier;
- if (getParser().parseIdentifier(Identifier)) {
- Error(getLoc(), "unknown identifier " + Identifier);
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseIdentifier(Identifier))
+ return Error(getLoc(), "unknown identifier " + Identifier);
CSKYMCExpr::VariantKind Kind = CSKYMCExpr::VK_CSKY_None;
if (Identifier.consume_back("@GOT"))
@@ -1293,8 +1273,7 @@ OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
const MCExpr *V = Sym->getVariableValue(/*SetUsed=*/false);
if (!isa<MCSymbolRefExpr>(V)) {
getLexer().UnLex(Tok); // Put back if it's not a bare symbol.
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
}
Res = V;
} else {
@@ -1304,8 +1283,7 @@ OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
MCBinaryExpr::Opcode Opcode;
switch (getLexer().getKind()) {
default:
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
case AsmToken::RBrac:
getLexer().Lex(); // Eat ']'.
@@ -1314,7 +1292,7 @@ OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
Res = CSKYMCExpr::create(Res, Kind, getContext());
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
case AsmToken::Plus:
Opcode = MCBinaryExpr::Add;
break;
@@ -1326,47 +1304,40 @@ OperandMatchResultTy CSKYAsmParser::parseDataSymbol(OperandVector &Operands) {
getLexer().Lex(); // eat + or -
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
if (parseToken(AsmToken::RBrac, "expected ']'"))
- return MatchOperand_ParseFail;
+ return ParseStatus::Failure;
Res = MCBinaryExpr::create(Opcode, Res, Expr, getContext());
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy
-CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
const MCExpr *Res;
if (!parseOptionalToken(AsmToken::LBrac))
- return MatchOperand_NoMatch;
+ return ParseStatus::NoMatch;
if (getLexer().getKind() != AsmToken::Identifier) {
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
if (parseToken(AsmToken::RBrac))
- return MatchOperand_ParseFail;
+ return ParseStatus::Failure;
Operands.push_back(CSKYOperand::createConstpoolOp(Expr, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
AsmToken Tok = getLexer().getTok();
StringRef Identifier;
- if (getParser().parseIdentifier(Identifier)) {
- Error(getLoc(), "unknown identifier");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseIdentifier(Identifier))
+ return Error(getLoc(), "unknown identifier");
MCSymbol *Sym = getContext().getInlineAsmLabel(Identifier);
@@ -1377,8 +1348,7 @@ CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
const MCExpr *V = Sym->getVariableValue(/*SetUsed=*/false);
if (!isa<MCSymbolRefExpr>(V)) {
getLexer().UnLex(Tok); // Put back if it's not a bare symbol.
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
}
Res = V;
} else {
@@ -1388,14 +1358,13 @@ CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
MCBinaryExpr::Opcode Opcode;
switch (getLexer().getKind()) {
default:
- Error(getLoc(), "unknown symbol");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "unknown symbol");
case AsmToken::RBrac:
getLexer().Lex(); // Eat ']'.
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
case AsmToken::Plus:
Opcode = MCBinaryExpr::Add;
break;
@@ -1407,19 +1376,17 @@ CSKYAsmParser::parseConstpoolSymbol(OperandVector &Operands) {
getLexer().Lex(); // eat + or -
const MCExpr *Expr;
- if (getParser().parseExpression(Expr)) {
- Error(getLoc(), "unknown expression");
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseExpression(Expr))
+ return Error(getLoc(), "unknown expression");
if (parseToken(AsmToken::RBrac, "expected ']'"))
- return MatchOperand_ParseFail;
+ return ParseStatus::Failure;
Res = MCBinaryExpr::create(Opcode, Res, Expr, getContext());
Operands.push_back(CSKYOperand::createConstpoolOp(Res, S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parsePSRFlag(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parsePSRFlag(OperandVector &Operands) {
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
@@ -1427,10 +1394,8 @@ OperandMatchResultTy CSKYAsmParser::parsePSRFlag(OperandVector &Operands) {
while (getLexer().isNot(AsmToken::EndOfStatement)) {
StringRef Identifier;
- if (getParser().parseIdentifier(Identifier)) {
- Error(getLoc(), "unknown identifier " + Identifier);
- return MatchOperand_ParseFail;
- }
+ if (getParser().parseIdentifier(Identifier))
+ return Error(getLoc(), "unknown identifier " + Identifier);
if (Identifier == "sie")
Flag = (1 << 4) | Flag;
@@ -1442,66 +1407,58 @@ OperandMatchResultTy CSKYAsmParser::parsePSRFlag(OperandVector &Operands) {
Flag = (1 << 1) | Flag;
else if (Identifier == "af")
Flag = (1 << 0) | Flag;
- else {
- Error(getLoc(), "expected " + Identifier);
- return MatchOperand_ParseFail;
- }
+ else
+ return Error(getLoc(), "expected " + Identifier);
if (getLexer().is(AsmToken::EndOfStatement))
break;
if (parseToken(AsmToken::Comma, "expected ','"))
- return MatchOperand_ParseFail;
+ return ParseStatus::Failure;
}
Operands.push_back(
CSKYOperand::createImm(MCConstantExpr::create(Flag, getContext()), S, E));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parseRegSeq(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseRegSeq(OperandVector &Operands) {
SMLoc S = getLoc();
- if (parseRegister(Operands) != MatchOperand_Success)
- return MatchOperand_NoMatch;
+ if (!parseRegister(Operands).isSuccess())
+ return ParseStatus::NoMatch;
auto Ry = Operands.back()->getReg();
Operands.pop_back();
if (parseToken(AsmToken::Minus, "expected '-'"))
- return MatchOperand_ParseFail;
- if (parseRegister(Operands) != MatchOperand_Success) {
- Error(getLoc(), "invalid register");
- return MatchOperand_ParseFail;
- }
+ return ParseStatus::Failure;
+ if (!parseRegister(Operands).isSuccess())
+ return Error(getLoc(), "invalid register");
auto Rz = Operands.back()->getReg();
Operands.pop_back();
Operands.push_back(CSKYOperand::createRegSeq(Ry, Rz, S));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
-OperandMatchResultTy CSKYAsmParser::parseRegList(OperandVector &Operands) {
+ParseStatus CSKYAsmParser::parseRegList(OperandVector &Operands) {
SMLoc S = getLoc();
SmallVector<unsigned, 4> reglist;
while (true) {
- if (parseRegister(Operands) != MatchOperand_Success) {
- Error(getLoc(), "invalid register");
- return MatchOperand_ParseFail;
- }
+ if (!parseRegister(Operands).isSuccess())
+ return Error(getLoc(), "invalid register");
auto Ry = Operands.back()->getReg();
Operands.pop_back();
if (parseOptionalToken(AsmToken::Minus)) {
- if (parseRegister(Operands) != MatchOperand_Success) {
- Error(getLoc(), "invalid register");
- return MatchOperand_ParseFail;
- }
+ if (!parseRegister(Operands).isSuccess())
+ return Error(getLoc(), "invalid register");
auto Rz = Operands.back()->getReg();
Operands.pop_back();
@@ -1520,13 +1477,12 @@ OperandMatchResultTy CSKYAsmParser::parseRegList(OperandVector &Operands) {
reglist.push_back(Ry);
break;
} else {
- Error(getLoc(), "invalid register list");
- return MatchOperand_ParseFail;
+ return Error(getLoc(), "invalid register list");
}
}
Operands.push_back(CSKYOperand::createRegList(reglist, S));
- return MatchOperand_Success;
+ return ParseStatus::Success;
}
bool CSKYAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
More information about the llvm-commits
mailing list