| 1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
| 2 | |* *| |
| 3 | |* Enum Utility Definitions *| |
| 4 | |* *| |
| 5 | |* Automatically generated file, do not edit! *| |
| 6 | |* From: EmitCAttributes.td *| |
| 7 | |* *| |
| 8 | \*===----------------------------------------------------------------------===*/ |
| 9 | |
| 10 | #include "llvm/ADT/StringSwitch.h" |
| 11 | #include "mlir/IR/BuiltinTypes.h" |
| 12 | #include "mlir/IR/OpImplementation.h" |
| 13 | |
| 14 | namespace mlir::emitc { |
| 15 | |
| 16 | ::llvm::StringRef stringifyClassType(ClassType val) { |
| 17 | switch (val) { |
| 18 | case ClassType::class_: return "class" ; |
| 19 | case ClassType::struct_: return "struct" ; |
| 20 | case ClassType::union_: return "union" ; |
| 21 | } |
| 22 | return "" ; |
| 23 | } |
| 24 | |
| 25 | ::std::optional<ClassType> symbolizeClassType(::llvm::StringRef str) { |
| 26 | return ::llvm::StringSwitch<::std::optional<ClassType>>(str) |
| 27 | .Case(S: "class" , Value: ClassType::class_) |
| 28 | .Case(S: "struct" , Value: ClassType::struct_) |
| 29 | .Case(S: "union" , Value: ClassType::union_) |
| 30 | .Default(Value: ::std::nullopt); |
| 31 | } |
| 32 | ::std::optional<ClassType> symbolizeClassType(uint32_t value) { |
| 33 | switch (value) { |
| 34 | case 0: return ClassType::class_; |
| 35 | case 1: return ClassType::struct_; |
| 36 | case 2: return ClassType::union_; |
| 37 | default: return ::std::nullopt; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | bool ClassTypeAttr::classof(::mlir::Attribute attr) { |
| 42 | return (((::llvm::isa<::mlir::IntegerAttr>(Val: attr))) && ((::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getType().isSignlessInteger(width: 32)))) && ((( |
| 43 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(32, 0)))) || (( |
| 44 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(32, 1)))) || (( |
| 45 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(32, 2))))); |
| 46 | } |
| 47 | ClassTypeAttr ClassTypeAttr::get(::mlir::MLIRContext *context, ClassType val) { |
| 48 | ::mlir::IntegerType intType = ::mlir::IntegerType::get(context, width: 32); |
| 49 | ::mlir::IntegerAttr baseAttr = ::mlir::IntegerAttr::get(type: intType, value: static_cast<uint32_t>(val)); |
| 50 | return ::llvm::cast<ClassTypeAttr>(Val&: baseAttr); |
| 51 | } |
| 52 | ClassType ClassTypeAttr::getValue() const { |
| 53 | return static_cast<ClassType>(::mlir::IntegerAttr::getValue().getZExtValue()); |
| 54 | } |
| 55 | |
| 56 | } // namespace mlir::emitc |
| 57 | |
| 58 | namespace mlir { |
| 59 | FailureOr<::mlir::emitc::ClassType> FieldParser<::mlir::emitc::ClassType, ::mlir::emitc::ClassType>::parse(AsmParser &parser) { |
| 60 | // Parse the keyword/string containing the enum. |
| 61 | std::string enumKeyword; |
| 62 | auto loc = parser.getCurrentLocation(); |
| 63 | if (failed(Result: parser.parseOptionalKeywordOrString(result: &enumKeyword))) |
| 64 | return parser.emitError(loc, message: "expected keyword for C++ aggregate type keyword" ); |
| 65 | |
| 66 | // Symbolize the keyword. |
| 67 | if (::std::optional<::mlir::emitc::ClassType> attr = ::mlir::emitc::symbolizeEnum<::mlir::emitc::ClassType>(str: enumKeyword)) |
| 68 | return *attr; |
| 69 | return parser.emitError(loc, message: "expected one of [class, struct, union] for C++ aggregate type keyword, got: " ) << enumKeyword; |
| 70 | } |
| 71 | |
| 72 | FailureOr<std::optional<::mlir::emitc::ClassType>> |
| 73 | FieldParser<std::optional<::mlir::emitc::ClassType>, std::optional<::mlir::emitc::ClassType>>::parse(AsmParser &parser) { |
| 74 | // Parse the keyword/string containing the enum. |
| 75 | std::string enumKeyword; |
| 76 | auto loc = parser.getCurrentLocation(); |
| 77 | if (failed(Result: parser.parseOptionalKeywordOrString(result: &enumKeyword, allowedValues: {"class" , "struct" , "union" }))) |
| 78 | return std::optional<::mlir::emitc::ClassType>{}; |
| 79 | |
| 80 | // Symbolize the keyword. |
| 81 | if (::std::optional<::mlir::emitc::ClassType> attr = ::mlir::emitc::symbolizeEnum<::mlir::emitc::ClassType>(str: enumKeyword)) |
| 82 | return attr; |
| 83 | return parser.emitError(loc, message: "expected one of [class, struct, union] for C++ aggregate type keyword, got: " ) << enumKeyword; |
| 84 | } |
| 85 | } // namespace mlir |
| 86 | namespace mlir::emitc { |
| 87 | |
| 88 | ::llvm::StringRef stringifyCmpPredicate(CmpPredicate val) { |
| 89 | switch (val) { |
| 90 | case CmpPredicate::eq: return "eq" ; |
| 91 | case CmpPredicate::ne: return "ne" ; |
| 92 | case CmpPredicate::lt: return "lt" ; |
| 93 | case CmpPredicate::le: return "le" ; |
| 94 | case CmpPredicate::gt: return "gt" ; |
| 95 | case CmpPredicate::ge: return "ge" ; |
| 96 | case CmpPredicate::three_way: return "three_way" ; |
| 97 | } |
| 98 | return "" ; |
| 99 | } |
| 100 | |
| 101 | ::std::optional<CmpPredicate> symbolizeCmpPredicate(::llvm::StringRef str) { |
| 102 | return ::llvm::StringSwitch<::std::optional<CmpPredicate>>(str) |
| 103 | .Case(S: "eq" , Value: CmpPredicate::eq) |
| 104 | .Case(S: "ne" , Value: CmpPredicate::ne) |
| 105 | .Case(S: "lt" , Value: CmpPredicate::lt) |
| 106 | .Case(S: "le" , Value: CmpPredicate::le) |
| 107 | .Case(S: "gt" , Value: CmpPredicate::gt) |
| 108 | .Case(S: "ge" , Value: CmpPredicate::ge) |
| 109 | .Case(S: "three_way" , Value: CmpPredicate::three_way) |
| 110 | .Default(Value: ::std::nullopt); |
| 111 | } |
| 112 | ::std::optional<CmpPredicate> symbolizeCmpPredicate(uint64_t value) { |
| 113 | switch (value) { |
| 114 | case 0: return CmpPredicate::eq; |
| 115 | case 1: return CmpPredicate::ne; |
| 116 | case 2: return CmpPredicate::lt; |
| 117 | case 3: return CmpPredicate::le; |
| 118 | case 4: return CmpPredicate::gt; |
| 119 | case 5: return CmpPredicate::ge; |
| 120 | case 6: return CmpPredicate::three_way; |
| 121 | default: return ::std::nullopt; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | bool CmpPredicateAttr::classof(::mlir::Attribute attr) { |
| 126 | return (((::llvm::isa<::mlir::IntegerAttr>(Val: attr))) && ((::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getType().isSignlessInteger(width: 64)))) && ((( |
| 127 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(64, 0)))) || (( |
| 128 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(64, 1)))) || (( |
| 129 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(64, 2)))) || (( |
| 130 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(64, 3)))) || (( |
| 131 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(64, 4)))) || (( |
| 132 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(64, 5)))) || (( |
| 133 | ::llvm::cast<::mlir::IntegerAttr>(Val&: attr).getValue().eq(RHS: ::llvm::APInt(64, 6))))); |
| 134 | } |
| 135 | CmpPredicateAttr CmpPredicateAttr::get(::mlir::MLIRContext *context, CmpPredicate val) { |
| 136 | ::mlir::IntegerType intType = ::mlir::IntegerType::get(context, width: 64); |
| 137 | ::mlir::IntegerAttr baseAttr = ::mlir::IntegerAttr::get(type: intType, value: static_cast<uint64_t>(val)); |
| 138 | return ::llvm::cast<CmpPredicateAttr>(Val&: baseAttr); |
| 139 | } |
| 140 | CmpPredicate CmpPredicateAttr::getValue() const { |
| 141 | return static_cast<CmpPredicate>(::mlir::IntegerAttr::getValue().getZExtValue()); |
| 142 | } |
| 143 | |
| 144 | } // namespace mlir::emitc |
| 145 | |
| 146 | namespace mlir { |
| 147 | FailureOr<::mlir::emitc::CmpPredicate> FieldParser<::mlir::emitc::CmpPredicate, ::mlir::emitc::CmpPredicate>::parse(AsmParser &parser) { |
| 148 | // Parse the keyword/string containing the enum. |
| 149 | std::string enumKeyword; |
| 150 | auto loc = parser.getCurrentLocation(); |
| 151 | if (failed(Result: parser.parseOptionalKeywordOrString(result: &enumKeyword))) |
| 152 | return parser.emitError(loc, message: "expected keyword for allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6" ); |
| 153 | |
| 154 | // Symbolize the keyword. |
| 155 | if (::std::optional<::mlir::emitc::CmpPredicate> attr = ::mlir::emitc::symbolizeEnum<::mlir::emitc::CmpPredicate>(str: enumKeyword)) |
| 156 | return *attr; |
| 157 | return parser.emitError(loc, message: "expected one of [eq, ne, lt, le, gt, ge, three_way] for allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, got: " ) << enumKeyword; |
| 158 | } |
| 159 | |
| 160 | FailureOr<std::optional<::mlir::emitc::CmpPredicate>> |
| 161 | FieldParser<std::optional<::mlir::emitc::CmpPredicate>, std::optional<::mlir::emitc::CmpPredicate>>::parse(AsmParser &parser) { |
| 162 | // Parse the keyword/string containing the enum. |
| 163 | std::string enumKeyword; |
| 164 | auto loc = parser.getCurrentLocation(); |
| 165 | if (failed(Result: parser.parseOptionalKeywordOrString(result: &enumKeyword, allowedValues: {"eq" , "ne" , "lt" , "le" , "gt" , "ge" , "three_way" }))) |
| 166 | return std::optional<::mlir::emitc::CmpPredicate>{}; |
| 167 | |
| 168 | // Symbolize the keyword. |
| 169 | if (::std::optional<::mlir::emitc::CmpPredicate> attr = ::mlir::emitc::symbolizeEnum<::mlir::emitc::CmpPredicate>(str: enumKeyword)) |
| 170 | return attr; |
| 171 | return parser.emitError(loc, message: "expected one of [eq, ne, lt, le, gt, ge, three_way] for allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, got: " ) << enumKeyword; |
| 172 | } |
| 173 | } // namespace mlir |
| 174 | |