LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
OpTraits.cpp
Go to the documentation of this file.
1//===-- OpTraits.cpp --------------------------------------------*- 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
11
14
15#include <mlir/IR/Operation.h>
16
17using namespace mlir;
18
19namespace llzk::function {
20
21namespace {
22
23auto parentFuncDefOpHasAttr = [](Operation *op, auto attrFn) -> bool {
24 if (FuncDefOp f = op->getParentOfType<FuncDefOp>()) {
25 return (f.*attrFn)();
26 }
27 return false;
28};
29
30} // namespace
31
32LogicalResult verifyConstraintGenTraitImpl(Operation *op) {
33 if (parentFuncDefOpHasAttr(op, &FuncDefOp::hasAllowConstraintAttr)) {
34 return success();
35 }
36 return op->emitOpError() << "only valid within a '" << FuncDefOp::getOperationName() << "' with '"
37 << AllowConstraintAttr::name << "' attribute";
38}
39
40LogicalResult verifyWitnessGenTraitImpl(Operation *op) {
41 if (parentFuncDefOpHasAttr(op, &FuncDefOp::hasAllowWitnessAttr)) {
42 return success();
43 }
44 return op->emitOpError() << "only valid within a '" << FuncDefOp::getOperationName() << "' with '"
45 << AllowWitnessAttr::name << "' attribute";
46}
47
48LogicalResult verifyNotFieldNativeTraitImpl(Operation *op) {
49 if (op->getParentOfType<llzk::polymorphic::TemplateExprOp>()) {
50 return success();
51 }
52 if (parentFuncDefOpHasAttr(op, &FuncDefOp::hasAllowNonNativeFieldOpsAttr)) {
53 return success();
54 }
55 return op->emitOpError() << "only valid within a '" << FuncDefOp::getOperationName() << "' with '"
56 << AllowNonNativeFieldOpsAttr::name << "' attribute or a '"
58}
59
60} // namespace llzk::function
bool hasAllowNonNativeFieldOpsAttr()
Return true iff the function def has the allow_non_native_field_ops attribute.
Definition Ops.h.inc:820
bool hasAllowWitnessAttr()
Return true iff the function def has the allow_witness attribute.
Definition Ops.h.inc:812
static constexpr ::llvm::StringLiteral getOperationName()
Definition Ops.h.inc:666
bool hasAllowConstraintAttr()
Return true iff the function def has the allow_constraint attribute.
Definition Ops.h.inc:804
static constexpr ::llvm::StringLiteral getOperationName()
Definition Ops.h.inc:636
LogicalResult verifyNotFieldNativeTraitImpl(Operation *op)
Definition OpTraits.cpp:48
LogicalResult verifyConstraintGenTraitImpl(Operation *op)
Definition OpTraits.cpp:32
LogicalResult verifyWitnessGenTraitImpl(Operation *op)
Definition OpTraits.cpp:40