20#include <mlir/CAPI/AffineMap.h>
21#include <mlir/CAPI/Registration.h>
22#include <mlir/CAPI/Support.h>
23#include <mlir/CAPI/Wrap.h>
24#include <mlir/IR/BuiltinAttributes.h>
26#include <mlir-c/Support.h>
28#include <llvm/ADT/STLExtras.h>
47 llvm::cast<SymbolRefAttr>(unwrap(
name)), llvm::cast<ArrayAttr>(unwrap(params))
54 SmallVector<Attribute> paramsSto;
57 llvm::cast<SymbolRefAttr>(unwrap(
name)), unwrapList(numParams, params, paramsSto)
65 return wrap(llvm::cast<StructType>(unwrap(type)).getNameRef());
69 return wrap(llvm::cast<StructType>(unwrap(type)).getParams());
79 return wrap(&llvm::cast<StructDefOp>(unwrap(op)).getBodyRegion());
83 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getBody());
87 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType());
91 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType(llvm::cast<ArrayAttr>(unwrap(attr))));
95 Builder builder(unwrap(op)->getContext());
96 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getFieldDef(builder.getStringAttr(unwrap(
name))));
100 for (
auto [offset, field] : llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getFieldDefs())) {
101 dst[offset] = wrap(field);
106 return static_cast<intptr_t
>(llvm::cast<StructDefOp>(unwrap(op)).getFieldDefs().size());
110 return wrap(llvm::cast<StructDefOp>(unwrap(op)).hasColumns());
114 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getComputeFuncOp());
118 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getConstrainFuncOp());
123 auto header = llvm::cast<StructDefOp>(unwrap(op)).getHeaderString();
124 *strSize =
static_cast<intptr_t
>(header.size()) + 1;
125 char *dst = alloc_string(*strSize);
126 dst[header.size()] = 0;
127 memcpy(dst, header.data(), header.size());
132 Builder builder(unwrap(op)->getContext());
133 return llvm::cast<StructDefOp>(unwrap(op)).hasParamNamed(builder.getStringAttr(unwrap(
name)));
137 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getFullyQualifiedName());
141 return llvm::cast<StructDefOp>(unwrap(op)).isMainComponent();
151 return llvm::cast<FieldDefOp>(unwrap(op)).hasPublicAttr();
155 llvm::cast<FieldDefOp>(unwrap(op)).setPublicAttr(value);
167 builder, location, unwrap(fieldType), unwrap(
component),
168 unwrap(builder)->getStringAttr(unwrap(
name))
175 MlirAffineMap map,
MlirValueRange mapOperands, int32_t numDimsPerMap
177 SmallVector<Value> mapOperandsSto;
178 auto nameAttr = unwrap(builder)->getStringAttr(unwrap(
name));
179 auto mapAttr = AffineMapAttr::get(unwrap(map));
182 builder, location, unwrap(fieldType), unwrap(
component), nameAttr, mapAttr,
183 unwrapList(mapOperands.
size, mapOperands.
values, mapOperandsSto), numDimsPerMap
190 MlirStringRef
name, MlirStringRef symbol
192 auto nameAttr = unwrap(builder)->getStringAttr(unwrap(
name));
195 builder, location, unwrap(fieldType), unwrap(
component), nameAttr,
196 FlatSymbolRefAttr::get(unwrap(builder)->getStringAttr(unwrap(symbol)))
205 auto nameAttr = unwrap(builder)->getStringAttr(unwrap(
name));
208 builder, location, unwrap(fieldType), unwrap(
component), nameAttr,
209 unwrap(builder)->getI64IntegerAttr(distance)
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Polymorphic, llzk__polymorphic, llzk::polymorphic::PolymorphicDialect) MlirType llzkTypeVarTypeGet(MlirContext ctx
void llzkFieldDefOpSetPublicAttr(MlirOperation op, bool value)
Sets the public attribute in the given field.
bool llzkFieldDefOpGetHasPublicAttr(MlirOperation op)
const char * llzkStructDefOpGetHeaderString(MlirOperation op, intptr_t *strSize, char *(*alloc_string)(size_t))
Returns the header string of the struct.
void llzkStructDefOpGetFieldDefs(MlirOperation op, MlirOperation *dst)
Fills the given array with the FieldDefOp operations inside this struct.
MlirAttribute llzkStructDefOpGetFullyQualifiedName(MlirOperation op)
Returns a StringAttr with the fully qualified name of the struct.
MlirType llzkStructDefOpGetTypeWithParams(MlirOperation op, MlirAttribute attr)
Returns the associated StructType to this op using the given const params instead of the parameters d...
bool llzkStructDefOpGetHasParamName(MlirOperation op, MlirStringRef name)
MlirType llzkStructTypeGetWithAttrs(MlirAttribute name, intptr_t numParams, MlirAttribute const *params)
Creates a llzk::component::StructType with an array of parameters.
MlirAttribute llzkStructTypeGetParams(MlirType type)
Returns the parameter of a llzk::component::StructType as an ArrayAttr.
MlirType llzkStructTypeGetWithArrayAttr(MlirAttribute name, MlirAttribute params)
Creates a llzk::component::StructType with an ArrayAttr as parameters.
bool llzkOperationIsAFieldDefOp(MlirOperation op)
bool llzkStructDefOpGetIsMainComponent(MlirOperation op)
bool llzkTypeIsAStructType(MlirType type)
MlirOperation llzkStructDefOpGetFieldDef(MlirOperation op, MlirStringRef name)
Returns the operation that defines the field with the given name, if present.
MlirOperation llzkStructDefOpGetComputeFuncOp(MlirOperation op)
Returns the FuncDefOp operation that defines the witness computation of the struct.
MlirBlock llzkStructDefOpGetBody(MlirOperation op)
Returns the single body Block within the StructDefOp's Region.
MlirRegion llzkStructDefOpGetBodyRegion(MlirOperation op)
Returns the single body Region of the StructDefOp.
MlirAttribute llzkStructTypeGetName(MlirType type)
Returns the fully qualified name of a llzk::component::StructType.
intptr_t llzkStructDefOpGetNumFieldDefs(MlirOperation op)
Returns the number of FieldDefOp operations defined in this struct.
bool llzkOperationIsAStructDefOp(MlirOperation op)
MlirType llzkStructTypeGet(MlirAttribute name)
Creates a llzk::component::StructType.
MlirOperation llzkStructDefOpGetConstrainFuncOp(MlirOperation op)
Returns the FuncDefOp operation that defines the constraints of the struct.
MlirLogicalResult llzkStructDefOpGetHasColumns(MlirOperation op)
Returns true if the struct has fields marked as columns.
MlirType llzkStructDefOpGetType(MlirOperation op)
Returns the associated StructType to this op using the const params defined by the op.
static StructType get(::mlir::SymbolRefAttr structName)
#define LLZK_DEFINE_OP_BUILD_METHOD(op,...)
#define LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD(op, suffix,...)
mlir::Operation * create(MlirOpBuilder cBuilder, MlirLocation cLocation, Args &&...args)
Creates a new operation using an ODS build method.