|
1 | 1 | #pragma once |
2 | 2 |
|
3 | | -#include "barretenberg/common/throw_or_abort.hpp" |
| 3 | +#include <cstdint> |
4 | 4 | #include <sstream> |
5 | 5 |
|
| 6 | +namespace bb { |
| 7 | +enum class AssertMode : std::uint8_t { ABORT, WARN }; |
| 8 | +AssertMode& get_assert_mode(); |
| 9 | +void assert_failure(std::string const& err); |
| 10 | + |
| 11 | +// NOTE do not use in threaded contexts! |
| 12 | +struct AssertGuard { |
| 13 | + AssertGuard(AssertMode mode) |
| 14 | + : previous_mode(get_assert_mode()) |
| 15 | + { |
| 16 | + get_assert_mode() = mode; |
| 17 | + } |
| 18 | + ~AssertGuard() { get_assert_mode() = (previous_mode); } |
| 19 | + AssertMode previous_mode; |
| 20 | +}; |
| 21 | +} // namespace bb |
| 22 | + |
| 23 | +// NOTE do not use in threaded contexts! |
| 24 | +#define BB_DISABLE_ASSERTS() bb::AssertGuard __bb_assert_guard(bb::AssertMode::WARN) |
| 25 | + |
6 | 26 | // NOLINTBEGIN |
7 | 27 | // Compiler should optimize this out in release builds, without triggering unused-variable warnings. |
8 | 28 | #define DONT_EVALUATE(expression) \ |
|
42 | 62 | if (!(expression)) { \ |
43 | 63 | info("Assertion failed: (" #expression ")"); \ |
44 | 64 | __VA_OPT__(info("Reason : ", __VA_ARGS__);) \ |
45 | | - throw_or_abort(""); \ |
| 65 | + bb::assert_failure(""); \ |
46 | 66 | } \ |
47 | 67 | } while (0) |
48 | 68 |
|
|
52 | 72 | std::ostringstream oss; \ |
53 | 73 | oss << "Assertion failed: (" #expression ")"; \ |
54 | 74 | __VA_OPT__(oss << " | Reason: " << __VA_ARGS__;) \ |
55 | | - throw_or_abort(oss.str()); \ |
| 75 | + bb::assert_failure(oss.str()); \ |
56 | 76 | } \ |
57 | 77 | } while (0) |
58 | 78 |
|
|
66 | 86 | oss << " Actual : " << _actual << "\n"; \ |
67 | 87 | oss << " Expected: " << _expected; \ |
68 | 88 | __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ |
69 | | - throw_or_abort(oss.str()); \ |
| 89 | + bb::assert_failure(oss.str()); \ |
70 | 90 | } \ |
71 | 91 | } while (0) |
72 | 92 |
|
|
80 | 100 | oss << " Actual : " << _actual << "\n"; \ |
81 | 101 | oss << " Not expected: " << _expected; \ |
82 | 102 | __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ |
83 | | - throw_or_abort(oss.str()); \ |
| 103 | + bb::assert_failure(oss.str()); \ |
84 | 104 | } \ |
85 | 105 | } while (0) |
86 | 106 |
|
|
94 | 114 | oss << " Left : " << _left << "\n"; \ |
95 | 115 | oss << " Right : " << _right; \ |
96 | 116 | __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ |
97 | | - throw_or_abort(oss.str()); \ |
| 117 | + bb::assert_failure(oss.str()); \ |
98 | 118 | } \ |
99 | 119 | } while (0) |
100 | 120 |
|
|
108 | 128 | oss << " Left : " << _left << "\n"; \ |
109 | 129 | oss << " Right : " << _right; \ |
110 | 130 | __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ |
111 | | - throw_or_abort(oss.str()); \ |
| 131 | + bb::assert_failure(oss.str()); \ |
112 | 132 | } \ |
113 | 133 | } while (0) |
114 | 134 |
|
|
122 | 142 | oss << " Left : " << _left << "\n"; \ |
123 | 143 | oss << " Right : " << _right; \ |
124 | 144 | __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ |
125 | | - throw_or_abort(oss.str()); \ |
| 145 | + bb::assert_failure(oss.str()); \ |
126 | 146 | } \ |
127 | 147 | } while (0) |
128 | 148 |
|
|
136 | 156 | oss << " Left : " << _left << "\n"; \ |
137 | 157 | oss << " Right : " << _right; \ |
138 | 158 | __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ |
139 | | - throw_or_abort(oss.str()); \ |
| 159 | + bb::assert_failure(oss.str()); \ |
140 | 160 | } \ |
141 | 161 | } while (0) |
142 | 162 | #endif // __wasm__ |
|
0 commit comments