Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/lib/executor/instantiate/export.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 "executor/executor.h"
5
6
#include <cstdint>
7
#include <string_view>
8
9
namespace WasmEdge {
10
namespace Executor {
11
12
// Instantiate exports. See "include/executor/executor.h".
13
Expect<void> Executor::instantiate(Runtime::Instance::ModuleInstance &ModInst,
14
0
                                   const AST::ExportSection &ExportSec) {
15
  // Iterate through the export descriptions and instantiate the exports.
16
0
  for (const auto &ExpDesc : ExportSec.getContent()) {
17
    // Get data from the export description.
18
0
    const auto ExtType = ExpDesc.getExternalType();
19
0
    std::string_view ExtName = ExpDesc.getExternalName();
20
0
    const uint32_t ExtIdx = ExpDesc.getExternalIndex();
21
22
    // Export the instance with the name.
23
0
    switch (ExtType) {
24
0
    case ExternalType::Function:
25
0
      ModInst.exportFunction(ExtName, ExtIdx);
26
0
      break;
27
0
    case ExternalType::Global:
28
0
      ModInst.exportGlobal(ExtName, ExtIdx);
29
0
      break;
30
0
    case ExternalType::Memory:
31
0
      ModInst.exportMemory(ExtName, ExtIdx);
32
0
      break;
33
0
    case ExternalType::Table:
34
0
      ModInst.exportTable(ExtName, ExtIdx);
35
0
      break;
36
0
    case ExternalType::Tag:
37
0
      ModInst.exportTag(ExtName, ExtIdx);
38
0
      break;
39
0
    default:
40
0
      break;
41
0
    }
42
0
  }
43
0
  return {};
44
0
}
45
46
} // namespace Executor
47
} // namespace WasmEdge