Skip to content

Commit f80a9c8

Browse files
committed
fix mac windows python shared library loading
1 parent 7497111 commit f80a9c8

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

lib/conversions/src/RLCToPython.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace mlir::rlc
103103
std::map<const void*, mlir::rlc::FunctionOp> dropFunction;
104104
std::map<const void*, mlir::rlc::FunctionOp> assignFunction;
105105
};
106-
static void printPrelude(StreamWriter& writer)
106+
static void printPrelude(StreamWriter& writer, bool isMac, bool isWindows)
107107
{
108108
writer.writenl("import ctypes");
109109
writer.writenl("import os");
@@ -112,9 +112,16 @@ namespace mlir::rlc
112112
writer.writenl("import builtins");
113113
writer.writenl("from collections import defaultdict");
114114

115+
std::string libName = "lib.so";
116+
if (isMac)
117+
libName = "lib.dylib";
118+
if (isWindows)
119+
libName = "lib.dll";
115120
writer.writenl(
116121
"lib = ctypes.CDLL(os.path.join(Path(__file__).resolve().parent, "
117-
"\"lib.so\"))");
122+
"\"",
123+
libName,
124+
"\"))");
118125
writer.writenl("actions = defaultdict(list)");
119126
writer.writenl("wrappers = defaultdict(list)");
120127
writer.writenl("signatures = {}");
@@ -854,12 +861,11 @@ namespace mlir::rlc
854861
OS.endLine();
855862
}
856863

857-
#define GEN_PASS_DEF_NEOPRINTPYTHONPASS
864+
#define GEN_PASS_DEF_PRINTPYTHONPASS
858865
#include "rlc/dialect/Passes.inc"
859-
struct NeoPrintPythonPass: impl::NeoPrintPythonPassBase<NeoPrintPythonPass>
866+
struct PrintPythonPass: impl::PrintPythonPassBase<PrintPythonPass>
860867
{
861-
using impl::NeoPrintPythonPassBase<
862-
NeoPrintPythonPass>::NeoPrintPythonPassBase;
868+
using impl::PrintPythonPassBase<PrintPythonPass>::PrintPythonPassBase;
863869

864870
void runOnOperation() override
865871
{
@@ -878,7 +884,7 @@ namespace mlir::rlc
878884
matcher.add<AliasToPythonAlias>();
879885

880886
// emit includes
881-
printPrelude(matcher.getWriter());
887+
printPrelude(matcher.getWriter(), isMac, isWindows);
882888

883889
// emit declarations of types
884890
for (auto t : ::rlc::postOrderTypes(getOperation()))

lib/dialect/src/Passes.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ def SerializeRLPass : Pass<"rlc-serialize-ir-pass", "mlir::ModuleOp"> {
181181
let dependentDialects = ["rlc::RLCDialect"];
182182
}
183183

184-
def NeoPrintPythonPass : Pass<"rlc-new-python-pass", "mlir::ModuleOp"> {
184+
def PrintPythonPass : Pass<"rlc-python-pass", "mlir::ModuleOp"> {
185185
let summary = "prints the python header on the provided stream";
186186
let options = [
187187
Option<"OS", "output stream", "llvm::raw_ostream*", /*default=*/"nullptr",
188-
"stream on which to print the module">
188+
"stream on which to print the module">,
189+
Option<"isMac", "true if target platform is mac", "bool", /*default=*/"false",
190+
"true if target platform is mac">,
191+
Option<"isWindows", "true if target platform is windows", "bool", /*default=*/"false",
192+
"true if target platform is windows">,
189193
];
190194
let dependentDialects = ["rlc::RLCDialect"];
191195
}

lib/driver/src/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ namespace mlir::rlc
107107
if (request == Request::dumpPythonWrapper)
108108
{
109109
manager.addPass(mlir::rlc::createSortTypeDeclarationsPass());
110-
manager.addPass(mlir::rlc::createNeoPrintPythonPass({ OS }));
110+
manager.addPass(mlir::rlc::createPrintPythonPass(
111+
{ OS, targetInfo->isMacOS(), targetInfo->isWindows() }));
111112
return;
112113
}
113114

0 commit comments

Comments
 (0)