/src/WasmEdge/include/runtime/instance/global.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright The WasmEdge Authors |
3 | | |
4 | | //===-- wasmedge/runtime/instance/global.h - Global Instance definition ---===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the global instance definition in store manager. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | |
16 | | #include "ast/type.h" |
17 | | |
18 | | namespace WasmEdge { |
19 | | namespace Runtime { |
20 | | namespace Instance { |
21 | | |
22 | | class ModuleInstance; |
23 | | |
24 | | class GlobalInstance { |
25 | | public: |
26 | | GlobalInstance() = delete; |
27 | | GlobalInstance(const AST::GlobalType >ype, |
28 | | ValVariant Val = uint128_t(0U)) noexcept |
29 | 0 | : GlobType(GType), Value(Val) { |
30 | 0 | assuming(GType.getValType().isNumType() || |
31 | 0 | GType.getValType().isNullableRefType() || |
32 | 0 | !Val.get<RefVariant>().isNull()); |
33 | 0 | } |
34 | | /// Constructor for a global instance defined by a module. |
35 | | GlobalInstance(const ModuleInstance *Mod, const AST::GlobalType >ype, |
36 | | ValVariant Val) noexcept |
37 | 0 | : GlobalInstance(GType, Val) { |
38 | 0 | ModInst = Mod; |
39 | 0 | } |
40 | | |
41 | | /// Getter for the defining module instance, if any. |
42 | 0 | const ModuleInstance *getModule() const noexcept { return ModInst; } |
43 | | |
44 | | /// Getter for global type. |
45 | 0 | const AST::GlobalType &getGlobalType() const noexcept { return GlobType; } |
46 | | |
47 | | /// Getter for value. |
48 | 0 | const ValVariant &getValue() const noexcept { return Value; } |
49 | 0 | ValVariant &getValue() noexcept { return Value; } |
50 | | |
51 | | /// Setter for value. |
52 | 0 | void setValue(const ValVariant &Val) noexcept { Value = Val; } |
53 | | |
54 | | private: |
55 | | /// \name Data of global instance. |
56 | | /// @{ |
57 | | const ModuleInstance *ModInst = nullptr; |
58 | | AST::GlobalType GlobType; |
59 | | alignas(16) ValVariant Value; |
60 | | /// @} |
61 | | }; |
62 | | |
63 | | } // namespace Instance |
64 | | } // namespace Runtime |
65 | | } // namespace WasmEdge |