feat(compiler): Python bindings (#53)

- feat(compiler): python bindings
- build: update docker image for python bindings
- pin pybind11 to 2.6.2, 2.7 is not having correct include_dirs set (still
a question why?)
- using generated parser/printer
This commit is contained in:
Ayoub Benaissa
2021-07-28 15:58:51 +01:00
committed by GitHub
parent 812268000c
commit ab53ef71c6
20 changed files with 337 additions and 14 deletions

View File

@@ -0,0 +1,35 @@
#include "DialectModules.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);
}