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 
12 namespace py = pybind11;
13 using namespace mlir::python::adaptors;
14 
PYBIND11_MODULE(_standaloneDialects,m)15 PYBIND11_MODULE(_standaloneDialects, m) {
16   //===--------------------------------------------------------------------===//
17   // standalone dialect
18   //===--------------------------------------------------------------------===//
19   auto standalone_m = m.def_submodule("standalone");
20 
21   standalone_m.def(
22       "register_dialect",
23       [](MlirContext context, bool load) {
24         MlirDialectHandle handle = mlirGetDialectHandle__standalone__();
25         mlirDialectHandleRegisterDialect(handle, context);
26         if (load) {
27           mlirDialectHandleLoadDialect(handle, context);
28         }
29       },
30       py::arg("context") = py::none(), py::arg("load") = true);
31 }
32