LLZK 0.1.0
Veridise's ZK Language IR
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
12
13#include <mlir/IR/Operation.h>
14
15using namespace mlir;
16
17namespace llzk::function {
18
19namespace {
20
21auto parentFuncDefOpHasAttr = [](Operation *op, auto attrFn) -> bool {
22 if (FuncDefOp f = op->getParentOfType<FuncDefOp>()) {
23 return (f.*attrFn)();
24 }
25 return false;
26};
27
28} // namespace
29
30LogicalResult verifyConstraintGenTraitImpl(Operation *op) {
31 if (!parentFuncDefOpHasAttr(op, &FuncDefOp::hasAllowConstraintAttr)) {
32 return op->emitOpError() << "only valid within a '" << FuncDefOp::getOperationName()
33 << "' with '" << AllowConstraintAttr::name << "' attribute";
34 }
35 return success();
36}
37
38LogicalResult verifyWitnessGenTraitImpl(Operation *op) {
39 if (!parentFuncDefOpHasAttr(op, &FuncDefOp::hasAllowWitnessAttr)) {
40 return op->emitOpError() << "only valid within a '" << FuncDefOp::getOperationName()
41 << "' with '" << AllowWitnessAttr::name << "' attribute";
42 }
43 return success();
44}
45
46} // namespace llzk::function
bool hasAllowWitnessAttr()
Return true iff the function def has the allow_witness attribute.
Definition Ops.h.inc:571
static constexpr ::llvm::StringLiteral getOperationName()
Definition Ops.h.inc:478
bool hasAllowConstraintAttr()
Return true iff the function def has the allow_constraint attribute.
Definition Ops.h.inc:563
LogicalResult verifyConstraintGenTraitImpl(Operation *op)
Definition OpTraits.cpp:30
LogicalResult verifyWitnessGenTraitImpl(Operation *op)
Definition OpTraits.cpp:38