LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
Ops.h
Go to the documentation of this file.
1//===-- Ops.h ---------------------------------------------------*- 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#pragma once
11
16
17namespace llzk {
18
19namespace component {
20
23template <typename TypeClass>
24class SetFuncAllowAttrs : public mlir::OpTrait::TraitBase<TypeClass, SetFuncAllowAttrs> {
25public:
26 static mlir::LogicalResult verifyTrait(mlir::Operation *op);
27};
28
29} // namespace component
30
31namespace function {
32class FuncDefOp;
33}
34
35} // namespace llzk
36
37// Include TableGen'd declarations
39
40// Include TableGen'd declarations
41#define GET_OP_CLASSES
43
44namespace llzk::component {
45
46mlir::InFlightDiagnostic
47genCompareErr(StructDefOp &expected, mlir::Operation *origin, const char *aspect);
48
49mlir::LogicalResult checkSelfType(
50 mlir::SymbolTableCollection &symbolTable, StructDefOp &expectedStruct, mlir::Type actualType,
51 mlir::Operation *origin, const char *aspect
52);
53
55bool isInStruct(mlir::Operation *op);
56
59mlir::FailureOr<StructDefOp> verifyInStruct(mlir::Operation *op);
60
63bool isInStructFunctionNamed(mlir::Operation *op, char const *funcName);
64
67template <char const *FuncName, unsigned PrefixLen>
68mlir::LogicalResult verifyInStructFunctionNamed(
69 mlir::Operation *op, llvm::function_ref<llvm::SmallString<PrefixLen>()> prefix
70) {
71 return isInStructFunctionNamed(op, FuncName)
72 ? mlir::success()
73 : op->emitOpError(prefix())
74 << "only valid within a '" << getOperationName<function::FuncDefOp>()
75 << "' named \"@" << FuncName << "\" within a '"
76 << getOperationName<StructDefOp>() << "' definition";
77}
78
81template <char const *FuncName> struct InStructFunctionNamed {
82 template <typename TypeClass> class Impl : public mlir::OpTrait::TraitBase<TypeClass, Impl> {
83 public:
84 static mlir::LogicalResult verifyTrait(mlir::Operation *op) {
85 return verifyInStructFunctionNamed<FuncName, 0>(op, [] { return llvm::SmallString<0>(); });
86 }
87 };
88};
89
90} // namespace llzk::component
static mlir::LogicalResult verifyTrait(mlir::Operation *op)
Definition Ops.h:84
Only valid/implemented for StructDefOp.
Definition Ops.h:24
static mlir::LogicalResult verifyTrait(mlir::Operation *op)
InFlightDiagnostic genCompareErr(StructDefOp &expected, Operation *origin, const char *aspect)
Definition Ops.cpp:76
bool isInStruct(Operation *op)
Definition Ops.cpp:37
FailureOr< StructDefOp > verifyInStruct(Operation *op)
Definition Ops.cpp:39
mlir::LogicalResult verifyInStructFunctionNamed(mlir::Operation *op, llvm::function_ref< llvm::SmallString< PrefixLen >()> prefix)
Checks if the given Operation is contained within a FuncDefOp with the given name that is itself cont...
Definition Ops.h:68
bool isInStructFunctionNamed(Operation *op, char const *funcName)
Definition Ops.cpp:48
LogicalResult checkSelfType(SymbolTableCollection &tables, StructDefOp &expectedStruct, Type actualType, Operation *origin, const char *aspect)
Verifies that the given actualType matches the StructDefOp given (i.e.
Definition Ops.cpp:91
llvm::StringLiteral getOperationName()
Get the operation name, like "constrain.eq" for the given OpClass.
Definition OpHelpers.h:27
This class provides a verifier for ops that are expecting to have an ancestor FuncDefOp with the give...
Definition Ops.h:81