[llvm] 15ef9b2 - [MC] Allow conversion between ParseStatus and MatchOperandResultTy
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 1 14:49:00 PDT 2023
Author: Sergei Barannikov
Date: 2023-07-02T00:48:13+03:00
New Revision: 15ef9b26adeb8c9dd98228fc26757966d8355986
URL: https://github.com/llvm/llvm-project/commit/15ef9b26adeb8c9dd98228fc26757966d8355986
DIFF: https://github.com/llvm/llvm-project/commit/15ef9b26adeb8c9dd98228fc26757966d8355986.diff
LOG: [MC] Allow conversion between ParseStatus and MatchOperandResultTy
This allows a smooth transition to ParseStatus.
Added:
Modified:
llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
index 299f9b055ff779..1d87f0131efcb0 100644
--- a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
+++ b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
@@ -122,6 +122,12 @@ struct ParseInstructionInfo {
: 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 @@ class ParseStatus {
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 {
More information about the llvm-commits
mailing list