diff --git a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h --- a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h +++ b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h @@ -122,6 +122,12 @@ : AsmRewrites(rewrites) {} }; +enum OperandMatchResultTy { + MatchOperand_Success, // operand matched successfully + MatchOperand_NoMatch, // operand did not match + MatchOperand_ParseFail // operand matched but had errors +}; + /// Ternary parse status returned by various parse* methods. class ParseStatus { enum class StatusTy { Success, Failure, NoMatch } Status; @@ -146,12 +152,17 @@ constexpr bool isSuccess() const { return Status == StatusTy::Success; } constexpr bool isFailure() const { return Status == StatusTy::Failure; } constexpr bool isNoMatch() const { return Status == StatusTy::NoMatch; } -}; -enum OperandMatchResultTy { - MatchOperand_Success, // operand matched successfully - MatchOperand_NoMatch, // operand did not match - MatchOperand_ParseFail // operand matched but had errors + // Allow implicit conversions to / from OperandMatchResultTy. + constexpr ParseStatus(OperandMatchResultTy R) + : Status(R == MatchOperand_Success ? Success + : R == MatchOperand_ParseFail ? Failure + : NoMatch) {} + constexpr operator OperandMatchResultTy() const { + return isSuccess() ? MatchOperand_Success + : isFailure() ? MatchOperand_ParseFail + : MatchOperand_NoMatch; + } }; enum class DiagnosticPredicateTy { diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp --- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp +++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp @@ -2927,7 +2927,7 @@ // Emit the operand class switch to call the correct custom parser for // the found operand class. - OS << "OperandMatchResultTy " << Target.getName() << ClassName << "::\n" + OS << "ParseStatus " << Target.getName() << ClassName << "::\n" << "tryCustomParseOperand(OperandVector" << " &Operands,\n unsigned MCK) {\n\n" << " switch(MCK) {\n"; @@ -2940,15 +2940,15 @@ } OS << " default:\n"; - OS << " return MatchOperand_NoMatch;\n"; + OS << " return ParseStatus::NoMatch;\n"; OS << " }\n"; - OS << " return MatchOperand_NoMatch;\n"; + OS << " return ParseStatus::NoMatch;\n"; OS << "}\n\n"; // Emit the static custom operand parser. This code is very similar with // the other matcher. Also use MatchResultTy here just in case we go for // a better error handling. - OS << "OperandMatchResultTy " << Target.getName() << ClassName << "::\n" + OS << "ParseStatus " << Target.getName() << ClassName << "::\n" << "MatchOperandParserImpl(OperandVector" << " &Operands,\n StringRef Mnemonic,\n" << " bool ParseForAllFeatures) {\n"; @@ -2979,7 +2979,7 @@ } OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; - OS << " return MatchOperand_NoMatch;\n\n"; + OS << " return ParseStatus::NoMatch;\n\n"; OS << " for (const OperandMatchEntry *it = MnemonicRange.first,\n" << " *ie = MnemonicRange.second; it != ie; ++it) {\n"; @@ -3005,14 +3005,13 @@ if (ParserName.empty()) ParserName = "tryCustomParseOperand"; OS << " // call custom parse method to handle the operand\n"; - OS << " OperandMatchResultTy Result = " << ParserName - << "(Operands, it->Class);\n"; - OS << " if (Result != MatchOperand_NoMatch)\n"; + OS << " ParseStatus Result = " << ParserName << "(Operands, it->Class);\n"; + OS << " if (!Result.isNoMatch())\n"; OS << " return Result;\n"; OS << " }\n\n"; OS << " // Okay, we had no match.\n"; - OS << " return MatchOperand_NoMatch;\n"; + OS << " return ParseStatus::NoMatch;\n"; OS << "}\n\n"; } @@ -3308,12 +3307,12 @@ if (!Info.OperandMatchInfo.empty()) { - OS << " OperandMatchResultTy MatchOperandParserImpl(\n"; + OS << " ParseStatus MatchOperandParserImpl(\n"; OS << " OperandVector &Operands,\n"; OS << " StringRef Mnemonic,\n"; OS << " bool ParseForAllFeatures = false);\n"; - OS << " OperandMatchResultTy tryCustomParseOperand(\n"; + OS << " ParseStatus tryCustomParseOperand(\n"; OS << " OperandVector &Operands,\n"; OS << " unsigned MCK);\n\n"; }