LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
Loading...
Searching...
No Matches
SMTTypes.cpp
Go to the documentation of this file.
1
//===- SMTTypes.cpp ---------------------------------------------*- C++ -*-===//
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
9
#include "
llzk/Dialect/SMT/IR/SMTTypes.h
"
10
11
#include "
llzk/Dialect/SMT/IR/SMTDialect.h
"
12
13
#include <mlir/IR/Builders.h>
14
#include <mlir/IR/DialectImplementation.h>
15
16
#include <llvm/ADT/TypeSwitch.h>
17
18
using namespace
mlir
;
19
using namespace
llzk::smt
;
20
21
#define GET_TYPEDEF_CLASSES
22
#include "
llzk/Dialect/SMT/IR/SMTTypes.cpp.inc
"
23
24
void
SMTDialect::registerTypes
() {
25
// clang-format off
26
// Suppress false positive from `clang-tidy`
27
// NOLINTNEXTLINE(clang-analyzer-core.StackAddressEscape)
28
addTypes<
29
#define GET_TYPEDEF_LIST
30
#include "
llzk/Dialect/SMT/IR/SMTTypes.cpp.inc
"
31
>();
32
// clang-format on
33
}
34
35
bool
llzk::smt::isAnyNonFuncSMTValueType
(Type type) {
36
return
isAnySMTValueType
(type) && !isa<SMTFuncType>(type);
37
}
38
39
bool
llzk::smt::isAnySMTValueType
(Type type) {
40
return
isa<BoolType, BitVectorType, ArrayType, IntType, SortType, SMTFuncType>(type);
41
}
42
43
//===----------------------------------------------------------------------===//
44
// BitVectorType
45
//===----------------------------------------------------------------------===//
46
47
LogicalResult
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
58
LogicalResult
59
ArrayType::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
74
LogicalResult
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
94
LogicalResult
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
}
SMTDialect.h
SMTTypes.cpp.inc
SMTTypes.h
llzk::smt::ArrayType::verify
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, mlir::Type domainType, mlir::Type rangeType)
llzk::smt::BitVectorType::verify
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int64_t width)
Definition
SMTTypes.cpp:47
llzk::smt::SMTDialect::registerTypes
void registerTypes()
Definition
SMTTypes.cpp:24
llzk::smt::SMTFuncType::verify
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::llvm::ArrayRef< mlir::Type > domainTypes, mlir::Type rangeType)
Definition
SMTTypes.cpp:74
llzk::smt::SortType::verify
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, mlir::StringAttr identifier, ::llvm::ArrayRef< mlir::Type > sortParams)
Definition
SMTTypes.cpp:94
llzk::smt
Definition
SMT.cpp.inc:80
llzk::smt::isAnyNonFuncSMTValueType
bool isAnyNonFuncSMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type (excluding functions).
llzk::smt::isAnySMTValueType
bool isAnySMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type.
mlir
Definition
ValueModel.h:30
lib
Dialect
SMT
SMTTypes.cpp
Generated by
1.17.0
Copyright 2025 Veridise Inc. under the Apache License v2.0. Copyright 2026 Project LLZK under the Apache License v2.0.