Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/lib/executor/instantiate/component.cpp
Line
Count
Source (jump to first uncovered line)
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2024 Second State INC
3
4
#include "ast/component/instance.h"
5
#include "ast/module.h"
6
#include "common/errcode.h"
7
#include "executor/executor.h"
8
9
#include "runtime/instance/module.h"
10
11
#include <string_view>
12
#include <variant>
13
14
using namespace std::literals;
15
16
namespace WasmEdge {
17
namespace Executor {
18
19
// Instantiate module instance. See "include/executor/Executor.h".
20
Expect<std::unique_ptr<Runtime::Instance::ComponentInstance>>
21
Executor::instantiate(Runtime::StoreManager &StoreMgr,
22
                      const AST::Component::Component &Comp,
23
0
                      std::optional<std::string_view> Name) {
24
0
  using namespace AST::Component;
25
26
0
  auto CompInst = std::make_unique<Runtime::Instance::ComponentInstance>(
27
0
      Name.value_or(""sv));
28
29
0
  for (auto &Section : Comp.getSections()) {
30
0
    auto Func = [&](auto &&Sec) -> Expect<void> {
31
0
      using T = std::decay_t<decltype(Sec)>;
32
0
      if constexpr (std::is_same_v<T, AST::CustomSection>) {
33
0
      } else if constexpr (std::is_same_v<T, CoreModuleSection>) {
34
0
        CompInst->addModule(Sec.getContent());
35
0
      } else if constexpr (std::is_same_v<T, ComponentSection>) {
36
0
        CompInst->addComponent(Sec.getContent());
37
0
      } else if constexpr (std::is_same_v<T, CoreInstanceSection>) {
38
0
        EXPECTED_TRY(instantiate(StoreMgr, *CompInst, Sec));
39
0
      } else if constexpr (std::is_same_v<T, InstanceSection>) {
40
0
        EXPECTED_TRY(instantiate(StoreMgr, *CompInst, Sec));
41
0
      } else if constexpr (std::is_same_v<T, ImportSection>) {
42
0
        EXPECTED_TRY(instantiate(StoreMgr, *CompInst, Sec));
43
0
      } else if constexpr (std::is_same_v<T, CoreTypeSection>) {
44
0
        EXPECTED_TRY(instantiate(StoreMgr, *CompInst, Sec));
45
0
      } else if constexpr (std::is_same_v<T, TypeSection>) {
46
0
        EXPECTED_TRY(instantiate(StoreMgr, *CompInst, Sec));
47
0
      } else if constexpr (std::is_same_v<T, StartSection>) {
48
0
        EXPECTED_TRY(instantiate(StoreMgr, *CompInst, Sec));
49
0
      } else if constexpr (std::is_same_v<T, CanonSection>) {
50
0
        EXPECTED_TRY(instantiate(StoreMgr, *CompInst, Sec));
51
0
      } else if constexpr (std::is_same_v<T, AliasSection>) {
52
0
        EXPECTED_TRY(instantiate(StoreMgr, *CompInst, Sec));
53
0
      } else if constexpr (std::is_same_v<T, ExportSection>) {
54
0
        EXPECTED_TRY(instantiate(StoreMgr, *CompInst, Sec));
55
0
      }
56
0
      return {};
57
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
58
0
    EXPECTED_TRY(std::visit(Func, Section));
59
0
  }
60
61
0
  StoreMgr.registerComponent(CompInst.get());
62
63
0
  return CompInst;
64
0
}
65
66
} // namespace Executor
67
} // namespace WasmEdge