MLIR 24.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
12using namespace mlir;
13using namespace smt;
14using namespace mlir;
15
16static mlir::ParseResult
19 return parser.parseCommaSeparatedList(
21 [&]() { return parser.parseType(types.emplace_back()); });
22}
23
26 printer << '(';
27 llvm::interleaveComma(types, 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
42 return isAnySMTValueType(type) && !isa<SMTFuncType>(type);
43}
44
46 return isa<BoolType, BitVectorType, ArrayType, IntType, SortType,
47 SMTFuncType>(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(domainType))
69 return emitError() << "domain must be any SMT value type";
70 if (!isAnySMTValueType(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(domainTypes, isAnyNonFuncSMTValueType))
83 return emitError() << "domain types must be any non-function SMT type";
84 if (!isAnyNonFuncSMTValueType(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(sortParams, isAnyNonFuncSMTValueType))
98 return emitError()
99 << "sort parameter types must be any non-function SMT type";
100
101 return success();
102}
return success()
static void printDomainTypes(mlir::AsmPrinter &printer, llvm::ArrayRef< mlir::Type > types)
Definition SMTTypes.cpp:24
static mlir::ParseResult parseDomainTypes(mlir::AsmParser &parser, llvm::SmallVectorImpl< mlir::Type > &types)
Definition SMTTypes.cpp:17
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:45
bool isAnyNonFuncSMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type (excluding functions).
Definition SMTTypes.cpp:41
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:155