Coverage Report

Created: 2026-06-30 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/include/ast/module.h
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright The WasmEdge Authors
3
4
//===-- wasmedge/ast/module.h - Module class definition -------------------===//
5
//
6
// Part of the WasmEdge Project.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// This file contains the declaration of the Module node class, which is the
12
/// module node in the AST.
13
///
14
//===----------------------------------------------------------------------===//
15
#pragma once
16
17
#include "ast/section.h"
18
19
#include <vector>
20
21
namespace WasmEdge {
22
namespace AST {
23
24
/// AST Module node.
25
class Module {
26
public:
27
  /// Getter for magic vector.
28
0
  const std::vector<Byte> &getMagic() const noexcept { return Magic; }
29
9.37k
  std::vector<Byte> &getMagic() noexcept { return Magic; }
30
31
  /// Getter for version vector.
32
0
  const std::vector<Byte> &getVersion() const noexcept { return Version; }
33
9.37k
  std::vector<Byte> &getVersion() noexcept { return Version; }
34
35
  /// Getters of references to sections.
36
0
  Span<const CustomSection> getCustomSections() const noexcept {
37
0
    return CustomSecs;
38
0
  }
39
102k
  std::vector<CustomSection> &getCustomSections() noexcept {
40
102k
    return CustomSecs;
41
102k
  }
42
6.60k
  const TypeSection &getTypeSection() const { return TypeSec; }
43
9.31k
  TypeSection &getTypeSection() { return TypeSec; }
44
6.54k
  const ImportSection &getImportSection() const { return ImportSec; }
45
4.65k
  ImportSection &getImportSection() { return ImportSec; }
46
6.52k
  const FunctionSection &getFunctionSection() const { return FunctionSec; }
47
8.89k
  FunctionSection &getFunctionSection() { return FunctionSec; }
48
6.51k
  const TableSection &getTableSection() const { return TableSec; }
49
539
  TableSection &getTableSection() { return TableSec; }
50
6.48k
  const MemorySection &getMemorySection() const { return MemorySec; }
51
1.49k
  MemorySection &getMemorySection() { return MemorySec; }
52
6.45k
  const GlobalSection &getGlobalSection() const { return GlobalSec; }
53
614
  GlobalSection &getGlobalSection() { return GlobalSec; }
54
6.32k
  const ExportSection &getExportSection() const { return ExportSec; }
55
1.04k
  ExportSection &getExportSection() { return ExportSec; }
56
3.97k
  const StartSection &getStartSection() const { return StartSec; }
57
49
  StartSection &getStartSection() { return StartSec; }
58
6.27k
  const ElementSection &getElementSection() const { return ElementSec; }
59
1.32k
  ElementSection &getElementSection() { return ElementSec; }
60
6.20k
  const CodeSection &getCodeSection() const { return CodeSec; }
61
9.06k
  CodeSection &getCodeSection() { return CodeSec; }
62
6.22k
  const DataSection &getDataSection() const { return DataSec; }
63
1.58k
  DataSection &getDataSection() { return DataSec; }
64
0
  const DataCountSection &getDataCountSection() const { return DataCountSec; }
65
4.46k
  DataCountSection &getDataCountSection() { return DataCountSec; }
66
4.04k
  const TagSection &getTagSection() const { return TagSec; }
67
4.39k
  TagSection &getTagSection() { return TagSec; }
68
0
  const AOTSection &getAOTSection() const { return AOTSec; }
69
0
  AOTSection &getAOTSection() { return AOTSec; }
70
71
  /// Get the number of imported functions.
72
0
  uint32_t getImportFuncCount() const noexcept {
73
0
    uint32_t Count = 0;
74
0
    for (const auto &ImpDesc : ImportSec.getContent()) {
75
0
      if (ImpDesc.getExternalType() == ExternalType::Function) {
76
0
        ++Count;
77
0
      }
78
0
    }
79
0
    return Count;
80
0
  }
81
82
  /// Get the number of defined (non-imported) functions.
83
2.30k
  uint32_t getDefinedFuncCount() const noexcept {
84
2.30k
    return static_cast<uint32_t>(CodeSec.getContent().size());
85
2.30k
  }
86
87
  /// Getter and setter for compiled symbol.
88
0
  const auto &getSymbol() const noexcept { return IntrSymbol; }
89
0
  void setSymbol(Symbol<const Executable::IntrinsicsTable *> S) noexcept {
90
0
    IntrSymbol = std::move(S);
91
0
  }
92
93
  /// Getter and setter for validated flag.
94
2.30k
  bool getIsValidated() const noexcept { return IsValidated; }
95
2.30k
  void setIsValidated(bool V = true) noexcept { IsValidated = V; }
96
97
private:
98
  /// \name Data of Module node.
99
  /// @{
100
  std::vector<Byte> Magic;
101
  std::vector<Byte> Version;
102
  /// @}
103
104
  /// \name Section nodes of Module node.
105
  /// @{
106
  std::vector<CustomSection> CustomSecs;
107
  TypeSection TypeSec;
108
  ImportSection ImportSec;
109
  FunctionSection FunctionSec;
110
  TableSection TableSec;
111
  MemorySection MemorySec;
112
  GlobalSection GlobalSec;
113
  ExportSection ExportSec;
114
  StartSection StartSec;
115
  ElementSection ElementSec;
116
  CodeSection CodeSec;
117
  DataSection DataSec;
118
  DataCountSection DataCountSec;
119
  TagSection TagSec;
120
  /// @}
121
122
  /// \name Data of AOT.
123
  /// @{
124
  AOTSection AOTSec;
125
  Symbol<const Executable::IntrinsicsTable *> IntrSymbol;
126
  /// @}
127
128
  /// \name Validated flag.
129
  /// @{
130
  bool IsValidated = false;
131
  /// @}
132
};
133
134
} // namespace AST
135
} // namespace WasmEdge