LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
SMTTypes.cpp
Go to the documentation of this file.
1//===- SMTTypes.cpp -------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
12
13#include <mlir/IR/Builders.h>
14#include <mlir/IR/DialectImplementation.h>
15
16#include <llvm/ADT/TypeSwitch.h>
17
18using namespace mlir;
19using namespace llzk::smt;
20
21#define GET_TYPEDEF_CLASSES
23
25 // clang-format off
26 // Suppress false positive from `clang-tidy`
27 // NOLINTNEXTLINE(clang-analyzer-core.StackAddressEscape)
28 addTypes<
29 #define GET_TYPEDEF_LIST
31 >();
32 // clang-format on
33}
34
36 return isAnySMTValueType(type) && !isa<SMTFuncType>(type);
37}
38
39bool llzk::smt::isAnySMTValueType(Type type) {
40 return isa<BoolType, BitVectorType, ArrayType, IntType, SortType, SMTFuncType>(type);
41}
42
43//===----------------------------------------------------------------------===//
44// BitVectorType
45//===----------------------------------------------------------------------===//
46
47LogicalResult BitVectorType::verify(function_ref<InFlightDiagnostic()> emitError, int64_t width) {
48 if (width <= 0U) {
49 return emitError() << "bit-vector must have at least a width of one";
50 }
51 return success();
52}
53
54//===----------------------------------------------------------------------===//
55// ArrayType
56//===----------------------------------------------------------------------===//
57
58LogicalResult
59ArrayType::verify(function_ref<InFlightDiagnostic()> emitError, Type domainType, Type rangeType) {
60 if (!isAnySMTValueType(domainType)) {
61 return emitError() << "domain must be any SMT value type";
62 }
63 if (!isAnySMTValueType(rangeType)) {
64 return emitError() << "range must be any SMT value type";
65 }
66
67 return success();
68}
69
70//===----------------------------------------------------------------------===//
71// SMTFuncType
72//===----------------------------------------------------------------------===//
73
74LogicalResult SMTFuncType::verify(
75 function_ref<InFlightDiagnostic()> emitError, ArrayRef<Type> domainTypes, Type rangeType
76) {
77 if (domainTypes.empty()) {
78 return emitError() << "domain must not be empty";
79 }
80 if (!llvm::all_of(domainTypes, isAnyNonFuncSMTValueType)) {
81 return emitError() << "domain types must be any non-function SMT type";
82 }
83 if (!isAnyNonFuncSMTValueType(rangeType)) {
84 return emitError() << "range type must be any non-function SMT type";
85 }
86
87 return success();
88}
89
90//===----------------------------------------------------------------------===//
91// SortType
92//===----------------------------------------------------------------------===//
93
94LogicalResult SortType::verify(
95 function_ref<InFlightDiagnostic()> emitError, StringAttr /*identifier*/,
96 ArrayRef<Type> sortParams
97) {
98 if (!llvm::all_of(sortParams, isAnyNonFuncSMTValueType)) {
99 return emitError() << "sort parameter types must be any non-function SMT type";
100 }
101
102 return success();
103}
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, mlir::Type domainType, mlir::Type rangeType)
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int64_t width)
Definition SMTTypes.cpp:47
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::llvm::ArrayRef< mlir::Type > domainTypes, mlir::Type rangeType)
Definition SMTTypes.cpp:74
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, mlir::StringAttr identifier, ::llvm::ArrayRef< mlir::Type > sortParams)
Definition SMTTypes.cpp:94
bool isAnyNonFuncSMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type (excluding functions).
bool isAnySMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type.