20#include <mlir/IR/DialectImplementation.h>
22#include <llvm/ADT/TypeSwitch.h>
27#define GET_TYPEDEF_CLASSES
29#define GET_ATTRDEF_CLASSES
43Attribute FieldSpecAttr::parse(AsmParser &odsParser, Type) {
44 Builder odsBuilder(odsParser.getContext());
45 llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
46 FailureOr<StringAttr> fieldNameAttrRes;
47 FailureOr<llvm::APInt> primeRes;
50 if (odsParser.parseLess()) {
56 if (failed(fieldNameAttrRes)) {
58 odsParser.getCurrentLocation(),
"failed to parse LLZK_FieldSpecAttr parameter 'fieldName' "
59 "which is to be a `StringAttr`"
64 if (odsParser.parseComma()) {
70 if (failed(primeRes)) {
72 odsParser.getCurrentLocation(),
73 "failed to parse LLZK_FieldSpecAttr parameter 'prime' which is to be a `llvm::APInt`"
78 if (odsParser.parseGreater()) {
81 assert(succeeded(fieldNameAttrRes));
82 assert(succeeded(primeRes));
85 auto errFn = [&odsParser]() {
86 return InFlightDiagnosticWrapper(odsParser.emitError(odsParser.getCurrentLocation()));
90 return odsParser.getChecked<FieldSpecAttr>(
91 odsLoc, odsParser.getContext(), StringAttr(*fieldNameAttrRes), llvm::APInt(*primeRes)
95void FieldSpecAttr::print(AsmPrinter &odsPrinter)
const {
96 Builder odsBuilder(getContext());
98 odsPrinter.printStrippedAttrOrType(getFieldName());
100 odsPrinter.printStrippedAttrOrType(getPrime());
108Attribute FeltConstAttr::parse(AsmParser &odsParser, Type) {
109 SMLoc odsLoc = odsParser.getCurrentLocation();
113 if (failed(valueRes)) {
115 odsParser.getCurrentLocation(),
116 "failed to parse LLZK_FeltConstAttr parameter 'value' which is to be a `::llvm::APInt`"
124 if (odsParser.parseOptionalColon().succeeded()) {
126 if (failed(typeRes)) {
128 odsParser.getCurrentLocation(),
129 "failed to parse LLZK_FeltConstAttr parameter 'type' which is to be a `FeltType`"
136 else if (odsParser.parseOptionalLess().succeeded()) {
138 if (failed(fieldNameRes)) {
140 odsParser.getCurrentLocation(),
"failed to parse LLZK_FeltConstAttr(version 1) field "
141 "name parameter which is to be a `StringAttr`"
145 if (odsParser.parseGreater()) {
148 type =
FeltType::get(odsParser.getContext(), (*fieldNameRes).getValue());
151 return odsParser.getChecked<FeltConstAttr>(odsLoc, odsParser.getContext(), *valueRes, type);
155void FeltConstAttr::print(AsmPrinter &odsPrinter)
const {
157 odsPrinter.printStrippedAttrOrType(getValue());
160 odsPrinter.printStrippedAttrOrType(getType());
184 if (
auto attr = llvm::dyn_cast<FeltConstAttr>(value)) {
190auto FeltDialect::initialize() ->
void {
200 #define GET_TYPEDEF_LIST
205 #define GET_ATTRDEF_LIST
209 addInterfaces<LLZKDialectBytecodeInterface<FeltDialect>>();
Information about the prime finite field used for the interval analysis.
static llvm::LogicalResult verifyFieldDefined(llvm::StringRef fieldName, EmitErrorFn errFn)
Search for a field with the given name, reporting an error if the field is not found.
static const Field & getField(llvm::StringRef fieldName, EmitErrorFn errFn)
Get a Field from a given field name string.
static void addField(llvm::StringRef fieldName, const llvm::APInt &prime, EmitErrorFn errFn)
Add a new field to the set of available prime fields.
::mlir::Operation * materializeConstant(::mlir::OpBuilder &builder, ::mlir::Attribute value, ::mlir::Type type, ::mlir::Location loc) override
Materialize a single constant operation from a given attribute value with the desired resultant type.
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::StringAttr fieldName)
const ::llzk::Field & getField() const
::mlir::StringAttr getFieldName() const
static FeltType get(::mlir::MLIRContext *context, ::mlir::StringAttr fieldName)
OwningEmitErrorFn wrapNonNullableInFlightDiagnostic(llvm::function_ref< mlir::InFlightDiagnostic()> emitError)