-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_assert.h
113 lines (90 loc) · 2.66 KB
/
lib_assert.h
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
// Copyright (c) 2015, XMOS Ltd, All rights reserved
#ifndef __xassert_h__
#define __xassert_h__
#ifdef __xassert_conf_h_exists__
#include "xassert_conf.h"
#endif
#ifdef __debug_conf_h_exists__
#include "debug_conf.h"
#endif
#ifndef DEBUG_UNIT
#define DEBUG_UNIT APPLICATION
#endif
#ifndef XASSERT_ENABLE_ASSERTIONS
#define XASSERT_ENABLE_ASSERTIONS 1
#endif
#ifndef XASSERT_ENABLE_DEBUG
#define XASSERT_ENABLE_DEBUG 0
#endif
#ifndef XASSERT_ENABLE_LINE_NUMBERS
#define XASSERT_ENABLE_LINE_NUMBERS 0
#endif
#define XASSERT_JOIN0(x,y) x ## y
#define XASSERT_JOIN(x,y) XASSERT_JOIN0(x,y)
#if XASSERT_JOIN(XASSERT_ENABLE_ASSERTIONS_,DEBUG_UNIT)
# define XASSERT_ENABLE_ASSERTIONS0 1
#endif
#if XASSERT_JOIN(XASSERT_DISABLE_ASSERTIONS_,DEBUG_UNIT)
# define XASSERT_ENABLE_ASSERTIONS0 0
#endif
#if !defined(XASSERT_ENABLE_ASSERTIONS0)
# define XASSERT_ENABLE_ASSERTIONS0 XASSERT_ENABLE_ASSERTIONS
#endif
#if XASSERT_JOIN(XASSERT_ENABLE_DEBUG_,DEBUG_UNIT)
# define XASSERT_ENABLE_DEBUG0 1
#endif
#if XASSERT_JOIN(XASSERT_DISABLE_DEBUG_,DEBUG_UNIT)
# define XASSERT_ENABLE_DEBUG0 0
#endif
#if !defined(XASSERT_ENABLE_DEBUG0)
# define XASSERT_ENABLE_DEBUG0 XASSERT_ENABLE_DEBUG
#endif
#if XASSERT_ENABLE_DEBUG0
# include "print.h"
#endif
#if XASSERT_ENABLE_LINE_NUMBERS
# define xassert_print_line do { printstr(" (" __FILE__ ":"); \
printint(__LINE__); \
printstrln(")"); \
} while(0)
#else
# define xassert_print_line do { printstrln(""); } while(0)
#endif
#if XASSERT_ENABLE_ASSERTIONS0
# if XASSERT_ENABLE_DEBUG0
# define xassert(e) do { if (!(e)) {\
printstr(#e); xassert_print_line; \
__builtin_trap();} \
} while(0)
# else
# define xassert(e) do { if (!(e)) __builtin_trap();} while(0)
# endif
#else
# define xassert(e) // disabled
#endif
#if XASSERT_ENABLE_ASSERTIONS0
# if XASSERT_ENABLE_DEBUG0
# define unreachable(msg) do { printstr(msg); xassert_print_line; __builtin_trap();} while(0)
# else
# define unreachable(msg) do { __builtin_trap();} while(0)
# endif
#else
# define unreachable(msg) do { __builtin_unreachable();} while(0)
#endif
#if XASSERT_ENABLE_DEBUG0
# define fail(msg) do { printstr(msg); xassert_print_line; __builtin_trap();} while(0)
#else
# define fail(msg) do { __builtin_trap();} while(0)
#endif
inline int xassert_msg(const char msg[]) { return 1; }
#ifdef __XC__
#define _msg(x) xassert_msg(x)
#define msg(x) xassert_msg(x)
#else
#define _msg(x) x
#define msg(x) x
#endif
#if !defined(assert) && !XASSERT_DISABLE_ASSERT_DEF
#define assert(...) xassert(__VA_ARGS__)
#endif
#endif // __xassert_h__