History

new subdirs: include, lib, tests

grischka committed 17 years ago

Commit ea5e81b1 parent e8a52a816 files · +0 −6Browse files

Showing the changes to include/stdarg.h (1 of 16 files). Show all

Unified · Split

include/stdarg.h+83−0
@@ -0,0 +1,83 @@
1#ifndef _STDARG_H
2#define _STDARG_H
3
4#ifdef __x86_64__
5
6#ifdef __TINYC__
7
8#include <stdlib.h>
9
10/* GCC compatible definition of va_list. */
11struct __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;
17 };
18 char *reg_save_area;
19};
20
21typedef struct __va_list_struct *va_list;
22
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 \
32 )
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)) \
48 ))
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)
53
54#else
55
56/* for GNU C */
57
58typedef __builtin_va_list va_list;
59
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)
64
65#endif
66
67#else
68
69typedef char *va_list;
70
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)
76
77#endif
78
79/* fix a buggy dependency on GCC in libio.h */
80typedef va_list __gnuc_va_list;
81#define _VA_LIST_DEFINED
82
83#endif /* _STDARG_H */