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