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