00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef INCLUDE_DEBUG_MACROS_H
00022 #define INCLUDE_DEBUG_MACROS_H
00023
00024 #include "debug/utils.h"
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifdef _WIN32
00035 #define __PRETTY_FUNCTION__ __FUNCTION__
00036 #ifndef NPRETTY_COLORS
00037 #define NPRETTY_COLORS
00038 #endif
00039 #endif
00040
00041
00042
00043
00044 #ifndef NPRETTY_COLORS
00045 #define THIN "0"
00046 #define BOLD "1"
00047 #define RED(S) "\033["S";31m"
00048 #define GREEN(S) "\033["S";32m"
00049 #define YELLOW(S) "\033["S";33m"
00050 #define BLUE(S) "\033["S";34m"
00051 #define MAGENTA(S) "\033["S";35m"
00052 #define CYAN(S) "\033["S";36m"
00053 #define WHITE(S) "\033["S";37m"
00054 #define NORMAL "\033[0;0m"
00055 #else
00056 #define THIN ""
00057 #define BOLD ""
00058 #define RED(S) ""
00059 #define GREEN(S) ""
00060 #define YELLOW(S) ""
00061 #define BLUE(S) ""
00062 #define MAGENTA(S) ""
00063 #define CYAN(S) ""
00064 #define WHITE(S) ""
00065 #define NORMAL ""
00066 #endif
00067
00068
00069
00070
00071 #ifdef __cplusplus
00072 #define DEFAULT_OUT std::cout
00073 #define DEFAULT_ERR std::cerr
00074 #else
00075 #define DEFAULT_OUT stdout
00076 #define DEFAULT_ERR stderr
00077 #endif
00078
00079 #ifndef NDEBUG
00080
00081
00082
00083 #ifdef __cplusplus
00084 #define PRINT(OUT,S) (OUT) << (S)
00085 #define PRINT_INT(OUT,N) (OUT) << (N)
00086 #else
00087 #define PRINT(OUT,S) fprintf(OUT,S)
00088 #define PRINT_INT(OUT,N) fprintf(OUT,"%d",(N))
00089 #endif
00090
00091
00092
00093 #ifndef NSHORTFILENAME
00094 #define PRINT_FILE(OUT) PRINT(OUT, debug_shortSource(__FILE__))
00095 #else
00096 #define PRINT_FILE(OUT) PRINT(OUT, __FILE__)
00097 #endif
00098
00099
00100
00101
00102
00103 #define DODEBUG(STATEMENT) STATEMENT
00104
00105
00106
00107
00108 #define PRINT_INFO(INFO) \
00109 do { \
00110 PRINT(DEFAULT_OUT, __PRETTY_FUNCTION__); \
00111 PRINT(DEFAULT_OUT, ": " INFO "\n"); \
00112 } while(0)
00113
00114
00115
00116
00117
00118
00119
00120 #ifndef NPRETTY_COLORS
00121 #define PRINT_CINFO(COLOR,INFO) \
00122 do { \
00123 PRINT(DEFAULT_OUT, COLOR); \
00124 PRINT(DEFAULT_OUT, __PRETTY_FUNCTION__); \
00125 PRINT(DEFAULT_OUT, ": " INFO NORMAL "\n");\
00126 } while(0)
00127 #else
00128 #define PRINT_CINFO(COLOR,INFO) PRINT_INFO(INFO)
00129 #endif
00130
00131
00132
00133
00134
00135 #ifndef NPRETTY_COLORS
00136 #define PRINT_COLOR(OUT, COLOR) PRINT(OUT, COLOR)
00137 #else
00138 #define PRINT_COLOR(OUT, COLOR)
00139 #endif
00140
00141
00142
00143
00144
00145
00146 #define ASSERT(COND, PRINTME) \
00147 do { \
00148 if (!(COND)) \
00149 { \
00150 PRINT_COLOR(DEFAULT_ERR, RED(BOLD)); \
00151 PRINT_FILE(DEFAULT_ERR); \
00152 PRINT(DEFAULT_ERR, "("); \
00153 PRINT_INT(DEFAULT_ERR, __LINE__); \
00154 PRINT(DEFAULT_ERR, ") "); \
00155 PRINT(DEFAULT_ERR, __PRETTY_FUNCTION__); \
00156 PRINT(DEFAULT_ERR, ": Assertion `" \
00157 MAGENTA(BOLD) #COND RED(BOLD) \
00158 "' failed." NORMAL "\n"); \
00159 PRINTME; \
00160 abort(); \
00161 } \
00162 } while(0)
00163
00164
00165
00166
00167 #ifndef DISABLE_ASSERTX
00168 #define assertx(STATEMENT) assert(STATEMENT)
00169 #define DODEBUGX(STATEMENT) STATEMENT
00170 #else
00171 #define assertx(STATEMENT)
00172 #define DODEBUGX(STATEMENT)
00173 #endif
00174
00175 #else
00176
00177 #define PRINT(OUT,S)
00178 #define PRINT_INT(OUT,N)
00179 #define PRINT_FILE(OUT)
00180 #define DODEBUG(STATEMENT)
00181 #define PRINT_INFO(INFO)
00182 #define PRINT_CINFO(COLOR,INFO)
00183 #define ASSERT(COND,PRINTME)
00184 #define PRINT_COLOR(OUT, COLOR)
00185 #define assertx(STATEMENT)
00186 #define DODEBUGX(STATEMENT)
00187
00188 #endif
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 #if INTEL_ARCH
00202
00203 #define RAND() rand()
00204
00205
00206 #define RAND64() \
00207 ((((uint64_t)rand()) << 32) | \
00208 (((uint64_t)rand())))
00209
00210 #else
00211
00212 #define RAND() (rand() | (rand() << 16))
00213
00214
00215 #define RAND64() \
00216 ((((uint64_t)rand()) << 48) | \
00217 (((uint64_t)rand()) << 32) | \
00218 (((uint64_t)rand()) << 16) | \
00219 (((uint64_t)rand())))
00220
00221 #endif
00222
00223
00224 #endif