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

Method loadFile

lib/plugin/plugin.cpp:397–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395Span<const Plugin> Plugin::plugins() noexcept { return PluginRegistry; }
396
397bool Plugin::loadFile(const std::filesystem::path &Path) noexcept {
398 std::unique_lock Lock(Mutex);
399 bool Result = false;
400 auto Lib = std::make_shared<Loader::SharedLibrary>();
401 if (auto Res = Lib->load(Path); unlikely(!Res)) {
402 return false;
403 }
404
405 if (auto GetDescriptor =
406 Lib->get<Plugin::PluginDescriptor const *()>("GetDescriptor")) {
407 Result = Plugin::registerPlugin(GetDescriptor());
408 }
409
410 if (!Result) {
411 // Check C interface
412 if (auto GetDescriptor = Lib->get<decltype(WasmEdge_Plugin_GetDescriptor)>(
413 "WasmEdge_Plugin_GetDescriptor");
414 unlikely(!GetDescriptor)) {
415 return false;
416 } else if (const auto *Descriptor = GetDescriptor();
417 unlikely(!Descriptor)) {
418 return false;
419 } else {
420 Result =
421 CAPIPluginRegisters
422 .emplace_back(std::make_unique<CAPIPluginRegister>(Descriptor))
423 ->result();
424 }
425 }
426
427 if (!Result) {
428 return false;
429 }
430
431 auto &Plugin = PluginRegistry.back();
432 Plugin.Path = Path;
433 Plugin.Lib = std::move(Lib);
434 return true;
435}
436
437void Plugin::registerBuiltInPlugins() noexcept {
438 std::unique_lock Lock(Mutex);

Callers 4

CompilerFunction · 0.45
compileMethod · 0.45
compileModuleFunction · 0.45

Calls 4

unlikelyFunction · 0.85
backMethod · 0.80
loadMethod · 0.45
resultMethod · 0.45

Tested by 2

compileMethod · 0.36
compileModuleFunction · 0.36