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::felt::FeltConstAttr
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::felt::FeltConstAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
22 value = ::llzk::felt::FeltConstAttr::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 ::mlir::LogicalResult generatedAttributePrinter(::mlir::Attribute def, ::mlir::AsmPrinter &printer) {
32 return ::llvm::TypeSwitch<::mlir::Attribute, ::mlir::LogicalResult>(def) .Case<::llzk::felt::FeltConstAttr>([&](auto t) {
33 printer << ::llzk::felt::FeltConstAttr::getMnemonic();
34t.print(printer);
35 return ::mlir::success();
36 })
37 .Default([](auto) { return ::mlir::failure(); });
38}
39
40namespace llzk {
41namespace felt {
42namespace detail {
43struct FeltConstAttrStorage : public ::mlir::AttributeStorage {
44 using KeyTy = std::tuple<::llvm::APInt>;
45 FeltConstAttrStorage(::llvm::APInt 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 (::llvm::APInt::isSameValue(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 FeltConstAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
60 auto value = std::move(std::get<0>(tblgenKey));
61 return new (allocator.allocate<FeltConstAttrStorage>()) FeltConstAttrStorage(std::move(value));
62 }
63
64 ::llvm::APInt value;
65};
66} // namespace detail
67FeltConstAttr FeltConstAttr::get(::mlir::MLIRContext *context, ::llvm::APInt value) {
68 return Base::get(context, std::move(value));
69}
70
71::mlir::Attribute FeltConstAttr::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<::llvm::APInt> _result_value;
76
77 // Parse variable 'value'
78 _result_value = ::mlir::FieldParser<::llvm::APInt>::parse(odsParser);
79 if (::mlir::failed(_result_value)) {
80 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_FeltConstAttr parameter 'value' which is to be a `::llvm::APInt`");
81 return {};
82 }
83 assert(::mlir::succeeded(_result_value));
84 return FeltConstAttr::get(odsParser.getContext(),
85 ::llvm::APInt((*_result_value)));
86}
87
88void FeltConstAttr::print(::mlir::AsmPrinter &odsPrinter) const {
89 ::mlir::Builder odsBuilder(getContext());
90 odsPrinter << ' ';
91 odsPrinter.printStrippedAttrOrType(getValue());
92}
93
94::llvm::APInt FeltConstAttr::getValue() const {
95 return getImpl()->value;
96}
97
98} // namespace felt
99} // namespace llzk
100MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::felt::FeltConstAttr)
101namespace llzk {
102namespace felt {
103
105::mlir::Attribute FeltDialect::parseAttribute(::mlir::DialectAsmParser &parser,
106 ::mlir::Type type) const {
107 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
108 ::llvm::StringRef attrTag;
109 {
110 ::mlir::Attribute attr;
111 auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
112 if (parseResult.has_value())
113 return attr;
114 }
115
116 parser.emitError(typeLoc) << "unknown attribute `"
117 << attrTag << "` in dialect `" << getNamespace() << "`";
118 return {};
119}
121void FeltDialect::printAttribute(::mlir::Attribute attr,
122 ::mlir::DialectAsmPrinter &printer) const {
123 if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
124 return;
125
126}
127} // namespace felt
128} // namespace llzk
129
130#endif // GET_ATTRDEF_CLASSES
131
::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.