diff --git a/Makefile b/Makefile index d41b81a2..19530407 100644 --- a/Makefile +++ b/Makefile @@ -221,8 +221,8 @@ endif endif # convert "include/tccdefs.h" to "tccdefs_.h" -%_.h : include/%.h tests/misc/c2str.c - $S$(CC) -o c2str.exe $(filter %.c,$^) && ./c2str.exe $< $@ +%_.h : include/%.h conftest.c + $S$(CC) -DC2STR $(filter %.c,$^) -o c2str.exe && ./c2str.exe $< $@ # target specific object rule $(X)%.o : %.c $(LIBTCC_INC) diff --git a/arm-gen.c b/arm-gen.c index 3f432d85..5c44b8e0 100644 --- a/arm-gen.c +++ b/arm-gen.c @@ -141,6 +141,21 @@ enum { #define USING_GLOBALS #include "tcc.h" +ST_DATA const char *target_machine_defs = + "__arm__\0" + "__arm\0" + "arm\0" + "__arm_elf__\0" + "__arm_elf\0" + "arm_elf\0" + "__ARM_ARCH_4__\0" + "__ARMEL__\0" + "__APCS_32__\0" +#if defined TCC_ARM_EABI + "__ARM_EABI__\0" +#endif + ; + enum float_abi float_abi; ST_DATA const int reg_classes[NB_REGS] = { diff --git a/arm64-gen.c b/arm64-gen.c index 4ce46e6d..feff7415 100644 --- a/arm64-gen.c +++ b/arm64-gen.c @@ -50,6 +50,10 @@ #include "tcc.h" #include +ST_DATA const char *target_machine_defs = + "__aarch64__\0" + ; + ST_DATA const int reg_classes[NB_REGS] = { RC_INT | RC_R(0), RC_INT | RC_R(1), diff --git a/c67-gen.c b/c67-gen.c index 3f963617..a1c1476c 100644 --- a/c67-gen.c +++ b/c67-gen.c @@ -114,8 +114,12 @@ enum { #define USING_GLOBALS #include "tcc.h" +ST_DATA const char *target_machine_defs = + "__C67__\0" + ; + ST_DATA const int reg_classes[NB_REGS] = { - /* eax */ RC_INT | RC_FLOAT | RC_EAX, + /* eax */ RC_INT | RC_FLOAT | RC_EAX, // only allow even regs for floats (allow for doubles) /* ecx */ RC_INT | RC_ECX, /* edx */ RC_INT | RC_INT_BSIDE | RC_FLOAT | RC_EDX, diff --git a/conftest.c b/conftest.c index f3b6ea65..4a221d3f 100644 --- a/conftest.c +++ b/conftest.c @@ -1,3 +1,173 @@ +/* ----------------------------------------------------------------------- */ +#if C2STR + +/* with -D C2STR: convert tccdefs.h to C-strings */ + +#include +#include + +/* replace native host macros by compile-time versions */ +const char *platform_macros[] = { + "__i386__", "TCC_TARGET_I386", + "__x86_64__", "TCC_TARGET_X86_64", + "_WIN32", "TCC_TARGET_PE", + "__arm__", "TCC_TARGET_ARM", + "__ARM_EABI__", "TCC_ARM_EABI", + "__aarch64__", "TCC_TARGET_ARM64", + "__riscv", "TCC_TARGET_RISCV64", + "__APPLE__", "TCC_TARGET_MACHO", + "__FreeBSD__", "TARGETOS_FreeBSD", + "__FreeBSD_kernel__", "TARGETOS_FreeBSD_kernel", + "__OpenBSD__", "TARGETOS_OpenBSD", + "__NetBSD__", "TARGETOS_NetBSD", + "__linux__", "TARGETOS_Linux", + "__SIZEOF_POINTER__", "PTR_SIZE", + "__SIZEOF_LONG__", "LONG_SIZE", + 0 +}; + +int isid(int c) +{ + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') + || (c >= '0' && c <= '9') || c == '_'; +} + +int isspc(int c) +{ + return (unsigned char)c <= ' ' && c != 0; +} + +int main(int argc, char **argv) +{ + char l[1000], l2[1000], *p, *q, *p0; + FILE *fp, *op; + int c, e, f, s, cmt, cmt_n; + const char *r; + + if (argc < 3) + return 1; + + fp = fopen(argv[1], "rb"); + op = fopen(argv[2], "wb"); + if (!fp || !op) { + fprintf(stderr, "c2str: file error\n"); + return 1; + } + + cmt = cmt_n = 0; + for (;;) { + p = l; + append: + if (fgets(p, sizeof l - (p - l), fp)) { + p = strchr(p, 0); + while (p > l && isspc(p[-1])) + --p; + *p = 0; + } else if (p == l) + break; + + /* check for continuation */ + if (p > l && p[-1] == '\\') { + p[-1] = ' '; + goto append; + } + + /* count & skip leading spaces */ + p = l, q = l2, f = 0; + while (*p && isspc(*p)) + ++p, ++f; + + /* handle comments */ + if (p[0] == '/' && cmt == 0) { + if (p[1] == '*') + cmt = 2; + if (p[1] == '/') + cmt = 1; + } + if (cmt) { + fprintf(op, "%s", l); + if (++cmt_n == 1) + fprintf(op, " (converted, do not edit this file)"); + fprintf(op, "\n"); + if (cmt == 1) + cmt = 0; + if (cmt == 2) { + p = strchr(l, 0); + if (p >= l + 2 && p[-1] == '/' && p[-2] == '*') + cmt = 0; + } + continue; + } + + if (f < 4) { + do { + /* replace machine/os macros by compile-time counterparts */ + for (e = f = 0; (r = platform_macros[f]); f += 2) { + c = strlen(r); + /* remove 'defined' */ + //e = memcmp(p, "defined ", 8) ? 0 : 8; + if (0 == memcmp(p + e, r, c)) { + p += e + c; + q = strchr(strcpy(q, platform_macros[f + 1]), 0); + break; + } + + } + if (r) + continue; + } while (!!(*q++ = *p++)); + /* output as is */ + fprintf(op, "%s\n", l2); + continue; + + } else { + s = e = f = 0, p0 = p; + for (;;) { + c = *p++; + + if (isspc(c)) { + s = 1; + continue; + } + if (c == '/' && (p[0] == '/' || p[0] == '*')) + c = 0; /* trailing comment detected */ + else if (s && q > l2 + && ((isid(q[-1]) && isid(c)) + // keep space after macro name + || (q >= l2 + 2 + && l2[0] == '#' + && l2[1] == 'd' + && f < 2 && !e + ))) + *q++ = ' ', ++f; + s = 0; + + if (c == '(') + ++e; + if (c == ')') + --e; + if (c == '\\' || c == '\"') + *q++ = '\\'; + *q++ = c; + if (c == 0) + break; + p0 = p; + } + /* output with quotes */ + fprintf(op, " \"%s\\n\"%s\n", l2, p0); + } + } + + fclose(fp); + fclose(op); + return 0; +} + +/* ----------------------------------------------------------------------- */ +#elif 1 + +/* get some information from the host compiler for configure */ + #include #if defined(_WIN32) @@ -123,3 +293,6 @@ int main(int argc, char *argv[]) } return 0; } + +/* ----------------------------------------------------------------------- */ +#endif diff --git a/i386-gen.c b/i386-gen.c index d2727980..96419901 100644 --- a/i386-gen.c +++ b/i386-gen.c @@ -81,6 +81,11 @@ enum { #define USING_GLOBALS #include "tcc.h" +ST_DATA const char *target_machine_defs = + "__i386__\0" + "__i386\0" + ; + /* define to 1/0 to [not] have EBX as 4th register */ #define USE_EBX 0 diff --git a/include/stddef.h b/include/stddef.h index bd2d5b2b..536ebee3 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -17,25 +17,11 @@ typedef union { long long __ll; long double __ld; } max_align_t; typedef signed char int8_t; typedef signed short int int16_t; typedef signed int int32_t; -#if defined(__LP64__) \ - && !defined(__APPLE__) \ - && !defined(__OpenBSD__) \ - && !(defined(__NetBSD__) && defined(__aarch64__)) -typedef signed long int int64_t; -#else -typedef signed long long int int64_t; -#endif +typedef signed __INT64_TYPE__ int64_t; typedef unsigned char uint8_t; typedef unsigned short int uint16_t; typedef unsigned int uint32_t; -#if defined(__LP64__) \ - && !defined(__APPLE__) \ - && !defined(__OpenBSD__) \ - && !(defined(__NetBSD__) && defined(__aarch64__)) -typedef unsigned long int uint64_t; -#else -typedef unsigned long long int uint64_t; -#endif +typedef unsigned __INT64_TYPE__ uint64_t; #endif #ifndef NULL diff --git a/include/tccdefs.h b/include/tccdefs.h index 99967895..5cac7564 100644 --- a/include/tccdefs.h +++ b/include/tccdefs.h @@ -1,27 +1,43 @@ /* tccdefs.h - * - * By using native platfórm macros this file may be included at runtime - * just as is. - * - * If converted to C-strings and included in tccpp.c, these are trahslated - * to tcc target macros accordingly. - */ + + Nothing is defined before this file except target machine, target os + and the few things related to option settings in tccpp.c:tcc_predefs(). + + This file is either included at runtime as is, or converted and + included as C-strings at compile-time (depending on CONFIG_TCC_PREDEFS). + + Note that line indent matters: + + - in lines starting at column 1, platform macros are replaced by + corresponding TCC target compile-time macros. See conftest.c for + the list of platform macros supported in lines starting at column 1. + + - only lines indented >= 4 are actually included into the executable, + check tccdefs_.h. +*/ #if __SIZEOF_POINTER__ == 4 /* 32bit systems. */ #define __SIZE_TYPE__ unsigned int #define __PTRDIFF_TYPE__ int #define __ILP32__ 1 + #define __INT64_TYPE__ long long #elif __SIZEOF_LONG__ == 4 /* 64bit Windows. */ #define __SIZE_TYPE__ unsigned long long #define __PTRDIFF_TYPE__ long long #define __LLP64__ 1 + #define __INT64_TYPE__ long long #else /* Other 64bit systems. */ #define __SIZE_TYPE__ unsigned long #define __PTRDIFF_TYPE__ long #define __LP64__ 1 +# if defined __linux__ + #define __INT64_TYPE__ long +# else /* APPLE, BSD */ + #define __INT64_TYPE__ long long +# endif #endif #define __SIZEOF_INT__ 4 #define __INT_MAX__ 0x7fffffff @@ -58,15 +74,10 @@ #endif #if defined _WIN32 - //#define _WIN32 1 -# if __SIZEOF_POINTER__ == 8 - #define _WIN64 1 -# endif #define __declspec(x) __attribute__((x)) #define __cdecl #elif defined __FreeBSD__ - //#define __FreeBSD__ 12 #define __GNUC__ 9 #define __GNUC_MINOR__ 3 #define __GNUC_PATCHLEVEL__ 0 @@ -78,27 +89,22 @@ # endif #elif defined __FreeBSD_kernel__ - //#define __FreeBSD_kernel__ 1 #elif defined __NetBSD__ - //#define __NetBSD__ 1 #define __GNUC__ 4 #define __GNUC_MINOR__ 1 #define __GNUC_PATCHLEVEL__ 0 #define _Pragma(x) #define __ELF__ 1 - #if defined(__aarch64__) && defined(__TINYC__) && !defined(_LOCORE) - /* avoids usage of __asm which is not yet supported by tcc */ - #define _LOCORE - #endif +#if defined __aarch64__ + #define _LOCORE /* avoids usage of __asm */ +#endif #elif defined __OpenBSD__ - //#define __OpenBSD__ 1 #define __GNUC__ 4 #define _ANSI_LIBRARY 1 #elif defined __APPLE__ - //#define __APPLE__ 1 /* emulate APPLE-GCC to make libc's headerfiles compile: */ #define __GNUC__ 4 /* darwin emits warning on GCC<4 */ #define __APPLE_CC__ 1 /* for */ @@ -108,8 +114,8 @@ #define _FORTIFY_SOURCE 0 #else - //#define __linux__ 1 - //#define __linux 1 + /* Linux */ + #endif #if !defined _WIN32 diff --git a/riscv64-gen.c b/riscv64-gen.c index 384d0ec7..bdf932fd 100644 --- a/riscv64-gen.c +++ b/riscv64-gen.c @@ -36,6 +36,17 @@ #include "tcc.h" #include +ST_DATA const char *target_machine_defs = + "__riscv\0" + "__riscv_xlen 64\0" + "__riscv_flen 64\0" + "__riscv_div\0" + "__riscv_mul\0" + "__riscv_fdiv\0" + "__riscv_fsqrt\0" + "__riscv_float_abi_double\0" + ; + #define XLEN 8 #define TREG_RA 17 diff --git a/tcc.h b/tcc.h index f28b9d86..03362b00 100644 --- a/tcc.h +++ b/tcc.h @@ -211,6 +211,11 @@ extern long double strtold (const char *__nptr, char **__endptr); # define ELF_OBJ_ONLY /* create elf .o but native executables */ #endif +/* No ten-byte long doubles on window except in cross-compilers made by GCC */ +#if defined TCC_TARGET_PE || (defined _WIN32 && !defined __GNUC__) +# define TCC_USING_DOUBLE_FOR_LDOUBLE 1 +#endif + /* ------------ path configuration ------------ */ #ifndef CONFIG_SYSROOT @@ -1620,7 +1625,7 @@ ST_FUNC void relocate_plt(TCCState *s1); ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val); /* ------------ xxx-gen.c ------------ */ - +ST_DATA const char *target_machine_defs; ST_DATA const int reg_classes[NB_REGS]; ST_FUNC void gsym_addr(int t, int a); diff --git a/tccgen.c b/tccgen.c index 0c3de487..1c9eb834 100644 --- a/tccgen.c +++ b/tccgen.c @@ -160,7 +160,11 @@ static const struct { { VT_BYTE | VT_DEFSIGN | VT_UNSIGNED, "unsigned char:t13=r13;0;255;" }, { VT_FLOAT, "float:t14=r1;4;0;" }, { VT_DOUBLE, "double:t15=r1;8;0;" }, +#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE + { VT_DOUBLE | VT_LONG, "long double:t16=r1;8;0;" }, +#else { VT_LDOUBLE, "long double:t16=r1;16;0;" }, +#endif { -1, "_Float32:t17=r1;4;0;" }, { -1, "_Float64:t18=r1;8;0;" }, { -1, "_Float128:t19=r1;16;0;" }, @@ -5061,7 +5065,7 @@ the_end: bt = t & (VT_BTYPE|VT_LONG); if (bt == VT_LONG) t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT; -#if defined TCC_TARGET_PE || (defined _WIN32 && defined _MSC_VER) +#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE if (bt == VT_LDOUBLE) t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG); #endif diff --git a/tccpp.c b/tccpp.c index 449035db..2aa2c583 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1840,8 +1840,6 @@ ST_FUNC void preprocess(int is_bof) if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE) tcc_error("#include recursion too deep"); - /* push current file on stack */ - *s1->include_stack_ptr++ = file; i = tok == TOK_INCLUDE_NEXT ? file->include_next_index + 1 : 0; n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths; for (; i < n; ++i) { @@ -1884,7 +1882,8 @@ ST_FUNC void preprocess(int is_bof) if (tcc_open(s1, buf1) < 0) continue; - + /* push previous file on stack */ + *s1->include_stack_ptr++ = file->prev; file->include_next_index = i; #ifdef INC_DEBUG printf("%s: including %s\n", file->prev->filename, file->filename); @@ -1907,7 +1906,6 @@ ST_FUNC void preprocess(int is_bof) } tcc_error("include file '%s' not found", buf); include_done: - --s1->include_stack_ptr; break; case TOK_IFNDEF: c = 1; @@ -3625,97 +3623,77 @@ ST_INLN void unget_tok(int last_tok) tok = last_tok; } +/* ------------------------------------------------------------------------- */ +/* init preprocessor */ + +static const char *target_os_defs = +#ifdef TCC_TARGET_PE + "_WIN32\0" +# if PTR_SIZE == 8 + "_WIN64\0" +# endif +#else +# if defined TCC_TARGET_MACHO + "__APPLE__\0" +# elif TARGETOS_FreeBSD + "__FreeBSD__ 12\0" +# elif TARGETOS_FreeBSD_kernel + "__FreeBSD_kernel__\0" +# elif TARGETOS_NetBSD + "__NetBSD__\0" +# elif TARGETOS_OpenBSD + "__OpenBSD__\0" +# else + "__linux__\0" + "__linux\0" +# endif + "__unix__\0" + "__unix\0" +#endif + ; + +static void putdef(CString *cs, const char *p) +{ + cstr_printf(cs, "#define %s%s\n", p, &" 1"[!!strchr(p, ' ')*2]); +} + static void tcc_predefs(TCCState *s1, CString *cs, int is_asm) { - int a,b,c; + int a, b, c; + const char *defs[] = { target_machine_defs, target_os_defs, NULL }; + const char *p; sscanf(TCC_VERSION, "%d.%d.%d", &a, &b, &c); cstr_printf(cs, "#define __TINYC__ %d\n", a*10000 + b*100 + c); - cstr_cat(cs, - /* target machine */ -#if defined TCC_TARGET_I386 - "#define __i386__ 1\n" - "#define __i386 1\n" -#elif defined TCC_TARGET_X86_64 - "#define __x86_64__ 1\n" - "#define __amd64__ 1\n" -#elif defined TCC_TARGET_ARM - "#define __ARM_ARCH_4__ 1\n" - "#define __arm_elf__ 1\n" - "#define __arm_elf 1\n" - "#define arm_elf 1\n" - "#define __arm__ 1\n" - "#define __arm 1\n" - "#define arm 1\n" - "#define __APCS_32__ 1\n" - "#define __ARMEL__ 1\n" -# if defined TCC_ARM_EABI - "#define __ARM_EABI__ 1\n" -# endif -#elif defined TCC_TARGET_ARM64 - "#define __aarch64__ 1\n" -#elif defined TCC_TARGET_C67 - "#define __C67__ 1\n" -#elif defined TCC_TARGET_RISCV64 - "#define __riscv 1\n" - "#define __riscv_xlen 64\n" - "#define __riscv_flen 64\n" - "#define __riscv_div 1\n" - "#define __riscv_mul 1\n" - "#define __riscv_fdiv 1\n" - "#define __riscv_fsqrt 1\n" - "#define __riscv_float_abi_double 1\n" -#endif - , -1); + for (a = 0; defs[a]; ++a) + for (p = defs[a]; *p; p = strchr(p, 0) + 1) + putdef(cs, p); #ifdef TCC_TARGET_ARM if (s1->float_abi == ARM_HARD_FLOAT) - cstr_printf(cs, "#define __ARM_PCS_VFP 1\n"); + putdef(cs, "__ARM_PCS_VFP"); #endif - cstr_cat(cs, - /* target platform */ -#ifdef TCC_TARGET_PE - "#define _WIN32 1\n" -#else - "#define __unix__ 1\n" - "#define __unix 1\n" -# if defined TCC_TARGET_MACHO - "#define __APPLE__ 1\n" -# elif TARGETOS_FreeBSD - "#define __FreeBSD__ 12\n" -# elif TARGETOS_FreeBSD_kernel - "#define __FreeBSD_kernel__ 1\n" -# elif TARGETOS_NetBSD - "#define __NetBSD__ 1\n" -# elif TARGETOS_OpenBSD - "#define __OpenBSD__ 1\n" -# else - "#define __linux__ 1\n" - "#define __linux 1\n" -# endif -#endif - , -1); if (is_asm) - cstr_printf(cs, "#define __ASSEMBLER__ 1\n"); + putdef(cs, "__ASSEMBLER__"); if (s1->output_type == TCC_OUTPUT_PREPROCESS) - cstr_printf(cs, "#define __TCC_PP__ 1\n"); + putdef(cs, "__TCC_PP__"); if (s1->output_type == TCC_OUTPUT_MEMORY) - cstr_printf(cs, "#define __TCC_RUN__ 1\n"); + putdef(cs, "__TCC_RUN__"); if (s1->char_is_unsigned) - cstr_printf(cs, "#define __CHAR_UNSIGNED__ 1\n"); + putdef(cs, "__CHAR_UNSIGNED__"); if (s1->optimize > 0) - cstr_printf(cs, "#define __OPTIMIZE__ 1\n"); + putdef(cs, "__OPTIMIZE__"); if (s1->option_pthread) - cstr_printf(cs, "#define _REENTRANT 1\n"); + putdef(cs, "_REENTRANT"); if (s1->leading_underscore) - cstr_printf(cs, "#define __leading_underscore 1\n"); + putdef(cs, "__leading_underscore"); #ifdef CONFIG_TCC_BCHECK if (s1->do_bounds_check) - cstr_printf(cs, "#define __BOUNDS_CHECKING_ON 1\n"); + putdef(cs, "__BOUNDS_CHECKING_ON"); #endif cstr_printf(cs, "#define __SIZEOF_POINTER__ %d\n", PTR_SIZE); cstr_printf(cs, "#define __SIZEOF_LONG__ %d\n", LONG_SIZE); if (!is_asm) { - cstr_printf(cs, "#define __STDC__ 1\n"); + putdef(cs, "__STDC__"); cstr_printf(cs, "#define __STDC_VERSION__ %dL\n", s1->cversion); cstr_cat(cs, /* load more predefs and __builtins */ diff --git a/tests/libtcc_test_mt.c b/tests/libtcc_test_mt.c index b17e8de2..47d493d8 100644 --- a/tests/libtcc_test_mt.c +++ b/tests/libtcc_test_mt.c @@ -269,7 +269,7 @@ int main(int argc, char **argv) printf("\n (%u ms)\n", getclock_ms() - t); #endif #if 1 - printf("running tcc.c in threads to run fib\n"), fflush(stdout); + printf("running tcc.c in threads to run fib\n "), fflush(stdout); t = getclock_ms(); for (n = 0; n < M; ++n) create_thread(thread_test_complex, n); diff --git a/tests/misc/c2str.c b/tests/misc/c2str.c deleted file mode 100644 index 71f242bc..00000000 --- a/tests/misc/c2str.c +++ /dev/null @@ -1,158 +0,0 @@ -#include -#include - -/* replace native host macros by compile-time versions */ -const char *platform_macros[] = { - "__i386__", "TCC_TARGET_I386", - "__x86_64__", "TCC_TARGET_X86_64", - "_WIN32", "TCC_TARGET_PE", - "__arm__", "TCC_TARGET_ARM", - "__ARM_EABI__", "TCC_ARM_EABI", - "__aarch64__", "TCC_TARGET_ARM64", - "__riscv", "TCC_TARGET_RISCV64", - "__APPLE__", "TCC_TARGET_MACHO", - "__FreeBSD__", "TARGETOS_FreeBSD", - "__FreeBSD_kernel__", "TARGETOS_FreeBSD_kernel", - "__OpenBSD__", "TARGETOS_OpenBSD", - "__NetBSD__", "TARGETOS_NetBSD", - "__linux__", "TARGETOS_Linux", - "__SIZEOF_POINTER__", "PTR_SIZE", - "__SIZEOF_LONG__", "LONG_SIZE", - 0 -}; - -int isid(int c) -{ - return (c >= 'a' && c <= 'z') - || (c >= 'A' && c <= 'Z') - || (c >= '0' && c <= '9') - || c == '_'; -} - -int isspc(int c) -{ - return c == ' ' || c == '\t'; -} - -int main(int argc, char **argv) -{ - char l[1000], l2[1000], *p, *q, *p0; - FILE *fp, *op; - int c, e, f, cmt, cmt_n; - const char *r; - - if (argc < 3) - return 1; - - fp = fopen(argv[1], "rb"); - op = fopen(argv[2], "wb"); - if (!fp || !op) { - fprintf(stderr, "c2str: file error\n"); - return 1; - } - - cmt = cmt_n = 0; - for (;;) { - p = l; - append: - if (fgets(p, sizeof l - (p - l), fp)) { - p = strchr(p, 0); - while (p > l && p[-1] <= ' ') - --p; - *p = 0; - } else if (p == l) - break; - - /* check for continuation */ - if (p > l && p[-1] == '\\') { - p[-1] = ' '; - goto append; - } - - p = l, q = l2, f = 0; - /* count & skip leading spaces */ - while (*p && isspc(*p)) - ++p, ++f; - - /* handle comments */ - if (p[0] == '/' && cmt == 0) { - if (p[1] == '*') - cmt = 2; - if (p[1] == '/') - cmt = 1; - } - if (cmt) { - fprintf(op, "%s", l); - if (++cmt_n == 1) - fprintf(op, " (converted, do not edit this file)"); - fprintf(op, "\n"); - if (cmt == 1) - cmt = 0; - if (cmt == 2) { - p = strchr(l, 0); - if (p >= l + 2 && p[-1] == '/' && p[-2] == '*') - cmt = 0; - } - continue; - } - - if (f < 4) { - /* less than 4 leading spaces : no quotes but replace macros - by compile-time versions */ - do { - for (f = 0; (r = platform_macros[f]); f += 2) { - c = strlen(r); - e = 0; - /*if (memcmp(p, "defined ", 8)) - e = 8;*/ - if (0 == memcmp(p + e, r, c)) { - p += e + c; - q = strchr(strcpy(q, platform_macros[f + 1]), 0); - break; - } - - } - if (r) - continue; - } while (!!(*q++ = *p++)); - fprintf(op, "%s\n", l2); - continue; - - } else { - /* output line as C string */ - e = f = 0, p0 = p; - for (;;) { - c = *p++; - - if (c == '/' && (p[0] == '/' || p[0] == '*')) - c = 0; /* trailing comment detected */ - - if (isspc(c)) { - /* remove spaces if possible */ - if (q == l2 || isspc(q[-1])) - continue; - /* keep space after macro identifier */ - if ((f >= 2 || e) && (!isid(q[-1]) || !isid(*p))) - continue; - if (f == 1) - f = 2; - } - if (c == '(') - ++e; - if (c == ')') - --e, f += e == 0; - if (c == '\\' || c == '\"') - *q++ = '\\'; - *q++ = c; - if (c == 0) - break; - p0 = p; - } - fprintf(op, " \"%s\\n\"%s\n", l2, p0); - } - } - - fclose(fp); - fclose(op); - return 0; -} diff --git a/win32/include/_mingw.h b/win32/include/_mingw.h index 4ac2651d..3f227f22 100644 --- a/win32/include/_mingw.h +++ b/win32/include/_mingw.h @@ -80,7 +80,6 @@ #define __stdcall __attribute__((__stdcall__)) #define _X86_ 1 #define _M_IX86 300 /* Visual Studio */ -#define WIN32 1 #define _USE_32BIT_TIME_T #endif @@ -160,5 +159,6 @@ typedef struct localeinfo_struct _locale_tstruct,*_locale_t; #define __MINGW_EXTENSION #define WINAPI_FAMILY_PARTITION(X) 1 #define MINGW_HAS_SECURE_API +#define WIN32 1 #endif /* __MINGW_H */ diff --git a/win32/include/errno.h b/win32/include/errno.h index c2df0158..574ffa9b 100644 --- a/win32/include/errno.h +++ b/win32/include/errno.h @@ -14,7 +14,7 @@ extern "C" { #ifndef _CRT_ERRNO_DEFINED #define _CRT_ERRNO_DEFINED - _CRTIMP extern int *__cdecl _errno(void); + _CRTIMP int *__cdecl _errno(void); #define errno (*_errno()) errno_t __cdecl _set_errno(int _Value); diff --git a/win32/include/math.h b/win32/include/math.h index 745ed376..8e66407e 100644 --- a/win32/include/math.h +++ b/win32/include/math.h @@ -274,7 +274,7 @@ extern "C" { : __signbitl (x)) */ #define signbit(x) \ - _Generic(x, float: __signbitf, double: __signbit, long double: signbitl)(x) + _Generic(x, float: __signbitf, double: __signbit, long double: __signbitl)(x) extern double __cdecl exp2(double); extern float __cdecl exp2f(float); diff --git a/win32/include/stdlib.h b/win32/include/stdlib.h index 96765b29..033c0fdf 100644 --- a/win32/include/stdlib.h +++ b/win32/include/stdlib.h @@ -136,7 +136,7 @@ extern "C" { #ifndef _CRT_ERRNO_DEFINED #define _CRT_ERRNO_DEFINED - _CRTIMP extern int *__cdecl _errno(void); + _CRTIMP int *__cdecl _errno(void); #define errno (*_errno()) errno_t __cdecl _set_errno(int _Value); errno_t __cdecl _get_errno(int *_Value); diff --git a/win32/include/tcc/tcc_libm.h b/win32/include/tcc/tcc_libm.h index cb256fe1..58b502e5 100644 --- a/win32/include/tcc/tcc_libm.h +++ b/win32/include/tcc/tcc_libm.h @@ -467,7 +467,7 @@ __CRT_INLINE long double __cdecl hypotl(long double x, long double y) { return h __CRT_INLINE long double __cdecl logl(long double x) { return log(x); } __CRT_INLINE long double __cdecl logbl(long double x) { return logb(x); } __CRT_INLINE long double __cdecl log10l(long double x) { return log10(x); } -__CRT_INLINE long double __cdecl modfl(long double x, long double* y) { return modf(x, y); } +__CRT_INLINE long double __cdecl modfl(long double x, long double* y) { double y1 = *y; x = modf(x, &y1); *y = y1; return x; } __CRT_INLINE long double __cdecl powl(long double x, long double y) { return pow(x, y); } __CRT_INLINE long double __cdecl sinhl(long double x) { return sinh(x); } __CRT_INLINE long double __cdecl sinl(long double x) { return sin(x); } diff --git a/x86_64-gen.c b/x86_64-gen.c index 9f9bf2c3..222249d4 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -112,6 +112,11 @@ enum { #include "tcc.h" #include +ST_DATA const char *target_machine_defs = + "__x86_64__\0" + "__amd64__\0" + ; + ST_DATA const int reg_classes[NB_REGS] = { /* eax */ RC_INT | RC_RAX, /* ecx */ RC_INT | RC_RCX,