1111#include " mlir-c/Dialect/LLVM.h"
1212#include " mlir-c/IR.h"
1313#include " mlir-c/Support.h"
14+ #include " mlir-c/Target/LLVMIR.h"
1415#include " mlir/Bindings/Python/Diagnostics.h"
1516#include " mlir/Bindings/Python/Nanobind.h"
1617#include " mlir/Bindings/Python/NanobindAdaptors.h"
@@ -24,7 +25,7 @@ using namespace mlir;
2425using namespace mlir ::python;
2526using namespace mlir ::python::nanobind_adaptors;
2627
27- static void populateDialectLLVMSubmodule (const nanobind::module_ &m) {
28+ static void populateDialectLLVMSubmodule (nanobind::module_ &m) {
2829
2930 // ===--------------------------------------------------------------------===//
3031 // StructType
@@ -154,6 +155,19 @@ static void populateDialectLLVMSubmodule(const nanobind::module_ &m) {
154155 .def_property_readonly (" address_space" , [](MlirType type) {
155156 return mlirLLVMPointerTypeGetAddressSpace (type);
156157 });
158+
159+ m.def (
160+ " translate_module_to_llvmir" ,
161+ [](MlirOperation module ) {
162+ // LLVMContextRef llvmCtx = LLVMContextCreate();
163+ // LLVMModuleRef llvmModule = mlirTranslateModuleToLLVMIR(module, llvmCtx);
164+ // char *llvmir = LLVMPrintModuleToString(llvmModule);
165+ // LLVMDisposeModule(llvmModule);
166+ // LLVMContextDispose(llvmCtx);
167+ // return llvmir;
168+ return mlirTranslateModuleToLLVMIRToString (module );
169+ },
170+ " module" _a, nb::rv_policy::take_ownership);
157171}
158172
159173NB_MODULE (_mlirDialectsLLVM, m) {
0 commit comments