LLZK 2.1.1
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::cast::OverflowSemanticsAttr
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::cast::OverflowSemanticsAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
22 value = ::llzk::cast::OverflowSemanticsAttr::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::cast::OverflowSemanticsAttr>([&](auto t) {
33 printer << ::llzk::cast::OverflowSemanticsAttr::getMnemonic();
34t.print(printer);
35 return ::mlir::success();
36 })
37 .Default([](auto) { return ::mlir::failure(); });
38}
39
40namespace llzk {
41namespace cast {
42namespace detail {
43struct OverflowSemanticsAttrStorage : public ::mlir::AttributeStorage {
44 using KeyTy = std::tuple<::llzk::cast::OverflowSemantics>;
45 OverflowSemanticsAttrStorage(::llzk::cast::OverflowSemantics value) : value(std::move(value)) {}
46
47 KeyTy getAsKey() const {
48 return KeyTy(value);
49 }
50
51 bool operator==(const KeyTy &tblgenKey) const {
52 return (value == std::get<0>(tblgenKey));
53 }
54
55 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
56 return ::llvm::hash_combine(std::get<0>(tblgenKey));
57 }
58
59 static OverflowSemanticsAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
60 auto value = std::move(std::get<0>(tblgenKey));
61 return new (allocator.allocate<OverflowSemanticsAttrStorage>()) OverflowSemanticsAttrStorage(std::move(value));
62 }
63
65};
66} // namespace detail
67OverflowSemanticsAttr OverflowSemanticsAttr::get(::mlir::MLIRContext *context, ::llzk::cast::OverflowSemantics value) {
68 return Base::get(context, std::move(value));
69}
70
71::mlir::Attribute OverflowSemanticsAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
72 ::mlir::Builder odsBuilder(odsParser.getContext());
73 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
74 (void) odsLoc;
75 ::mlir::FailureOr<::llzk::cast::OverflowSemantics> _result_value;
76
77 // Parse variable 'value'
78 _result_value = [&]() -> ::mlir::FailureOr<::llzk::cast::OverflowSemantics> {
79 auto loc = odsParser.getCurrentLocation();
80 ::llvm::StringRef enumKeyword;
81 if (::mlir::failed(odsParser.parseKeyword(&enumKeyword)))
82 return ::mlir::failure();
83 auto maybeEnum = ::llzk::cast::symbolizeOverflowSemantics(enumKeyword);
84 if (maybeEnum)
85 return *maybeEnum;
86 return {(::llvm::LogicalResult)(odsParser.emitError(loc) << "expected " << "::llzk::cast::OverflowSemantics" << " to be one of: " << "assert" << ", " << "sat" << ", " << "wrap" << ", " << "trunc")};
87 }();
88 if (::mlir::failed(_result_value)) {
89 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_OverflowSemanticsAttr parameter 'value' which is to be a `::llzk::cast::OverflowSemantics`");
90 return {};
91 }
92 assert(::mlir::succeeded(_result_value));
93 return OverflowSemanticsAttr::get(odsParser.getContext(),
94 ::llzk::cast::OverflowSemantics((*_result_value)));
95}
96
97void OverflowSemanticsAttr::print(::mlir::AsmPrinter &odsPrinter) const {
98 ::mlir::Builder odsBuilder(getContext());
99 odsPrinter << ' ';
100 odsPrinter << stringifyOverflowSemantics(getValue());
101}
102
103::llzk::cast::OverflowSemantics OverflowSemanticsAttr::getValue() const {
104 return getImpl()->value;
105}
106
107} // namespace cast
108} // namespace llzk
109MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::cast::OverflowSemanticsAttr)
110namespace llzk {
111namespace cast {
112
114::mlir::Attribute CastDialect::parseAttribute(::mlir::DialectAsmParser &parser,
115 ::mlir::Type type) const {
116 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
117 ::llvm::StringRef attrTag;
118 {
119 ::mlir::Attribute attr;
120 auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
121 if (parseResult.has_value())
122 return attr;
123 }
124
125 parser.emitError(typeLoc) << "unknown attribute `"
126 << attrTag << "` in dialect `" << getNamespace() << "`";
127 return {};
128}
130void CastDialect::printAttribute(::mlir::Attribute attr,
131 ::mlir::DialectAsmPrinter &printer) const {
132 if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
133 return;
134
135}
136} // namespace cast
137} // namespace llzk
138
139#endif // GET_ATTRDEF_CLASSES
140
::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.
::llvm::StringRef stringifyOverflowSemantics(OverflowSemantics val)
Definition Enums.cpp.inc:12
::std::optional< OverflowSemantics > symbolizeOverflowSemantics(::llvm::StringRef str)
Definition Enums.cpp.inc:22