114c92070SAlex Zinenko //===- PythonTestModule.cpp - Python extension for the PythonTest dialect -===//
214c92070SAlex Zinenko //
314c92070SAlex Zinenko // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
414c92070SAlex Zinenko // See https://llvm.org/LICENSE.txt for license information.
514c92070SAlex Zinenko // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
614c92070SAlex Zinenko //
714c92070SAlex Zinenko //===----------------------------------------------------------------------===//
814c92070SAlex Zinenko 
914c92070SAlex Zinenko #include "PythonTestCAPI.h"
1014c92070SAlex Zinenko #include "mlir/Bindings/Python/PybindAdaptors.h"
1114c92070SAlex Zinenko 
1214c92070SAlex Zinenko namespace py = pybind11;
13*89a92fb3SAlex Zinenko using namespace mlir::python::adaptors;
1414c92070SAlex Zinenko 
PYBIND11_MODULE(_mlirPythonTest,m)1514c92070SAlex Zinenko PYBIND11_MODULE(_mlirPythonTest, m) {
1614c92070SAlex Zinenko   m.def(
1714c92070SAlex Zinenko       "register_python_test_dialect",
1814c92070SAlex Zinenko       [](MlirContext context, bool load) {
1914c92070SAlex Zinenko         MlirDialectHandle pythonTestDialect =
2014c92070SAlex Zinenko             mlirGetDialectHandle__python_test__();
2114c92070SAlex Zinenko         mlirDialectHandleRegisterDialect(pythonTestDialect, context);
2214c92070SAlex Zinenko         if (load) {
2314c92070SAlex Zinenko           mlirDialectHandleLoadDialect(pythonTestDialect, context);
2414c92070SAlex Zinenko         }
2514c92070SAlex Zinenko       },
2614c92070SAlex Zinenko       py::arg("context"), py::arg("load") = true);
27*89a92fb3SAlex Zinenko 
28*89a92fb3SAlex Zinenko   mlir_attribute_subclass(m, "TestAttr",
29*89a92fb3SAlex Zinenko                           mlirAttributeIsAPythonTestTestAttribute)
30*89a92fb3SAlex Zinenko       .def_classmethod(
31*89a92fb3SAlex Zinenko           "get",
32*89a92fb3SAlex Zinenko           [](py::object cls, MlirContext ctx) {
33*89a92fb3SAlex Zinenko             return cls(mlirPythonTestTestAttributeGet(ctx));
34*89a92fb3SAlex Zinenko           },
35*89a92fb3SAlex Zinenko           py::arg("cls"), py::arg("context") = py::none());
36*89a92fb3SAlex Zinenko   mlir_type_subclass(m, "TestType", mlirTypeIsAPythonTestTestType)
37*89a92fb3SAlex Zinenko       .def_classmethod(
38*89a92fb3SAlex Zinenko           "get",
39*89a92fb3SAlex Zinenko           [](py::object cls, MlirContext ctx) {
40*89a92fb3SAlex Zinenko             return cls(mlirPythonTestTestTypeGet(ctx));
41*89a92fb3SAlex Zinenko           },
42*89a92fb3SAlex Zinenko           py::arg("cls"), py::arg("context") = py::none());
4314c92070SAlex Zinenko }
44