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
35 return isAnySMTValueType(type) && !isa<SMTFuncType>(type);
36}
37
39 return isa<BoolType, BitVectorType, ArrayType, IntType, SortType,
40 SMTFuncType>(type);
41}
42
43//===----------------------------------------------------------------------===//
44// BitVectorType
45//===----------------------------------------------------------------------===//
46
47LogicalResult
48BitVectorType::verify(function_ref<InFlightDiagnostic()> emitError,
49 int64_t width) {
50 if (width <= 0U)
51 return emitError() << "bit-vector must have at least a width of one";
52 return success();
53}
54
55//===----------------------------------------------------------------------===//
56// ArrayType
57//===----------------------------------------------------------------------===//
58
59LogicalResult ArrayType::verify(function_ref<InFlightDiagnostic()> emitError,
60 Type domainType, Type rangeType) {
61 if (!isAnySMTValueType(domainType))
62 return emitError() << "domain must be any SMT value type";
63 if (!isAnySMTValueType(rangeType))
64 return emitError() << "range must be any SMT value type";
65
66 return success();
67}
68
69//===----------------------------------------------------------------------===//
70// SMTFuncType
71//===----------------------------------------------------------------------===//
72
73LogicalResult SMTFuncType::verify(function_ref<InFlightDiagnostic()> emitError,
74 ArrayRef<Type> domainTypes, Type rangeType) {
75 if (!llvm::all_of(domainTypes, isAnyNonFuncSMTValueType))
76 return emitError() << "domain types must be any non-function SMT type";
77 if (!isAnyNonFuncSMTValueType(rangeType))
78 return emitError() << "range type must be any non-function SMT type";
79
80 return success();
81}
82
83//===----------------------------------------------------------------------===//
84// SortType
85//===----------------------------------------------------------------------===//
86
87LogicalResult SortType::verify(function_ref<InFlightDiagnostic()> emitError,
88 StringAttr identifier,
89 ArrayRef<Type> sortParams) {
90 if (!llvm::all_of(sortParams, isAnyNonFuncSMTValueType))
91 return emitError()
92 << "sort parameter types must be any non-function SMT type";
93
94 return success();
95}
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:38
bool isAnyNonFuncSMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type (excluding functions).
Definition SMTTypes.cpp:34
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