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

source code of mlir/examples/standalone/python/StandaloneExtension.cpp