00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #pragma once
00025 #ifndef ASSUME_H
00026 #define ASSUME_H
00027
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #define __LB(l, ...) l
00061 #define __RB(l, ...) __VA_ARGS__
00062
00063 #include <sys/cdefs.h>
00064 #define __XCB(a, b) __CONCAT(a, b)
00065 #define __XCA(a, b) __XCB(a, __XCB(b, __XCB(atcg ,a)))
00066
00067 #define __emitmsg_fp stderr
00068
00069
00070
00071
00072
00073
00074 #define __atomic_emitmsg(...) \
00075 do { \
00076 if (ftrylockfile(__emitmsg_fp) == 0) { \
00077 fprintf (stderr, __VA_ARGS__); \
00078 funlockfile(__emitmsg_fp); \
00079 } \
00080 } while (0)
00081
00082 #ifndef NDEBUG
00083 # define __terminate(retval) abort()
00084 # define __emitmsg(...) __atomic_emitmsg (__VA_ARGS__)
00085 #else
00086 # define __terminate(retval) return(retval)
00087 # ifdef ASSUME_VERBOSE
00088 # define __emitmsg(...) __atomic_emitmsg (__VA_ARGS__)
00089 # else
00090 # define __emitmsg(...) while(0)
00091 # endif
00092 #endif
00093
00094 #define __assume(expr, exprstr, retval, ...) \
00095 do { \
00096 int __XCA(__cont, __LINE__) = 1; \
00097 if (!(expr)) { \
00098 __emitmsg ("%s:%d (%s): Assumption `%s' not fulfilled!\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, exprstr); \
00099 do {__LB(__VA_ARGS__)} while((__XCA(__cont, __LINE__) = 0)); \
00100 if (__XCA(__cont, __LINE__) == 0) __terminate(retval); \
00101 } else { \
00102 do {__RB(__VA_ARGS__)} while(0); \
00103 } \
00104 } while (0)
00105
00106 #if defined(__GNUC__)
00107 # define assume(expr, retval, ...) __assume(__builtin_expect(expr, 1), #expr, retval, __VA_ARGS__)
00108 #else
00109 # define assume(expr, retval, ...) __assume(expr, #expr, retval, __VA_ARGS__)
00110 #endif
00111
00115 #define assume_r(...) assume(__VA_ARGS__)
00116
00120 #ifndef NDEBUG
00121 # define assume_d(...) assume(__VA_ARGS__)
00122 #else
00123 # define assume_d(...) while(0)
00124 #endif
00125
00126 #endif