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