00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00040 #ifndef _MACEDON_MACROS_H
00041 #define _MACEDON_MACROS_H
00042
00043 #ifndef MAX_LOG
00044 #define MAX_LOG UINT_MAX
00045 #endif
00046
00047 #ifndef SELECTOR_TAG
00048 #define SELECTOR_TAG
00049 #endif
00050
00051 #include "RandomUtil.h"
00052 #include "LogIdSet.h"
00053
00054 #define MSEC *1000
00055 #define SEC *1000 MSEC
00056
00057
00058
00059
00060
00061 #define LOGLOGTYPE Log::MaceOutputStream
00062
00064 inline int randint(int x) { return RandomUtil::randInt(x); }
00065
00073 #define upcallAllVoid(func, args...) \
00074 for(std::map<int, typeof_upcall_##func*>::iterator _m_i = map_typeof_upcall_##func.begin(); \
00075 _m_i != map_typeof_upcall_##func.end(); _m_i++) { \
00076 upcall_##func(args, _m_i->first); \
00077 }
00078
00088 #define upcallAll(var, ag, func, args...) \
00089 for(std::map<int, typeof_upcall_##func*>::iterator _m_i = map_typeof_upcall_##func.begin(); \
00090 _m_i != map_typeof_upcall_##func.end(); _m_i++) { \
00091 ag(var, upcall_##func(args, _m_i->first)); \
00092 }
00093
00094 #define andEq(x, y) x = x && y
00095
00096 #define orEq(x, y) x = x || y
00097
00099 #define ADD_LOG_BACKING \
00100 LOGLOGTYPE* _maceout __attribute((unused)) = NULL;\
00101 LOGLOGTYPE* _macedbg[6] __attribute((unused)) = { NULL, NULL, NULL, NULL, NULL, NULL };\
00102 LOGLOGTYPE* _macewarn __attribute((unused)) = NULL;\
00103 LOGLOGTYPE* _maceerr __attribute((unused)) = NULL;\
00104 LOGLOGTYPE* _macecompiler[2] __attribute((unused)) = { NULL, NULL };\
00105
00106
00113 #define ADD_SELECTORS(x) \
00114 static const std::string selector = x; \
00115 static const LogIdSet* const selectorId __attribute((unused)) = new LogIdSet(selector); \
00116 static const log_id_t __trace_selector __attribute((unused)) = Log::getTraceId(x); \
00117 ADD_LOG_BACKING
00118
00120 #define ADD_FUNC_SELECTORS ADD_SELECTORS(__PRETTY_FUNCTION__)
00121
00123 #define PREPARE_FUNCTION \
00124 uint64_t _curtime __attribute__((unused)) = 0; \
00125
00126
00132 #define maceDebug(pri, args...) do { if(pri < MAX_LOG) { Log::logf(selectorId->debug, pri, args); } } while(0)
00133
00148 #if MAX_LOG != 0
00149 #define maceLog(args...) Log::logf(selectorId->log, args)
00150 #define maceWarn(args...) Log::logf(selectorId->warn, args)
00151 #define maceError(args...) Log::logf(selectorId->error, args)
00152 #else
00153 #define maceLog(args...)
00154 #define maceWarn(args...)
00155 #define maceError(args...)
00156 #endif
00157
00162 #define maceCompiler(pri,args...) do { if(pri < MAX_LOG) { Log::logf(selectorId->compiler, pri, args); } } while(0)
00163
00164
00165 #define traceout Log::trace(__trace_selector)
00166 #define tracein Log::replay(__trace_selector)
00167
00169 #define maceout (_maceout == NULL? *(_maceout = &Log::log((0 != MAX_LOG?selectorId->log:Log::NULL_ID))): *_maceout)
00171 #define macedbg(pri) (pri < 6? (_macedbg[pri] == NULL? *(_macedbg[pri] = &Log::log((pri < MAX_LOG?selectorId->debug:Log::NULL_ID), (log_level_t)pri)): *_macedbg[pri]): Log::log((pri < MAX_LOG?selectorId->debug:Log::NULL_ID), (log_level_t)pri))
00173 #define macewarn (_macewarn == NULL? *(_macewarn = &Log::log((0 != MAX_LOG?selectorId->warn:Log::NULL_ID))): *_macewarn)
00175 #define maceerr (_maceerr == NULL? *(_maceerr = &Log::log((0 != MAX_LOG?selectorId->error:Log::NULL_ID))): *_maceerr)
00177 #define macecompiler(pri) (pri < 2? (_macecompiler[pri] == NULL? *(_macecompiler[pri] = &Log::log((pri < MAX_LOG?selectorId->compiler:Log::NULL_ID), (log_level_t)pri)): *_macecompiler[pri]): Log::log((pri < MAX_LOG?selectorId->compiler:Log::NULL_ID), (log_level_t)pri))
00178
00179 #define curtime (_curtime==0?(_curtime=TimeUtil::timeu()):_curtime)
00180
00182
00198 #define EXPECT(x) if(!(x)) { maceerr << "EXPECT_FAILURE: Condition " << #x << " failed!" << Log::endl; } else
00199
00200 #endif // _MACEDON_MACROS_H