#include "CompilerAPIModule.h" #include "zamalang-c/Support/CompilerEngine.h" #include "zamalang/Dialect/HLFHE/IR/HLFHEOpsDialect.h.inc" #include "zamalang/Support/CompilerEngine.h" #include "zamalang/Support/ExecutionArgument.h" #include #include #include #include #include #include #include #include #include using mlir::zamalang::CompilerEngine; using mlir::zamalang::ExecutionArgument; /// Populate the compiler API python module. void mlir::zamalang::python::populateCompilerAPISubmodule(pybind11::module &m) { m.doc() = "Zamalang compiler python API"; m.def("round_trip", [](std::string mlir_input) { mlir::MLIRContext context; context.getOrLoadDialect(); context.getOrLoadDialect(); context.getOrLoadDialect(); auto module_ref = mlir::parseSourceString(mlir_input, &context); if (!module_ref) { throw std::logic_error("mlir parsing failed"); } std::string result; llvm::raw_string_ostream os(result); module_ref->print(os); return os.str(); }); pybind11::class_>( m, "ExecutionArgument") .def("create", pybind11::overload_cast(&ExecutionArgument::create)) .def("create", pybind11::overload_cast>( &ExecutionArgument::create)) .def("is_tensor", &ExecutionArgument::isTensor) .def("is_int", &ExecutionArgument::isInt); pybind11::class_(m, "CompilerEngine") .def(pybind11::init()) .def("run", [](CompilerEngine &engine, std::vector args) { // wrap and call CAPI compilerEngine e{&engine}; exectuionArguments a{args.data(), args.size()}; return compilerEngineRun(e, a); }) .def("compile_fhe", [](CompilerEngine &engine, std::string mlir_input) { // wrap and call CAPI compilerEngine e{&engine}; compilerEngineCompile(e, mlir_input.c_str()); }) .def("get_compiled_module", &CompilerEngine::getCompiledModule); }