[lldb] Use llvm::Error instead of CommandReturnObject for error reporting (#125125)
[llvm-project.git] / mlir / examples / standalone / python / StandaloneExtensionNanobind.cpp
blob189ebac368bf59efa6ba63bf0eba5da687c86e94
1 //===- StandaloneExtension.cpp - Extension module -------------------------===//
2 //
3 // This is the nanobind version of the example module. There is also a pybind11
4 // example in StandaloneExtensionPybind11.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 //===----------------------------------------------------------------------===//
12 #include "Standalone-c/Dialects.h"
13 #include "mlir/Bindings/Python/Nanobind.h"
14 #include "mlir/Bindings/Python/NanobindAdaptors.h"
16 namespace nb = nanobind;
18 NB_MODULE(_standaloneDialectsNanobind, m) {
19 //===--------------------------------------------------------------------===//
20 // standalone dialect
21 //===--------------------------------------------------------------------===//
22 auto standaloneM = m.def_submodule("standalone");
24 standaloneM.def(
25 "register_dialect",
26 [](MlirContext context, bool load) {
27 MlirDialectHandle handle = mlirGetDialectHandle__standalone__();
28 mlirDialectHandleRegisterDialect(handle, context);
29 if (load) {
30 mlirDialectHandleLoadDialect(handle, context);
33 nb::arg("context").none() = nb::none(), nb::arg("load") = true);