: 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;
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 {
// 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";
}
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";
}
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";
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";
}
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";
}