Coverage Report

Created: 2025-08-25 06:58

/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 <cstdint>
19
#include <string>
20
#include <variant>
21
22
namespace WasmEdge {
23
namespace AST {
24
namespace Component {
25
26
// core:alias       ::= s:<core:sort> t:<core:aliastarget> => (alias t (s))
27
// core:aliastarget ::= 0x01 ct:<u32> idx:<u32>            => outer ct idx
28
29
/// AST Component::CoreAlias node.
30
class CoreAlias {
31
public:
32
0
  Sort &getSort() noexcept { return S; }
33
0
  const Sort &getSort() const noexcept { return S; }
34
35
0
  uint32_t getComponentJump() const noexcept { return CompJump; }
36
0
  void setComponentJump(const uint32_t Ct) noexcept { CompJump = Ct; }
37
38
0
  uint32_t getIndex() const noexcept { return Index; }
39
0
  void setIndex(const uint32_t Idx) noexcept { Index = Idx; }
40
41
private:
42
  Sort S;
43
  uint32_t CompJump;
44
  uint32_t Index;
45
};
46
47
// alias       ::= s:<sort> t:<aliastarget>                => (alias t (s))
48
// aliastarget ::= 0x00 i:<instanceidx> n:<name>           => export i n
49
//               | 0x01 i:<core:instanceidx> n:<core:name> => core export i n
50
//               | 0x02 ct:<u32> idx:<u32>                 => outer ct idx
51
52
/// AST Component::Alias node.
53
class Alias {
54
public:
55
  enum class TargetType : uint8_t {
56
    Export = 0x00,
57
    CoreExport = 0x01,
58
    Outer = 0x02
59
  };
60
61
0
  TargetType getTargetType() const noexcept { return Type; }
62
0
  void setTargetType(const TargetType T) noexcept { Type = T; }
63
64
0
  Sort &getSort() noexcept { return S; }
65
0
  const Sort &getSort() const noexcept { return S; }
66
67
0
  const std::pair<uint32_t, std::string> &getExport() const noexcept {
68
0
    return *std::get_if<std::pair<uint32_t, std::string>>(&Target);
69
0
  }
70
0
  void setExport(const uint32_t Idx, std::string_view Name) noexcept {
71
0
    Target.emplace<std::pair<uint32_t, std::string>>(Idx, Name);
72
0
  }
73
74
0
  const std::pair<uint32_t, uint32_t> &getOuter() const noexcept {
75
0
    return *std::get_if<std::pair<uint32_t, uint32_t>>(&Target);
76
0
  }
77
0
  void setOuter(const uint32_t Ct, const uint32_t Idx) noexcept {
78
0
    Target.emplace<std::pair<uint32_t, uint32_t>>(Ct, Idx);
79
0
  }
80
81
private:
82
  TargetType Type;
83
  Sort S;
84
  std::variant<std::pair<uint32_t, std::string>, std::pair<uint32_t, uint32_t>>
85
      Target;
86
};
87
88
} // namespace Component
89
} // namespace AST
90
} // namespace WasmEdge