LLZK 0.1.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::pod::RecordAttr
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::pod::RecordAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
22 value = ::llzk::pod::RecordAttr::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::pod::RecordAttr>([&](auto t) {
33 printer << ::llzk::pod::RecordAttr::getMnemonic();
34t.print(printer);
35 return ::mlir::success();
36 })
37 .Default([](auto) { return ::mlir::failure(); });
38}
39
40namespace llzk {
41namespace pod {
42namespace detail {
43struct RecordAttrStorage : public ::mlir::AttributeStorage {
44 using KeyTy = std::tuple<::mlir::StringAttr, ::mlir::Type>;
45 RecordAttrStorage(::mlir::StringAttr name, ::mlir::Type type) : name(std::move(name)), type(std::move(type)) {}
46
47 KeyTy getAsKey() const {
48 return KeyTy(name, type);
49 }
50
51 bool operator==(const KeyTy &tblgenKey) const {
52 return (name == std::get<0>(tblgenKey)) && (type == std::get<1>(tblgenKey));
53 }
54
55 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
56 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey));
57 }
58
59 static RecordAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
60 auto name = std::move(std::get<0>(tblgenKey));
61 auto type = std::move(std::get<1>(tblgenKey));
62 return new (allocator.allocate<RecordAttrStorage>()) RecordAttrStorage(std::move(name), std::move(type));
63 }
64
65 ::mlir::StringAttr name;
66 ::mlir::Type type;
67};
68} // namespace detail
69RecordAttr RecordAttr::get(::mlir::MLIRContext *context, ::mlir::StringAttr name, ::mlir::Type type) {
70 return Base::get(context, std::move(name), std::move(type));
71}
72
73::mlir::Attribute RecordAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
74 ::mlir::Builder odsBuilder(odsParser.getContext());
75 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
76 (void) odsLoc;
77 ::mlir::FailureOr<::mlir::StringAttr> _result_name;
78 ::mlir::FailureOr<::mlir::Type> _result_type;
79 {
80 auto odsCustomLoc = odsParser.getCurrentLocation();
81 (void)odsCustomLoc;
82 auto odsCustomResult = parseRecord(odsParser,
83 ::mlir::detail::unwrapForCustomParse(_result_name),
84 ::mlir::detail::unwrapForCustomParse(_result_type));
85 if (::mlir::failed(odsCustomResult)) return {};
86 if (::mlir::failed(_result_name)) {
87 odsParser.emitError(odsCustomLoc, "custom parser failed to parse parameter 'name'");
88 return {};
89 }
90 if (::mlir::failed(_result_type)) {
91 odsParser.emitError(odsCustomLoc, "custom parser failed to parse parameter 'type'");
92 return {};
93 }
94 }
95 assert(::mlir::succeeded(_result_name));
96 assert(::mlir::succeeded(_result_type));
97 return RecordAttr::get(odsParser.getContext(),
98 ::mlir::StringAttr((*_result_name)),
99 ::mlir::Type((*_result_type)));
100}
101
102void RecordAttr::print(::mlir::AsmPrinter &odsPrinter) const {
103 ::mlir::Builder odsBuilder(getContext());
104 printRecord(odsPrinter,
105 getName(),
106 getType());
107}
108
109::mlir::StringAttr RecordAttr::getName() const {
110 return getImpl()->name;
111}
112
113::mlir::Type RecordAttr::getType() const {
114 return getImpl()->type;
115}
116
117} // namespace pod
118} // namespace llzk
119MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::pod::RecordAttr)
120namespace llzk {
121namespace pod {
122
124::mlir::Attribute PODDialect::parseAttribute(::mlir::DialectAsmParser &parser,
125 ::mlir::Type type) const {
126 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
127 ::llvm::StringRef attrTag;
128 {
129 ::mlir::Attribute attr;
130 auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
131 if (parseResult.has_value())
132 return attr;
133 }
134
135 parser.emitError(typeLoc) << "unknown attribute `"
136 << attrTag << "` in dialect `" << getNamespace() << "`";
137 return {};
138}
140void PODDialect::printAttribute(::mlir::Attribute attr,
141 ::mlir::DialectAsmPrinter &printer) const {
142 if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
143 return;
144
145}
146} // namespace pod
147} // namespace llzk
148
149#endif // GET_ATTRDEF_CLASSES
150
::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.
void printRecord(AsmPrinter &printer, StringAttr name, Type type)
Definition Attrs.cpp:35
ParseResult parseRecord(AsmParser &parser, StringAttr &name, Type &type)
Definition Attrs.cpp:27