MLIR 23.0.0git
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
11#include "mlir/IR/Builders.h"
13#include "llvm/ADT/TypeSwitch.h"
14
15using namespace mlir;
16using namespace smt;
17using namespace mlir;
18
19static mlir::ParseResult
22 return parser.parseCommaSeparatedList(
24 [&]() { return parser.parseType(types.emplace_back()); });
25}
26
29 printer << '(';
30 llvm::interleaveComma(types, printer);
31 printer << ')';
32}
33
34#define GET_TYPEDEF_CLASSES
35#include "mlir/Dialect/SMT/IR/SMTTypes.cpp.inc"
36
37void SMTDialect::registerTypes() {
38 addTypes<
39#define GET_TYPEDEF_LIST
40#include "mlir/Dialect/SMT/IR/SMTTypes.cpp.inc"
41 >();
42}
43
45 return isAnySMTValueType(type) && !isa<SMTFuncType>(type);
46}
47
49 return isa<BoolType, BitVectorType, ArrayType, IntType, SortType,
50 SMTFuncType>(type);
51}
52
53//===----------------------------------------------------------------------===//
54// BitVectorType
55//===----------------------------------------------------------------------===//
56
57LogicalResult
58BitVectorType::verify(function_ref<InFlightDiagnostic()> emitError,
59 int64_t width) {
60 if (width <= 0U)
61 return emitError() << "bit-vector must have at least a width of one";
62 return success();
63}
64
65//===----------------------------------------------------------------------===//
66// ArrayType
67//===----------------------------------------------------------------------===//
68
69LogicalResult ArrayType::verify(function_ref<InFlightDiagnostic()> emitError,
70 Type domainType, Type rangeType) {
71 if (!isAnySMTValueType(domainType))
72 return emitError() << "domain must be any SMT value type";
73 if (!isAnySMTValueType(rangeType))
74 return emitError() << "range must be any SMT value type";
75
76 return success();
77}
78
79//===----------------------------------------------------------------------===//
80// SMTFuncType
81//===----------------------------------------------------------------------===//
82
83LogicalResult SMTFuncType::verify(function_ref<InFlightDiagnostic()> emitError,
84 ArrayRef<Type> domainTypes, Type rangeType) {
85 if (!llvm::all_of(domainTypes, isAnyNonFuncSMTValueType))
86 return emitError() << "domain types must be any non-function SMT type";
87 if (!isAnyNonFuncSMTValueType(rangeType))
88 return emitError() << "range type must be any non-function SMT type";
89
90 return success();
91}
92
93//===----------------------------------------------------------------------===//
94// SortType
95//===----------------------------------------------------------------------===//
96
97LogicalResult SortType::verify(function_ref<InFlightDiagnostic()> emitError,
98 StringAttr identifier,
99 ArrayRef<Type> sortParams) {
100 if (!llvm::all_of(sortParams, isAnyNonFuncSMTValueType))
101 return emitError()
102 << "sort parameter types must be any non-function SMT type";
103
104 return success();
105}
return success()
static void printDomainTypes(mlir::AsmPrinter &printer, llvm::ArrayRef< mlir::Type > types)
Definition SMTTypes.cpp:27
static mlir::ParseResult parseDomainTypes(mlir::AsmParser &parser, llvm::SmallVectorImpl< mlir::Type > &types)
Definition SMTTypes.cpp:20
This base class exposes generic asm parser hooks, usable across the various derived parsers.
@ Paren
Parens surrounding zero or more operands.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
virtual ParseResult parseType(Type &result)=0
Parse a type.
This base class exposes generic asm printer hooks, usable across the various derived printers.
This class represents a diagnostic that is inflight and set to be reported.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
bool isAnySMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type.
Definition SMTTypes.cpp:48
bool isAnyNonFuncSMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type (excluding functions).
Definition SMTTypes.cpp:44
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::function_ref< Fn > function_ref
Definition LLVM.h:147