7dd657048e45f7c89d62172c8fde346af7bd39f7
[riscv-isa-sim.git] / riscv / common.h
1 #ifndef _RISCV_COMMON_H
2 #define _RISCV_COMMON_H
3
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7
8 #ifdef __cplusplus
9 # include <stdexcept>
10 # define print_and_die(s) throw std::runtime_error(s)
11 #else
12 # define print_and_die(s) do { fprintf(stderr,"%s\n",s); abort(); } while(0)
13 #endif
14
15 #define demand(cond,str,...) \
16 do { if(!(cond)) { \
17 char __str[256]; \
18 snprintf(__str,256,"in %s, line %d: " str, \
19 __FILE__,__LINE__,##__VA_ARGS__); \
20 print_and_die(__str); \
21 } } while(0)
22
23 #define static_assert(x) switch (x) case 0: case (x):
24
25 #define likely(x) __builtin_expect(x, 1)
26 #define unlikely(x) __builtin_expect(x, 0)
27
28 #endif