/src/WasmEdge/include/common/errcode.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/common/errcode.h - Error code definition -----------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the `Expected` wrappers. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | |
16 | | #include "common/enum_errcode.hpp" |
17 | | #include "common/expected.h" |
18 | | #include "common/hexstr.h" |
19 | | #include "common/spdlog.h" |
20 | | |
21 | | #include <cassert> |
22 | | #include <ostream> |
23 | | |
24 | | #if defined(_MSC_VER) && !defined(__clang__) |
25 | | #define __builtin_unreachable() __assume(0) |
26 | | #endif |
27 | | |
28 | | #ifdef NDEBUG |
29 | | #define assuming(R) \ |
30 | 2.07M | (static_cast<bool>(R) ? static_cast<void>(0) : __builtin_unreachable()) |
31 | 0 | #define assumingUnreachable() __builtin_unreachable() |
32 | | #else |
33 | | #define assuming(expr) assert(expr) |
34 | | #define assumingUnreachable() \ |
35 | | (assert(false && "unreachable"), __builtin_unreachable()) |
36 | | #endif |
37 | | |
38 | | namespace WasmEdge { |
39 | | |
40 | 60.6M | static inline constexpr bool likely(bool V) noexcept { |
41 | 60.6M | return __builtin_expect(V, true); |
42 | 60.6M | } Unexecuted instantiation: wasmedge.cpp:WasmEdge::likely(bool) Unexecuted instantiation: fuzzTool.cpp:WasmEdge::likely(bool) Unexecuted instantiation: fuzzPO.cpp:WasmEdge::likely(bool) Unexecuted instantiation: uniTool.cpp:WasmEdge::likely(bool) Unexecuted instantiation: compilerTool.cpp:WasmEdge::likely(bool) Unexecuted instantiation: runtimeTool.cpp:WasmEdge::likely(bool) Unexecuted instantiation: vm.cpp:WasmEdge::likely(bool) Unexecuted instantiation: plugin.cpp:WasmEdge::likely(bool) module.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 65.9k | static inline constexpr bool likely(bool V) noexcept { | 41 | 65.9k | return __builtin_expect(V, true); | 42 | 65.9k | } |
Unexecuted instantiation: func.cpp:WasmEdge::likely(bool) Unexecuted instantiation: argument_parser.cpp:WasmEdge::likely(bool) section.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 480k | static inline constexpr bool likely(bool V) noexcept { | 41 | 480k | return __builtin_expect(V, true); | 42 | 480k | } |
description.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 109k | static inline constexpr bool likely(bool V) noexcept { | 41 | 109k | return __builtin_expect(V, true); | 42 | 109k | } |
segment.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 125k | static inline constexpr bool likely(bool V) noexcept { | 41 | 125k | return __builtin_expect(V, true); | 42 | 125k | } |
type.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 119k | static inline constexpr bool likely(bool V) noexcept { | 41 | 119k | return __builtin_expect(V, true); | 42 | 119k | } |
Unexecuted instantiation: expression.cpp:WasmEdge::likely(bool) instruction.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 30.5M | static inline constexpr bool likely(bool V) noexcept { | 41 | 30.5M | return __builtin_expect(V, true); | 42 | 30.5M | } |
loader.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 37.1k | static inline constexpr bool likely(bool V) noexcept { | 41 | 37.1k | return __builtin_expect(V, true); | 42 | 37.1k | } |
Unexecuted instantiation: component.cpp:WasmEdge::likely(bool) Unexecuted instantiation: component_section.cpp:WasmEdge::likely(bool) Unexecuted instantiation: component_instance.cpp:WasmEdge::likely(bool) Unexecuted instantiation: component_sort.cpp:WasmEdge::likely(bool) Unexecuted instantiation: component_alias.cpp:WasmEdge::likely(bool) Unexecuted instantiation: component_canonical.cpp:WasmEdge::likely(bool) Unexecuted instantiation: component_start.cpp:WasmEdge::likely(bool) Unexecuted instantiation: component_type.cpp:WasmEdge::likely(bool) Unexecuted instantiation: component_import.cpp:WasmEdge::likely(bool) Unexecuted instantiation: component_export.cpp:WasmEdge::likely(bool) Unexecuted instantiation: serial_module.cpp:WasmEdge::likely(bool) Unexecuted instantiation: serial_section.cpp:WasmEdge::likely(bool) Unexecuted instantiation: serial_segment.cpp:WasmEdge::likely(bool) Unexecuted instantiation: serial_type.cpp:WasmEdge::likely(bool) Unexecuted instantiation: serial_description.cpp:WasmEdge::likely(bool) Unexecuted instantiation: serial_expression.cpp:WasmEdge::likely(bool) Unexecuted instantiation: serial_instruction.cpp:WasmEdge::likely(bool) filemgr.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 14.8M | static inline constexpr bool likely(bool V) noexcept { | 41 | 14.8M | return __builtin_expect(V, true); | 42 | 14.8M | } |
Unexecuted instantiation: shared_library.cpp:WasmEdge::likely(bool) Unexecuted instantiation: aot_section.cpp:WasmEdge::likely(bool) validator.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 8.51M | static inline constexpr bool likely(bool V) noexcept { | 41 | 8.51M | return __builtin_expect(V, true); | 42 | 8.51M | } |
Unexecuted instantiation: validator_component.cpp:WasmEdge::likely(bool) formchecker.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 5.82M | static inline constexpr bool likely(bool V) noexcept { | 41 | 5.82M | return __builtin_expect(V, true); | 42 | 5.82M | } |
Unexecuted instantiation: proxy.cpp:WasmEdge::likely(bool) Unexecuted instantiation: threadInstr.cpp:WasmEdge::likely(bool) Unexecuted instantiation: refInstr.cpp:WasmEdge::likely(bool) Unexecuted instantiation: engine.cpp:WasmEdge::likely(bool) Unexecuted instantiation: helper.cpp:WasmEdge::likely(bool) Unexecuted instantiation: executor.cpp:WasmEdge::likely(bool) Unexecuted instantiation: coredump.cpp:WasmEdge::likely(bool) Unexecuted instantiation: instantiate_component_alias.cpp:WasmEdge::likely(bool) Unexecuted instantiation: instantiate_component_canon.cpp:WasmEdge::likely(bool) Unexecuted instantiation: instantiate_component_export.cpp:WasmEdge::likely(bool) Unexecuted instantiation: instantiate_component_import.cpp:WasmEdge::likely(bool) Unexecuted instantiation: instantiate_component_instance.cpp:WasmEdge::likely(bool) Unexecuted instantiation: instantiate_component_start.cpp:WasmEdge::likely(bool) Unexecuted instantiation: instantiate_component_type.cpp:WasmEdge::likely(bool) Unexecuted instantiation: tag.cpp:WasmEdge::likely(bool) Unexecuted instantiation: controlInstr.cpp:WasmEdge::likely(bool) Unexecuted instantiation: tableInstr.cpp:WasmEdge::likely(bool) Unexecuted instantiation: memoryInstr.cpp:WasmEdge::likely(bool) Unexecuted instantiation: variableInstr.cpp:WasmEdge::likely(bool) Unexecuted instantiation: import.cpp:WasmEdge::likely(bool) Unexecuted instantiation: function.cpp:WasmEdge::likely(bool) Unexecuted instantiation: global.cpp:WasmEdge::likely(bool) Unexecuted instantiation: table.cpp:WasmEdge::likely(bool) Unexecuted instantiation: memory.cpp:WasmEdge::likely(bool) Unexecuted instantiation: elem.cpp:WasmEdge::likely(bool) Unexecuted instantiation: data.cpp:WasmEdge::likely(bool) Unexecuted instantiation: export.cpp:WasmEdge::likely(bool) Unexecuted instantiation: environ.cpp:WasmEdge::likely(bool) Unexecuted instantiation: vinode.cpp:WasmEdge::likely(bool) Unexecuted instantiation: wasimodule.cpp:WasmEdge::likely(bool) Unexecuted instantiation: inode-linux.cpp:WasmEdge::likely(bool) Unexecuted instantiation: wasifunc.cpp:WasmEdge::likely(bool) Unexecuted instantiation: clock-linux.cpp:WasmEdge::likely(bool) Unexecuted instantiation: environ-linux.cpp:WasmEdge::likely(bool) Unexecuted instantiation: compiler.cpp:WasmEdge::likely(bool) codegen.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 4.28k | static inline constexpr bool likely(bool V) noexcept { | 41 | 4.28k | return __builtin_expect(V, true); | 42 | 4.28k | } |
Unexecuted instantiation: jit.cpp:WasmEdge::likely(bool) Unexecuted instantiation: allocator.cpp:WasmEdge::likely(bool) Unexecuted instantiation: fault.cpp:WasmEdge::likely(bool) Unexecuted instantiation: stacktrace.cpp:WasmEdge::likely(bool) hash.cpp:WasmEdge::likely(bool) Line | Count | Source | 40 | 26.3k | static inline constexpr bool likely(bool V) noexcept { | 41 | 26.3k | return __builtin_expect(V, true); | 42 | 26.3k | } |
Unexecuted instantiation: errinfo.cpp:WasmEdge::likely(bool) |
43 | 37.5M | static inline constexpr bool unlikely(bool V) noexcept { |
44 | 37.5M | return __builtin_expect(V, false); |
45 | 37.5M | } Unexecuted instantiation: wasmedge.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: fuzzTool.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: fuzzPO.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: uniTool.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: compilerTool.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: runtimeTool.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: vm.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: plugin.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: module.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: func.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: argument_parser.cpp:WasmEdge::unlikely(bool) section.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 110k | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 110k | return __builtin_expect(V, false); | 45 | 110k | } |
description.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 565 | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 565 | return __builtin_expect(V, false); | 45 | 565 | } |
segment.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 6.27k | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 6.27k | return __builtin_expect(V, false); | 45 | 6.27k | } |
type.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 140k | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 140k | return __builtin_expect(V, false); | 45 | 140k | } |
Unexecuted instantiation: expression.cpp:WasmEdge::unlikely(bool) instruction.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 9.08M | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 9.08M | return __builtin_expect(V, false); | 45 | 9.08M | } |
Unexecuted instantiation: loader.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component_section.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component_instance.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component_sort.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component_alias.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component_canonical.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component_start.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component_type.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component_import.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: component_export.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: serial_module.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: serial_section.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: serial_segment.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: serial_type.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: serial_description.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: serial_expression.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: serial_instruction.cpp:WasmEdge::unlikely(bool) filemgr.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 28.1M | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 28.1M | return __builtin_expect(V, false); | 45 | 28.1M | } |
Unexecuted instantiation: shared_library.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: aot_section.cpp:WasmEdge::unlikely(bool) validator.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 6.73k | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 6.73k | return __builtin_expect(V, false); | 45 | 6.73k | } |
Unexecuted instantiation: validator_component.cpp:WasmEdge::unlikely(bool) formchecker.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 6.55k | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 6.55k | return __builtin_expect(V, false); | 45 | 6.55k | } |
Unexecuted instantiation: proxy.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: threadInstr.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: refInstr.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: engine.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: helper.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: executor.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: coredump.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: instantiate_component_alias.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: instantiate_component_canon.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: instantiate_component_export.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: instantiate_component_import.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: instantiate_component_instance.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: instantiate_component_start.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: instantiate_component_type.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: tag.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: controlInstr.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: tableInstr.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: memoryInstr.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: variableInstr.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: import.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: function.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: global.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: table.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: memory.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: elem.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: data.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: export.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: environ.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: vinode.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: wasimodule.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: inode-linux.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: wasifunc.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: clock-linux.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: environ-linux.cpp:WasmEdge::unlikely(bool) compiler.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 2.14k | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 2.14k | return __builtin_expect(V, false); | 45 | 2.14k | } |
codegen.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 33.9k | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 33.9k | return __builtin_expect(V, false); | 45 | 33.9k | } |
Unexecuted instantiation: jit.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: allocator.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: fault.cpp:WasmEdge::unlikely(bool) Unexecuted instantiation: stacktrace.cpp:WasmEdge::unlikely(bool) hash.cpp:WasmEdge::unlikely(bool) Line | Count | Source | 43 | 4.93k | static inline constexpr bool unlikely(bool V) noexcept { | 44 | 4.93k | return __builtin_expect(V, false); | 45 | 4.93k | } |
Unexecuted instantiation: errinfo.cpp:WasmEdge::unlikely(bool) |
46 | | |
47 | | /// Type aliasing for Expected<T, ErrCode>. |
48 | | template <typename T> using Expect = Expected<T, ErrCode>; |
49 | | |
50 | | /// Helper function for Unexpected<ErrCode>. |
51 | 5.76k | constexpr auto Unexpect(const ErrCode &Val) { return Unexpected<ErrCode>(Val); } |
52 | 8.83k | template <typename... ArgsT> constexpr auto Unexpect(ArgsT... Args) { |
53 | 8.83k | return Unexpected<ErrCode>(ErrCode(Args...)); |
54 | 8.83k | } auto WasmEdge::Unexpect<WasmEdge::ErrCode::Value>(WasmEdge::ErrCode::Value) Line | Count | Source | 52 | 8.83k | template <typename... ArgsT> constexpr auto Unexpect(ArgsT... Args) { | 53 | 8.83k | return Unexpected<ErrCode>(ErrCode(Args...)); | 54 | 8.83k | } |
Unexecuted instantiation: auto WasmEdge::Unexpect<WasmEdge::ErrCategory, unsigned int>(WasmEdge::ErrCategory, unsigned int) |
55 | 0 | template <typename T> constexpr auto Unexpect(const Expect<T> &Val) { |
56 | 0 | return Unexpected<ErrCode>(Val.error()); |
57 | 0 | } |
58 | | |
59 | | } // namespace WasmEdge |
60 | | |
61 | | template <> |
62 | | struct fmt::formatter<WasmEdge::ErrCode> : fmt::formatter<std::string_view> { |
63 | | fmt::format_context::iterator |
64 | | format(const WasmEdge::ErrCode &Code, |
65 | 0 | fmt::format_context &Ctx) const noexcept { |
66 | 0 | using namespace std::literals; |
67 | 0 | std::string Output = |
68 | 0 | fmt::format("{} failed: {}, Code: 0x{:03x}"sv, Code.getErrCodePhase(), |
69 | 0 | WasmEdge::ErrCodeStr[Code.getEnum()], Code.getCode()); |
70 | 0 | return formatter<std::string_view>::format(Output, Ctx); |
71 | 0 | } |
72 | | }; |
73 | | |
74 | | template <> |
75 | | struct fmt::formatter<WasmEdge::ErrCode::Value> |
76 | | : fmt::formatter<WasmEdge::ErrCode> { |
77 | | fmt::format_context::iterator |
78 | | format(const WasmEdge::ErrCode::Value &Value, |
79 | 0 | fmt::format_context &Ctx) const noexcept { |
80 | 0 | return formatter<WasmEdge::ErrCode>::format(WasmEdge::ErrCode(Value), Ctx); |
81 | 0 | } |
82 | | }; |