LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Attrs.cpp.inc
Go to the documentation of this file.
1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* AttrDef Definitions *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* *|
7\*===----------------------------------------------------------------------===*/
8
9#ifdef GET_ATTRDEF_LIST
10#undef GET_ATTRDEF_LIST
11
12::llzk::cast::OverflowSemanticsAttr
13
14#endif // GET_ATTRDEF_LIST
15
16#ifdef GET_ATTRDEF_CLASSES
17#undef GET_ATTRDEF_CLASSES
18
19static ::mlir::OptionalParseResult generatedAttributeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type type, ::mlir::Attribute &value) {
20 return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
21 .Case(::llzk::cast::OverflowSemanticsAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
22 value = ::llzk::cast::OverflowSemanticsAttr::parse(parser, type);
23 return ::mlir::success(!!value);
24 })
25 .Default([&](llvm::StringRef keyword, llvm::SMLoc) {
26 *mnemonic = keyword;
27 return std::nullopt;
28 });
29}
30
31static ::llvm::LogicalResult generatedAttributePrinter(::mlir::Attribute def, ::mlir::AsmPrinter &printer) {
32 return ::llvm::TypeSwitch<::mlir::Attribute, ::llvm::LogicalResult>(def) .Case<::llzk::cast::OverflowSemanticsAttr>([&](auto t) {
33 printer << ::llzk::cast::OverflowSemanticsAttr::getMnemonic();
34printer << ' ';
35t.print(printer);
36 return ::mlir::success();
37 })
38 .Default([](auto) { return ::mlir::failure(); });
39}
40
41namespace llzk::cast {
42
43namespace detail {
44
45struct OverflowSemanticsAttrStorage : public ::mlir::AttributeStorage {
46 using KeyTy = std::tuple<::llzk::cast::OverflowSemantics>;
47 OverflowSemanticsAttrStorage(::llzk::cast::OverflowSemantics value) : value(std::move(value)) {}
48
49 KeyTy getAsKey() const {
50 return KeyTy(value);
51 }
52
53 bool operator==(const KeyTy &tblgenKey) const {
54 return (value == std::get<0>(tblgenKey));
55 }
56
57 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
58 return ::llvm::hash_combine(std::get<0>(tblgenKey));
59 }
60
61 static OverflowSemanticsAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
62 auto value = std::move(std::get<0>(tblgenKey));
63 return new (allocator.allocate<OverflowSemanticsAttrStorage>()) OverflowSemanticsAttrStorage(std::move(value));
64 }
65
67};
68
69} // namespace detail
70OverflowSemanticsAttr OverflowSemanticsAttr::get(::mlir::MLIRContext *context, ::llzk::cast::OverflowSemantics value) {
71 return Base::get(context, std::move(value));
72}
73
74::mlir::Attribute OverflowSemanticsAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
75 ::mlir::Builder odsBuilder(odsParser.getContext());
76 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
77 (void) odsLoc;
78 ::mlir::FailureOr<::llzk::cast::OverflowSemantics> _result_value;
79
80 // Parse variable 'value'
81 _result_value = [&]() -> ::mlir::FailureOr<::llzk::cast::OverflowSemantics> {
82 auto loc = odsParser.getCurrentLocation();
83 std::string enumKeyword;
84 if (::mlir::failed(odsParser.parseKeywordOrString(&enumKeyword)))
85 return ::mlir::failure();
86 auto maybeEnum = ::llzk::cast::symbolizeOverflowSemantics(enumKeyword);
87 if (maybeEnum)
88 return *maybeEnum;
89 return {(::llvm::LogicalResult)(odsParser.emitError(loc) << "expected " << "::llzk::cast::OverflowSemantics" << " to be one of: " << "assert" << ", " << "sat" << ", " << "wrap" << ", " << "trunc")};
90 }();
91 if (::mlir::failed(_result_value)) {
92 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_OverflowSemanticsAttr parameter 'value' which is to be a `::llzk::cast::OverflowSemantics`");
93 return {};
94 }
95 assert(::mlir::succeeded(_result_value));
96 return OverflowSemanticsAttr::get(odsParser.getContext(),
97 ::llzk::cast::OverflowSemantics((*_result_value)));
98}
99
100void OverflowSemanticsAttr::print(::mlir::AsmPrinter &odsPrinter) const {
101 ::mlir::Builder odsBuilder(getContext());
102 odsPrinter << stringifyOverflowSemantics(getValue());
103}
104
105::llzk::cast::OverflowSemantics OverflowSemanticsAttr::getValue() const {
106 return getImpl()->value;
107}
108
109
110} // namespace llzk::cast
111MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::cast::OverflowSemanticsAttr)
112namespace llzk::cast {
113
114
116::mlir::Attribute CastDialect::parseAttribute(::mlir::DialectAsmParser &parser,
117 ::mlir::Type type) const {
118 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
119 ::llvm::StringRef attrTag;
120 {
121 ::mlir::Attribute attr;
122 auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
123 if (parseResult.has_value())
124 return attr;
125 }
126
127 parser.emitError(typeLoc) << "unknown attribute `"
128 << attrTag << "` in dialect `" << getNamespace() << "`";
129 return {};
130}
132void CastDialect::printAttribute(::mlir::Attribute attr,
133 ::mlir::DialectAsmPrinter &printer) const {
134 if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
135 return;
136
137}
138
139} // namespace llzk::cast
140
141#endif // GET_ATTRDEF_CLASSES
142
::mlir::Attribute parseAttribute(::mlir::DialectAsmParser &parser, ::mlir::Type type) const override
Parse an attribute registered to this dialect.
void printAttribute(::mlir::Attribute attr, ::mlir::DialectAsmPrinter &os) const override
Print an attribute registered to this dialect.
::llvm::StringRef stringifyOverflowSemantics(OverflowSemantics val)
Definition Enums.cpp.inc:12
::std::optional< OverflowSemantics > symbolizeOverflowSemantics(::llvm::StringRef str)
Definition Enums.cpp.inc:22