drop alloca #define
[tinycc.git] / include / stdarg.h
blob86e556ca3fb1dde21c41d9285d839fcdef8cc108
1 #ifndef _STDARG_H
2 #define _STDARG_H
4 #ifdef __x86_64__
5 #include <stdlib.h>
7 /* GCC compatible definition of va_list. */
8 struct __va_list_struct {
9 unsigned int gp_offset;
10 unsigned int fp_offset;
11 union {
12 unsigned int overflow_offset;
13 char *overflow_arg_area;
15 char *reg_save_area;
18 typedef struct __va_list_struct *va_list;
20 /* we use __builtin_(malloc|free) to avoid #define malloc tcc_malloc */
21 /* XXX: this lacks the support of aggregated types. */
22 #define va_start(ap, last) \
23 (ap = (va_list)__builtin_malloc(sizeof(struct __va_list_struct)), \
24 *ap = *(struct __va_list_struct*)( \
25 (char*)__builtin_frame_address(0) - 16), \
26 ap->overflow_arg_area = ((char *)__builtin_frame_address(0) + \
27 ap->overflow_offset), \
28 ap->reg_save_area = (char *)__builtin_frame_address(0) - 176 - 16 \
30 #define va_arg(ap, type) \
31 (*(type*)(__builtin_types_compatible_p(type, long double) \
32 ? (ap->overflow_arg_area += 16, \
33 ap->overflow_arg_area - 16) \
34 : __builtin_types_compatible_p(type, double) \
35 ? (ap->fp_offset < 128 + 48 \
36 ? (ap->fp_offset += 16, \
37 ap->reg_save_area + ap->fp_offset - 16) \
38 : (ap->overflow_arg_area += 8, \
39 ap->overflow_arg_area - 8)) \
40 : (ap->gp_offset < 48 \
41 ? (ap->gp_offset += 8, \
42 ap->reg_save_area + ap->gp_offset - 8) \
43 : (ap->overflow_arg_area += 8, \
44 ap->overflow_arg_area - 8)) \
46 #define va_copy(dest, src) \
47 ((dest) = (va_list)malloc(sizeof(struct __va_list_struct)), \
48 *(dest) = *(src))
49 #define va_end(ap) __builtin_free(ap)
51 #else
53 typedef char *va_list;
55 /* only correct for i386 */
56 #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
57 #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
58 #define va_copy(dest, src) (dest) = (src)
59 #define va_end(ap)
61 #endif
63 /* fix a buggy dependency on GCC in libio.h */
64 typedef va_list __gnuc_va_list;
65 #define _VA_LIST_DEFINED
67 #endif /* _STDARG_H */