LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
Loading...
Searching...
No Matches
Types.cpp
Go to the documentation of this file.
1
//===-- Types.cpp - Struct type implementations -----------------*- C++ -*-===//
2
//
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
7
//
8
//===----------------------------------------------------------------------===//
9
10
#include "
llzk/Dialect/Struct/IR/Types.h
"
11
12
#include "
llzk/Dialect/Polymorphic/IR/Ops.h
"
13
#include "
llzk/Dialect/Struct/IR/Ops.h
"
14
15
using namespace
mlir
;
16
using namespace
llzk::polymorphic
;
17
18
namespace
llzk::component
{
19
20
LogicalResult
StructType::verify
(
21
function_ref<InFlightDiagnostic()> emitError, SymbolRefAttr
/*nameRef*/
, ArrayAttr params
22
) {
23
return
verifyStructTypeParams
(
wrapNonNullableInFlightDiagnostic
(emitError), params);
24
}
25
26
FailureOr<SymbolLookupResult<StructDefOp>>
StructType::getDefinition
(
27
SymbolTableCollection &symbolTable, Operation *op,
bool
reportMissing
28
)
const
{
29
// First ensure this StructType passes verification
30
ArrayAttr typeParams = this->
getParams
();
31
if
(failed(
StructType::verify
([op] {
return
op->emitError(); },
getNameRef
(), typeParams))) {
32
return
failure();
33
}
34
// Perform lookup and ensure the symbol references a StructDefOp
35
auto
res =
lookupTopLevelSymbol<StructDefOp>
(symbolTable,
getNameRef
(), op, reportMissing);
36
if
(failed(res) || !res.value()) {
37
if
(reportMissing) {
38
return
op->emitError() <<
"could not find '"
<<
StructDefOp::getOperationName
()
39
<<
"' named \""
<<
getNameRef
() <<
'"'
;
40
}
else
{
41
return
failure();
42
}
43
}
44
// If this StructType contains parameters, make sure the StructDefOp is within a TemplateOp with
45
// the same number of params.
46
if
(typeParams) {
47
size_t
numExpected = 0;
48
if
(
TemplateOp
parent =
getParentOfType<TemplateOp>
(*res.value())) {
49
numExpected = parent.numConstOps<
TemplateParamOp
>();
50
}
51
if
(typeParams.size() != numExpected) {
52
return
op->emitError() <<
'\''
<<
StructType::name
<<
"' type has "
<< typeParams.size()
53
<<
" parameters but \""
<< res.value().get().getSymName()
54
<<
"\" expects "
<< numExpected;
55
}
56
}
57
return
res;
58
}
59
60
LogicalResult
StructType::verifySymbolRef
(SymbolTableCollection &symbolTable, Operation *op) {
61
return
getDefinition
(symbolTable, op);
62
}
63
64
LogicalResult
StructType::hasColumns
(SymbolTableCollection &symbolTable, Operation *op)
const
{
65
auto
lookup =
getDefinition
(symbolTable, op);
66
if
(failed(lookup)) {
67
return
lookup;
68
}
69
return
lookup->get().hasColumns();
70
}
71
72
}
// namespace llzk::component
Ops.h
Ops.h
Types.h
llzk::component::StructDefOp::getOperationName
static constexpr ::llvm::StringLiteral getOperationName()
Definition
Ops.h.inc:1170
llzk::component::StructType::getNameRef
::mlir::SymbolRefAttr getNameRef() const
Definition
Types.cpp.inc:181
llzk::component::StructType::hasColumns
mlir::LogicalResult hasColumns(mlir::SymbolTableCollection &symbolTable, mlir::Operation *op) const
Returns wether the struct this type refers to has members marked as columns.
Definition
Types.cpp:64
llzk::component::StructType::getDefinition
::mlir::FailureOr< SymbolLookupResult< StructDefOp > > getDefinition(::mlir::SymbolTableCollection &symbolTable, ::mlir::Operation *op, bool reportMissing=true) const
Gets the struct op that defines this struct.
Definition
Types.cpp:26
llzk::component::StructType::verify
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::SymbolRefAttr nameRef, ::mlir::ArrayAttr params)
Definition
Types.cpp:20
llzk::component::StructType::getParams
::mlir::ArrayAttr getParams() const
Definition
Types.cpp.inc:185
llzk::component::StructType::verifySymbolRef
::mlir::LogicalResult verifySymbolRef(::mlir::SymbolTableCollection &symbolTable, ::mlir::Operation *op)
Definition
Types.cpp:60
llzk::component::StructType::name
static constexpr ::llvm::StringLiteral name
Definition
Types.h.inc:38
llzk::polymorphic::TemplateOp
Definition
Ops.h.inc:827
llzk::polymorphic::TemplateParamOp
Definition
Ops.h.inc:1112
llzk::component
Definition
Dialect.cpp:209
llzk::polymorphic
Definition
Ops.cpp:32
llzk::lookupTopLevelSymbol
mlir::FailureOr< SymbolLookupResultUntyped > lookupTopLevelSymbol(mlir::SymbolTableCollection &tables, mlir::SymbolRefAttr symbol, mlir::Operation *origin, bool reportMissing=true)
Definition
SymbolLookup.h:234
llzk::getParentOfType
OpClass getParentOfType(mlir::Operation *op)
Return the closest surrounding parent/ancestor operation that is of type 'OpClass'.
Definition
OpHelpers.h:53
llzk::wrapNonNullableInFlightDiagnostic
OwningEmitErrorFn wrapNonNullableInFlightDiagnostic(llvm::function_ref< mlir::InFlightDiagnostic()> emitError)
Definition
ErrorHelper.h:186
llzk::verifyStructTypeParams
LogicalResult verifyStructTypeParams(EmitErrorFn emitError, ArrayAttr params)
Definition
TypeHelper.cpp:1054
mlir
Definition
ValueModel.h:30
lib
Dialect
Struct
IR
Types.cpp
Generated by
1.17.0
Copyright 2025 Veridise Inc. under the Apache License v2.0. Copyright 2026 Project LLZK under the Apache License v2.0.