Add va_* macro implementation for ARM
[tinycc.git] / include / stdarg.h
blob3c1318ebe4d1a95e296b0c5c39adc873c1118001
1 #ifndef _STDARG_H
2 #define _STDARG_H
4 #ifdef __x86_64__
5 #ifndef _WIN64
7 typedef void *va_list;
9 va_list __va_start(void *fp);
10 void *__va_arg(va_list ap, int arg_type, int size, int align);
11 va_list __va_copy(va_list src);
12 void __va_end(va_list ap);
14 #define va_start(ap, last) ((ap) = __va_start(__builtin_frame_address(0)))
15 #define va_arg(ap, type) \
16 (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type))))
17 #define va_copy(dest, src) ((dest) = __va_copy(src))
18 #define va_end(ap) __va_end(ap)
20 #else /* _WIN64 */
21 typedef char *va_list;
22 #define va_start(ap,last) __builtin_va_start(ap,last)
23 #define va_arg(ap,type) (ap += 8, sizeof(type)<=8 ? *(type*)ap : **(type**)ap)
24 #define va_copy(dest, src) ((dest) = (src))
25 #define va_end(ap)
26 #endif
28 #elif __arm__
29 typedef char *va_list;
30 #define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x)
31 #define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \
32 & ~(_tcc_alignof(type) - 1))
33 #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
34 #define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
35 &~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
36 #define va_copy(dest, src) (dest) = (src)
37 #define va_end(ap)
39 #else /* __i386__ */
40 typedef char *va_list;
41 /* only correct for i386 */
42 #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
43 #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
44 #define va_copy(dest, src) (dest) = (src)
45 #define va_end(ap)
46 #endif
48 /* fix a buggy dependency on GCC in libio.h */
49 typedef va_list __gnuc_va_list;
50 #define _VA_LIST_DEFINED
52 #endif /* _STDARG_H */