/src/WasmEdge/include/ast/component/alias.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/component/alias.h - Alias class definitions ----------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the declaration of the Alias node related classes. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | |
16 | | #include "ast/component/sort.h" |
17 | | |
18 | | #include <string> |
19 | | #include <variant> |
20 | | #include <vector> |
21 | | |
22 | | namespace WasmEdge { |
23 | | namespace AST { |
24 | | namespace Component { |
25 | | |
26 | | // aliastarget ::= 0x00 i:<instanceidx> n:<name> => export i n |
27 | | // | 0x01 i:<core:instanceidx> n:<core:name> => core export i n |
28 | | // | 0x02 ct:<u32> idx:<u32> => outer ct idx |
29 | | |
30 | | /// AST Component::AliasTargetExport class. |
31 | | class AliasTargetExport { |
32 | | public: |
33 | 0 | uint32_t getInstanceIdx() const noexcept { return InstanceIndex; } |
34 | 0 | uint32_t &getInstanceIdx() noexcept { return InstanceIndex; } |
35 | 0 | std::string_view getName() const noexcept { return Name; } |
36 | 0 | std::string &getName() noexcept { return Name; } |
37 | | |
38 | | private: |
39 | | uint32_t InstanceIndex; |
40 | | std::string Name; |
41 | | }; |
42 | | |
43 | | /// AST Component::AliasTargetOuter class. |
44 | | class AliasTargetOuter { |
45 | | public: |
46 | 0 | uint32_t getComponent() const noexcept { return ComponentIndex; } |
47 | 0 | uint32_t &getComponent() noexcept { return ComponentIndex; } |
48 | 0 | uint32_t getIndex() const noexcept { return Index; } |
49 | 0 | uint32_t &getIndex() noexcept { return Index; } |
50 | | |
51 | | private: |
52 | | uint32_t ComponentIndex; |
53 | | uint32_t Index; |
54 | | }; |
55 | | |
56 | | /// AST Component::AliasTarget aliasing. |
57 | | using AliasTarget = std::variant<AliasTargetExport, AliasTargetOuter>; |
58 | | |
59 | | // TODO: COMPONENT - Combine the AliasTarget variant into the Alias class. |
60 | | |
61 | | // alias ::= s:<sort> t:<aliastarget> => (alias t (s)) |
62 | | |
63 | | /// AST Component::Alias node. |
64 | | class Alias { |
65 | | public: |
66 | 0 | Sort &getSort() noexcept { return S; } |
67 | 0 | const Sort &getSort() const noexcept { return S; } |
68 | | |
69 | 0 | AliasTarget &getTarget() noexcept { return Target; } |
70 | 0 | const AliasTarget &getTarget() const noexcept { return Target; } |
71 | | |
72 | | private: |
73 | | Sort S; |
74 | | AliasTarget Target; |
75 | | }; |
76 | | |
77 | | } // namespace Component |
78 | | } // namespace AST |
79 | | } // namespace WasmEdge |