MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / outputWasmLibrary

Function outputWasmLibrary

lib/llvm/codegen.cpp:305–506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303}
304
305Expect<void> outputWasmLibrary(LLVM::Context LLContext,
306 const std::filesystem::path &OutputPath,
307 Span<const Byte> Data,
308 const LLVM::MemoryBuffer &OSVec) noexcept {
309 std::filesystem::path SharedObjectName;
310 {
311 // tempfile
312 std::filesystem::path SOPath(OutputPath);
313 SOPath.replace_extension("%%%%%%%%%%" WASMEDGE_LIB_EXTENSION);
314 SharedObjectName = createTemp(SOPath);
315 if (SharedObjectName.empty()) {
316 // TODO:return error
317 spdlog::error("so file creation failed:{}"sv, SOPath.u8string());
318 return Unexpect(ErrCode::Value::IllegalPath);
319 }
320 std::ofstream OS(SharedObjectName, std::ios_base::binary);
321 OS.write(OSVec.data(), static_cast<std::streamsize>(OSVec.size()));
322 OS.close();
323 }
324
325 EXPECTED_TRY(outputNativeLibrary(SharedObjectName, OSVec));
326
327 LLVM::MemoryBuffer SOFile;
328 if (auto [Res, ErrorMessage] =
329 LLVM::MemoryBuffer::getFile(SharedObjectName.u8string().c_str());
330 unlikely(ErrorMessage)) {
331 spdlog::error("object file open error:{}"sv, ErrorMessage.string_view());
332 return Unexpect(ErrCode::Value::IllegalPath);
333 } else {
334 SOFile = std::move(Res);
335 }
336
337 LLVM::Binary ObjFile;
338 if (auto [Res, ErrorMessage] = LLVM::Binary::create(SOFile, LLContext);
339 unlikely(ErrorMessage)) {
340 spdlog::error("object file parse error:{}"sv, ErrorMessage.string_view());
341 return Unexpect(ErrCode::Value::IllegalPath);
342 } else {
343 ObjFile = std::move(Res);
344 }
345
346 std::string OSCustomSecVec;
347 {
348 std::ostringstream OS;
349 WriteName(OS, "wasmedge"sv);
350 WriteU32(OS, AOT::kBinaryVersion);
351
352#if WASMEDGE_OS_LINUX
353 WriteByte(OS, UINT8_C(1));
354#elif WASMEDGE_OS_MACOS
355 WriteByte(OS, UINT8_C(2));
356#elif WASMEDGE_OS_WINDOWS
357 WriteByte(OS, UINT8_C(3));
358#else
359#error Unsupported operating system!
360#endif
361
362#if defined(__x86_64__)

Callers 1

codegenMethod · 0.85

Calls 15

createTempFunction · 0.85
UnexpectFunction · 0.85
unlikelyFunction · 0.85
WriteNameFunction · 0.85
WriteU32Function · 0.85
WriteByteFunction · 0.85
WriteU64Function · 0.85
c_strMethod · 0.80
symbolsMethod · 0.80
isSymbolEndMethod · 0.80
strMethod · 0.80
resizeMethod · 0.80

Tested by

no test coverage detected