diff options
Diffstat (limited to 'tinyc/include')
-rw-r--r-- | tinyc/include/float.h | 2 | ||||
-rw-r--r-- | tinyc/include/stdarg.h | 84 | ||||
-rw-r--r-- | tinyc/include/stdbool.h | 1 | ||||
-rw-r--r-- | tinyc/include/stddef.h | 46 | ||||
-rw-r--r-- | tinyc/include/tcclib.h | 78 | ||||
-rw-r--r-- | tinyc/include/varargs.h | 13 |
6 files changed, 97 insertions, 127 deletions
diff --git a/tinyc/include/float.h b/tinyc/include/float.h index 5f1c6f73c..f16f1f0cb 100644 --- a/tinyc/include/float.h +++ b/tinyc/include/float.h @@ -27,7 +27,7 @@ #define DBL_MAX_10_EXP 308 /* horrible intel long double */ -#ifdef __i386__ +#if defined __i386__ || defined __x86_64__ #define LDBL_MANT_DIG 64 #define LDBL_DIG 18 diff --git a/tinyc/include/stdarg.h b/tinyc/include/stdarg.h index 86e556ca3..10ce733b4 100644 --- a/tinyc/include/stdarg.h +++ b/tinyc/include/stdarg.h @@ -2,10 +2,11 @@ #define _STDARG_H #ifdef __x86_64__ -#include <stdlib.h> +#ifndef _WIN64 +//This should be in sync with the declaration on our lib/libtcc1.c /* GCC compatible definition of va_list. */ -struct __va_list_struct { +typedef struct { unsigned int gp_offset; unsigned int fp_offset; union { @@ -13,51 +14,62 @@ struct __va_list_struct { char *overflow_arg_area; }; char *reg_save_area; -}; +} __va_list_struct; -typedef struct __va_list_struct *va_list; +typedef __va_list_struct va_list[1]; -/* 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) +void __va_start(__va_list_struct *ap, void *fp); +void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); -#else +#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0)) +#define va_arg(ap, type) \ + (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) +#define va_copy(dest, src) (*(dest) = *(src)) +#define va_end(ap) + +/* avoid conflicting definition for va_list on Macs. */ +#define _VA_LIST_T +#else /* _WIN64 */ typedef char *va_list; +#define va_start(ap,last) __builtin_va_start(ap,last) +#define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \ + ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8)) +#define va_copy(dest, src) ((dest) = (src)) +#define va_end(ap) +#endif +#elif __arm__ +typedef char *va_list; +#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x) +#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \ + & ~(_tcc_alignof(type) - 1)) +#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) +#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ + &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) +#define va_copy(dest, src) (dest) = (src) +#define va_end(ap) + +#elif defined(__aarch64__) +typedef struct { + void *__stack; + void *__gr_top; + void *__vr_top; + int __gr_offs; + int __vr_offs; +} va_list; +#define va_start(ap, last) __va_start(ap, last) +#define va_arg(ap, type) __va_arg(ap, type) +#define va_end(ap) +#define va_copy(dest, src) ((dest) = (src)) + +#else /* __i386__ */ +typedef char *va_list; /* only correct for i386 */ #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) #define va_copy(dest, src) (dest) = (src) #define va_end(ap) - #endif /* fix a buggy dependency on GCC in libio.h */ diff --git a/tinyc/include/stdbool.h b/tinyc/include/stdbool.h index 6ed13a611..d2ee446e7 100644 --- a/tinyc/include/stdbool.h +++ b/tinyc/include/stdbool.h @@ -6,5 +6,6 @@ #define bool _Bool #define true 1 #define false 0 +#define __bool_true_false_are_defined 1 #endif /* _STDBOOL_H */ diff --git a/tinyc/include/stddef.h b/tinyc/include/stddef.h index aef5b3923..694d50375 100644 --- a/tinyc/include/stddef.h +++ b/tinyc/include/stddef.h @@ -1,20 +1,54 @@ #ifndef _STDDEF_H #define _STDDEF_H -#define NULL ((void *)0) typedef __SIZE_TYPE__ size_t; +typedef __PTRDIFF_TYPE__ ssize_t; typedef __WCHAR_TYPE__ wchar_t; typedef __PTRDIFF_TYPE__ ptrdiff_t; -#define offsetof(type, field) ((size_t) &((type *)0)->field) +typedef __PTRDIFF_TYPE__ intptr_t; +typedef __SIZE_TYPE__ uintptr_t; #ifndef __int8_t_defined #define __int8_t_defined -typedef char int8_t; -typedef short int int16_t; -typedef int int32_t; -typedef long long int int64_t; +typedef signed char int8_t; +typedef signed short int int16_t; +typedef signed int int32_t; +#ifdef __LP64__ +typedef signed long int int64_t; +#else +typedef signed long long int int64_t; +#endif +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +#ifdef __LP64__ +typedef unsigned long int uint64_t; +#else +typedef unsigned long long int uint64_t; +#endif +#endif + +#ifndef NULL +#define NULL ((void*)0) #endif +#define offsetof(type, field) ((size_t)&((type *)0)->field) + void *alloca(size_t size); #endif + +/* Older glibc require a wint_t from <stddef.h> (when requested + by __need_wint_t, as otherwise stddef.h isn't allowed to + define this type). Note that this must be outside the normal + _STDDEF_H guard, so that it works even when we've included the file + already (without requiring wint_t). Some other libs define _WINT_T + if they've already provided that type, so we can use that as guard. + TCC defines __WINT_TYPE__ for us. */ +#if defined (__need_wint_t) +#ifndef _WINT_T +#define _WINT_T +typedef __WINT_TYPE__ wint_t; +#endif +#undef __need_wint_t +#endif diff --git a/tinyc/include/tcclib.h b/tinyc/include/tcclib.h deleted file mode 100644 index 42f8f3f57..000000000 --- a/tinyc/include/tcclib.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Simple libc header for TCC - * - * Add any function you want from the libc there. This file is here - * only for your convenience so that you do not need to put the whole - * glibc include files on your floppy disk - */ -#ifndef _TCCLIB_H -#define _TCCLIB_H - -#include <stddef.h> -#include <stdarg.h> - -/* stdlib.h */ -void *calloc(size_t nmemb, size_t size); -void *malloc(size_t size); -void free(void *ptr); -void *realloc(void *ptr, size_t size); -int atoi(const char *nptr); -long int strtol(const char *nptr, char **endptr, int base); -unsigned long int strtoul(const char *nptr, char **endptr, int base); -void exit(int); - -/* stdio.h */ -typedef struct __FILE FILE; -#define EOF (-1) -extern FILE *stdin; -extern FILE *stdout; -extern FILE *stderr; -FILE *fopen(const char *path, const char *mode); -FILE *fdopen(int fildes, const char *mode); -FILE *freopen(const char *path, const char *mode, FILE *stream); -int fclose(FILE *stream); -size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); -size_t fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream); -int fgetc(FILE *stream); -char *fgets(char *s, int size, FILE *stream); -int getc(FILE *stream); -int getchar(void); -char *gets(char *s); -int ungetc(int c, FILE *stream); -int fflush(FILE *stream); - -int printf(const char *format, ...); -int fprintf(FILE *stream, const char *format, ...); -int sprintf(char *str, const char *format, ...); -int snprintf(char *str, size_t size, const char *format, ...); -int asprintf(char **strp, const char *format, ...); -int dprintf(int fd, const char *format, ...); -int vprintf(const char *format, va_list ap); -int vfprintf(FILE *stream, const char *format, va_list ap); -int vsprintf(char *str, const char *format, va_list ap); -int vsnprintf(char *str, size_t size, const char *format, va_list ap); -int vasprintf(char **strp, const char *format, va_list ap); -int vdprintf(int fd, const char *format, va_list ap); - -void perror(const char *s); - -/* string.h */ -char *strcat(char *dest, const char *src); -char *strchr(const char *s, int c); -char *strrchr(const char *s, int c); -char *strcpy(char *dest, const char *src); -void *memcpy(void *dest, const void *src, size_t n); -void *memmove(void *dest, const void *src, size_t n); -void *memset(void *s, int c, size_t n); -char *strdup(const char *s); - -/* dlfcn.h */ -#define RTLD_LAZY 0x001 -#define RTLD_NOW 0x002 -#define RTLD_GLOBAL 0x100 - -void *dlopen(const char *filename, int flag); -const char *dlerror(void); -void *dlsym(void *handle, char *symbol); -int dlclose(void *handle); - -#endif /* _TCCLIB_H */ diff --git a/tinyc/include/varargs.h b/tinyc/include/varargs.h index daee29e87..d614366ed 100644 --- a/tinyc/include/varargs.h +++ b/tinyc/include/varargs.h @@ -1,11 +1,12 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within this package. + */ #ifndef _VARARGS_H #define _VARARGS_H -#include <stdarg.h> - -#define va_dcl -#define va_alist __va_alist -#undef va_start -#define va_start(ap) ap = __builtin_varargs_start +#error "TinyCC no longer implements <varargs.h>." +#error "Revise your code to use <stdarg.h>." #endif |