MLIR 22.0.0git
DialectSMT.cpp
Go to the documentation of this file.
1//===- DialectSMT.cpp - Pybind module for SMT dialect API support ---------===//
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 "NanobindUtils.h"
10
11#include "mlir-c/Dialect/SMT.h"
12#include "mlir-c/IR.h"
13#include "mlir-c/Support.h"
18
19namespace nb = nanobind;
20
21using namespace nanobind::literals;
22
23using namespace mlir;
24using namespace mlir::python;
26
27static void populateDialectSMTSubmodule(nanobind::module_ &m) {
28
29 auto smtBoolType =
32 "get",
33 [](MlirContext context) { return mlirSMTTypeGetBool(context); },
34 "context"_a = nb::none());
35 auto smtBitVectorType =
38 "get",
39 [](int32_t width, MlirContext context) {
40 return mlirSMTTypeGetBitVector(context, width);
41 },
42 "width"_a, "context"_a = nb::none());
43 auto smtIntType =
46 "get",
47 [](MlirContext context) { return mlirSMTTypeGetInt(context); },
48 "context"_a = nb::none());
49
50 auto exportSMTLIB = [](MlirOperation module, bool inlineSingleUseValues,
51 bool indentLetBody) {
54 PyPrintAccumulator printAccum;
56 module, printAccum.getCallback(), printAccum.getUserData(),
57 inlineSingleUseValues, indentLetBody);
59 return printAccum.join();
60 throw nb::value_error(
61 ("Failed to export smtlib.\nDiagnostic message " + scope.takeMessage())
62 .c_str());
63 };
64
65 m.def(
66 "export_smtlib",
67 [&exportSMTLIB](MlirOperation module, bool inlineSingleUseValues,
68 bool indentLetBody) {
69 return exportSMTLIB(module, inlineSingleUseValues, indentLetBody);
70 },
71 "module"_a, "inline_single_use_values"_a = false,
72 "indent_let_body"_a = false);
73 m.def(
74 "export_smtlib",
75 [&exportSMTLIB](MlirModule module, bool inlineSingleUseValues,
76 bool indentLetBody) {
77 return exportSMTLIB(mlirModuleGetOperation(module),
78 inlineSingleUseValues, indentLetBody);
79 },
80 "module"_a, "inline_single_use_values"_a = false,
81 "indent_let_body"_a = false);
82}
83
84NB_MODULE(_mlirDialectsSMT, m) {
85 m.doc() = "MLIR SMT Dialect";
86
88}
static void populateDialectSMTSubmodule(nanobind::module_ &m)
NB_MODULE(_mlirDialectsSMT, m)
MlirOperation mlirModuleGetOperation(MlirModule module)
Definition IR.cpp:460
MlirContext mlirOperationGetContext(MlirOperation op)
Definition IR.cpp:651
MLIR_CAPI_EXPORTED MlirType mlirSMTTypeGetBitVector(MlirContext ctx, int32_t width)
Creates a smt::BitVectorType with the given width.
Definition SMT.cpp:48
MLIR_CAPI_EXPORTED MlirType mlirSMTTypeGetInt(MlirContext ctx)
Creates a smt::IntType.
Definition SMT.cpp:60
MLIR_CAPI_EXPORTED bool mlirSMTTypeIsABool(MlirType type)
Checks if the given type is a smt::BoolType.
Definition SMT.cpp:52
MLIR_CAPI_EXPORTED bool mlirSMTTypeIsAInt(MlirType type)
Checks if the given type is a smt::IntType.
Definition SMT.cpp:58
MLIR_CAPI_EXPORTED MlirType mlirSMTTypeGetBool(MlirContext ctx)
Creates a smt::BoolType.
Definition SMT.cpp:54
MLIR_CAPI_EXPORTED bool mlirSMTTypeIsABitVector(MlirType type)
Checks if the given type is a smt::BitVectorType.
Definition SMT.cpp:44
RAII scope intercepting all diagnostics into a string.
Definition Diagnostics.h:25
Creates a custom subclass of mlir.ir.Type, implementing a casting constructor and type checking metho...
pure_subclass & def_staticmethod(const char *name, Func &&f, const Extra &...extra)
static bool mlirLogicalResultIsSuccess(MlirLogicalResult res)
Checks if the given logical result represents a success.
Definition Support.h:122
MLIR_CAPI_EXPORTED MlirLogicalResult mlirTranslateOperationToSMTLIB(MlirOperation, MlirStringCallback, void *userData, bool inlineSingleUseValues, bool indentLetBody)
Include the generated interface declarations.
A logical result value, essentially a boolean with named states.
Definition Support.h:116
Accumulates into a python string from a method that accepts an MlirStringCallback.
MlirStringCallback getCallback()