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::PublicAttr,
13::llzk::LoopBoundsAttr
14
15#endif // GET_ATTRDEF_LIST
16
17#ifdef GET_ATTRDEF_CLASSES
18#undef GET_ATTRDEF_CLASSES
19
20static ::mlir::OptionalParseResult generatedAttributeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type type, ::mlir::Attribute &value) {
21 return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
22 .Case(::llzk::PublicAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
23 value = ::llzk::PublicAttr::get(parser.getContext());
24 return ::mlir::success(!!value);
25 })
26 .Case(::llzk::LoopBoundsAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
27 value = ::llzk::LoopBoundsAttr::parse(parser, type);
28 return ::mlir::success(!!value);
29 })
30 .Default([&](llvm::StringRef keyword, llvm::SMLoc) {
31 *mnemonic = keyword;
32 return std::nullopt;
33 });
34}
35
36static ::llvm::LogicalResult generatedAttributePrinter(::mlir::Attribute def, ::mlir::AsmPrinter &printer) {
37 return ::llvm::TypeSwitch<::mlir::Attribute, ::llvm::LogicalResult>(def) .Case<::llzk::PublicAttr>([&](auto t) {
38 printer << ::llzk::PublicAttr::getMnemonic();
39 return ::mlir::success();
40 })
41 .Case<::llzk::LoopBoundsAttr>([&](auto t) {
42 printer << ::llzk::LoopBoundsAttr::getMnemonic();
43t.print(printer);
44 return ::mlir::success();
45 })
46 .Default([](auto) { return ::mlir::failure(); });
47}
48
49namespace llzk {
50} // namespace llzk
51MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::PublicAttr)
52namespace llzk {
53namespace detail {
54struct LoopBoundsAttrStorage : public ::mlir::AttributeStorage {
55 using KeyTy = std::tuple<::llzk::APIntValue, ::llzk::APIntValue, ::llzk::APIntValue>;
56 LoopBoundsAttrStorage(::llzk::APIntValue lower, ::llzk::APIntValue upper, ::llzk::APIntValue step) : lower(std::move(lower)), upper(std::move(upper)), step(std::move(step)) {}
57
58 KeyTy getAsKey() const {
59 return KeyTy(lower, upper, step);
60 }
61
62 bool operator==(const KeyTy &tblgenKey) const {
63 return (lower == std::get<0>(tblgenKey)) && (upper == std::get<1>(tblgenKey)) && (step == std::get<2>(tblgenKey));
64 }
65
66 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
67 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey), std::get<2>(tblgenKey));
68 }
69
70 static LoopBoundsAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
71 auto lower = std::move(std::get<0>(tblgenKey));
72 auto upper = std::move(std::get<1>(tblgenKey));
73 auto step = std::move(std::get<2>(tblgenKey));
74 return new (allocator.allocate<LoopBoundsAttrStorage>()) LoopBoundsAttrStorage(std::move(lower), std::move(upper), std::move(step));
75 }
76
77 ::llzk::APIntValue lower;
78 ::llzk::APIntValue upper;
79 ::llzk::APIntValue step;
80};
81} // namespace detail
82LoopBoundsAttr LoopBoundsAttr::get(::mlir::MLIRContext *context, ::llzk::APIntValue lower, ::llzk::APIntValue upper, ::llzk::APIntValue step) {
83 return Base::get(context, std::move(lower), std::move(upper), std::move(step));
84}
85
86LoopBoundsAttr LoopBoundsAttr::get(::mlir::MLIRContext *context, ::llvm::APInt lower, ::llvm::APInt upper, ::llvm::APInt step) {
87 return Base::get(context, ::llzk::APIntValue(std::move(lower)),
88 ::llzk::APIntValue(std::move(upper)),
89 ::llzk::APIntValue(std::move(step)));
90}
91
92::mlir::Attribute LoopBoundsAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
93 ::mlir::Builder odsBuilder(odsParser.getContext());
94 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
95 (void) odsLoc;
96 ::mlir::FailureOr<::llzk::APIntValue> _result_lower;
97 ::mlir::FailureOr<::llzk::APIntValue> _result_upper;
98 ::mlir::FailureOr<::llzk::APIntValue> _result_step;
99 // Parse literal '<'
100 if (odsParser.parseLess()) return {};
101
102 // Parse variable 'lower'
103 _result_lower = ::llzk::parseAPIntValue(odsParser);
104 if (::mlir::failed(_result_lower)) {
105 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_LoopBoundsAttr parameter 'lower' which is to be a `::llzk::APIntValue`");
106 return {};
107 }
108 // Parse literal 'to'
109 if (odsParser.parseKeyword("to")) return {};
110
111 // Parse variable 'upper'
112 _result_upper = ::llzk::parseAPIntValue(odsParser);
113 if (::mlir::failed(_result_upper)) {
114 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_LoopBoundsAttr parameter 'upper' which is to be a `::llzk::APIntValue`");
115 return {};
116 }
117 // Parse literal 'step'
118 if (odsParser.parseKeyword("step")) return {};
119
120 // Parse variable 'step'
121 _result_step = ::llzk::parseAPIntValue(odsParser);
122 if (::mlir::failed(_result_step)) {
123 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_LoopBoundsAttr parameter 'step' which is to be a `::llzk::APIntValue`");
124 return {};
125 }
126 // Parse literal '>'
127 if (odsParser.parseGreater()) return {};
128 assert(::mlir::succeeded(_result_lower));
129 assert(::mlir::succeeded(_result_upper));
130 assert(::mlir::succeeded(_result_step));
131 return LoopBoundsAttr::get(odsParser.getContext(),
132 ::llzk::APIntValue((*_result_lower)),
133 ::llzk::APIntValue((*_result_upper)),
134 ::llzk::APIntValue((*_result_step)));
135}
136
137void LoopBoundsAttr::print(::mlir::AsmPrinter &odsPrinter) const {
138 ::mlir::Builder odsBuilder(getContext());
139 odsPrinter << "<";
140 odsPrinter << getLower();
141 odsPrinter << ' ' << "to";
142 odsPrinter << ' ';
143 odsPrinter << getUpper();
144 odsPrinter << ' ' << "step";
145 odsPrinter << ' ';
146 odsPrinter << getStep();
147 odsPrinter << ">";
148}
149
150const ::llvm::APInt &LoopBoundsAttr::getLower() const {
151 return getImpl()->lower;
152}
153
154const ::llvm::APInt &LoopBoundsAttr::getUpper() const {
155 return getImpl()->upper;
156}
157
158const ::llvm::APInt &LoopBoundsAttr::getStep() const {
159 return getImpl()->step;
160}
161
162} // namespace llzk
163MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::LoopBoundsAttr)
164namespace llzk {
165
167::mlir::Attribute LLZKDialect::parseAttribute(::mlir::DialectAsmParser &parser,
168 ::mlir::Type type) const {
169 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
170 ::llvm::StringRef attrTag;
171 {
172 ::mlir::Attribute attr;
173 auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
174 if (parseResult.has_value())
175 return attr;
176 }
177
178 parser.emitError(typeLoc) << "unknown attribute `"
179 << attrTag << "` in dialect `" << getNamespace() << "`";
180 return {};
181}
183void LLZKDialect::printAttribute(::mlir::Attribute attr,
184 ::mlir::DialectAsmPrinter &printer) const {
185 if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
186 return;
187
188}
189} // namespace llzk
190
191#endif // GET_ATTRDEF_CLASSES
192
::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.
mlir::FailureOr< APIntValue > parseAPIntValue(mlir::AsmParser &parser)