/src/WasmEdge/include/ast/component/alias.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright The WasmEdge Authors |
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 <cstdint> |
19 | | #include <string> |
20 | | #include <variant> |
21 | | |
22 | | namespace WasmEdge { |
23 | | namespace AST { |
24 | | namespace Component { |
25 | | |
26 | | // core:alias ::= 0x10 0x01 ct:<u32> idx:<u32> => (alias outer ct idx (type)) |
27 | | |
28 | | /// AST Component::CoreAlias node. |
29 | | class CoreAlias { |
30 | | public: |
31 | 728 | uint32_t getComponentJump() const noexcept { return CompJump; } |
32 | 790 | void setComponentJump(const uint32_t Ct) noexcept { CompJump = Ct; } |
33 | | |
34 | 736 | uint32_t getIndex() const noexcept { return Index; } |
35 | 790 | void setIndex(const uint32_t Idx) noexcept { Index = Idx; } |
36 | | |
37 | | private: |
38 | | uint32_t CompJump; |
39 | | uint32_t Index; |
40 | | }; |
41 | | |
42 | | // alias ::= s:<sort> 0x00 i:<instanceidx> n:<name> => export i n |
43 | | // | s:<sort> 0x01 i:<core:instanceidx> n:<core:name> => core export |
44 | | // | s:<sort> 0x02 ct:<u32> idx:<u32> => outer ct idx |
45 | | // (if s in outeraliassort) |
46 | | |
47 | | /// AST Component::Alias node. |
48 | | class Alias { |
49 | | public: |
50 | | enum class TargetType : uint8_t { |
51 | | Export = 0x00, |
52 | | CoreExport = 0x01, |
53 | | Outer = 0x02 |
54 | | }; |
55 | | |
56 | 5.40k | TargetType getTargetType() const noexcept { return Type; } |
57 | 12.9k | void setTargetType(const TargetType T) noexcept { Type = T; } |
58 | | |
59 | 18.9k | Sort &getSort() noexcept { return S; } |
60 | 5.40k | const Sort &getSort() const noexcept { return S; } |
61 | | |
62 | 615 | const std::pair<uint32_t, std::string> &getExport() const noexcept { |
63 | 615 | return *std::get_if<std::pair<uint32_t, std::string>>(&Target); |
64 | 615 | } |
65 | 7.06k | void setExport(const uint32_t Idx, std::string_view Name) noexcept { |
66 | 7.06k | Target.emplace<std::pair<uint32_t, std::string>>(Idx, Name); |
67 | 7.06k | } |
68 | | |
69 | 4.77k | const std::pair<uint32_t, uint32_t> &getOuter() const noexcept { |
70 | 4.77k | return *std::get_if<std::pair<uint32_t, uint32_t>>(&Target); |
71 | 4.77k | } |
72 | 5.90k | void setOuter(const uint32_t Ct, const uint32_t Idx) noexcept { |
73 | 5.90k | Target.emplace<std::pair<uint32_t, uint32_t>>(Ct, Idx); |
74 | 5.90k | } |
75 | | |
76 | | private: |
77 | | TargetType Type; |
78 | | Sort S; |
79 | | std::variant<std::pair<uint32_t, std::string>, std::pair<uint32_t, uint32_t>> |
80 | | Target; |
81 | | }; |
82 | | |
83 | | } // namespace Component |
84 | | } // namespace AST |
85 | | } // namespace WasmEdge |