forked from uli/cascade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.h
58 lines (51 loc) · 1.7 KB
/
debug.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
/*
* debug.h
*
* (C) Copyright 2014 Ulrich Hecht
*
* This file is part of CASCADE. CASCADE is almost free software; you can
* redistribute it and/or modify it under the terms of the Cascade Public
* License 1.0. Read the file "LICENSE" for details.
*/
#include <stdio.h>
#include <stdint.h>
#define DEBUG_WARN 0x00000010UL
#define DEBUG_IO 0x00000100UL
#define DEBUG_TRACE 0x00001000UL
#define DEBUG_MEM 0x00010000UL
#define DEBUG_OP 0x00100000UL
#define DEBUG_INT 0x01000000UL
#define DEBUG_LCD 0x10000000UL
#define DEBUG_SERIAL 0x20000000UL
#define DEBUG_ABRIDGED 0x80000000UL
#define DEBUG_IFACE 0x00000002UL
#define DEBUG_OS 0x00000004UL
#define DEBUG_KEY 0x00000008UL
#define DEBUG_HSIO 0x00000020UL
#define DEBUG_EVENT 0x00000040UL
#define DEBUG_HINTS 0x00000080UL
#define DEBUG_UI 0x00000200UL
#define DEBUG_DEFAULT (DEBUG_WARN | DEBUG_SERIAL | DEBUG_ABRIDGED | DEBUG_IFACE | DEBUG_OS | DEBUG_KEY | DEBUG_HSIO | DEBUG_HINTS | DEBUG_UI)
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#ifdef __MINGW32__
extern FILE *win_stderr;
#endif
#ifdef NDEBUG
#define DEBUG(level, bla...) do {} while(0)
#else
#ifdef __MINGW32__
#define DEBUG(level, bla...) \
do { if (unlikely(debug_level & DEBUG_ ##level)) __mingw_fprintf(win_stderr, bla); /* fflush(win_stderr); */ } while(0)
#else
#define DEBUG(level, bla...) \
do { if (unlikely(debug_level & DEBUG_ ##level)) fprintf(stderr, bla); } while(0)
#endif
#endif
#ifdef __MINGW32__
#undef ERROR
#define ERROR(bla...) do { __mingw_fprintf(win_stderr, bla); fflush(win_stderr); } while(0)
#else
#define ERROR(bla...) fprintf(stderr, bla)
#endif
extern uint32_t debug_level;