/src/WasmEdge/include/common/enum_ast.hpp
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/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 Wasm VM used AST and instruction nodes |
12 | | /// enumerations. |
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/spare_enum_map.h" |
22 | | #include "common/spdlog.h" |
23 | | |
24 | | #include <cstdint> |
25 | | #include <string> |
26 | | |
27 | | namespace WasmEdge { |
28 | | |
29 | | /// AST node attributes enumeration class. |
30 | | enum class ASTNodeAttr : uint8_t { |
31 | | #define UseASTNodeAttr |
32 | | #define Line(NAME, STRING) NAME, |
33 | | #include "enum.inc" |
34 | | #undef Line |
35 | | #undef UseASTNodeAttr |
36 | | }; |
37 | | |
38 | | /// AST node attributes enumeration string mapping. |
39 | | static inline constexpr auto ASTNodeAttrStr = []() constexpr { |
40 | | using namespace std::literals::string_view_literals; |
41 | | std::pair<ASTNodeAttr, std::string_view> Array[] = { |
42 | | #define UseASTNodeAttr |
43 | | #define Line(NAME, STRING) {ASTNodeAttr::NAME, STRING}, |
44 | | #include "enum.inc" |
45 | | #undef Line |
46 | | #undef UseASTNodeAttr |
47 | | }; |
48 | | return DenseEnumMap(Array); |
49 | | }(); |
50 | | |
51 | | /// Instruction opcode enumeration class. |
52 | | enum class OpCode : uint32_t { |
53 | | #define UseOpCode |
54 | | #define Line(NAME, STRING, PREFIX) NAME, |
55 | | #define Line_FB(NAME, STRING, PREFIX, EXTEND) NAME, |
56 | | #define Line_FC(NAME, STRING, PREFIX, EXTEND) NAME, |
57 | | #define Line_FD(NAME, STRING, PREFIX, EXTEND) NAME, |
58 | | #define Line_FE(NAME, STRING, PREFIX, EXTEND) NAME, |
59 | | #include "enum.inc" |
60 | | #undef Line |
61 | | #undef Line_FB |
62 | | #undef Line_FC |
63 | | #undef Line_FD |
64 | | #undef Line_FE |
65 | | #undef UseOpCode |
66 | | }; |
67 | | |
68 | | /// Instruction opcode enumeration string mapping. |
69 | | static inline constexpr const auto OpCodeStr = []() constexpr { |
70 | | using namespace std::literals::string_view_literals; |
71 | | std::pair<OpCode, std::string_view> Array[] = { |
72 | | #define UseOpCode |
73 | | #define Line(NAME, STRING, PREFIX) {OpCode::NAME, STRING}, |
74 | | #define Line_FB(NAME, STRING, PREFIX, EXTEND) {OpCode::NAME, STRING}, |
75 | | #define Line_FC(NAME, STRING, PREFIX, EXTEND) {OpCode::NAME, STRING}, |
76 | | #define Line_FD(NAME, STRING, PREFIX, EXTEND) {OpCode::NAME, STRING}, |
77 | | #define Line_FE(NAME, STRING, PREFIX, EXTEND) {OpCode::NAME, STRING}, |
78 | | #include "enum.inc" |
79 | | #undef Line |
80 | | #undef Line_FB |
81 | | #undef Line_FC |
82 | | #undef Line_FD |
83 | | #undef Line_FE |
84 | | #undef UseOpCode |
85 | | }; |
86 | | return SpareEnumMap(Array); |
87 | | }(); |
88 | | |
89 | | } // namespace WasmEdge |
90 | | |
91 | | template <> |
92 | | struct fmt::formatter<WasmEdge::ASTNodeAttr> |
93 | | : fmt::formatter<std::string_view> { |
94 | | fmt::format_context::iterator |
95 | | format(const WasmEdge::ASTNodeAttr &Attr, |
96 | 0 | fmt::format_context &Ctx) const noexcept { |
97 | 0 | return formatter<std::string_view>::format(WasmEdge::ASTNodeAttrStr[Attr], |
98 | 0 | Ctx); |
99 | 0 | } |
100 | | }; |
101 | | |
102 | | template <> |
103 | | struct fmt::formatter<WasmEdge::OpCode> : fmt::formatter<std::string_view> { |
104 | | fmt::format_context::iterator |
105 | | format(const WasmEdge::OpCode &Code, |
106 | 0 | fmt::format_context &Ctx) const noexcept { |
107 | 0 | return formatter<std::string_view>::format(WasmEdge::OpCodeStr[Code], Ctx); |
108 | 0 | } |
109 | | }; |