Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/include/runtime/instance/composite.h
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
//===-- wasmedge/runtime/instance/composite.h - Composite base definition -===//
5
//
6
// Part of the WasmEdge Project.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// This file contains the base class definition of composite instances
12
/// (function, struct, and array).
13
///
14
//===----------------------------------------------------------------------===//
15
#pragma once
16
17
#include "ast/type.h"
18
#include "common/types.h"
19
20
#include <vector>
21
22
namespace WasmEdge {
23
namespace Runtime {
24
namespace Instance {
25
26
class ModuleInstance;
27
28
class CompositeBase {
29
public:
30
  /// Constructor for only host function instance case.
31
0
  CompositeBase() noexcept : ModInst(nullptr), TypeIdx(0) {}
32
  /// Constructor for function, array, and struct instances.
33
  CompositeBase(const ModuleInstance *Mod, const uint32_t Idx) noexcept
34
0
      : ModInst(Mod), TypeIdx(Idx) {
35
0
    assuming(ModInst);
36
0
  }
37
38
  /// Getter of module instance of this instance.
39
0
  const ModuleInstance *getModule() const noexcept { return ModInst; }
40
41
  /// Getter of closed type index of this instance in the module.
42
0
  uint32_t getTypeIndex() const noexcept { return TypeIdx; }
43
44
  /// Getter of value type in defined type form.
45
0
  ValType getDefType() const noexcept {
46
0
    if (ModInst) {
47
0
      return ValType(TypeCode::Ref, TypeIdx);
48
0
    } else {
49
      // nullptr `ModInst` case is only for host function instance case.
50
0
      return ValType(TypeCode::Ref, TypeCode::FuncRef);
51
0
    }
52
0
  }
53
54
protected:
55
  friend class ModuleInstance;
56
  void linkDefinedType(const ModuleInstance *Mod,
57
0
                       const uint32_t Index) noexcept {
58
0
    assuming(Mod);
59
0
    ModInst = Mod;
60
0
    TypeIdx = Index;
61
0
  }
62
63
  /// \name Data of composite instances.
64
  /// @{
65
  const ModuleInstance *ModInst;
66
  uint32_t TypeIdx;
67
  /// @}
68
};
69
70
} // namespace Instance
71
} // namespace Runtime
72
} // namespace WasmEdge