Coverage Report

Created: 2026-06-30 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/include/common/enum_ast.hpp
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright The WasmEdge Authors
3
4
//===-- wasmedge/common/enum_ast.hpp - AST C++ enumerations ---------------===//
5
//
6
// Part of the WasmEdge Project.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// This file contains the definitions of AST and instruction node enumerations
12
/// used by the Wasm VM.
13
///
14
//===----------------------------------------------------------------------===//
15
16
// This header is not exported to the C API.
17
18
#pragma once
19
20
#include "common/dense_enum_map.h"
21
#include "common/fmt.h"
22
#include "common/spare_enum_map.h"
23
#include "common/spdlog.h"
24
25
#include <cstdint>
26
#include <string>
27
28
namespace WasmEdge {
29
30
/// AST node attributes enumeration class.
31
enum class ASTNodeAttr : uint8_t {
32
#define UseASTNodeAttr
33
#define Line(NAME, STRING) NAME,
34
#include "enum.inc"
35
#undef Line
36
#undef UseASTNodeAttr
37
};
38
39
/// AST node attributes enumeration string mapping.
40
static inline constexpr auto ASTNodeAttrStr = []() constexpr {
41
  using namespace std::literals::string_view_literals;
42
  std::pair<ASTNodeAttr, std::string_view> Array[] = {
43
#define UseASTNodeAttr
44
#define Line(NAME, STRING) {ASTNodeAttr::NAME, STRING},
45
#include "enum.inc"
46
#undef Line
47
#undef UseASTNodeAttr
48
  };
49
  return DenseEnumMap(Array);
50
}();
51
52
/// Instruction opcode enumeration class.
53
enum class OpCode : uint32_t {
54
#define UseOpCode
55
#define Line(NAME, STRING, PREFIX) NAME,
56
#define Line_FB(NAME, STRING, PREFIX, EXTEND) NAME,
57
#define Line_FC(NAME, STRING, PREFIX, EXTEND) NAME,
58
#define Line_FD(NAME, STRING, PREFIX, EXTEND) NAME,
59
#define Line_FE(NAME, STRING, PREFIX, EXTEND) NAME,
60
#include "enum.inc"
61
#undef Line
62
#undef Line_FB
63
#undef Line_FC
64
#undef Line_FD
65
#undef Line_FE
66
#undef UseOpCode
67
};
68
69
/// Instruction opcode enumeration string mapping.
70
static inline constexpr const auto OpCodeStr = []() constexpr {
71
  using namespace std::literals::string_view_literals;
72
  std::pair<OpCode, std::string_view> Array[] = {
73
#define UseOpCode
74
#define Line(NAME, STRING, PREFIX) {OpCode::NAME, STRING},
75
#define Line_FB(NAME, STRING, PREFIX, EXTEND) {OpCode::NAME, STRING},
76
#define Line_FC(NAME, STRING, PREFIX, EXTEND) {OpCode::NAME, STRING},
77
#define Line_FD(NAME, STRING, PREFIX, EXTEND) {OpCode::NAME, STRING},
78
#define Line_FE(NAME, STRING, PREFIX, EXTEND) {OpCode::NAME, STRING},
79
#include "enum.inc"
80
#undef Line
81
#undef Line_FB
82
#undef Line_FC
83
#undef Line_FD
84
#undef Line_FE
85
#undef UseOpCode
86
  };
87
  return SpareEnumMap(Array);
88
}();
89
90
/// Component Model Value opcode C++ enumeration class.
91
enum class ComponentCanonOpCode : uint8_t {
92
#define UseComponentCanonOpCode
93
#define Line(NAME, VALUE, STRING) NAME = VALUE,
94
#include "enum.inc"
95
#undef Line
96
#undef UseComponentCanonOpCode
97
};
98
99
static inline constexpr const auto ComponentCanonOpCodeStr = []() constexpr {
100
  using namespace std::literals::string_view_literals;
101
  std::pair<ComponentCanonOpCode, std::string_view> Array[] = {
102
#define UseComponentCanonOpCode
103
#define Line(NAME, VALUE, STRING) {ComponentCanonOpCode::NAME, STRING},
104
#include "enum.inc"
105
#undef Line
106
#undef UseComponentCanonOpCode
107
  };
108
  return SpareEnumMap(Array);
109
}();
110
111
/// Component Model Value Opt code C++ enumeration class.
112
enum class ComponentCanonOptCode : uint8_t {
113
#define UseComponentCanonOptCode
114
#define Line(NAME, VALUE, STRING) NAME = VALUE,
115
#include "enum.inc"
116
#undef Line
117
#undef UseComponentCanonOptCode
118
};
119
120
static inline constexpr const auto ComponentCanonOptCodeStr = []() constexpr {
121
  using namespace std::literals::string_view_literals;
122
  std::pair<ComponentCanonOptCode, std::string_view> Array[] = {
123
#define UseComponentCanonOptCode
124
#define Line(NAME, VALUE, STRING) {ComponentCanonOptCode::NAME, STRING},
125
#include "enum.inc"
126
#undef Line
127
#undef UseComponentCanonOptCode
128
  };
129
  return DenseEnumMap(Array);
130
}();
131
132
} // namespace WasmEdge
133
134
template <>
135
struct fmt::formatter<WasmEdge::ASTNodeAttr>
136
    : fmt::formatter<std::string_view> {
137
  template <typename FmtCtx>
138
  auto format(const WasmEdge::ASTNodeAttr &Attr,
139
0
              FmtCtx &Ctx) WASMEDGE_FMT_CONST noexcept -> decltype(Ctx.out()) {
140
0
    return formatter<std::string_view>::format(WasmEdge::ASTNodeAttrStr[Attr],
141
0
                                               Ctx);
142
0
  }
143
};
144
145
template <>
146
struct fmt::formatter<WasmEdge::OpCode> : fmt::formatter<std::string_view> {
147
  template <typename FmtCtx>
148
  auto format(const WasmEdge::OpCode &Code,
149
0
              FmtCtx &Ctx) WASMEDGE_FMT_CONST noexcept -> decltype(Ctx.out()) {
150
0
    return formatter<std::string_view>::format(WasmEdge::OpCodeStr[Code], Ctx);
151
0
  }
152
};