From 4260ce1889f6f0f2fe25f4c783dae2b23a4a0021 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 25 Nov 2013 11:24:02 +0800 Subject: Add va_* macro implementation for ARM --- include/stdarg.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/stdarg.h b/include/stdarg.h index efca0e5..3c1318e 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -25,6 +25,17 @@ typedef char *va_list; #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) + #else /* __i386__ */ typedef char *va_list; /* only correct for i386 */ -- cgit v1.3.1 From 262eec3e8361d25682387df7a077e4afcea96fd3 Mon Sep 17 00:00:00 2001 From: Vincent Lefevre Date: Sun, 12 Jan 2014 22:26:09 +0100 Subject: Fixed the LDBL_* macros in include/float.h for x86-64: as said when x86-64 support was added, "for long double, we use x87 FPU". And indeed, tests show that Intel's extended precision is used, not double precision. --- include/float.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/float.h b/include/float.h index 5f1c6f7..f16f1f0 100644 --- a/include/float.h +++ b/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 -- cgit v1.3.1 From c025478d7c03eb8d32022f1aec4537bd0a75a743 Mon Sep 17 00:00:00 2001 From: mingodad Date: Fri, 28 Mar 2014 20:28:19 +0000 Subject: New implementation of va_list/va_start/var_copy that do not use dynamic memory, with this when compiling fossil-scm with tcc on linux X86_64 it works fine. --- include/stdarg.h | 32 +++++++++++++++++++++----------- lib/libtcc1.c | 30 +++++++++--------------------- 2 files changed, 30 insertions(+), 32 deletions(-) (limited to 'include') diff --git a/include/stdarg.h b/include/stdarg.h index 3c1318e..b6a30f7 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -4,18 +4,28 @@ #ifdef __x86_64__ #ifndef _WIN64 -typedef void *va_list; - -va_list __va_start(void *fp); -void *__va_arg(va_list ap, int arg_type, int size, int align); -va_list __va_copy(va_list src); -void __va_end(va_list ap); - -#define va_start(ap, last) ((ap) = __va_start(__builtin_frame_address(0))) +//This should be in sync with the declaration on our lib/libtcc1.c +/* GCC compatible definition of va_list. */ +typedef struct { + unsigned int gp_offset; + unsigned int fp_offset; + union { + unsigned int overflow_offset; + char *overflow_arg_area; + }; + char *reg_save_area; +} __va_list_struct; + +typedef __va_list_struct va_list; + +void __va_start(__va_list_struct *ap, void *fp); +void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); + +#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) = __va_copy(src)) -#define va_end(ap) __va_end(ap) + (*(type *)(__va_arg(&ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) +#define va_copy(dest, src) ((dest) = (src)) +#define va_end(ap) #else /* _WIN64 */ typedef char *va_list; diff --git a/lib/libtcc1.c b/lib/libtcc1.c index a5896a4..284965e 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -626,10 +626,12 @@ long long __fixxfdi (long double a1) #ifndef __TINYC__ #include #include +#include #else /* Avoid including stdlib.h because it is not easily available when cross compiling */ extern void *malloc(unsigned long long); +void *memset(void *s, int c, size_t n); extern void free(void*); extern void abort(void); #endif @@ -638,8 +640,9 @@ enum __va_arg_type { __va_gen_reg, __va_float_reg, __va_stack }; +//This should be in sync with the declaration on our include/stdarg.h /* GCC compatible definition of va_list. */ -struct __va_list_struct { +typedef struct { unsigned int gp_offset; unsigned int fp_offset; union { @@ -647,24 +650,22 @@ struct __va_list_struct { char *overflow_arg_area; }; char *reg_save_area; -}; +} __va_list_struct; #undef __va_start #undef __va_arg #undef __va_copy #undef __va_end -void *__va_start(void *fp) +void __va_start(__va_list_struct *ap, void *fp) { - struct __va_list_struct *ap = - (struct __va_list_struct *)malloc(sizeof(struct __va_list_struct)); - *ap = *(struct __va_list_struct *)((char *)fp - 16); + memset(ap, 0, sizeof(__va_list_struct)); + *ap = *(__va_list_struct *)((char *)fp - 16); ap->overflow_arg_area = (char *)fp + ap->overflow_offset; ap->reg_save_area = (char *)fp - 176 - 16; - return ap; } -void *__va_arg(struct __va_list_struct *ap, +void *__va_arg(__va_list_struct *ap, enum __va_arg_type arg_type, int size, int align) { @@ -701,19 +702,6 @@ void *__va_arg(struct __va_list_struct *ap, } } -void *__va_copy(struct __va_list_struct *src) -{ - struct __va_list_struct *dest = - (struct __va_list_struct *)malloc(sizeof(struct __va_list_struct)); - *dest = *src; - return dest; -} - -void __va_end(struct __va_list_struct *ap) -{ - free(ap); -} - #endif /* __x86_64__ */ /* Flushing for tccrun */ -- cgit v1.3.1 From 3900b235e06af99f46714eb7950cd3fcc3b11c61 Mon Sep 17 00:00:00 2001 From: Daniel Glöckner Date: Sun, 30 Mar 2014 00:08:05 +0100 Subject: x86_64: pass va_list as pointer The ABI requires that va_list is passed as a pointer although its contents is a kept in a structure. Therefore make it a single element array. --- include/stdarg.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/stdarg.h b/include/stdarg.h index b6a30f7..5aa9d57 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -16,15 +16,15 @@ typedef struct { char *reg_save_area; } __va_list_struct; -typedef __va_list_struct va_list; +typedef __va_list_struct va_list[1]; void __va_start(__va_list_struct *ap, void *fp); void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); -#define va_start(ap, last) __va_start(&ap, __builtin_frame_address(0)) +#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)) + (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) +#define va_copy(dest, src) (*(dest) = *(src)) #define va_end(ap) #else /* _WIN64 */ -- cgit v1.3.1 From 0961a38493c545cd23a791cf66b45d8fc78accbd Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 7 Apr 2014 00:26:36 +0200 Subject: Declare wint_t in when needed Some old glibcs require to provide wint_t, accomodate them. --- include/stddef.h | 15 +++++++++++++++ libtcc.c | 9 +++++++++ 2 files changed, 24 insertions(+) (limited to 'include') diff --git a/include/stddef.h b/include/stddef.h index fbc61fc..eaf0669 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -26,3 +26,18 @@ typedef unsigned long long int uint64_t; void *alloca(size_t size); #endif + +/* Older glibc require a wint_t from (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 requring 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/libtcc.c b/libtcc.c index 601999e..cc84cd7 100644 --- a/libtcc.c +++ b/libtcc.c @@ -988,8 +988,17 @@ LIBTCCAPI TCCState *tcc_new(void) #ifdef TCC_TARGET_PE tcc_define_symbol(s, "__WCHAR_TYPE__", "unsigned short"); + tcc_define_symbol(s, "__WINT_TYPE__", "unsigned short"); #else tcc_define_symbol(s, "__WCHAR_TYPE__", "int"); + /* wint_t is unsigned int by default, but (signed) int on BSDs + and unsigned short on windows. Other OSes might have still + other conventions, sigh. */ +#if defined(__FreeBSD__) || defined (__FreeBSD_kernel__) + tcc_define_symbol(s, "__WINT_TYPE__", "int"); +#else + tcc_define_symbol(s, "__WINT_TYPE__", "unsigned int"); +#endif #endif #ifndef TCC_TARGET_PE -- cgit v1.3.1 From f01373765b1ac5270fbb1859a2f6d42510f34cde Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 7 Apr 2014 00:30:31 +0200 Subject: stdbool.h: Make conformant to ISOC99 For conformance to ISO C the stdbool.h header has to provide the macro __bool_true_false_are_defined (defined to 1). Yep, that name is really in the standard. --- include/stdbool.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/stdbool.h b/include/stdbool.h index 6ed13a6..d2ee446 100644 --- a/include/stdbool.h +++ b/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 */ -- cgit v1.3.1 From 3e9a7e9d69e3adb0e9ed65d11caf415e74458fe9 Mon Sep 17 00:00:00 2001 From: Vincent Lefevre Date: Mon, 7 Apr 2014 13:31:00 +0200 Subject: Corrected spelling mistakes in comments and strings --- arm-gen.c | 4 ++-- c67-gen.c | 4 ++-- i386-asm.c | 2 +- i386-tok.h | 2 +- include/stddef.h | 2 +- lib/bcheck.c | 2 +- tccasm.c | 2 +- tccgen.c | 4 ++-- tests/Makefile | 2 +- tests/tcctest.c | 2 +- tests/tests2/46_grep.c | 10 +++++----- 11 files changed, 18 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/arm-gen.c b/arm-gen.c index a9c05fe..680a490 100644 --- a/arm-gen.c +++ b/arm-gen.c @@ -943,7 +943,7 @@ struct plan { Returns the amount of stack space needed for parameter passing Note: this function allocated an array in plan->pplans with tcc_malloc. It - is the responsability of the caller to free this array once used (ie not + is the responsibility of the caller to free this array once used (ie not before copy_params). */ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) { @@ -1860,7 +1860,7 @@ void gen_opf(int op) case TOK_UGE: case TOK_ULE: case TOK_UGT: - tcc_error("unsigned comparision on floats?"); + tcc_error("unsigned comparison on floats?"); break; case TOK_LT: op=TOK_Nset; diff --git a/c67-gen.c b/c67-gen.c index 6d9068a..a26dfaa 100644 --- a/c67-gen.c +++ b/c67-gen.c @@ -245,8 +245,8 @@ void gsym(int t) } // these are regs that tcc doesn't really know about, -// but asign them unique values so the mapping routines -// can distinquish them +// but assign them unique values so the mapping routines +// can distinguish them #define C67_A0 105 #define C67_SP 106 diff --git a/i386-asm.c b/i386-asm.c index 8473d06..a524658 100644 --- a/i386-asm.c +++ b/i386-asm.c @@ -1382,7 +1382,7 @@ ST_FUNC void subst_asm_operand(CString *add_str, } } -/* generate prolog and epilog code for asm statment */ +/* generate prolog and epilog code for asm statement */ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, diff --git a/i386-tok.h b/i386-tok.h index d1e4bf3..6ba865d 100644 --- a/i386-tok.h +++ b/i386-tok.h @@ -191,7 +191,7 @@ DEF_FP(mul) DEF_ASM(fcom) - DEF_ASM(fcom_1) /* non existant op, just to have a regular table */ + DEF_ASM(fcom_1) /* non existent op, just to have a regular table */ DEF_FP1(com) DEF_FP(comp) diff --git a/include/stddef.h b/include/stddef.h index eaf0669..9e43de9 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -31,7 +31,7 @@ void *alloca(size_t size); 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 requring wint_t). Some other libs define _WINT_T + 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) diff --git a/lib/bcheck.c b/lib/bcheck.c index 968cdf4..76413ad 100644 --- a/lib/bcheck.c +++ b/lib/bcheck.c @@ -635,7 +635,7 @@ int __bound_delete_region(void *p) } /* return the size of the region starting at p, or EMPTY_SIZE if non - existant region. */ + existent region. */ static unsigned long get_region_size(void *p) { unsigned long addr = (unsigned long)p; diff --git a/tccasm.c b/tccasm.c index 9c77960..1c6a65d 100644 --- a/tccasm.c +++ b/tccasm.c @@ -232,7 +232,7 @@ static inline void asm_expr_sum(TCCState *s1, ExprValue *pe) } else { goto cannot_relocate; } - pe->sym = NULL; /* same symbols can be substracted to NULL */ + pe->sym = NULL; /* same symbols can be subtracted to NULL */ } else { cannot_relocate: tcc_error("invalid operation with label"); diff --git a/tccgen.c b/tccgen.c index e6e0fe1..ec92797 100644 --- a/tccgen.c +++ b/tccgen.c @@ -1579,7 +1579,7 @@ static inline int is_integer_btype(int bt) bt == VT_INT || bt == VT_LLONG); } -/* check types for comparison or substraction of pointers */ +/* check types for comparison or subtraction of pointers */ static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op) { CType *type1, *type2, tmp_type1, tmp_type2; @@ -5574,7 +5574,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, if (sym->type.t & VT_EXTERN) { /* if the variable is extern, it was not allocated */ sym->type.t &= ~VT_EXTERN; - /* set array size if it was ommited in extern + /* set array size if it was omitted in extern declaration */ if ((sym->type.t & VT_ARRAY) && sym->type.ref->c < 0 && diff --git a/tests/Makefile b/tests/Makefile index 55bf29c..ee0eafe 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -158,7 +158,7 @@ btest: boundtest.c @for i in $(BOUNDS_OK); do \ echo ; echo --- boundtest $$i ---; \ if $(TCC) -b -run $< $$i ; then \ - echo succeded as expected; \ + echo succeeded as expected; \ else\ echo Failed positive test $$i ; exit 1 ; \ fi ;\ diff --git a/tests/tcctest.c b/tests/tcctest.c index c48c1bc..cc8ffd8 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2254,7 +2254,7 @@ void c99_vla_test(int size1, int size2) printf("%s\n", (sizeof tab1 == size1 * size2 * 2 * sizeof(int)) ? "PASSED" : "FAILED"); tab1_ptr = tab1; tab2_ptr = tab2; - printf("Test C99 VLA 2 (ptrs substract): "); + printf("Test C99 VLA 2 (ptrs subtract): "); printf("%s\n", (tab2 - tab1 == (tab2_ptr - tab1_ptr) / (sizeof(int) * 2)) ? "PASSED" : "FAILED"); printf("Test C99 VLA 3 (ptr add): "); printf("%s\n", &tab1[5][1] == (tab1_ptr + (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED"); diff --git a/tests/tests2/46_grep.c b/tests/tests2/46_grep.c index 5f52220..27589a4 100644 --- a/tests/tests2/46_grep.c +++ b/tests/tests2/46_grep.c @@ -29,10 +29,10 @@ char *documentation[] = { "grep searches a file for a given pattern. Execute by", " grep [flags] regular_expression file_list\n", - "Flags are single characters preceeded by '-':", + "Flags are single characters preceded by '-':", " -c Only a count of matching lines is printed", " -f Print file name for matching lines switch, see below", - " -n Each line is preceeded by its line number", + " -n Each line is preceded by its line number", " -v Only print non-matching lines\n", "The file_list is a list of files (wildcards are acceptable on RSX modes).", "\nThe file name is normally printed if there is a file given.", @@ -54,10 +54,10 @@ char *patdoc[] = { "':n' \":n\" matches alphanumerics, \": \" matches spaces, tabs, and", "': ' other control characters, such as new-line.", "'*' An expression followed by an asterisk matches zero or more", - " occurrances of that expression: \"fo*\" matches \"f\", \"fo\"", + " occurrences of that expression: \"fo*\" matches \"f\", \"fo\"", " \"foo\", etc.", "'+' An expression followed by a plus sign matches one or more", - " occurrances of that expression: \"fo+\" matches \"fo\", etc.", + " occurrences of that expression: \"fo+\" matches \"fo\", etc.", "'-' An expression followed by a minus sign optionally matches", " the expression.", "'[]' A string enclosed in square brackets matches any character in", @@ -153,7 +153,7 @@ void compile(char *source) o == STAR || o == PLUS || o == MINUS) - badpat("Illegal occurrance op.", source, s); + badpat("Illegal occurrence op.", source, s); store(ENDPAT); store(ENDPAT); spp = pp; /* Save pattern end */ -- cgit v1.3.1