Broom
1.0.0
A thread-local C++ Garbage Collector
Loading...
Searching...
No Matches
src
macros.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <cassert>
4
#include <cstdlib>
5
#include <print>
6
#include <string>
7
8
#define BROOM_UNLIKELY [[unlikely]]
9
#define BROOM_LIKELY [[likely]]
10
#define BROOM_NORETURN [[noreturn]]
11
12
template
<
typename
... Args>
13
inline
void
Broom_Ensure
(
bool
cond,
const
char
* file,
size_t
line,
14
std::format_string<Args...> fmt, Args&&... args) {
15
if
(!cond) {
16
std::print(
"{}:{}: "
, file, line);
17
std::println(fmt, std::forward<Args>(args)...);
18
abort();
19
}
20
}
21
22
#define BENSURE(x, m, ...) \
23
Broom_Ensure(x, __FILE__, __LINE__, m __VA_OPT__(, ) __VA_ARGS__)
24
#define BENSURE_IMPLIES(lhs, rhs, m, ...) \
25
BASSERT(!(lhs) || (rhs), m __VA_OPT__(, ) __VA_ARGS__)
26
#define BENSURE_EQ(lhs, rhs, m, ...) \
27
BENSURE(lhs == rhs, m __VA_OPT__(, ) __VA_ARGS__)
28
#define BENSURE_GE(lhs, rhs, m, ...) \
29
BENSURE(lhs >= rhs, m __VA_OPT__(, ) __VA_ARGS__)
30
#define BENSURE_GT(lhs, rhs, m, ...) \
31
BENSURE(lhs > rhs, m __VA_OPT__(, ) __VA_ARGS__)
32
#define BENSURE_LE(lhs, rhs, m, ...) \
33
BENSURE(lhs <= rhs, m __VA_OPT__(, ) __VA_ARGS__)
34
#define BENSURE_LT(lhs, rhs, m, ...) \
35
BENSURE(lhs < rhs, m __VA_OPT__(, ) __VA_ARGS__)
36
#define BENSURE_NE(lhs, rhs, m, ...) \
37
BENSURE(lhs != rhs, m __VA_OPT__(, ) __VA_ARGS__)
38
39
#ifdef BROOM_DEBUG
40
#define BASSERT(x, m, ...) BENSURE(x, m __VA_OPT__(, ) __VA_ARGS__)
41
#define BASSERT_IMPLIES(lhs, rhs, m, ...) \
42
BASSERT(!(lhs) || (rhs), m __VA_OPT__(, ) __VA_ARGS__)
43
#define BASSERT_EQ(lhs, rhs, m, ...) \
44
BASSERT(lhs == rhs, m __VA_OPT__(, ) __VA_ARGS__)
45
#define BASSERT_GE(lhs, rhs, m, ...) \
46
BASSERT(lhs >= rhs, m __VA_OPT__(, ) __VA_ARGS__)
47
#define BASSERT_GT(lhs, rhs, m, ...) \
48
BASSERT(lhs > rhs, m __VA_OPT__(, ) __VA_ARGS__)
49
#define BASSERT_LE(lhs, rhs, m, ...) \
50
BASSERT(lhs <= rhs, m __VA_OPT__(, ) __VA_ARGS__)
51
#define BASSERT_LT(lhs, rhs, m, ...) \
52
BASSERT(lhs < rhs, m __VA_OPT__(, ) __VA_ARGS__)
53
#define BASSERT_NE(lhs, rhs, m, ...) \
54
BASSERT(lhs != rhs, m __VA_OPT__(, ) __VA_ARGS__)
55
#define BROOM_DEBUG_BOOL true
56
#else
57
#define BASSERT(x, m, ...)
58
#define BASSERT_EQ(lhs, rhs, m, ...)
59
#define BASSERT_GE(lhs, rhs, m, ...)
60
#define BASSERT_GT(lhs, rhs, m, ...)
61
#define BASSERT_LE(lhs, rhs, m, ...)
62
#define BASSERT_LT(lhs, rhs, m, ...)
63
#define BASSERT_NE(lhs, rhs, m, ...)
64
#define BROOM_DEBUG_BOOL false
65
#endif
66
67
#ifdef BROOM_DEBUG_SLOW
68
#define BROOM_DEBUG_SLOW_BOOL true
69
#define BASSERT_SLOW(x, m, ...) BENSURE(x, m __VA_OPT__(, ) __VA_ARGS__)
70
#define BASSERT_SLOW_IMPLIES(lhs, rhs, m, ...) \
71
BASSERT_SLOW(!(lhs) || (rhs), m __VA_OPT__(, ) __VA_ARGS__)
72
#define BASSERT_SLOW_EQ(lhs, rhs, m, ...) \
73
BASSERT_SLOW(lhs == rhs, m __VA_OPT__(, ) __VA_ARGS__)
74
#define BASSERT_SLOW_GE(lhs, rhs, m, ...) \
75
BASSERT_SLOW(lhs >= rhs, m __VA_OPT__(, ) __VA_ARGS__)
76
#define BASSERT_SLOW_GT(lhs, rhs, m, ...) \
77
BASSERT_SLOW(lhs > rhs, m __VA_OPT__(, ) __VA_ARGS__)
78
#define BASSERT_SLOW_LE(lhs, rhs, m, ...) \
79
BASSERT_SLOW(lhs <= rhs, m __VA_OPT__(, ) __VA_ARGS__)
80
#define BASSERT_SLOW_LT(lhs, rhs, m, ...) \
81
BASSERT_SLOW(lhs < rhs, m __VA_OPT__(, ) __VA_ARGS__)
82
#define BASSERT_SLOW_NE(lhs, rhs, m, ...) \
83
BASSERT_SLOW(lhs != rhs, m __VA_OPT__(, ) __VA_ARGS__)
84
#else
85
#define BASSERT_SLOW(x, m, ...)
86
#define BASSERT_SLOW_EQ(lhs, rhs, m, ...)
87
#define BASSERT_SLOW_GE(lhs, rhs, m, ...)
88
#define BASSERT_SLOW_GT(lhs, rhs, m, ...)
89
#define BASSERT_SLOW_LE(lhs, rhs, m, ...)
90
#define BASSERT_SLOW_LT(lhs, rhs, m, ...)
91
#define BASSERT_SLOW_NE(lhs, rhs, m, ...)
92
#define BROOM_DEBUG_SLOW_BOOL false
93
#endif
94
95
#ifdef BROOM_VERBOSE_LOG
96
#define BDEBUG_LOG(m, ...) std::print(m __VA_OPT__(, ) __VA_ARGS__)
97
#else
98
#define BDEBUG_LOG(m, ...)
99
#endif
100
101
#if defined(__clang__) || defined(__GNUC__)
102
#define BROOM_NOINLINE __attribute__((noinline))
103
#define BROOM_INLINE __attribute__((always_inline))
104
#elif defined(_MSC_VER)
105
#define BROOM_NOINLINE __declspec(noinline)
106
#define BROOM_INLINE __forceinline
107
#endif
108
109
#define BROOM_UNUSED [[maybe_unused]]
110
111
#if defined(__has_feature)
112
#if __has_feature(address_sanitizer)
113
#define BROOM_NOASAN __attribute__((no_sanitize("address")))
114
#else
115
#define BROOM_NOASAN
116
#endif
117
118
#if __has_feature(thread_sanitizer)
119
#define BROOM_NOTSAN __attribute__((no_sanitize("thread")))
120
#else
121
#define BROOM_NOTSAN
122
#endif
123
124
#if __has_feature(memory_sanitizer)
125
#define BROOM_NOMSAN __attribute__((no_sanitize("memory")))
126
#else
127
#define BROOM_NOMSAN
128
#endif
129
130
#if __has_feature(undefined_sanitizer)
131
#define BROOM_NOUBSAN __attribute__((no_sanitize("undefined")))
132
#else
133
#define BROOM_NOUBSAN
134
#endif
135
136
#if __has_feature(leak_sanitizer)
137
#define BROOM_NOLSAN __attribute__((no_sanitize("leak")))
138
#else
139
#define BROOM_NOLSAN
140
#endif
141
142
#else
143
#define BROOM_NOASAN
144
#define BROOM_NOTSAN
145
#define BROOM_NOMSAN
146
#define BROOM_NOUBSAN
147
#define BROOM_NOLSAN
148
#endif
149
Broom_Ensure
void Broom_Ensure(bool cond, const char *file, size_t line, std::format_string< Args... > fmt, Args &&... args)
Definition
macros.h:13
Generated by
1.9.8