modernc.org/qbe@v0.0.9/cc/assets/builtin.h (about) 1 // Copyright 2021 The QBE Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #ifdef __PTRDIFF_TYPE__ 6 typedef __PTRDIFF_TYPE__ ptrdiff_t; 7 #else 8 #error __PTRDIFF_TYPE__ undefined 9 #endif 10 11 #ifdef __SIZE_TYPE__ 12 typedef __SIZE_TYPE__ size_t; 13 #else 14 #error __SIZE_TYPE__ undefined 15 #endif 16 17 #ifdef __WCHAR_TYPE__ 18 typedef __WCHAR_TYPE__ wchar_t; 19 #else 20 #error __WCHAR_TYPE__ undefined 21 #endif 22 23 #ifdef __SIZEOF_INT128__ 24 typedef struct { __INT64_TYPE__ lo, hi; } __int128_t; 25 typedef struct { __UINT64_TYPE__ lo, hi; } __uint128_t; 26 #endif; 27 28 #define __FUNCTION__ __func__ 29 #define __PRETTY_FUNCTION__ __func__ 30 #define __asm __asm__ 31 #define __builtin_constant_p(x) __builtin_constant_p_impl(0, x) 32 #define __builtin_offsetof(type, member) ((__SIZE_TYPE__)&(((type*)0)->member)) 33 #define __builtin_va_arg(ap, type) ((type)__ecc_va_arg(ap)) 34 #define __builtin_va_copy(dst, src) __qbe_va_copy(dst, src) 35 #define __builtin_va_end(ap) __qbe_va_end(ap) 36 #define __builtin_va_start(ap, v) __ecc_va_start(&ap) 37 #define __extension__ 38 #define __has_include(...) __has_include_impl(#__VA_ARGS__) 39 #define __has_include_impl(x) 40 #define __inline__ inline 41 #define __signed signed 42 #define asm __asm__ 43 44 // OS https://sourceforge.net/p/predef/wiki/OperatingSystems/ 45 // Architecture https://sourceforge.net/p/predef/wiki/Architectures/ 46 #ifdef __gnu_linux__ 47 48 // linux/amd64 49 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) 50 // https://stackoverflow.com/a/4958507 51 typedef struct { 52 unsigned int gp_offset; 53 unsigned int fp_offset; 54 void *overflow_arg_area; 55 void *reg_save_area; 56 } __builtin_va_list[1]; 57 58 // linux/386 59 #elif defined(i386) || defined(__i386) || defined(__i386__) 60 // Only by trial and error. 61 // TODO need authoritative source. 62 typedef char *__builtin_va_list; 63 typedef long double __float128; 64 65 66 // linux/arm 67 #elif defined(__arm__) 68 // Procedure Call Standard for the Arm Architecture, Release 2020Q2, Document number: IHI 0042J 69 // https://documentation-service.arm.com/static/5fa187c2b1a7c5445f29028a?token= 70 // 8.1.4 Additional Types, pg. 33 71 typedef struct { 72 void *__ap; 73 } __builtin_va_list; 74 75 // linux/arm64 76 #elif defined(__aarch64__) 77 // https://developer.arm.com/documentation/ihi0055/latest 78 // Table 6, Definition of va_list 79 typedef struct { 80 void *__stack; 81 void *__gr_top; 82 void *__vr_top; 83 int __gr_offs; 84 int __vr_offs; 85 } __builtin_va_list; 86 87 // linux/s390x 88 #elif defined(__s390x__) 89 // Only by trial and error. 90 // TODO need authoritative source. 91 typedef struct { 92 void *a[4]; 93 } __builtin_va_list[1]; 94 95 #else 96 #error unknown/usupported linux architecture 97 typedef void *__builtin_va_list; 98 #endif 99 100 #elif defined(__APPLE__) && defined(__MACH__) 101 102 // darwin/amd64 103 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) 104 // According to https://en.wikipedia.org/wiki/X86_calling_conventions#List_of_x86_calling_conventions 105 // the ABI is the same as for linux/amd64 106 typedef struct { 107 unsigned int gp_offset; 108 unsigned int fp_offset; 109 void *overflow_arg_area; 110 void *reg_save_area; 111 } __builtin_va_list[1]; 112 113 #else 114 #error unknown/usupported darwin architecture 115 typedef void *__builtin_va_list; 116 #endif 117 118 #elif defined(__MINGW64__) 119 120 // windows/amd64 121 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) 122 // Only by trial and error. 123 // TODO need authoritative source. 124 typedef char *__builtin_va_list; 125 typedef __builtin_va_list va_list; 126 127 #else 128 #error unknown/usupported windows architecture 129 typedef void *__builtin_va_list; 130 #endif 131 132 #else 133 #error unknown/usupported operating system 134 typedef void *__builtin_va_list; 135 #endif 136 137 #if defined(__MINGW32__) || defined(__MINGW64__) 138 int gnu_printf(const char *format, ...); 139 int gnu_scanf(const char *format, ...); 140 int ms_printf(const char *format, ...); 141 int ms_scanf(const char *format, ...); 142 #define _VA_LIST_DEFINED 143 #define __extension__ 144 #endif 145 146 __UINT16_TYPE__ __builtin_bswap16(__UINT16_TYPE__ x); 147 __UINT32_TYPE__ __builtin_bswap32(__UINT32_TYPE__ x); 148 __UINT64_TYPE__ __builtin_bswap64(__UINT64_TYPE__ x); 149 char *__builtin___strcat_chk(char *dest, const char *src, size_t os); 150 char *__builtin___strcpy_chk(char *dest, const char *src, size_t os); 151 char *__builtin___strncpy_chk(char *dest, char *src, size_t n, size_t os); 152 char *__builtin_strchr(const char *s, int c); 153 char *__builtin_strcpy(char *dest, const char *src); 154 char *__builtin_strncpy(char *dest, const char *src, size_t n); 155 double __builtin_copysign( double x, double y ); 156 double __builtin_fabs(double x); 157 double __builtin_huge_val(void); 158 double __builtin_inf(void); 159 double __builtin_nan(const char *str); 160 float __builtin_copysignf( float x, float y ); 161 float __builtin_huge_valf(void); 162 float __builtin_inff(void); 163 float __builtin_nanf(const char *str); 164 int __builtin___snprintf_chk(char *s, size_t maxlen, int flag, size_t os, const char *fmt, ...); 165 int __builtin___sprintf_chk(char *s, int flag, size_t os, const char *fmt, ...); 166 int __builtin___vsnprintf_chk(char *s, size_t maxlen, int flag, size_t os, const char *fmt, __builtin_va_list ap); 167 int __builtin__snprintf_chk(char * str, size_t maxlen, int flag, size_t strlen, const char * format); 168 int __builtin_abs(int j); 169 int __builtin_add_overflow(); 170 int __builtin_clrsb(int x); 171 int __builtin_clrsbl(long); 172 int __builtin_clrsbll(long long); 173 int __builtin_clz(unsigned int x); 174 int __builtin_clzl(unsigned long); 175 int __builtin_clzll(unsigned long long); 176 int __builtin_constant_p_impl(); 177 int __builtin_ctz(unsigned int x); 178 int __builtin_ctzl(unsigned long); 179 int __builtin_ctzll(unsigned long long); 180 int __builtin_ffs(int i); 181 int __builtin_ffsl(long int i); 182 int __builtin_ffsll(long long); 183 int __builtin_isgreater(); 184 int __builtin_isgreaterequal(); 185 int __builtin_isinf(x); 186 int __builtin_isinff(float x); 187 int __builtin_isinfl(long double x); 188 int __builtin_isless(); 189 int __builtin_islessequal(); 190 int __builtin_islessgreater(); 191 int __builtin_isnan(double); 192 int __builtin_isprint(int c); 193 int __builtin_isunordered(); 194 int __builtin_memcmp(const void *s1, const void *s2, size_t n); 195 int __builtin_mul_overflow(); 196 int __builtin_parity(unsigned int x); 197 int __builtin_parityl(unsigned long); 198 int __builtin_parityll(unsigned long long); 199 int __builtin_popcount(unsigned int x); 200 int __builtin_popcountl(unsigned long); 201 int __builtin_popcountll(unsigned long long); 202 int __builtin_printf(const char *format, ...); 203 int __builtin_setjmp(); 204 int __builtin_signbit(); 205 int __builtin_snprintf(char *str, size_t size, const char *format, ...); 206 int __builtin_sprintf(char *str, const char *format, ...); 207 int __builtin_strcmp(const char *s1, const char *s2); 208 int __builtin_sub_overflow(); 209 long __builtin_expect(long exp, long c); 210 long double __builtin_huge_vall(void); 211 long double __builtin_infl(void); 212 long double __builtin_nan(const char *str); 213 long long __builtin_llabs(long long j); 214 size_t __builtin_object_size(void * ptr, int type); 215 size_t __builtin_strlen(const char *s); 216 void *__builtin___memcpy_chk(void *dest, const void *src, size_t n, size_t os); 217 void *__builtin___memmove_chk(void *dest, const void *src, size_t n, size_t os); 218 void *__builtin___memset_chk(void *dstpp, int c, size_t len, size_t dstlen); 219 void *__builtin_alloca(size_t size); 220 void *__builtin_frame_address (unsigned int level); 221 void *__builtin_malloc(size_t size); 222 void *__builtin_memcpy(void *dest, const void *src, size_t n); 223 void *__builtin_memmove(void *dest, const void *src, size_t n); 224 void *__builtin_memset(void *s, int c, size_t n); 225 void *__builtin_mmap(void *addr, size_t length, int prot, int flags, int fd, __INTPTR_TYPE__ offset); 226 void *__builtin_return_address(unsigned int level); 227 void *__ecc_va_arg(__builtin_va_list ap); 228 void __builtin_abort(void); 229 void __builtin_exit(int status); 230 void __builtin_free(void *ptr); 231 void __builtin_longjmp(); 232 void __builtin_prefetch(const void *addr, ...); 233 void __builtin_trap(void); 234 void __builtin_unreachable(void); 235 void __ecc_va_start(__builtin_va_list *ap); 236 void __qbe_va_copy(__builtin_va_list dst, __builtin_va_list src); 237 void __qbe_va_end(__builtin_va_list ap);