
This is a companion to #118583, although it can be landed independently because since #117922 dialects do not have to use the same Python binding framework as the Python core code. This PR ports all of the in-tree dialect and pass extensions to nanobind, with the exception of those that remain for testing pybind11 support. This PR also: * removes CollectDiagnosticsToStringScope from NanobindAdaptors.h. This was overlooked in a previous PR and it is duplicated in Diagnostics.h. --------- Co-authored-by: Jacques Pienaar <jpienaar@google.com>
35 lines
1.3 KiB
C++
35 lines
1.3 KiB
C++
//===- StandaloneExtension.cpp - Extension module -------------------------===//
|
|
//
|
|
// This is the nanobind version of the example module. There is also a pybind11
|
|
// example in StandaloneExtensionPybind11.cpp.
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "Standalone-c/Dialects.h"
|
|
#include "mlir/Bindings/Python/Nanobind.h"
|
|
#include "mlir/Bindings/Python/NanobindAdaptors.h"
|
|
|
|
namespace nb = nanobind;
|
|
|
|
NB_MODULE(_standaloneDialectsNanobind, m) {
|
|
//===--------------------------------------------------------------------===//
|
|
// standalone dialect
|
|
//===--------------------------------------------------------------------===//
|
|
auto standaloneM = m.def_submodule("standalone");
|
|
|
|
standaloneM.def(
|
|
"register_dialect",
|
|
[](MlirContext context, bool load) {
|
|
MlirDialectHandle handle = mlirGetDialectHandle__standalone__();
|
|
mlirDialectHandleRegisterDialect(handle, context);
|
|
if (load) {
|
|
mlirDialectHandleLoadDialect(handle, context);
|
|
}
|
|
},
|
|
nb::arg("context").none() = nb::none(), nb::arg("load") = true);
|
|
}
|