/src/WasmEdge/include/ast/description.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/ast/description.h - Desc classes definitions -------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the declaration of the Desc node class and the derived |
12 | | /// ImportDesc and ExportDesc classes. |
13 | | /// |
14 | | //===----------------------------------------------------------------------===// |
15 | | #pragma once |
16 | | |
17 | | #include "ast/type.h" |
18 | | #include "common/enum_types.hpp" |
19 | | |
20 | | #include <string> |
21 | | #include <string_view> |
22 | | #include <variant> |
23 | | |
24 | | namespace WasmEdge { |
25 | | namespace AST { |
26 | | |
27 | | /// Base class of Desc node. |
28 | | class Desc { |
29 | | public: |
30 | | /// Getter and setter of external type. |
31 | 48.5k | ExternalType getExternalType() const noexcept { return ExtType; } |
32 | 32.9k | void setExternalType(ExternalType ET) noexcept { ExtType = ET; } |
33 | | |
34 | | /// Getter and setter of external name. |
35 | 14.5k | std::string_view getExternalName() const noexcept { return ExtName; } |
36 | 32.9k | void setExternalName(std::string_view Name) { ExtName = Name; } |
37 | | |
38 | | protected: |
39 | | /// \name Data of Desc: rxternal name and external type. |
40 | | /// @{ |
41 | | ExternalType ExtType; |
42 | | std::string ExtName; |
43 | | /// @} |
44 | | }; |
45 | | |
46 | | /// Derived import description class. |
47 | | class ImportDesc : public Desc { |
48 | | public: |
49 | | /// Getter and setter of module name. |
50 | 0 | std::string_view getModuleName() const noexcept { return ModName; } |
51 | 11.1k | void setModuleName(std::string_view Name) { ModName = Name; } |
52 | | |
53 | | /// Getter and setter of external contents. |
54 | 506 | uint32_t getExternalFuncTypeIdx() const noexcept { return FuncTypeIdx; } |
55 | 3.03k | void setExternalFuncTypeIdx(uint32_t Idx) noexcept { FuncTypeIdx = Idx; } |
56 | 30 | const TableType &getExternalTableType() const noexcept { return TabType; } |
57 | 157 | TableType &getExternalTableType() noexcept { return TabType; } |
58 | 32 | const MemoryType &getExternalMemoryType() const noexcept { return MemType; } |
59 | 259 | MemoryType &getExternalMemoryType() noexcept { return MemType; } |
60 | 83 | const GlobalType &getExternalGlobalType() const noexcept { return GlobType; } |
61 | 15.3k | GlobalType &getExternalGlobalType() noexcept { return GlobType; } |
62 | 0 | const TagType &getExternalTagType() const noexcept { return TgType; } |
63 | 0 | TagType &getExternalTagType() noexcept { return TgType; } |
64 | | |
65 | | private: |
66 | | /// \name Data of ImportDesc: Module name, External name, and content node. |
67 | | /// @{ |
68 | | std::string ModName; |
69 | | uint32_t FuncTypeIdx = 0; |
70 | | TableType TabType; |
71 | | MemoryType MemType; |
72 | | GlobalType GlobType; |
73 | | TagType TgType; |
74 | | /// @} |
75 | | }; |
76 | | |
77 | | /// Derived export description class. |
78 | | class ExportDesc : public Desc { |
79 | | public: |
80 | | /// Getter and setter of external index. |
81 | 14.4k | uint32_t getExternalIndex() const noexcept { return ExtIdx; } |
82 | 21.8k | void setExternalIndex(uint32_t Idx) noexcept { ExtIdx = Idx; } |
83 | | |
84 | | private: |
85 | | /// \name Data of ExportDesc: external index. |
86 | | /// @{ |
87 | | uint32_t ExtIdx; |
88 | | /// @} |
89 | | }; |
90 | | |
91 | | } // namespace AST |
92 | | } // namespace WasmEdge |