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
9#include "mlir/Dialect/SMT/IR/SMTTypes.h"
10#include "mlir/Dialect/SMT/IR/SMTDialect.h"
11
12using namespace mlir;
13using namespace smt;
14using namespace mlir;
15
16static mlir::ParseResult
17parseDomainTypes(mlir::AsmParser &parser,
18 llvm::SmallVectorImpl<mlir::Type> &types) {
19 return parser.parseCommaSeparatedList(
20 delimiter: mlir::AsmParser::Delimiter::Paren,
21 parseElementFn: [&]() { return parser.parseType(result&: types.emplace_back()); });
22}
23
24static void printDomainTypes(mlir::AsmPrinter &printer,
25 llvm::ArrayRef<mlir::Type> types) {
26 printer << '(';
27 llvm::interleaveComma(c: types, os&: printer);
28 printer << ')';
29}
30
31#define GET_TYPEDEF_CLASSES
32#include "mlir/Dialect/SMT/IR/SMTTypes.cpp.inc"
33
34void SMTDialect::registerTypes() {
35 addTypes<
36#define GET_TYPEDEF_LIST
37#include "mlir/Dialect/SMT/IR/SMTTypes.cpp.inc"
38 >();
39}
40
41bool smt::isAnyNonFuncSMTValueType(Type type) {
42 return isAnySMTValueType(type) && !isa<SMTFuncType>(Val: type);
43}
44
45bool smt::isAnySMTValueType(Type type) {
46 return isa<BoolType, BitVectorType, ArrayType, IntType, SortType,
47 SMTFuncType>(Val: type);
48}
49
50//===----------------------------------------------------------------------===//
51// BitVectorType
52//===----------------------------------------------------------------------===//
53
54LogicalResult
55BitVectorType::verify(function_ref<InFlightDiagnostic()> emitError,
56 int64_t width) {
57 if (width <= 0U)
58 return emitError() << "bit-vector must have at least a width of one";
59 return success();
60}
61
62//===----------------------------------------------------------------------===//
63// ArrayType
64//===----------------------------------------------------------------------===//
65
66LogicalResult ArrayType::verify(function_ref<InFlightDiagnostic()> emitError,
67 Type domainType, Type rangeType) {
68 if (!isAnySMTValueType(type: domainType))
69 return emitError() << "domain must be any SMT value type";
70 if (!isAnySMTValueType(type: rangeType))
71 return emitError() << "range must be any SMT value type";
72
73 return success();
74}
75
76//===----------------------------------------------------------------------===//
77// SMTFuncType
78//===----------------------------------------------------------------------===//
79
80LogicalResult SMTFuncType::verify(function_ref<InFlightDiagnostic()> emitError,
81 ArrayRef<Type> domainTypes, Type rangeType) {
82 if (!llvm::all_of(Range&: domainTypes, P: isAnyNonFuncSMTValueType))
83 return emitError() << "domain types must be any non-function SMT type";
84 if (!isAnyNonFuncSMTValueType(type: rangeType))
85 return emitError() << "range type must be any non-function SMT type";
86
87 return success();
88}
89
90//===----------------------------------------------------------------------===//
91// SortType
92//===----------------------------------------------------------------------===//
93
94LogicalResult SortType::verify(function_ref<InFlightDiagnostic()> emitError,
95 StringAttr identifier,
96 ArrayRef<Type> sortParams) {
97 if (!llvm::all_of(Range&: sortParams, P: isAnyNonFuncSMTValueType))
98 return emitError()
99 << "sort parameter types must be any non-function SMT type";
100
101 return success();
102}
103