39 lines · cpp
1//===- StandaloneExtensionPybind11.cpp - Extension module -----------------===//2//3// This is the pybind11 version of the example module. There is also a nanobind4// 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-exception9//10//===----------------------------------------------------------------------===//11 12#include "Standalone-c/Dialects.h"13#include "mlir-c/Dialect/Arith.h"14#include "mlir/Bindings/Python/PybindAdaptors.h"15 16using namespace mlir::python::adaptors;17 18PYBIND11_MODULE(_standaloneDialectsPybind11, m) {19 //===--------------------------------------------------------------------===//20 // standalone dialect21 //===--------------------------------------------------------------------===//22 auto standaloneM = m.def_submodule("standalone");23 24 standaloneM.def(25 "register_dialects",26 [](MlirContext context, bool load) {27 MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__();28 MlirDialectHandle standaloneHandle =29 mlirGetDialectHandle__standalone__();30 mlirDialectHandleRegisterDialect(arithHandle, context);31 mlirDialectHandleRegisterDialect(standaloneHandle, context);32 if (load) {33 mlirDialectHandleLoadDialect(arithHandle, context);34 mlirDialectHandleRegisterDialect(standaloneHandle, context);35 }36 },37 py::arg("context") = py::none(), py::arg("load") = true);38}39