| 64 | } |
| 65 | |
| 66 | Expect<std::shared_ptr<Executable>> JIT::load(Data D) noexcept { |
| 67 | OrcLLJIT J; |
| 68 | if (auto Res = OrcLLJIT::create(); !Res) { |
| 69 | spdlog::error("{}"sv, Res.error().message().string_view()); |
| 70 | return Unexpect(ErrCode::Value::HostFuncError); |
| 71 | } else { |
| 72 | J = std::move(*Res); |
| 73 | } |
| 74 | |
| 75 | auto &LLModule = D.extract().LLModule; |
| 76 | auto TSContext = D.extract().getTSContext(); |
| 77 | |
| 78 | if (Conf.getCompilerConfigure().isDumpIR()) { |
| 79 | if (auto ErrorMessage = LLModule.printModuleToFile("wasm-jit.ll")) { |
| 80 | spdlog::error("printModuleToFile failed"sv); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | auto MainJD = J.getMainJITDylib(); |
| 85 | if (auto Err = J.addLLVMIRModule( |
| 86 | MainJD, OrcThreadSafeModule(LLModule.release(), TSContext))) { |
| 87 | spdlog::error("{}"sv, Err.message().string_view()); |
| 88 | return Unexpect(ErrCode::Value::HostFuncError); |
| 89 | } |
| 90 | |
| 91 | return std::make_shared<JITLibrary>(std::move(J)); |
| 92 | } |
| 93 | } // namespace WasmEdge::LLVM |