Files
concrete/compiler/python/ZamalangModule.cpp
2021-08-04 14:14:37 +02:00

39 lines
1.3 KiB
C++

#include "DialectModules.h"
#include "CompilerAPIModule.h"
#include "mlir-c/Bindings/Python/Interop.h"
#include "mlir-c/Registration.h"
#include "mlir/Bindings/Python/PybindAdaptors.h"
#include "zamalang-c/Dialect/HLFHE.h"
#include "llvm-c/ErrorHandling.h"
#include "llvm/Support/Signals.h"
#include <pybind11/pybind11.h>
namespace py = pybind11;
PYBIND11_MODULE(_zamalang, m) {
m.doc() = "Zamalang Python Native Extension";
llvm::sys::PrintStackTraceOnErrorSignal(/*argv=*/"");
LLVMEnablePrettyStackTrace();
m.def(
"register_dialects",
[](py::object capsule) {
// Get the MlirContext capsule from PyMlirContext capsule.
auto wrappedCapsule = capsule.attr(MLIR_PYTHON_CAPI_PTR_ATTR);
MlirContext context = mlirPythonCapsuleToContext(wrappedCapsule.ptr());
// Collect Zamalang dialects to register.
MlirDialectHandle hlfhe = mlirGetDialectHandle__hlfhe__();
mlirDialectHandleRegisterDialect(hlfhe, context);
mlirDialectHandleLoadDialect(hlfhe, context);
},
"Register Zamalang dialects on a PyMlirContext.");
py::module hlfhe = m.def_submodule("_hlfhe", "HLFHE API");
zamalang::python::populateDialectHLFHESubmodule(hlfhe);
py::module api = m.def_submodule("_compiler", "Compiler API");
zamalang::python::populateCompilerAPISubmodule(api);
}