xref: /llvm-project/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp (revision ce8c64fc8e067608be0dd44ca5399f85bab9e20d)
1 //===- StandaloneExtensionPybind11.cpp - Extension module -----------------===//
2 //
3 // This is the pybind11 version of the example module. There is also a nanobind
4 // example in StandaloneExtensionNanobind.cpp.
5 //
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 // See https://llvm.org/LICENSE.txt for license information.
8 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //
10 //===----------------------------------------------------------------------===//
11 
12 #include "Standalone-c/Dialects.h"
13 #include "mlir/Bindings/Python/PybindAdaptors.h"
14 
15 using namespace mlir::python::adaptors;
16 
17 PYBIND11_MODULE(_standaloneDialectsPybind11, m) {
18   //===--------------------------------------------------------------------===//
19   // standalone dialect
20   //===--------------------------------------------------------------------===//
21   auto standaloneM = m.def_submodule("standalone");
22 
23   standaloneM.def(
24       "register_dialect",
25       [](MlirContext context, bool load) {
26         MlirDialectHandle handle = mlirGetDialectHandle__standalone__();
27         mlirDialectHandleRegisterDialect(handle, context);
28         if (load) {
29           mlirDialectHandleLoadDialect(handle, context);
30         }
31       },
32       py::arg("context") = py::none(), py::arg("load") = true);
33 }
34