Coverage Report

Created: 2025-09-27 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/lib/executor/instantiate/component/component.cpp
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2024 Second State INC
3
4
#include "executor/executor.h"
5
6
namespace WasmEdge {
7
namespace Executor {
8
9
// Instantiate component module instance. See "include/executor/Executor.h".
10
Expect<std::unique_ptr<Runtime::Instance::ComponentInstance>>
11
Executor::instantiate(Runtime::StoreManager &StoreMgr,
12
                      const AST::Component::Component &Comp,
13
0
                      std::optional<std::string_view> Name) {
14
0
  auto CompInst =
15
0
      std::make_unique<Runtime::Instance::ComponentInstance>(Name.value_or(""));
16
17
0
  for (const auto &Section : Comp.getSections()) {
18
0
    auto Func = [&](auto &&Sec) -> Expect<void> {
19
0
      using T = std::decay_t<decltype(Sec)>;
20
0
      if constexpr (std::is_same_v<T, AST::CustomSection>) {
21
        // Do nothing to custom section.
22
0
      } else if constexpr (std::is_same_v<T, AST::Component::ImportSection>) {
23
0
        EXPECTED_TRY(
24
0
            instantiate(StoreMgr, *CompInst, Sec).map_error([](auto E) {
25
0
              spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Component));
26
0
              return E;
27
0
            }));
28
0
      } else {
29
0
        EXPECTED_TRY(instantiate(*CompInst, Sec).map_error([](auto E) {
30
0
          spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Component));
31
0
          return E;
32
0
        }));
33
0
      }
34
0
      return {};
35
0
    };
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::CustomSection const&>(WasmEdge::AST::CustomSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::CoreModuleSection const&>(WasmEdge::AST::Component::CoreModuleSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::CoreInstanceSection const&>(WasmEdge::AST::Component::CoreInstanceSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::CoreTypeSection const&>(WasmEdge::AST::Component::CoreTypeSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::ComponentSection const&>(WasmEdge::AST::Component::ComponentSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::InstanceSection const&>(WasmEdge::AST::Component::InstanceSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::AliasSection const&>(WasmEdge::AST::Component::AliasSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::TypeSection const&>(WasmEdge::AST::Component::TypeSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::CanonSection const&>(WasmEdge::AST::Component::CanonSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::StartSection const&>(WasmEdge::AST::Component::StartSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::ImportSection const&>(WasmEdge::AST::Component::ImportSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Component::Component const&, std::__1::optional<std::__1::basic_string_view<char, std::__1::char_traits<char> > >)::$_0::operator()<WasmEdge::AST::Component::ExportSection const&>(WasmEdge::AST::Component::ExportSection const&) const
36
0
    EXPECTED_TRY(std::visit(Func, Section));
37
0
  }
38
39
0
  if (Name.has_value()) {
40
0
    StoreMgr.registerComponent(CompInst.get());
41
0
  }
42
0
  return CompInst;
43
0
}
44
45
// Instantiate component module instance. See "include/executor/Executor.h".
46
Expect<std::unique_ptr<Runtime::Instance::ComponentInstance>>
47
Executor::instantiate(Runtime::Instance::ComponentImportManager &ImportMgr,
48
0
                      const AST::Component::Component &Comp) {
49
0
  auto CompInst = std::make_unique<Runtime::Instance::ComponentInstance>("");
50
51
0
  for (const auto &Section : Comp.getSections()) {
52
0
    auto Func = [&](auto &&Sec) -> Expect<void> {
53
0
      using T = std::decay_t<decltype(Sec)>;
54
0
      if constexpr (std::is_same_v<T, AST::CustomSection>) {
55
        // Do nothing to custom section.
56
0
      } else if constexpr (std::is_same_v<T, AST::Component::ImportSection>) {
57
0
        EXPECTED_TRY(
58
0
            instantiate(ImportMgr, *CompInst, Sec).map_error([](auto E) {
59
0
              spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Component));
60
0
              return E;
61
0
            }));
62
0
      } else {
63
0
        EXPECTED_TRY(instantiate(*CompInst, Sec).map_error([](auto E) {
64
0
          spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Component));
65
0
          return E;
66
0
        }));
67
0
      }
68
0
      return {};
69
0
    };
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::CustomSection const&>(WasmEdge::AST::CustomSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::CoreModuleSection const&>(WasmEdge::AST::Component::CoreModuleSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::CoreInstanceSection const&>(WasmEdge::AST::Component::CoreInstanceSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::CoreTypeSection const&>(WasmEdge::AST::Component::CoreTypeSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::ComponentSection const&>(WasmEdge::AST::Component::ComponentSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::InstanceSection const&>(WasmEdge::AST::Component::InstanceSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::AliasSection const&>(WasmEdge::AST::Component::AliasSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::TypeSection const&>(WasmEdge::AST::Component::TypeSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::CanonSection const&>(WasmEdge::AST::Component::CanonSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::StartSection const&>(WasmEdge::AST::Component::StartSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::ImportSection const&>(WasmEdge::AST::Component::ImportSection const&) const
Unexecuted instantiation: component.cpp:cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::instantiate(WasmEdge::Runtime::Instance::ComponentImportManager&, WasmEdge::AST::Component::Component const&)::$_0::operator()<WasmEdge::AST::Component::ExportSection const&>(WasmEdge::AST::Component::ExportSection const&) const
70
0
    EXPECTED_TRY(std::visit(Func, Section));
71
0
  }
72
0
  return CompInst;
73
0
}
74
75
// Instantiate component section. See "include/executor/Executor.h".
76
Expect<void>
77
Executor::instantiate(Runtime::Instance::ComponentInstance &CompInst,
78
0
                      const AST::Component::ComponentSection &CompSec) {
79
0
  CompInst.addComponent(CompSec.getContent());
80
0
  return {};
81
0
}
82
83
} // namespace Executor
84
} // namespace WasmEdge