-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.h
More file actions
459 lines (407 loc) · 11.6 KB
/
config.h
File metadata and controls
459 lines (407 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#pragma once
// MSVC++ with unknown standard lib
#ifndef RPP_MSVC
# define RPP_MSVC _MSC_VER
#endif
// MSVC++ with VC standard libs
#ifndef RPP_MSVC_WIN
# if (_WIN32 && _MSC_VER)
# define RPP_MSVC_WIN 1
# else
# define RPP_MSVC_WIN 0
# endif
#endif
// GCC with unknown standard lib
#ifndef RPP_GCC
# if (__GNUC__ && !__clang__)
# define RPP_GCC 1
# else
# define RPP_GCC 0
# endif
#endif
// Clang using GCC/LLVM standard libs
#ifndef RPP_CLANG_LLVM
# if (__GNUC__ && __clang__)
# define RPP_CLANG_LLVM 1
# else
# define RPP_CLANG_LLVM 0
# endif
#endif
// Android, any compiler
#ifndef RPP_ANDROID
# if defined(__ANDROID__)
# define RPP_ANDROID 1
# else
# define RPP_ANDROID 0
# endif
#endif
// Android using Clang
#ifndef RPP_ANDROID_CLANG
# if defined(__ANDROID__) && defined(__clang__)
# define RPP_ANDROID_CLANG 1
# else
# define RPP_ANDROID_CLANG 0
# endif
#endif
#ifndef RPPAPI
# if _MSC_VER
# define RPPAPI //__declspec(dllexport)
# else // clang/gcc
# define RPPAPI __attribute__((visibility("default")))
# endif
#endif
#ifndef RPP_EXTERNC
# ifdef __cplusplus
# define RPP_EXTERNC extern "C"
# else
# define RPP_EXTERNC
# endif
#endif
#ifndef RPPCAPI
# define RPPCAPI RPP_EXTERNC RPPAPI
#endif
#if __cplusplus
# if _MSC_VER
# define RPP_HAS_CXX17 (_MSVC_LANG > 201402)
# else
# define RPP_HAS_CXX17 (__cplusplus >= 201703L)
# endif
#endif
#if __cplusplus
# if _MSC_VER
# define RPP_HAS_CXX20 (_MSVC_LANG >= 202002L)
# else
# define RPP_HAS_CXX20 (__cplusplus >= 202002L)
# endif
#endif
#if __cplusplus
# if _MSC_VER
# define RPP_HAS_CXX23 (_MSVC_LANG > 202002L)
# else
# define RPP_HAS_CXX23 (__cplusplus > 202002L)
# endif
#endif
#if __cplusplus
# if _MSC_VER
# define RPP_HAS_CXX26 (_MSVC_LANG > 202302L)
# else
# define RPP_HAS_CXX26 (__cplusplus > 202302L)
# endif
#endif
#if __cplusplus
# if RPP_HAS_CXX17
# define RPP_INLINE_STATIC inline static
# else
# define RPP_INLINE_STATIC static
# endif
#endif
#if __cplusplus
# if __cpp_if_constexpr
# define RPP_CXX17_IF_CONSTEXPR if constexpr
# else
# define RPP_CXX17_IF_CONSTEXPR if
# endif
#endif
/// @brief evaluates TRUE if AddressSanitizer is enabled
#if defined(__SANITIZE_ADDRESS__)
# define RPP_ASAN 1
#elif __clang__
# if __has_feature(address_sanitizer)
# define RPP_ASAN 1
# endif
#endif
#if defined(__SANITIZE_THREAD__)
# define RPP_TSAN 1
#elif __clang__
# if __has_feature(thread_sanitizer)
# define RPP_TSAN 1
# endif
#endif
#if __clang__
# if __has_feature(undefined_behavior_sanitizer)
# define RPP_UBSAN 1
# endif
#endif
/// @brief evaluates TRUE if any sanitizers are enabled
#ifndef RPP_SANITIZERS
# if defined(RPP_ASAN) || defined(RPP_TSAN) || defined(RPP_UBSAN)
# define RPP_SANITIZERS 1
# else
# define RPP_SANITIZERS 0
# endif
#endif
/// @brief QT support detection
#if !defined(RPP_HAS_QT) && defined(__cplusplus)
# if defined(QT_VERSION) || defined(QT_CORE_LIB)
# define RPP_HAS_QT 1
# else
# define RPP_HAS_QT 0
# endif
#endif
/// @brief Unicode (wstring) support conditionally enabled for relevant platforms
#ifndef RPP_ENABLE_UNICODE
// explicitly disable for embedded platforms that shouldn't use UTF16 strings
# if defined(YOCTO_LINUX) || defined(MIPS) || defined(RASPI)
# define RPP_ENABLE_UNICODE 0
# elif defined(_MSC_VER) || defined(__ANDROID__) || defined(__linux__)
# define RPP_ENABLE_UNICODE 1
# else
# define RPP_ENABLE_UNICODE 0
# endif
#endif
#ifndef RPP_FREERTOS
# define RPP_FREERTOS 0
#endif
#ifndef RPP_STM32_HAL
# define RPP_STM32_HAL 0
#else
# ifndef RPP_STM32_HAL_H
# error "RPP_STM32_HAL_H has to be defined and has to have a valid path to the STM32 HAL header file, e.g., <stm32f1xx_hal.h>"
# endif
#endif
#if RPP_FREERTOS || RPP_STM32_HAL
# define RPP_BARE_METAL 1
#else
# define RPP_BARE_METAL 0
#endif
#ifndef RPP_USE_EYALROZ_PRINTF
# define RPP_USE_EYALROZ_PRINTF 0
#endif
#ifndef RPP_CORTEX_M_ARCH
# if RPP_STM32_HAL // STM32 is always Cortex-M
# define RPP_CORTEX_M_ARCH 1
# else
# define RPP_CORTEX_M_ARCH 0
# endif
#endif
#if RPP_CORTEX_M_ARCH
# ifndef RPP_CORTEX_M_CORE_H
# error "RPP_CORTEX_M_CORE_H has to be defined and has to have a valid path to the STM32 core header file, e.g., <core_cm3.h>"
# endif
# ifndef RPP_CORTEX_M_DEVICE_H
# error "RPP_CORTEX_M_DEVICE_H has to be defined and has to have a valid path to the device header file (provided by vendor), e.g., <stm32f103xx.h>"
# endif
#endif
#if defined(__thumb__) || defined(__arm__)
# define RPP_ARM_ARCH 1
#else
# define RPP_ARM_ARCH 0
#endif
//// @note Some functions get inlined too aggressively, leading to some serious code bloat
//// Need to hint the compiler to take it easy ^_^'
#ifndef NOINLINE
# if _MSC_VER
# define NOINLINE __declspec(noinline)
# else
# define NOINLINE __attribute__((noinline))
# endif
#endif
//// @note Some strong hints that some functions are merely wrappers, so should be forced inline
#ifndef FINLINE
# if _MSC_VER
# define FINLINE __forceinline
# else
# define FINLINE inline __attribute__((always_inline))
# endif
#endif
#if INTPTR_MAX == INT64_MAX
# define RPP_64BIT 1
#endif
#ifdef _LIBCPP_STD_VER
# define _HAS_STD_BYTE (_LIBCPP_STD_VER > 16)
#elif !defined(_HAS_STD_BYTE)
# define _HAS_STD_BYTE 0
#endif
// libc++ headers do transitive includes, which causes some issues with clang-tidy, so we disable them here
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
# define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES 1
#endif
#ifndef NOCOPY_NOMOVE
#define NOCOPY_NOMOVE(T) \
T(T&& fwd) = delete; \
T& operator=(T&& fwd) = delete; \
T(const T&) = delete; \
T& operator=(const T&) = delete;
#endif
#ifndef NODISCARD
# if __cplusplus >= 201500
# define NODISCARD [[nodiscard]]
# elif _MSC_VER > 1916
# ifdef __has_cpp_attribute
# if __has_cpp_attribute(nodiscard)
# define NODISCARD [[nodiscard]]
# endif
# endif
# ifndef NODISCARD
# define NODISCARD
# endif
# else
# define NODISCARD
# endif
#endif
// MSVC printf format string validator
// USAGE:
// void foobar(int arg1, PRINTF_FMTSTR const char* formatArg2, ...) PRINTF_CHECKFMT2;
// void foobar(int arg1, PRINTF_FMTSTR const char* formatArg2, ...)
// {
// }
#ifndef PRINTF_FMTSTR
# if _MSC_VER
# define PRINTF_FMTSTR _In_z_ _Printf_format_string_
# else
# define PRINTF_FMTSTR
# endif
#endif
// printf format string validator
// validates the 1st argument as a printf vararg format string, 2nd arg as input
// for member functions, the first argument is the 'this' pointer
#ifndef PRINTF_CHECKFMT1 // 1st arg is format, 2nd arg is input
# if !_MSC_VER
# define PRINTF_CHECKFMT1 __attribute__((__format__ (__printf__, 1, 2)))
# define PRINTF_CHECKFMT2 __attribute__((__format__ (__printf__, 2, 3)))
# define PRINTF_CHECKFMT3 __attribute__((__format__ (__printf__, 3, 4)))
# define PRINTF_CHECKFMT4 __attribute__((__format__ (__printf__, 4, 5)))
# define PRINTF_CHECKFMT5 __attribute__((__format__ (__printf__, 5, 6)))
# define PRINTF_CHECKFMT6 __attribute__((__format__ (__printf__, 6, 7)))
# define PRINTF_CHECKFMT7 __attribute__((__format__ (__printf__, 7, 8)))
# define PRINTF_CHECKFMT8 __attribute__((__format__ (__printf__, 8, 9)))
# else
# define PRINTF_CHECKFMT1
# define PRINTF_CHECKFMT2
# define PRINTF_CHECKFMT3
# define PRINTF_CHECKFMT4
# define PRINTF_CHECKFMT5
# define PRINTF_CHECKFMT6
# define PRINTF_CHECKFMT7
# define PRINTF_CHECKFMT8
# endif
#endif
// Define the noreturn attribute
// Prefixed before function return type:
// RPP_NORETURN void func() { ... }
#ifndef RPP_NORETURN
# if !__clang__ && __cplusplus >= 201103
# define RPP_NORETURN [[noreturn]]
# elif _MSC_VER
# define RPP_NORETURN __declspec(noreturn)
# elif __GNUC__ || __clang__
# define RPP_NORETURN __attribute__((noreturn))
# else
# define RPP_NORETURN
# endif
#endif
// Provides hints to the compiler about lifetimes of input arguments.
// Required for proper strview validation, to prevent dangling pointers.
#ifndef RPP_LIFETIMEBOUND
# if defined(_MSC_VER) // MSVC
# if _MSC_VER >= 1937 // support was added in MSVC 17.7 (19.37)
# define RPP_LIFETIMEBOUND [[msvc::lifetimebound]]
# else
# define RPP_LIFETIMEBOUND
# endif
# elif defined(__clang__)
# define RPP_LIFETIMEBOUND [[clang::lifetimebound]]
# else
# define RPP_LIFETIMEBOUND
# endif
#endif // RPP_LIFETIMEBOUND
// Provides a hint to the compiler that this type is a CRT (Coroutine Return Type)
// Clang (>18) will enforce that all functions that return a CRT are either coroutines or
// or marked with [[clang::coro_wrapper]]. Clang will enforce this with an error.
#ifndef RPP_CORO_RETURN_TYPE
# if defined(__clang__) && __clang_major__ > 18
# define RPP_CORO_RETURN_TYPE [[clang::coro_return_type]]
# define RPP_CORO_WRAPPER [[clang::coro_wrapper]]
# define RPP_CORO_LIFETIMEBOUND [[clang::coro_lifetimebound]]
# else
# define RPP_CORO_RETURN_TYPE
# define RPP_CORO_WRAPPER
# define RPP_CORO_LIFETIMEBOUND
# endif
#endif // RPP_CORO_RETURN_TYPE
// Define the basic size of integer types
#if _MSC_VER
# define RPP_SHORT_SIZE 2
# define RPP_INT_SIZE 4
# define RPP_LONG_SIZE 4
# define RPP_LONG_LONG_SIZE 8
#else // GCC/Clang
# define RPP_SHORT_SIZE __SIZEOF_SHORT__
# define RPP_INT_SIZE __SIZEOF_INT__
# define RPP_LONG_SIZE __SIZEOF_LONG__
# define RPP_LONG_LONG_SIZE __SIZEOF_LONG_LONG__
#endif // _MSC_VER
#define RPP_INT64_MAX 0x7FFFFFFFFFFFFFFFLL
#define RPP_INT64_MIN 0x8000000000000000LL
#define RPP_UINT64_MAX 0xFFFFFFFFFFFFFFFFULL
#define RPP_UINT64_MIN 0x0000000000000000ULL
#define RPP_INT32_MAX 0x7FFFFFFF
#define RPP_INT32_MIN 0x80000000
#define RPP_UINT32_MAX 0xFFFFFFFFU
#define RPP_UINT32_MIN 0x00000000U
#ifndef RPP_BIG_ENDIAN
# if _MSC_VER
# if defined(_M_X64) || defined(_M_IX86)
# define RPP_LITTLE_ENDIAN 1
# else
# error "Unsupported Windows machine type"
# endif
# else
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define RPP_LITTLE_ENDIAN 1
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define RPP_BIG_ENDIAN 1
# else
# error "Unsupported endianness"
# endif
# endif
#endif
#ifndef RPP_HAS_EXCEPTIONS
# if defined(_MSC_VER)
# if defined(_CPPUNWIND)
# define RPP_HAS_EXCEPTIONS 1
# else
# define RPP_HAS_EXCEPTIONS 0
# endif
# elif defined(__GNUC__) || defined(__clang__)
# if defined(__EXCEPTIONS) || defined(__cpp_exceptions)
# define RPP_HAS_EXCEPTIONS 1
# else
# define RPP_HAS_EXCEPTIONS 0
# endif
# else
# define RPP_HAS_EXCEPTIONS 1 // By default, assume exceptions are supported
# endif
#endif
#ifdef __cplusplus
namespace rpp
{
#ifndef RPP_BASIC_INTEGER_TYPEDEFS
#define RPP_BASIC_INTEGER_TYPEDEFS
using byte = unsigned char;
using ushort = unsigned short;
using uint = unsigned int;
using ulong = unsigned long;
using int16 = short;
using uint16 = unsigned short;
#if RPP_INT_SIZE == 4
using int32 = int;
using uint32 = unsigned int;
#else
using int32 = long;
using uint32 = unsigned long;
#endif
using int64 = long long;
using uint64 = unsigned long long;
#endif // RPP_BASIC_INTEGER_TYPEDEFS
/**
* @brief Common base type for wrapping arguments in <rpp/debugging.h>
* Helps us to efficiently convert custom argument types to strings.
*/
template<class T>
struct __wrap
{
FINLINE static constexpr const T& w(const T& arg) noexcept { return arg; }
};
}
#endif