LLZK 0.1.0
Veridise's ZK Language IR
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 ::mlir::LogicalResult generatedAttributePrinter(::mlir::Attribute def, ::mlir::AsmPrinter &printer) {
37 return ::llvm::TypeSwitch<::mlir::Attribute, ::mlir::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<::llvm::APInt, ::llvm::APInt, ::llvm::APInt>;
56 LoopBoundsAttrStorage(::llvm::APInt lower, ::llvm::APInt upper, ::llvm::APInt 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 (::llvm::APInt::isSameValue(lower, std::get<0>(tblgenKey))) && (::llvm::APInt::isSameValue(upper, std::get<1>(tblgenKey))) && (::llvm::APInt::isSameValue(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 ::llvm::APInt lower;
78 ::llvm::APInt upper;
79 ::llvm::APInt step;
80};
81} // namespace detail
82LoopBoundsAttr LoopBoundsAttr::get(::mlir::MLIRContext *context, ::llvm::APInt lower, ::llvm::APInt upper, ::llvm::APInt step) {
83 return Base::get(context, std::move(lower), std::move(upper), std::move(step));
84}
85
86::mlir::Attribute LoopBoundsAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
87 ::mlir::Builder odsBuilder(odsParser.getContext());
88 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
89 (void) odsLoc;
90 ::mlir::FailureOr<::llvm::APInt> _result_lower;
91 ::mlir::FailureOr<::llvm::APInt> _result_upper;
92 ::mlir::FailureOr<::llvm::APInt> _result_step;
93 // Parse literal '<'
94 if (odsParser.parseLess()) return {};
95
96 // Parse variable 'lower'
97 _result_lower = ::mlir::FieldParser<::llvm::APInt>::parse(odsParser);
98 if (::mlir::failed(_result_lower)) {
99 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_LoopBoundsAttr parameter 'lower' which is to be a `::llvm::APInt`");
100 return {};
101 }
102 // Parse literal 'to'
103 if (odsParser.parseKeyword("to")) return {};
104
105 // Parse variable 'upper'
106 _result_upper = ::mlir::FieldParser<::llvm::APInt>::parse(odsParser);
107 if (::mlir::failed(_result_upper)) {
108 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_LoopBoundsAttr parameter 'upper' which is to be a `::llvm::APInt`");
109 return {};
110 }
111 // Parse literal 'step'
112 if (odsParser.parseKeyword("step")) return {};
113
114 // Parse variable 'step'
115 _result_step = ::mlir::FieldParser<::llvm::APInt>::parse(odsParser);
116 if (::mlir::failed(_result_step)) {
117 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_LoopBoundsAttr parameter 'step' which is to be a `::llvm::APInt`");
118 return {};
119 }
120 // Parse literal '>'
121 if (odsParser.parseGreater()) return {};
122 assert(::mlir::succeeded(_result_lower));
123 assert(::mlir::succeeded(_result_upper));
124 assert(::mlir::succeeded(_result_step));
125 return LoopBoundsAttr::get(odsParser.getContext(),
126 ::llvm::APInt((*_result_lower)),
127 ::llvm::APInt((*_result_upper)),
128 ::llvm::APInt((*_result_step)));
129}
130
131void LoopBoundsAttr::print(::mlir::AsmPrinter &odsPrinter) const {
132 ::mlir::Builder odsBuilder(getContext());
133 odsPrinter << "<";
134 odsPrinter.printStrippedAttrOrType(getLower());
135 odsPrinter << ' ' << "to";
136 odsPrinter << ' ';
137 odsPrinter.printStrippedAttrOrType(getUpper());
138 odsPrinter << ' ' << "step";
139 odsPrinter << ' ';
140 odsPrinter.printStrippedAttrOrType(getStep());
141 odsPrinter << ">";
142}
143
144::llvm::APInt LoopBoundsAttr::getLower() const {
145 return getImpl()->lower;
146}
147
148::llvm::APInt LoopBoundsAttr::getUpper() const {
149 return getImpl()->upper;
150}
151
152::llvm::APInt LoopBoundsAttr::getStep() const {
153 return getImpl()->step;
154}
155
156} // namespace llzk
157MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::LoopBoundsAttr)
158namespace llzk {
159
161::mlir::Attribute LLZKDialect::parseAttribute(::mlir::DialectAsmParser &parser,
162 ::mlir::Type type) const {
163 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
164 ::llvm::StringRef attrTag;
165 {
166 ::mlir::Attribute attr;
167 auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
168 if (parseResult.has_value())
169 return attr;
170 }
171
172 parser.emitError(typeLoc) << "unknown attribute `"
173 << attrTag << "` in dialect `" << getNamespace() << "`";
174 return {};
175}
177void LLZKDialect::printAttribute(::mlir::Attribute attr,
178 ::mlir::DialectAsmPrinter &printer) const {
179 if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
180 return;
181
182}
183} // namespace llzk
184
185#endif // GET_ATTRDEF_CLASSES
186
::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.