00001 #pragma once
00002 #ifndef ASSUME_H
00003 #define ASSUME_H
00004
00005 #include <stdio.h>
00006 #include <stdlib.h>
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
00034
00035
00036
00037 #define __LB(l, ...) l
00038 #define __RB(l, ...) __VA_ARGS__
00039
00040 #include <sys/cdefs.h>
00041 #define __XCB(a, b) __CONCAT(a, b)
00042 #define __XCA(a, b) __XCB(a, __XCB(b, __XCB(atcg ,a)))
00043
00044 #define __emitmsg_fp stderr
00045
00046
00047
00048
00049
00050
00051 #define __atomic_emitmsg(...) \
00052 do { \
00053 if (ftrylockfile(__emitmsg_fp) == 0) { \
00054 fprintf (stderr, __VA_ARGS__); \
00055 funlockfile(__emitmsg_fp); \
00056 } \
00057 } while (0)
00058
00059 #ifndef NDEBUG
00060 # define __terminate(retval) abort()
00061 # define __emitmsg(...) __atomic_emitmsg (__VA_ARGS__)
00062 #else
00063 # define __terminate(retval) return(retval)
00064 # ifdef ASSUME_VERBOSE
00065 # define __emitmsg(...) __atomic_emitmsg (__VA_ARGS__)
00066 # else
00067 # define __emitmsg(...) while(0)
00068 # endif
00069 #endif
00070
00071 #define __assume(expr, exprstr, retval, ...) \
00072 do { \
00073 int __XCA(__cont, __LINE__) = 1; \
00074 if (!(expr)) { \
00075 __emitmsg ("%s:%d (%s): Assumption `%s' not fulfilled!\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, exprstr); \
00076 do {__LB(__VA_ARGS__)} while((__XCA(__cont, __LINE__) = 0)); \
00077 if (__XCA(__cont, __LINE__) == 0) __terminate(retval); \
00078 } else { \
00079 do {__RB(__VA_ARGS__)} while(0); \
00080 } \
00081 } while (0)
00082
00083 #if defined(__GNUC__)
00084 # define assume(expr, retval, ...) __assume(__builtin_expect(expr, 1), #expr, retval, __VA_ARGS__)
00085 #else
00086 # define assume(expr, retval, ...) __assume(expr, #expr, retval, __VA_ARGS__)
00087 #endif
00088
00092 #define assume_r(...) assume(__VA_ARGS__)
00093
00097 #ifndef NDEBUG
00098 # define assume_d(...) assume(__VA_ARGS__)
00099 #else
00100 # define assume_d(...) while(0)
00101 #endif
00102
00103 #endif