aboutsummaryrefslogtreecommitdiff
path: root/include/stdarg.h
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2010-12-28 19:32:40 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2010-12-28 19:32:40 +0900
commit0ed7ba3f5e79f407a206b387079c9fd68327064b (patch)
tree1e1ddb5103cf8a90b8cef2b7c28eef1606ac4a41 /include/stdarg.h
parent07fd82b4113c9f912383dff448e3dd8b71179b7b (diff)
downloadtinycc-0ed7ba3f5e79f407a206b387079c9fd68327064b.tar.gz
tinycc-0ed7ba3f5e79f407a206b387079c9fd68327064b.tar.bz2
Support struct arguments with stdarg.h
- add __builtin_va_arg_types to check how arguments were passed - move most code of stdarg into libtcc1.c - remove __builtin_malloc and __builtin_free - add a test case based on the bug report (http://www.mail-archive.com/tinycc-devel@nongnu.org/msg03036.html)
Diffstat (limited to 'include/stdarg.h')
-rw-r--r--include/stdarg.h52
1 files changed, 10 insertions, 42 deletions
diff --git a/include/stdarg.h b/include/stdarg.h
index b5844d0..6dd6e9e 100644
--- a/include/stdarg.h
+++ b/include/stdarg.h
@@ -3,51 +3,19 @@
#ifdef __x86_64__
#ifndef _WIN64
-#include <stdlib.h>
-/* GCC compatible definition of va_list. */
-struct __va_list_struct {
- unsigned int gp_offset;
- unsigned int fp_offset;
- union {
- unsigned int overflow_offset;
- char *overflow_arg_area;
- };
- char *reg_save_area;
-};
+typedef void *va_list;
-typedef struct __va_list_struct *va_list;
+va_list __va_start(void *fp);
+void *__va_arg(va_list ap, int arg_type, int size);
+va_list __va_copy(va_list src);
+void __va_end(va_list ap);
-/* we use __builtin_(malloc|free) to avoid #define malloc tcc_malloc */
-/* XXX: this lacks the support of aggregated types. */
-#define va_start(ap, last) \
- (ap = (va_list)__builtin_malloc(sizeof(struct __va_list_struct)), \
- *ap = *(struct __va_list_struct*)( \
- (char*)__builtin_frame_address(0) - 16), \
- ap->overflow_arg_area = ((char *)__builtin_frame_address(0) + \
- ap->overflow_offset), \
- ap->reg_save_area = (char *)__builtin_frame_address(0) - 176 - 16 \
- )
-#define va_arg(ap, type) \
- (*(type*)(__builtin_types_compatible_p(type, long double) \
- ? (ap->overflow_arg_area += 16, \
- ap->overflow_arg_area - 16) \
- : __builtin_types_compatible_p(type, double) \
- ? (ap->fp_offset < 128 + 48 \
- ? (ap->fp_offset += 16, \
- ap->reg_save_area + ap->fp_offset - 16) \
- : (ap->overflow_arg_area += 8, \
- ap->overflow_arg_area - 8)) \
- : (ap->gp_offset < 48 \
- ? (ap->gp_offset += 8, \
- ap->reg_save_area + ap->gp_offset - 8) \
- : (ap->overflow_arg_area += 8, \
- ap->overflow_arg_area - 8)) \
- ))
-#define va_copy(dest, src) \
- ((dest) = (va_list)malloc(sizeof(struct __va_list_struct)), \
- *(dest) = *(src))
-#define va_end(ap) __builtin_free(ap)
+#define va_start(ap, last) ((ap) = __va_start(__builtin_frame_address(0)))
+#define va_arg(ap, type) \
+ (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type))));
+#define va_copy(dest, src) ((dest) = __va_copy(src))
+#define va_end(ap) __va_end(ap)
#else /* _WIN64 */
typedef char *va_list;