Fix test90 for 32 bits targets
[tinycc.git] / include / tccdefs.h
blob814edf37b3c6253ca5fb5e66eeb1d8aed4e66ac3
1 /* tccdefs.h
3 Nothing is defined before this file except target machine, target os
4 and the few things related to option settings in tccpp.c:tcc_predefs().
6 This file is either included at runtime as is, or converted and
7 included as C-strings at compile-time (depending on CONFIG_TCC_PREDEFS).
9 Note that line indent matters:
11 - in lines starting at column 1, platform macros are replaced by
12 corresponding TCC target compile-time macros. See conftest.c for
13 the list of platform macros supported in lines starting at column 1.
15 - only lines indented >= 4 are actually included into the executable,
16 check tccdefs_.h.
19 #if __SIZEOF_POINTER__ == 4
20 /* 32bit systems. */
21 #if defined TARGETOS_OpenBSD
22 #define __SIZE_TYPE__ unsigned long
23 #define __PTRDIFF_TYPE__ long
24 #else
25 #define __SIZE_TYPE__ unsigned int
26 #define __PTRDIFF_TYPE__ int
27 #endif
28 #define __ILP32__ 1
29 #define __INT64_TYPE__ long long
30 #elif __SIZEOF_LONG__ == 4
31 /* 64bit Windows. */
32 #define __SIZE_TYPE__ unsigned long long
33 #define __PTRDIFF_TYPE__ long long
34 #define __LLP64__ 1
35 #define __INT64_TYPE__ long long
36 #else
37 /* Other 64bit systems. */
38 #define __SIZE_TYPE__ unsigned long
39 #define __PTRDIFF_TYPE__ long
40 #define __LP64__ 1
41 # if defined __linux__
42 #define __INT64_TYPE__ long
43 # else /* APPLE, BSD */
44 #define __INT64_TYPE__ long long
45 # endif
46 #endif
47 #define __SIZEOF_INT__ 4
48 #define __INT_MAX__ 0x7fffffff
49 #if __SIZEOF_LONG__ == 4
50 #define __LONG_MAX__ 0x7fffffffL
51 #else
52 #define __LONG_MAX__ 0x7fffffffffffffffL
53 #endif
54 #define __SIZEOF_LONG_LONG__ 8
55 #define __LONG_LONG_MAX__ 0x7fffffffffffffffLL
56 #define __CHAR_BIT__ 8
57 #define __ORDER_LITTLE_ENDIAN__ 1234
58 #define __ORDER_BIG_ENDIAN__ 4321
59 #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
60 #if defined _WIN32
61 #define __WCHAR_TYPE__ unsigned short
62 #define __WINT_TYPE__ unsigned short
63 #elif defined __linux__
64 #define __WCHAR_TYPE__ int
65 #define __WINT_TYPE__ unsigned int
66 #else
67 #define __WCHAR_TYPE__ int
68 #define __WINT_TYPE__ int
69 #endif
71 #if __STDC_VERSION__ == 201112L
72 # define __STDC_NO_ATOMICS__ 1
73 # define __STDC_NO_COMPLEX__ 1
74 # define __STDC_NO_THREADS__ 1
75 #if !defined _WIN32
76 # define __STDC_UTF_16__ 1
77 # define __STDC_UTF_32__ 1
78 #endif
79 #endif
81 #if defined _WIN32
82 #define __declspec(x) __attribute__((x))
83 #define __cdecl
85 #elif defined __FreeBSD__
86 #define __GNUC__ 9
87 #define __GNUC_MINOR__ 3
88 #define __GNUC_PATCHLEVEL__ 0
89 #define __GNUC_STDC_INLINE__ 1
90 #define __NO_TLS 1
91 #define __RUNETYPE_INTERNAL 1
92 # if __SIZEOF_POINTER__ == 8
93 /* FIXME, __int128_t is used by setjump */
94 #define __int128_t struct { unsigned char _dummy[16] __attribute((aligned(16))); }
95 #define __SIZEOF_SIZE_T__ 8
96 #define __SIZEOF_PTRDIFF_T__ 8
97 #else
98 #define __SIZEOF_SIZE_T__ 4
99 #define __SIZEOF_PTRDIFF_T__ 4
100 # endif
102 #elif defined __FreeBSD_kernel__
104 #elif defined __NetBSD__
105 #define __GNUC__ 4
106 #define __GNUC_MINOR__ 1
107 #define __GNUC_PATCHLEVEL__ 0
108 #define _Pragma(x)
109 #define __ELF__ 1
110 #if defined __aarch64__
111 #define _LOCORE /* avoids usage of __asm */
112 #endif
114 #elif defined __OpenBSD__
115 #define __GNUC__ 4
116 #define _ANSI_LIBRARY 1
118 #elif defined __APPLE__
119 /* emulate APPLE-GCC to make libc's headerfiles compile: */
120 #define __GNUC__ 4 /* darwin emits warning on GCC<4 */
121 #define __APPLE_CC__ 1 /* for <TargetConditionals.h> */
122 #define __LITTLE_ENDIAN__ 1
123 #define _DONT_USE_CTYPE_INLINE_ 1
124 /* avoids usage of GCC/clang specific builtins in libc-headerfiles: */
125 #define __FINITE_MATH_ONLY__ 1
126 #define _FORTIFY_SOURCE 0
128 #elif defined __ANDROID__
129 #define BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD
130 #define __PRETTY_FUNCTION__ __FUNCTION__
131 #define __has_builtin(x) 0
132 #define _Nonnull
133 #define _Nullable
135 #else
136 /* Linux */
138 #endif
139 /* Some derived integer types needed to get stdint.h to compile correctly on some platforms */
140 #ifndef __NetBSD__
141 #define __UINTPTR_TYPE__ unsigned __PTRDIFF_TYPE__
142 #define __INTPTR_TYPE__ __PTRDIFF_TYPE__
143 #endif
144 #define __INT32_TYPE__ int
146 #if !defined _WIN32
147 /* glibc defines */
148 #define __REDIRECT(name, proto, alias) name proto __asm__ (#alias)
149 #define __REDIRECT_NTH(name, proto, alias) name proto __asm__ (#alias) __THROW
150 #endif
152 /* skip __builtin... with -E */
153 #ifndef __TCC_PP__
155 #define __builtin_offsetof(type, field) ((__SIZE_TYPE__)&((type*)0)->field)
156 #define __builtin_extract_return_addr(x) x
157 #if !defined __linux__ && !defined _WIN32
158 /* used by math.h */
159 #define __builtin_huge_val() 1e500
160 #define __builtin_huge_valf() 1e50f
161 #define __builtin_huge_vall() 1e5000L
162 # if defined __APPLE__
163 #define __builtin_nanf(ignored_string) (0.0F/0.0F)
164 /* used by floats.h to implement FLT_ROUNDS C99 macro. 1 == to nearest */
165 #define __builtin_flt_rounds() 1
166 /* used by _fd_def.h */
167 #define __builtin_bzero(p, ignored_size) bzero(p, sizeof(*(p)))
168 # else
169 #define __builtin_nanf(ignored_string) (0.0F/0.0F)
170 # endif
171 #endif
173 /* __builtin_va_list */
174 #if defined __x86_64__
175 #if !defined _WIN32
176 /* GCC compatible definition of va_list. */
177 /* This should be in sync with the declaration in our lib/libtcc1.c */
178 typedef struct {
179 unsigned gp_offset, fp_offset;
180 union {
181 unsigned overflow_offset;
182 char *overflow_arg_area;
184 char *reg_save_area;
185 } __builtin_va_list[1];
187 void *__va_arg(__builtin_va_list ap, int arg_type, int size, int align);
188 #define __builtin_va_start(ap, last) \
189 (*(ap) = *(__builtin_va_list)((char*)__builtin_frame_address(0) - 24))
190 #define __builtin_va_arg(ap, t) \
191 (*(t *)(__va_arg(ap, __builtin_va_arg_types(t), sizeof(t), __alignof__(t))))
192 #define __builtin_va_copy(dest, src) (*(dest) = *(src))
194 #else /* _WIN64 */
195 typedef char *__builtin_va_list;
196 #define __builtin_va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \
197 ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))
198 #endif
200 #elif defined __arm__
201 typedef char *__builtin_va_list;
202 #define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x)
203 #define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \
204 & ~(_tcc_alignof(type) - 1))
205 #define __builtin_va_start(ap,last) (ap = ((char *)&(last)) + ((sizeof(last)+3)&~3))
206 #define __builtin_va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
207 &~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
209 #elif defined __aarch64__
210 #if defined __APPLE__
211 typedef struct {
212 void *__stack;
213 } __builtin_va_list;
215 #else
216 typedef struct {
217 void *__stack, *__gr_top, *__vr_top;
218 int __gr_offs, __vr_offs;
219 } __builtin_va_list;
221 #endif
222 #elif defined __riscv
223 typedef char *__builtin_va_list;
224 #define __va_reg_size (__riscv_xlen >> 3)
225 #define _tcc_align(addr,type) (((unsigned long)addr + __alignof__(type) - 1) \
226 & -(__alignof__(type)))
227 #define __builtin_va_arg(ap,type) (*(sizeof(type) > (2*__va_reg_size) ? *(type **)((ap += __va_reg_size) - __va_reg_size) : (ap = (va_list)(_tcc_align(ap,type) + (sizeof(type)+__va_reg_size - 1)& -__va_reg_size), (type *)(ap - ((sizeof(type)+ __va_reg_size - 1)& -__va_reg_size)))))
229 #else /* __i386__ */
230 typedef char *__builtin_va_list;
231 #define __builtin_va_start(ap,last) (ap = ((char *)&(last)) + ((sizeof(last)+3)&~3))
232 #define __builtin_va_arg(ap,t) (*(t*)((ap+=(sizeof(t)+3)&~3)-((sizeof(t)+3)&~3)))
234 #endif
235 #define __builtin_va_end(ap) (void)(ap)
236 #ifndef __builtin_va_copy
237 # define __builtin_va_copy(dest, src) (dest) = (src)
238 #endif
240 /* TCC BBUILTIN AND BOUNDS ALIASES */
241 #ifdef __leading_underscore
242 # define __RENAME(X) __asm__("_"X)
243 #else
244 # define __RENAME(X) __asm__(X)
245 #endif
247 #ifdef __BOUNDS_CHECKING_ON
248 # define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME("__bound_"#name);
249 # define __BOUND(ret,name,params) ret name params __RENAME("__bound_"#name);
250 #else
251 # define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME(#name);
252 # define __BOUND(ret,name,params)
253 #endif
254 #ifdef _WIN32
255 #define __BOTH __BOUND
256 #define __BUILTIN(ret,name,params)
257 #else
258 #define __BOTH(ret,name,params) __BUILTINBC(ret,name,params)__BOUND(ret,name,params)
259 #define __BUILTIN(ret,name,params) ret __builtin_##name params __RENAME(#name);
260 #endif
262 __BOTH(void*, memcpy, (void *, const void*, __SIZE_TYPE__))
263 __BOTH(void*, memmove, (void *, const void*, __SIZE_TYPE__))
264 __BOTH(void*, memset, (void *, int, __SIZE_TYPE__))
265 __BOTH(int, memcmp, (const void *, const void*, __SIZE_TYPE__))
266 __BOTH(__SIZE_TYPE__, strlen, (const char *))
267 __BOTH(char*, strcpy, (char *, const char *))
268 __BOTH(char*, strncpy, (char *, const char*, __SIZE_TYPE__))
269 __BOTH(int, strcmp, (const char*, const char*))
270 __BOTH(int, strncmp, (const char*, const char*, __SIZE_TYPE__))
271 __BOTH(char*, strcat, (char*, const char*))
272 __BOTH(char*, strncat, (char*, const char*, __SIZE_TYPE__))
273 __BOTH(char*, strchr, (const char*, int))
274 __BOTH(char*, strrchr, (const char*, int))
275 __BOTH(char*, strdup, (const char*))
276 #if defined __ARM_EABI__
277 __BOUND(void*,__aeabi_memcpy,(void*,const void*,__SIZE_TYPE__))
278 __BOUND(void*,__aeabi_memmove,(void*,const void*,__SIZE_TYPE__))
279 __BOUND(void*,__aeabi_memmove4,(void*,const void*,__SIZE_TYPE__))
280 __BOUND(void*,__aeabi_memmove8,(void*,const void*,__SIZE_TYPE__))
281 __BOUND(void*,__aeabi_memset,(void*,int,__SIZE_TYPE__))
282 #endif
284 #if defined __linux__ || defined __APPLE__ // HAVE MALLOC_REDIR
285 #define __MAYBE_REDIR __BUILTIN
286 #else
287 #define __MAYBE_REDIR __BOTH
288 #endif
289 __MAYBE_REDIR(void*, malloc, (__SIZE_TYPE__))
290 __MAYBE_REDIR(void*, realloc, (void *, __SIZE_TYPE__))
291 __MAYBE_REDIR(void*, calloc, (__SIZE_TYPE__, __SIZE_TYPE__))
292 __MAYBE_REDIR(void*, memalign, (__SIZE_TYPE__, __SIZE_TYPE__))
293 __MAYBE_REDIR(void, free, (void*))
294 #if defined __i386__ || defined __x86_64__
295 __BOTH(void*, alloca, (__SIZE_TYPE__))
296 #else
297 __BUILTIN(void*, alloca, (__SIZE_TYPE__))
298 #endif
299 __BUILTIN(void, abort, (void))
300 __BOUND(void, longjmp, ())
301 #if !defined _WIN32
302 __BOUND(void*, mmap, ())
303 __BOUND(int, munmap, ())
304 #endif
305 #undef __BUILTINBC
306 #undef __BUILTIN
307 #undef __BOUND
308 #undef __BOTH
309 #undef __MAYBE_REDIR
310 #undef __RENAME
312 #if !defined _WIN32
313 #define __BUILTIN_EXTERN(name,u) \
314 int __builtin_##name(u int); \
315 int __builtin_##name##l(u long); \
316 int __builtin_##name##ll(u long long);
318 __BUILTIN_EXTERN(ffs,)
319 __BUILTIN_EXTERN(clz, unsigned)
320 __BUILTIN_EXTERN(ctz, unsigned)
321 __BUILTIN_EXTERN(clrsb,)
322 __BUILTIN_EXTERN(popcount, unsigned)
323 __BUILTIN_EXTERN(parity, unsigned)
324 #undef __BUILTIN_EXTERN
325 #endif
327 #endif /* ndef __TCC_PP__ */