LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
Loading...
Searching...
No Matches
Attrs.cpp
Go to the documentation of this file.
1
//===-- Attrs.cpp - Felt Attr method implementations ------------*- C++ -*-===//
2
//
3
// Part of the LLZK Project, under the Apache License v2.0.
4
// See LICENSE.txt for license information.
5
// Copyright 2026 Project LLZK
6
// SPDX-License-Identifier: Apache-2.0
7
//
8
//===----------------------------------------------------------------------===//
9
10
#include "
llzk/Dialect/Felt/IR/Attrs.h
"
11
12
#include "
llzk/Util/DynamicAPIntHelper.h
"
13
14
using namespace
mlir
;
15
16
namespace
llzk::felt
{
17
18
LogicalResult FieldSpecAttr::verify(
19
llvm::function_ref<InFlightDiagnostic()> emitError, StringAttr,
20
// TableGen requires this parameter to be passed by value.
21
llzk::DynamicAPIntValue
primeWrapper
// NOLINT(performance-unnecessary-value-param)
22
) {
23
const
llvm::DynamicAPInt &prime = primeWrapper;
// implict unwrap
24
if
(prime < 2) {
25
return
emitError() <<
"field modulus must be at least 2"
;
26
}
27
return
success();
28
}
29
30
StringAttr FeltConstAttr::getFieldName()
const
{
31
FeltType
ft = getType();
32
return
ft ? ft.
getFieldName
() : StringAttr();
33
}
34
35
std::optional<llvm::DynamicAPInt> FeltConstAttr::getReducedValue()
const
{
36
FeltType
type = getType();
37
if
(!type || !type.
hasField
()) {
38
return
std::nullopt;
39
}
40
return
type.
getField
().
reduce
(getRawValue());
41
}
42
43
llvm::DynamicAPInt FeltConstAttr::getReducedValueOrRaw()
const
{
44
if
(
auto
reduced = getReducedValue()) {
45
return
*reduced;
46
}
47
return
getRawValue();
48
}
49
50
}
// namespace llzk::felt
DynamicAPIntHelper.h
This file implements helpers for DynamicAPInt operations and conversions that LLVM does not provide.
Attrs.h
llzk::DynamicAPIntValue
Attribute storage adapter providing numeric hashing for DynamicAPInt.
Definition
AttributeHelper.h:43
llzk::Field::reduce
llvm::DynamicAPInt reduce(const llvm::DynamicAPInt &i) const
Returns the canonical representative of i mod p in [0, p).
llzk::felt::FeltType
Definition
Types.h.inc:47
llzk::felt::FeltType::getField
const ::llzk::Field & getField() const
Definition
Dialect.cpp:255
llzk::felt::FeltType::getFieldName
::mlir::StringAttr getFieldName() const
Definition
Types.cpp.inc:133
llzk::felt::FeltType::hasField
bool hasField() const
Definition
Types.h.inc:50
llzk::felt
Definition
Attrs.cpp:16
mlir
Definition
CommonCAPIGen.h:50
lib
Dialect
Felt
IR
Attrs.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.