Coverage Report

Created: 2026-09-28 06:22

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: Copyright The WasmEdge Authors
3
4
#include "executor/executor.h"
5
6
#include "common/spdlog.h"
7
8
#include <string_view>
9
10
namespace WasmEdge {
11
namespace Executor {
12
13
using namespace std::literals;
14
15
// Instantiate component module instance. See "include/executor/Executor.h".
16
Expect<std::unique_ptr<Runtime::Instance::ComponentInstance>>
17
Executor::instantiate(Runtime::StoreManager &StoreMgr,
18
                      const AST::Component::Component &Comp,
19
0
                      std::optional<std::string_view> Name) {
20
0
  auto CompInst =
21
0
      std::make_unique<Runtime::Instance::ComponentInstance>(Name.value_or(""));
22
23
0
  for (const auto &Section : Comp.getSections()) {
24
0
    auto Func = [&](auto &&Sec) -> Expect<void> {
25
0
      using T = std::decay_t<decltype(Sec)>;
26
0
      if constexpr (std::is_same_v<T, AST::CustomSection>) {
27
        // Do nothing to custom section.
28
0
      } else if constexpr (std::is_same_v<T, AST::Component::ValueSection>) {
29
        // TODO: COMPONENT - instantiate component value section.
30
0
        spdlog::warn("component value section is not yet supported during "
31
0
                     "instantiation; its values will be ignored."sv);
32
0
      } else if constexpr (std::is_same_v<T, AST::Component::ImportSection>) {
33
0
        EXPECTED_TRY(
34
0
            instantiate(StoreMgr, *CompInst, Sec).map_error([](auto E) {
35
0
              spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Component));
36
0
              return E;
37
0
            }));
38
0
      } else {
39
0
        EXPECTED_TRY(instantiate(*CompInst, Sec).map_error([](auto E) {
40
0
          spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Component));
41
0
          return E;
42
0
        }));
43
0
      }
44
0
      return {};
45
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
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::ValueSection const&>(WasmEdge::AST::Component::ValueSection const&) const
46
0
    EXPECTED_TRY(std::visit(Func, Section));
47
0
  }
48
49
0
  if (Name.has_value()) {
50
0
    StoreMgr.registerComponent(CompInst.get());
51
0
  }
52
0
  return CompInst;
53
0
}
54
55
// Instantiate component module instance. See "include/executor/Executor.h".
56
Expect<std::unique_ptr<Runtime::Instance::ComponentInstance>>
57
Executor::instantiate(Runtime::Instance::ComponentImportManager &ImportMgr,
58
0
                      const AST::Component::Component &Comp) {
59
0
  auto CompInst = std::make_unique<Runtime::Instance::ComponentInstance>("");
60
61
0
  for (const auto &Section : Comp.getSections()) {
62
0
    auto Func = [&](auto &&Sec) -> Expect<void> {
63
0
      using T = std::decay_t<decltype(Sec)>;
64
0
      if constexpr (std::is_same_v<T, AST::CustomSection>) {
65
        // Do nothing to custom section.
66
0
      } else if constexpr (std::is_same_v<T, AST::Component::ValueSection>) {
67
        // TODO: COMPONENT - instantiate component value section.
68
0
        spdlog::warn("component value section is not yet supported during "
69
0
                     "instantiation; its values will be ignored."sv);
70
0
      } else if constexpr (std::is_same_v<T, AST::Component::ImportSection>) {
71
0
        EXPECTED_TRY(
72
0
            instantiate(ImportMgr, *CompInst, Sec).map_error([](auto E) {
73
0
              spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Component));
74
0
              return E;
75
0
            }));
76
0
      } else {
77
0
        EXPECTED_TRY(instantiate(*CompInst, Sec).map_error([](auto E) {
78
0
          spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Component));
79
0
          return E;
80
0
        }));
81
0
      }
82
0
      return {};
83
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
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::ValueSection const&>(WasmEdge::AST::Component::ValueSection const&) const
84
0
    EXPECTED_TRY(std::visit(Func, Section));
85
0
  }
86
0
  return CompInst;
87
0
}
88
89
// Instantiate component section. See "include/executor/Executor.h".
90
Expect<void>
91
Executor::instantiate(Runtime::Instance::ComponentInstance &CompInst,
92
0
                      const AST::Component::ComponentSection &CompSec) {
93
0
  CompInst.addComponent(CompSec.getContent());
94
0
  return {};
95
0
}
96
97
} // namespace Executor
98
} // namespace WasmEdge