LLZK 2.0.0
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
11#include "llvm/ADT/TypeSwitch.h"
12#include "mlir/IR/Builders.h"
13#include "mlir/IR/DialectImplementation.h"
14
16
17using namespace mlir;
18using namespace llzk::smt;
19using namespace mlir;
20
21#define GET_TYPEDEF_CLASSES
23
25 addTypes<
26#define GET_TYPEDEF_LIST
28 >();
29}
30
32 return isAnySMTValueType(type) && !isa<SMTFuncType>(type);
33}
34
35bool llzk::smt::isAnySMTValueType(Type type) {
36 return isa<BoolType, BitVectorType, ArrayType, IntType, SortType, SMTFuncType>(type);
37}
38
39//===----------------------------------------------------------------------===//
40// BitVectorType
41//===----------------------------------------------------------------------===//
42
43LogicalResult BitVectorType::verify(function_ref<InFlightDiagnostic()> emitError, int64_t width) {
44 if (width <= 0U) {
45 return emitError() << "bit-vector must have at least a width of one";
46 }
47 return success();
48}
49
50//===----------------------------------------------------------------------===//
51// ArrayType
52//===----------------------------------------------------------------------===//
53
54LogicalResult
55ArrayType::verify(function_ref<InFlightDiagnostic()> emitError, Type domainType, Type rangeType) {
56 if (!isAnySMTValueType(domainType)) {
57 return emitError() << "domain must be any SMT value type";
58 }
59 if (!isAnySMTValueType(rangeType)) {
60 return emitError() << "range must be any SMT value type";
61 }
62
63 return success();
64}
65
66//===----------------------------------------------------------------------===//
67// SMTFuncType
68//===----------------------------------------------------------------------===//
69
70LogicalResult SMTFuncType::verify(
71 function_ref<InFlightDiagnostic()> emitError, ArrayRef<Type> domainTypes, Type rangeType
72) {
73 if (domainTypes.empty()) {
74 return emitError() << "domain must not be empty";
75 }
76 if (!llvm::all_of(domainTypes, isAnyNonFuncSMTValueType)) {
77 return emitError() << "domain types must be any non-function SMT type";
78 }
79 if (!isAnyNonFuncSMTValueType(rangeType)) {
80 return emitError() << "range type must be any non-function SMT type";
81 }
82
83 return success();
84}
85
86//===----------------------------------------------------------------------===//
87// SortType
88//===----------------------------------------------------------------------===//
89
90LogicalResult SortType::verify(
91 function_ref<InFlightDiagnostic()> emitError, StringAttr identifier, ArrayRef<Type> sortParams
92) {
93 if (!llvm::all_of(sortParams, isAnyNonFuncSMTValueType)) {
94 return emitError() << "sort parameter types must be any non-function SMT type";
95 }
96
97 return success();
98}
::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:43
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::llvm::ArrayRef< mlir::Type > domainTypes, mlir::Type rangeType)
Definition SMTTypes.cpp:70
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, mlir::StringAttr identifier, ::llvm::ArrayRef< mlir::Type > sortParams)
Definition SMTTypes.cpp:90
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.