Merge evaluate() functionnality into find_edges(), get delta for missed edges.
[goir.git] / log.hh
blob3b29d66f2daf06a16dbbd8e74e75749e6483bdca
1 #ifndef _GOIR_LOG_HH
2 #define _GOIR_LOG_HH
4 #include <cstdarg>
5 #include <cstdio>
7 namespace goir {
8 namespace log {
10 typedef enum {
11 wm_trace, wm_summary, // watermarks
12 histo,
13 data_out,
14 edge_details,
15 debug_eval,
17 NULLFLAG = -1
18 } flag;
20 /* Tracing flags currently in effect. */
21 extern unsigned flags;
24 * Takes a NULLFLAG-terminated list of flag arguments, and return
25 * a bitmask with all those flags set.
27 static inline unsigned bitmask(flag f, ...) {
28 unsigned mask = 1 << f;
29 va_list vl;
30 va_start(vl, f);
31 do {
32 flag vf = (flag)va_arg(vl, int);
33 if (vf == NULLFLAG) break;
34 mask |= 1 << vf;
35 } while(1);
36 va_end(vl);
38 return mask;
41 static inline bool is_set(flag f) { return (flags & bitmask(f, NULLFLAG)); }
44 * Trace to stderr, conditionned by the activation of the given
45 * flag.
47 static inline void trace(flag f, const char* fmt, ...) {
48 va_list vl;
49 va_start(vl, fmt);
50 if (is_set(f))
51 vfprintf(stderr, fmt, vl);
52 va_end(vl);
58 #endif // _GOIR_LOG_HH