1//===-- Types.td -------------------------------------------*- tablegen -*-===//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
8//===----------------------------------------------------------------------===//
10#ifndef LLZK_STRUCT_TYPES
11#define LLZK_STRUCT_TYPES
13include "llzk/Dialect/Shared/Types.td"
14include "llzk/Dialect/Struct/IR/Dialect.td"
16include "mlir/IR/AttrTypeBase.td"
17include "mlir/IR/BuiltinTypes.td"
18include "mlir/Interfaces/MemorySlotInterfaces.td"
19include "mlir/IR/BuiltinTypeInterfaces.td"
21class StructDialectType<string name, string typeMnemonic,
22 list<Trait> traits = []>
23 : TypeDef<StructDialect, name, traits> {
24 let mnemonic = typeMnemonic;
27def LLZK_StructType : StructDialectType<"Struct", "type"> {
28 let summary = "circuit component";
29 let description = [{}];
33 "::mlir::SymbolRefAttr",
34 "Fully-qualified name of the struct definition.">:$nameRef,
35 OptionalParameter<"::mlir::ArrayAttr", "Struct parameters">:$params);
38 [{ `<` $nameRef ( `<` custom<StructParams>($params)^ `>` )? `>` }];
40 let genVerifyDecl = 1;
42 let skipDefaultBuilders = 1;
43 let builders = [TypeBuilderWithInferredContext<
44 (ins "::mlir::SymbolRefAttr":$structName), [{
45 return $_get(structName.getContext(), structName, ::mlir::ArrayAttr());
47 TypeBuilderWithInferredContext<
48 (ins "::mlir::SymbolRefAttr":$structName,
49 "::mlir::ArrayAttr":$params),
51 ::mlir::MLIRContext *ctx = structName.getContext();
53 params = ::mlir::ArrayAttr::get(ctx, forceIntAttrTypes(params.getValue()));
55 return $_get(ctx, structName, params);
57 TypeBuilderWithInferredContext<
58 (ins "::mlir::SymbolRefAttr":$structName,
59 "::llvm::ArrayRef<::mlir::Attribute>":$paramsRef),
61 ::mlir::MLIRContext *ctx = structName.getContext();
62 ::llvm::SmallVector<::mlir::Attribute> p = forceIntAttrTypes(paramsRef);
63 return $_get(ctx, structName, ::mlir::ArrayAttr::get(ctx, p));
66 let extraClassDeclaration = [{
67 /// Gets the `struct` op that defines this struct. Provided `op` is
68 /// used as a starting point for the lookup. Should not be assumed to
69 /// be non-`null` as we don't verify all types during verification.
70 ::mlir::FailureOr<SymbolLookupResult<StructDefOp>> getDefinition
71 (::mlir::SymbolTableCollection &symbolTable, ::mlir::Operation *op) const;
73 // Verifies that this type references a valid struct, relative to the given `op`.
74 ::mlir::LogicalResult verifySymbolRef(::mlir::SymbolTableCollection &symbolTable, ::mlir::Operation *op);
76 /// Returns wether the struct this type refers to has fields marked as columns.
77 /// A lookup is necessary first and will forward the failure state if it fails.
78 mlir::LogicalResult hasColumns(mlir::SymbolTableCollection &symbolTable, mlir::Operation *op) const;
82#endif // LLZK_STRUCT_TYPES