/src/WasmEdge/include/common/enum_errinfo.hpp
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright The WasmEdge Authors |
3 | | |
4 | | //===-- wasmedge/common/enum_errinfo.hpp - ErrInfo C++ enumerations -------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the definitions of C++ enumerations used by ErrInfo. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | // This header is not exported to the C API. |
16 | | |
17 | | #pragma once |
18 | | |
19 | | #include "dense_enum_map.h" |
20 | | #include "fmt.h" |
21 | | |
22 | | #include <cstdint> |
23 | | #include <string_view> |
24 | | |
25 | | namespace WasmEdge { |
26 | | namespace ErrInfo { |
27 | | |
28 | | /// Error info type C++ enumeration class. |
29 | | enum class InfoType : uint8_t { |
30 | | File, // Information about file name which loading from |
31 | | Loading, // Information about bytecode offset |
32 | | AST, // Information about tracing AST nodes |
33 | | InstanceBound, // Information about over boundary of limited #instances |
34 | | ForbidIndex, // Information about forbidden accessing of indices |
35 | | Exporting, // Information about exporting instances |
36 | | Limit, // Information about Limit value |
37 | | Registering, // Information about instantiating modules |
38 | | Linking, // Information about linking instances |
39 | | Executing, // Information about running functions |
40 | | Mismatch, // Information about comparison error |
41 | | Instruction, // Information about aborted instructions and parameters |
42 | | Boundary // Information about forbidden offset accessing |
43 | | }; |
44 | | |
45 | | /// Error info instance addressing type C++ enumeration class. |
46 | | enum class PtrType : uint8_t { |
47 | | #define UsePtrType |
48 | | #define Line(NAME, STRING) NAME, |
49 | | #include "enum.inc" |
50 | | #undef Line |
51 | | #undef UsePtrType |
52 | | }; |
53 | | |
54 | | static inline constexpr auto PtrTypeStr = []() constexpr { |
55 | | using namespace std::literals::string_view_literals; |
56 | | std::pair<PtrType, std::string_view> Array[] = { |
57 | | #define UsePtrType |
58 | | #define Line(NAME, STRING) {PtrType::NAME, STRING}, |
59 | | #include "enum.inc" |
60 | | #undef Line |
61 | | #undef UsePtrType |
62 | | }; |
63 | | return DenseEnumMap(Array); |
64 | | }(); |
65 | | |
66 | | /// Error info mismatch category C++ enumeration class. |
67 | | enum class MismatchCategory : uint8_t { |
68 | | #define UseMismatchCategory |
69 | | #define Line(NAME, STRING) NAME, |
70 | | #include "enum.inc" |
71 | | #undef Line |
72 | | #undef UseMismatchCategory |
73 | | }; |
74 | | |
75 | | static inline constexpr auto MismatchCategoryStr = []() constexpr { |
76 | | using namespace std::literals::string_view_literals; |
77 | | std::pair<MismatchCategory, std::string_view> Array[] = { |
78 | | #define UseMismatchCategory |
79 | | #define Line(NAME, STRING) {MismatchCategory::NAME, STRING}, |
80 | | #include "enum.inc" |
81 | | #undef Line |
82 | | #undef UseMismatchCategory |
83 | | }; |
84 | | return DenseEnumMap(Array); |
85 | | }(); |
86 | | |
87 | | /// Error info index category C++ enumeration class. |
88 | | enum class IndexCategory : uint8_t { |
89 | | #define UseIndexCategory |
90 | | #define Line(NAME, STRING) NAME, |
91 | | #include "enum.inc" |
92 | | #undef Line |
93 | | #undef UseIndexCategory |
94 | | }; |
95 | | |
96 | | static inline constexpr auto IndexCategoryStr = []() constexpr { |
97 | | using namespace std::literals::string_view_literals; |
98 | | std::pair<IndexCategory, std::string_view> Array[] = { |
99 | | #define UseIndexCategory |
100 | | #define Line(NAME, STRING) {IndexCategory::NAME, STRING}, |
101 | | #include "enum.inc" |
102 | | #undef Line |
103 | | #undef UseIndexCategory |
104 | | }; |
105 | | return DenseEnumMap(Array); |
106 | | }(); |
107 | | |
108 | | } // namespace ErrInfo |
109 | | } // namespace WasmEdge |
110 | | |
111 | | template <> |
112 | | struct fmt::formatter<WasmEdge::ErrInfo::PtrType> |
113 | | : fmt::formatter<std::string_view> { |
114 | | template <typename FmtCtx> |
115 | | auto format(const WasmEdge::ErrInfo::PtrType &Type, |
116 | | FmtCtx &Ctx) WASMEDGE_FMT_CONST noexcept -> decltype(Ctx.out()) { |
117 | | return formatter<std::string_view>::format( |
118 | | WasmEdge::ErrInfo::PtrTypeStr[Type], Ctx); |
119 | | } |
120 | | }; |
121 | | |
122 | | template <> |
123 | | struct fmt::formatter<WasmEdge::ErrInfo::MismatchCategory> |
124 | | : fmt::formatter<std::string_view> { |
125 | | template <typename FmtCtx> |
126 | | auto format(const WasmEdge::ErrInfo::MismatchCategory &Category, |
127 | 0 | FmtCtx &Ctx) WASMEDGE_FMT_CONST noexcept -> decltype(Ctx.out()) { |
128 | 0 | return formatter<std::string_view>::format( |
129 | 0 | WasmEdge::ErrInfo::MismatchCategoryStr[Category], Ctx); |
130 | 0 | } |
131 | | }; |
132 | | |
133 | | template <> |
134 | | struct fmt::formatter<WasmEdge::ErrInfo::IndexCategory> |
135 | | : fmt::formatter<std::string_view> { |
136 | | template <typename FmtCtx> |
137 | | auto format(const WasmEdge::ErrInfo::IndexCategory &Category, |
138 | 0 | FmtCtx &Ctx) WASMEDGE_FMT_CONST noexcept -> decltype(Ctx.out()) { |
139 | 0 | return formatter<std::string_view>::format( |
140 | 0 | WasmEdge::ErrInfo::IndexCategoryStr[Category], Ctx); |
141 | 0 | } |
142 | | }; |