Fix TSO Bugs
[satcheck.git] / common.h
1 /*      Copyright (c) 2015 Regents of the University of California
2  *
3  *      Author: Brian Demsky <bdemsky@uci.edu>
4  *
5  *      This program is free software; you can redistribute it and/or
6  *      modify it under the terms of the GNU General Public License
7  *      version 2 as published by the Free Software Foundation.
8  */
9
10 /** @file common.h
11  *  @brief General purpose macros.
12  */
13
14 #ifndef __COMMON_H__
15 #define __COMMON_H__
16
17 #include <stdio.h>
18 #include "config.h"
19
20 extern int model_out;
21
22 #define model_print(fmt, ...) do { dprintf(model_out, fmt, ##__VA_ARGS__); } while (0)
23
24 #ifdef CONFIG_DEBUG
25 #define DEBUG(fmt, ...) do { model_print("*** %15s:%-4d %25s() *** " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); } while (0)
26 #define DBG() DEBUG("\n")
27 #define DBG_ENABLED() (1)
28 #else
29 #define DEBUG(fmt, ...)
30 #define DBG()
31 #define DBG_ENABLED() (0)
32 #endif
33
34 void assert_hook(void);
35
36 #ifdef CONFIG_ASSERT
37 #define ASSERT(expr) \
38 do { \
39         if (!(expr)) { \
40                 fprintf(stderr, "Error: assertion failed in %s at line %d\n", __FILE__, __LINE__); \
41                 /* print_trace(); // Trace printing may cause dynamic memory allocation */ \
42                 assert_hook();                           \
43                 exit(EXIT_FAILURE); \
44         } \
45 } while (0)
46 #else
47 #define ASSERT(expr) \
48         do { } while (0)
49 #endif /* CONFIG_ASSERT */
50
51 #define error_msg(...) fprintf(stderr, "Error: " __VA_ARGS__)
52
53 void print_trace(void);
54 #endif /* __COMMON_H__ */