Fix silly typos in the previous change.
[tinycc.git] / stdarg.h
blobc49e6dfde8df071740a799b56968949ec4f400a2
1 #ifndef _STDARG_H
2 #define _STDARG_H
4 #ifdef __x86_64__
6 #ifdef __TINYC__
8 #include <stdlib.h>
10 /* GCC compatible definition of va_list. */
11 struct __va_list_struct {
12 unsigned int gp_offset;
13 unsigned int fp_offset;
14 union {
15 unsigned int overflow_offset;
16 char *overflow_arg_area;
18 char *reg_save_area;
21 typedef struct __va_list_struct *va_list;
23 /* we use __builtin_(malloc|free) to avoid #define malloc tcc_malloc */
24 /* XXX: this lacks the support of aggregated types. */
25 #define va_start(ap, last) \
26 (ap = (va_list)__builtin_malloc(sizeof(struct __va_list_struct)), \
27 *ap = *(struct __va_list_struct*)( \
28 (char*)__builtin_frame_address(0) - 16), \
29 ap->overflow_arg_area = ((char *)__builtin_frame_address(0) + \
30 ap->overflow_offset), \
31 ap->reg_save_area = (char *)__builtin_frame_address(0) - 176 - 16 \
33 #define va_arg(ap, type) \
34 (*(type*)(__builtin_types_compatible_p(type, long double) \
35 ? (ap->overflow_arg_area += 16, \
36 ap->overflow_arg_area - 16) \
37 : __builtin_types_compatible_p(type, double) \
38 ? (ap->fp_offset < 128 + 48 \
39 ? (ap->fp_offset += 16, \
40 ap->reg_save_area + ap->fp_offset - 16) \
41 : (ap->overflow_arg_area += 8, \
42 ap->overflow_arg_area - 8)) \
43 : (ap->gp_offset < 48 \
44 ? (ap->gp_offset += 8, \
45 ap->reg_save_area + ap->gp_offset - 8) \
46 : (ap->overflow_arg_area += 8, \
47 ap->overflow_arg_area - 8)) \
49 #define va_copy(dest, src) \
50 ((dest) = (va_list)malloc(sizeof(struct __va_list_struct)), \
51 *(dest) = *(src))
52 #define va_end(ap) __builtin_free(ap)
54 #else
56 /* for GNU C */
58 typedef __builtin_va_list va_list;
60 #define va_start(ap, last) __builtin_va_start(ap, last)
61 #define va_arg(ap, type) __builtin_va_arg(ap, type)
62 #define va_copy(dest, src) __builtin_va_copy(dest, src)
63 #define va_end(ap) __builtin_va_end(ap)
65 #endif
67 #else
69 typedef char *va_list;
71 /* only correct for i386 */
72 #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
73 #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
74 #define va_copy(dest, src) (dest) = (src)
75 #define va_end(ap)
77 #endif
79 /* fix a buggy dependency on GCC in libio.h */
80 typedef va_list __gnuc_va_list;
81 #define _VA_LIST_DEFINED
83 #endif /* _STDARG_H */