LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Types.cpp.inc
Go to the documentation of this file.
1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* TypeDef Definitions *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* *|
7\*===----------------------------------------------------------------------===*/
8
9#ifdef GET_TYPEDEF_LIST
10#undef GET_TYPEDEF_LIST
11
13
14#endif // GET_TYPEDEF_LIST
15
16#ifdef GET_TYPEDEF_CLASSES
17#undef GET_TYPEDEF_CLASSES
18
19static ::mlir::OptionalParseResult generatedTypeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type &value) {
20 return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
21 .Case(::llzk::component::StructType::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
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 generatedTypePrinter(::mlir::Type def, ::mlir::AsmPrinter &printer) {
32 return ::llvm::TypeSwitch<::mlir::Type, ::llvm::LogicalResult>(def) .Case<::llzk::component::StructType>([&](auto t) {
34t.print(printer);
35 return ::mlir::success();
36 })
37 .Default([](auto) { return ::mlir::failure(); });
38}
39
40namespace llzk::component {
41
42namespace detail {
43
44struct StructTypeStorage : public ::mlir::TypeStorage {
45 using KeyTy = std::tuple<::mlir::SymbolRefAttr, ::mlir::ArrayAttr>;
46 StructTypeStorage(::mlir::SymbolRefAttr nameRef, ::mlir::ArrayAttr params) : nameRef(std::move(nameRef)), params(std::move(params)) {}
47
48 KeyTy getAsKey() const {
49 return KeyTy(nameRef, params);
50 }
51
52 bool operator==(const KeyTy &tblgenKey) const {
53 return (nameRef == std::get<0>(tblgenKey)) && (params == std::get<1>(tblgenKey));
54 }
55
56 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
57 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey));
58 }
59
60 static StructTypeStorage *construct(::mlir::TypeStorageAllocator &allocator, KeyTy &&tblgenKey) {
61 auto nameRef = std::move(std::get<0>(tblgenKey));
62 auto params = std::move(std::get<1>(tblgenKey));
63 return new (allocator.allocate<StructTypeStorage>()) StructTypeStorage(std::move(nameRef), std::move(params));
64 }
65
66 ::mlir::SymbolRefAttr nameRef;
67 ::mlir::ArrayAttr params;
68};
69
70} // namespace detail
71namespace {
79 const ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError = nullptr;
80}
81StructType StructType::get(::mlir::SymbolRefAttr structName) {
82 return Base::get(structName.getContext(), structName, ::mlir::ArrayAttr());
83}
84
85StructType StructType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::SymbolRefAttr structName) {
86 return Base::getChecked(emitError, structName.getContext(), structName, ::mlir::ArrayAttr());
87}
88
89StructType StructType::get(::mlir::SymbolRefAttr structName, ::mlir::ArrayAttr params) {
90 ::mlir::MLIRContext *ctx = structName.getContext();
91 if (params) {
93 auto paramsRes = forceIntAttrTypes(params.getValue(), emitErrorFn);
94 if(::mlir::failed(paramsRes)) { return StructType(); }
95 params = ::mlir::ArrayAttr::get(ctx, *paramsRes);
96 }
97 return Base::get(ctx, structName, params);
98}
99
100StructType StructType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::SymbolRefAttr structName, ::mlir::ArrayAttr params) {
101 ::mlir::MLIRContext *ctx = structName.getContext();
102 if (params) {
103 OwningEmitErrorFn emitErrorFn = ::llzk::wrapNullableInFlightDiagnostic(emitError, ctx);
104 auto paramsRes = forceIntAttrTypes(params.getValue(), emitErrorFn);
105 if(::mlir::failed(paramsRes)) { return StructType(); }
106 params = ::mlir::ArrayAttr::get(ctx, *paramsRes);
107 }
108 return Base::getChecked(emitError, ctx, structName, params);
109}
110
111StructType StructType::get(::mlir::SymbolRefAttr structName, ::llvm::ArrayRef<::mlir::Attribute> paramsRef) {
112 ::mlir::MLIRContext *ctx = structName.getContext();
113 OwningEmitErrorFn emitErrorFn = ::llzk::wrapNullableInFlightDiagnostic(emitError, ctx);
114 auto paramsRes = forceIntAttrTypes(paramsRef, emitErrorFn);
115 if(::mlir::failed(paramsRes)) { return StructType(); }
116 return Base::get(ctx, structName, ::mlir::ArrayAttr::get(ctx, *paramsRes));
117}
118
119StructType StructType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::SymbolRefAttr structName, ::llvm::ArrayRef<::mlir::Attribute> paramsRef) {
120 ::mlir::MLIRContext *ctx = structName.getContext();
121 OwningEmitErrorFn emitErrorFn = ::llzk::wrapNullableInFlightDiagnostic(emitError, ctx);
122 auto paramsRes = forceIntAttrTypes(paramsRef, emitErrorFn);
123 if(::mlir::failed(paramsRes)) { return StructType(); }
124 return Base::getChecked(emitError, ctx, structName, ::mlir::ArrayAttr::get(ctx, *paramsRes));
125}
126
127::llvm::LogicalResult StructType::verifyInvariants(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::SymbolRefAttr nameRef, ::mlir::ArrayAttr params) {
128 if (::mlir::failed(verify(emitError, nameRef, params)))
129 return ::mlir::failure();
130 return ::mlir::success();
131}
132
133::mlir::Type StructType::parse(::mlir::AsmParser &odsParser) {
134 ::mlir::Builder odsBuilder(odsParser.getContext());
135 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
136 (void) odsLoc;
137 ::mlir::FailureOr<::mlir::SymbolRefAttr> _result_nameRef;
138 ::mlir::FailureOr<::mlir::ArrayAttr> _result_params;
139 // Parse literal '<'
140 if (odsParser.parseLess()) return {};
141
142 // Parse variable 'nameRef'
143 _result_nameRef = ::mlir::FieldParser<::mlir::SymbolRefAttr>::parse(odsParser);
144 if (::mlir::failed(_result_nameRef)) {
145 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_StructType parameter 'nameRef' which is to be a `::mlir::SymbolRefAttr`");
146 return {};
147 }
148 // Parse literal '<'
149 if (odsParser.parseOptionalLess()) {
150 } else {
151 {
152 auto odsCustomLoc = odsParser.getCurrentLocation();
153 (void)odsCustomLoc;
154 auto odsCustomResult = parseTemplateParams(odsParser,
155 ::mlir::detail::unwrapForCustomParse(_result_params));
156 if (::mlir::failed(odsCustomResult)) return {};
157 }
158 // Parse literal '>'
159 if (odsParser.parseGreater()) return {};
160 }
161 // Parse literal '>'
162 if (odsParser.parseGreater()) return {};
163 assert(::mlir::succeeded(_result_nameRef));
164 return odsParser.getChecked<StructType>(odsLoc, odsParser.getContext(),
165 ::mlir::SymbolRefAttr((*_result_nameRef)),
166 ::mlir::ArrayAttr((_result_params.value_or(::mlir::ArrayAttr()))));
167}
168
169void StructType::print(::mlir::AsmPrinter &odsPrinter) const {
170 ::mlir::Builder odsBuilder(getContext());
171 odsPrinter << "<";
172 odsPrinter.printStrippedAttrOrType(getNameRef());
173 if (!(getParams() == ::mlir::ArrayAttr())) {
174 odsPrinter << "<";
175 printTemplateParams(odsPrinter,
176 getParams());
177 odsPrinter << ">";
178 } else {
179 }
180 odsPrinter << ">";
181}
182
183::mlir::SymbolRefAttr StructType::getNameRef() const {
184 return getImpl()->nameRef;
185}
186
187::mlir::ArrayAttr StructType::getParams() const {
188 return getImpl()->params;
189}
190
191
192} // namespace llzk::component
193MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::component::StructType)
194namespace llzk::component {
195
196
198::mlir::Type StructDialect::parseType(::mlir::DialectAsmParser &parser) const {
199 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
200 ::llvm::StringRef mnemonic;
201 ::mlir::Type genType;
202 auto parseResult = generatedTypeParser(parser, &mnemonic, genType);
203 if (parseResult.has_value())
204 return genType;
205
206 parser.emitError(typeLoc) << "unknown type `"
207 << mnemonic << "` in dialect `" << getNamespace() << "`";
208 return {};
209}
210
211void StructDialect::printType(::mlir::Type type,
212 ::mlir::DialectAsmPrinter &printer) const {
213 if (::mlir::succeeded(generatedTypePrinter(type, printer)))
214 return;
215
216}
217
218} // namespace llzk::component
219
220#endif // GET_TYPEDEF_CLASSES
221
void printType(::mlir::Type type, ::mlir::DialectAsmPrinter &os) const override
Print a type registered to this dialect.
::mlir::Type parseType(::mlir::DialectAsmParser &parser) const override
Parse a type registered to this dialect.
::mlir::SymbolRefAttr getNameRef() const
static StructType getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::SymbolRefAttr structName)
Definition Types.cpp.inc:85
void print(::mlir::AsmPrinter &odsPrinter) const
static StructType get(::mlir::SymbolRefAttr structName)
Definition Types.cpp.inc:81
::mlir::Type parse(::mlir::AsmParser &odsParser)
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::SymbolRefAttr nameRef, ::mlir::ArrayAttr params)
Definition Types.cpp:20
static constexpr ::llvm::StringLiteral getMnemonic()
Definition Types.h.inc:78
::mlir::ArrayAttr getParams() const
::llvm::LogicalResult verifyInvariants(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::SymbolRefAttr nameRef, ::mlir::ArrayAttr params)
Common interface for operations that read or write from a struct member.
void printTemplateParams(mlir::AsmPrinter &printer, mlir::ArrayAttr value)
Definition OpHelpers.h:198
FailureOr< SmallVector< Attribute > > forceIntAttrTypes(ArrayRef< Attribute > attrList, EmitErrorFn emitError)
std::function< InFlightDiagnosticWrapper()> OwningEmitErrorFn
This type is required in cases like the functions below to take ownership of the lambda so it is not ...
mlir::ParseResult parseTemplateParams(mlir::AsmParser &parser, mlir::ArrayAttr &value)
Definition OpHelpers.h:165
OwningEmitErrorFn wrapNullableInFlightDiagnostic(llvm::function_ref< mlir::InFlightDiagnostic()> emitError, mlir::MLIRContext *ctx)
If the given emitError is non-null, return it.
::llvm::hash_code hashKey(const KeyTy &tblgenKey)
Definition Types.cpp.inc:56
StructTypeStorage(::mlir::SymbolRefAttr nameRef, ::mlir::ArrayAttr params)
Definition Types.cpp.inc:46
static StructTypeStorage * construct(::mlir::TypeStorageAllocator &allocator, KeyTy &&tblgenKey)
Definition Types.cpp.inc:60
std::tuple<::mlir::SymbolRefAttr, ::mlir::ArrayAttr > KeyTy
Definition Types.cpp.inc:45
bool operator==(const KeyTy &tblgenKey) const
Definition Types.cpp.inc:52