| 445 | /// Generic helper to parse an enum attribute. |
| 446 | template <typename AttrType> |
| 447 | static LogicalResult parseGenericEnumAttr(EncodingReader &reader, |
| 448 | MLIRContext &context, |
| 449 | AttrType &nativeValue) { |
| 450 | uint64_t rawEnumValueU64; |
| 451 | if (failed(reader.readVarInt(rawEnumValueU64))) |
| 452 | return reader.emitError() << "failed to read VarInt for enum attribute."; |
| 453 | uint32_t rawEnumValue = static_cast<uint32_t>(rawEnumValueU64); |
| 454 | |
| 455 | using EnumType = decltype(std::declval<AttrType>().getValue()); |
| 456 | static_assert(!std::is_void_v<EnumType>, |
| 457 | "EnumType cannot be void for enum attribute."); |
| 458 | std::optional<EnumType> enumOpt = symbolizeEnum<EnumType>(rawEnumValue); |
| 459 | if (!enumOpt) |
| 460 | return reader.emitError() |
| 461 | << "invalid integer value for enum type: " << rawEnumValue; |
| 462 | nativeValue = AttrType::get(&context, enumOpt.value()); |
| 463 | return success(); |
| 464 | } |
| 465 | |
| 466 | //===----------------------------------------------------------------------===// |
| 467 | // LazyTypeTable: Manages lazy parsing and caching of types from the type |
no test coverage detected