Index: mlir/examples/toy/Ch6/toyc.cpp =================================================================== --- mlir/examples/toy/Ch6/toyc.cpp +++ mlir/examples/toy/Ch6/toyc.cpp @@ -56,6 +56,10 @@ cl::values(clEnumValN(MLIR, "mlir", "load the input file as an MLIR file"))); +static cl::list sharedLibs( + "shared-lib", + cl::desc("Shared library to be loaded. Can be specified multiple times in case of multiple libraries")); + namespace { enum Action { None, @@ -239,6 +243,15 @@ // the module. mlir::ExecutionEngineOptions engineOptions; engineOptions.transformer = optPipeline; + + std::vector libs; + + for (const auto& sharedLib : sharedLibs) { + libs.emplace_back(sharedLib); + } + + engineOptions.sharedLibPaths = libs; + auto maybeEngine = mlir::ExecutionEngine::create(module, engineOptions); assert(maybeEngine && "failed to construct an execution engine"); auto &engine = maybeEngine.get(); Index: mlir/examples/toy/Ch7/toyc.cpp =================================================================== --- mlir/examples/toy/Ch7/toyc.cpp +++ mlir/examples/toy/Ch7/toyc.cpp @@ -82,6 +82,10 @@ static cl::opt enableOpt("opt", cl::desc("Enable optimizations")); +static cl::list sharedLibs( + "shared-lib", + cl::desc("Shared library to be loaded. Can be specified multiple times in case of multiple libraries")); + /// Returns a Toy AST resulting from parsing the file or a nullptr on error. std::unique_ptr parseInputFile(llvm::StringRef filename) { llvm::ErrorOr> fileOrErr = @@ -240,6 +244,15 @@ // the module. mlir::ExecutionEngineOptions engineOptions; engineOptions.transformer = optPipeline; + + std::vector libs; + + for (const auto& sharedLib : sharedLibs) { + libs.emplace_back(sharedLib); + } + + engineOptions.sharedLibPaths = libs; + auto maybeEngine = mlir::ExecutionEngine::create(module, engineOptions); assert(maybeEngine && "failed to construct an execution engine"); auto &engine = maybeEngine.get(); Index: mlir/test/Examples/Toy/Ch6/jit.toy =================================================================== --- mlir/test/Examples/Toy/Ch6/jit.toy +++ mlir/test/Examples/Toy/Ch6/jit.toy @@ -1,4 +1,4 @@ -# RUN: toyc-ch6 -emit=jit %s +# RUN: toyc-ch6 -emit=jit -shared-lib=%mlir_runner_utils_dir/libmlir_runner_utils%shlibext %s # UNSUPPORTED: windows def main() { Index: mlir/test/Examples/Toy/Ch7/jit.toy =================================================================== --- mlir/test/Examples/Toy/Ch7/jit.toy +++ mlir/test/Examples/Toy/Ch7/jit.toy @@ -1,4 +1,4 @@ -# RUN: toyc-ch7 -emit=jit %s +# RUN: toyc-ch7 -emit=jit -shared-lib=%mlir_runner_utils_dir/libmlir_runner_utils%shlibext %s # UNSUPPORTED: windows def main() {