1392622d0SMaksim Levental //===- StandaloneExtensionPybind11.cpp - Extension module -----------------===// 2392622d0SMaksim Levental // 3392622d0SMaksim Levental // This is the pybind11 version of the example module. There is also a nanobind 4392622d0SMaksim Levental // example in StandaloneExtensionNanobind.cpp. 5392622d0SMaksim Levental // 6392622d0SMaksim Levental // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 7392622d0SMaksim Levental // See https://llvm.org/LICENSE.txt for license information. 8392622d0SMaksim Levental // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 9392622d0SMaksim Levental // 10392622d0SMaksim Levental //===----------------------------------------------------------------------===// 11392622d0SMaksim Levental 12392622d0SMaksim Levental #include "Standalone-c/Dialects.h" 13392622d0SMaksim Levental #include "mlir/Bindings/Python/PybindAdaptors.h" 14392622d0SMaksim Levental 15392622d0SMaksim Levental using namespace mlir::python::adaptors; 16392622d0SMaksim Levental 17*ce8c64fcSvfdev PYBIND11_MODULE(_standaloneDialectsPybind11, m) { 18392622d0SMaksim Levental //===--------------------------------------------------------------------===// 19392622d0SMaksim Levental // standalone dialect 20392622d0SMaksim Levental //===--------------------------------------------------------------------===// 21392622d0SMaksim Levental auto standaloneM = m.def_submodule("standalone"); 22392622d0SMaksim Levental 23392622d0SMaksim Levental standaloneM.def( 24392622d0SMaksim Levental "register_dialect", 25392622d0SMaksim Levental [](MlirContext context, bool load) { 26392622d0SMaksim Levental MlirDialectHandle handle = mlirGetDialectHandle__standalone__(); 27392622d0SMaksim Levental mlirDialectHandleRegisterDialect(handle, context); 28392622d0SMaksim Levental if (load) { 29392622d0SMaksim Levental mlirDialectHandleLoadDialect(handle, context); 30392622d0SMaksim Levental } 31392622d0SMaksim Levental }, 32392622d0SMaksim Levental py::arg("context") = py::none(), py::arg("load") = true); 33392622d0SMaksim Levental } 34