-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathOpTraits.cpp
More file actions
54 lines (43 loc) · 1.73 KB
/
OpTraits.cpp
File metadata and controls
54 lines (43 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//===-- OpTraits.cpp --------------------------------------------*- C++ -*-===//
//
// Part of the LLZK Project, under the Apache License v2.0.
// See LICENSE.txt for license information.
// Copyright 2025 Veridise Inc.
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
#include "llzk/Dialect/Function/IR/OpTraits.h"
#include "llzk/Dialect/Function/IR/Ops.h"
#include <mlir/IR/Operation.h>
using namespace mlir;
namespace llzk::function {
namespace {
auto parentFuncDefOpHasAttr = [](Operation *op, auto attrFn) -> bool {
if (FuncDefOp f = op->getParentOfType<FuncDefOp>()) {
return (f.*attrFn)();
}
return false;
};
} // namespace
LogicalResult verifyConstraintGenTraitImpl(Operation *op) {
if (!parentFuncDefOpHasAttr(op, &FuncDefOp::hasAllowConstraintAttr)) {
return op->emitOpError() << "only valid within a '" << FuncDefOp::getOperationName()
<< "' with '" << AllowConstraintAttr::name << "' attribute";
}
return success();
}
LogicalResult verifyWitnessGenTraitImpl(Operation *op) {
if (!parentFuncDefOpHasAttr(op, &FuncDefOp::hasAllowWitnessAttr)) {
return op->emitOpError() << "only valid within a '" << FuncDefOp::getOperationName()
<< "' with '" << AllowWitnessAttr::name << "' attribute";
}
return success();
}
LogicalResult verifyNotFieldNativeTraitImpl(Operation *op) {
if (!parentFuncDefOpHasAttr(op, &FuncDefOp::hasAllowNonNativeFieldOpsAttr)) {
return op->emitOpError() << "only valid within a '" << FuncDefOp::getOperationName()
<< "' with '" << AllowNonNativeFieldOpsAttr::name << "' attribute";
}
return success();
}
} // namespace llzk::function