History

tccpp: cleanup target-os defines

moved target_machine defines to the <target>-gen.c files.

grischka committed 5 years ago

Commit ea82d081 parent d784b2820 files · +316 −278Browse files

Unified · Split

20 files
  1. Makefile +2 −2
  2. arm-gen.c +15 −0
  3. arm64-gen.c +4 −0
  4. c67-gen.c +5 −1
  5. conftest.c +173 −0
  6. i386-gen.c +5 −0
  7. include/stddef.h +2 −16
  8. include/tccdefs.h +28 −22
  9. riscv64-gen.c +11 −0
  10. tcc.h +6 −1
  11. tccgen.c +5 −1
  12. tccpp.c +49 −71
  13. tests/libtcc_test_mt.c +1 −1
  14. tests/misc/c2str.c +0 −158
  15. win32/include/_mingw.h +1 −1
  16. win32/include/errno.h +1 −1
  17. win32/include/math.h +1 −1
  18. win32/include/stdlib.h +1 −1
  19. win32/include/tcc/tcc_libm.h +1 −1
  20. x86_64-gen.c +5 −0
Makefile+2−2
@@ -221,8 +221,8 @@ endif · 220 unmodified lines
221221 endif
222222
223223 # convert "include/tccdefs.h" to "tccdefs_.h"
224−%_.h : include/%.h tests/misc/c2str.c
225− $S$(CC) -o c2str.exe $(filter %.c,$^) && ./c2str.exe $< $@
224+%_.h : include/%.h conftest.c
225+ $S$(CC) -DC2STR $(filter %.c,$^) -o c2str.exe && ./c2str.exe $< $@
226226
227227 # target specific object rule
228228 $(X)%.o : %.c $(LIBTCC_INC)
arm-gen.c+15−0
@@ -141,6 +141,21 @@ enum { · 140 unmodified lines
141141 #define USING_GLOBALS
142142 #include "tcc.h"
143143
144+ST_DATA const char *target_machine_defs =
145+ "__arm__\0"
146+ "__arm\0"
147+ "arm\0"
148+ "__arm_elf__\0"
149+ "__arm_elf\0"
150+ "arm_elf\0"
151+ "__ARM_ARCH_4__\0"
152+ "__ARMEL__\0"
153+ "__APCS_32__\0"
154+#if defined TCC_ARM_EABI
155+ "__ARM_EABI__\0"
156+#endif
157+ ;
158+
144159 enum float_abi float_abi;
145160
146161 ST_DATA const int reg_classes[NB_REGS] = {
arm64-gen.c+4−0
@@ -50,6 +50,10 @@ · 49 unmodified lines
5050 #include "tcc.h"
5151 #include <assert.h>
5252
53+ST_DATA const char *target_machine_defs =
54+ "__aarch64__\0"
55+ ;
56+
5357 ST_DATA const int reg_classes[NB_REGS] = {
5458 RC_INT | RC_R(0),
5559 RC_INT | RC_R(1),
c67-gen.c+5−1
@@ -114,8 +114,12 @@ enum { · 113 unmodified lines
114114 #define USING_GLOBALS
115115 #include "tcc.h"
116116
117+ST_DATA const char *target_machine_defs =
118+ "__C67__\0"
119+ ;
120+
117121 ST_DATA const int reg_classes[NB_REGS] = {
118− /* eax */ RC_INT | RC_FLOAT | RC_EAX,
122+ /* eax */ RC_INT | RC_FLOAT | RC_EAX,
119123 // only allow even regs for floats (allow for doubles)
120124 /* ecx */ RC_INT | RC_ECX,
121125 /* edx */ RC_INT | RC_INT_BSIDE | RC_FLOAT | RC_EDX,
conftest.c+173−0
@@ -1,3 +1,173 @@
1+/* ----------------------------------------------------------------------- */
2+#if C2STR
3+
4+/* with -D C2STR: convert tccdefs.h to C-strings */
5+
6+#include <stdio.h>
7+#include <string.h>
8+
9+/* replace native host macros by compile-time versions */
10+const char *platform_macros[] = {
11+ "__i386__", "TCC_TARGET_I386",
12+ "__x86_64__", "TCC_TARGET_X86_64",
13+ "_WIN32", "TCC_TARGET_PE",
14+ "__arm__", "TCC_TARGET_ARM",
15+ "__ARM_EABI__", "TCC_ARM_EABI",
16+ "__aarch64__", "TCC_TARGET_ARM64",
17+ "__riscv", "TCC_TARGET_RISCV64",
18+ "__APPLE__", "TCC_TARGET_MACHO",
19+ "__FreeBSD__", "TARGETOS_FreeBSD",
20+ "__FreeBSD_kernel__", "TARGETOS_FreeBSD_kernel",
21+ "__OpenBSD__", "TARGETOS_OpenBSD",
22+ "__NetBSD__", "TARGETOS_NetBSD",
23+ "__linux__", "TARGETOS_Linux",
24+ "__SIZEOF_POINTER__", "PTR_SIZE",
25+ "__SIZEOF_LONG__", "LONG_SIZE",
26+ 0
27+};
28+
29+int isid(int c)
30+{
31+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
32+ || (c >= '0' && c <= '9') || c == '_';
33+}
34+
35+int isspc(int c)
36+{
37+ return (unsigned char)c <= ' ' && c != 0;
38+}
39+
40+int main(int argc, char **argv)
41+{
42+ char l[1000], l2[1000], *p, *q, *p0;
43+ FILE *fp, *op;
44+ int c, e, f, s, cmt, cmt_n;
45+ const char *r;
46+
47+ if (argc < 3)
48+ return 1;
49+
50+ fp = fopen(argv[1], "rb");
51+ op = fopen(argv[2], "wb");
52+ if (!fp || !op) {
53+ fprintf(stderr, "c2str: file error\n");
54+ return 1;
55+ }
56+
57+ cmt = cmt_n = 0;
58+ for (;;) {
59+ p = l;
60+ append:
61+ if (fgets(p, sizeof l - (p - l), fp)) {
62+ p = strchr(p, 0);
63+ while (p > l && isspc(p[-1]))
64+ --p;
65+ *p = 0;
66+ } else if (p == l)
67+ break;
68+
69+ /* check for continuation */
70+ if (p > l && p[-1] == '\\') {
71+ p[-1] = ' ';
72+ goto append;
73+ }
74+
75+ /* count & skip leading spaces */
76+ p = l, q = l2, f = 0;
77+ while (*p && isspc(*p))
78+ ++p, ++f;
79+
80+ /* handle comments */
81+ if (p[0] == '/' && cmt == 0) {
82+ if (p[1] == '*')
83+ cmt = 2;
84+ if (p[1] == '/')
85+ cmt = 1;
86+ }
87+ if (cmt) {
88+ fprintf(op, "%s", l);
89+ if (++cmt_n == 1)
90+ fprintf(op, " (converted, do not edit this file)");
91+ fprintf(op, "\n");
92+ if (cmt == 1)
93+ cmt = 0;
94+ if (cmt == 2) {
95+ p = strchr(l, 0);
96+ if (p >= l + 2 && p[-1] == '/' && p[-2] == '*')
97+ cmt = 0;
98+ }
99+ continue;
100+ }
101+
102+ if (f < 4) {
103+ do {
104+ /* replace machine/os macros by compile-time counterparts */
105+ for (e = f = 0; (r = platform_macros[f]); f += 2) {
106+ c = strlen(r);
107+ /* remove 'defined' */
108+ //e = memcmp(p, "defined ", 8) ? 0 : 8;
109+ if (0 == memcmp(p + e, r, c)) {
110+ p += e + c;
111+ q = strchr(strcpy(q, platform_macros[f + 1]), 0);
112+ break;
113+ }
114+
115+ }
116+ if (r)
117+ continue;
118+ } while (!!(*q++ = *p++));
119+ /* output as is */
120+ fprintf(op, "%s\n", l2);
121+ continue;
122+
123+ } else {
124+ s = e = f = 0, p0 = p;
125+ for (;;) {
126+ c = *p++;
127+
128+ if (isspc(c)) {
129+ s = 1;
130+ continue;
131+ }
132+ if (c == '/' && (p[0] == '/' || p[0] == '*'))
133+ c = 0; /* trailing comment detected */
134+ else if (s && q > l2
135+ && ((isid(q[-1]) && isid(c))
136+ // keep space after macro name
137+ || (q >= l2 + 2
138+ && l2[0] == '#'
139+ && l2[1] == 'd'
140+ && f < 2 && !e
141+ )))
142+ *q++ = ' ', ++f;
143+ s = 0;
144+
145+ if (c == '(')
146+ ++e;
147+ if (c == ')')
148+ --e;
149+ if (c == '\\' || c == '\"')
150+ *q++ = '\\';
151+ *q++ = c;
152+ if (c == 0)
153+ break;
154+ p0 = p;
155+ }
156+ /* output with quotes */
157+ fprintf(op, " \"%s\\n\"%s\n", l2, p0);
158+ }
159+ }
160+
161+ fclose(fp);
162+ fclose(op);
163+ return 0;
164+}
165+
166+/* ----------------------------------------------------------------------- */
167+#elif 1
168+
169+/* get some information from the host compiler for configure */
170+
1171 #include <stdio.h>
2172
3173 #if defined(_WIN32)
@@ -123,3 +293,6 @@ int main(int argc, char *argv[]) · 119 unmodified lines
123293 }
124294 return 0;
125295 }
296+
297+/* ----------------------------------------------------------------------- */
298+#endif
i386-gen.c+5−0
@@ -81,6 +81,11 @@ enum { · 80 unmodified lines
8181 #define USING_GLOBALS
8282 #include "tcc.h"
8383
84+ST_DATA const char *target_machine_defs =
85+ "__i386__\0"
86+ "__i386\0"
87+ ;
88+
8489 /* define to 1/0 to [not] have EBX as 4th register */
8590 #define USE_EBX 0
8691
include/stddef.h+2−16
@@ -17,25 +17,11 @@ typedef union { long long __ll; long double __ld; } max_align_t; · 16 unmodified lines
1717 typedef signed char int8_t;
1818 typedef signed short int int16_t;
1919 typedef signed int int32_t;
20−#if defined(__LP64__) \
21− && !defined(__APPLE__) \
22− && !defined(__OpenBSD__) \
23− && !(defined(__NetBSD__) && defined(__aarch64__))
24−typedef signed long int int64_t;
25−#else
26−typedef signed long long int int64_t;
27−#endif
20+typedef signed __INT64_TYPE__ int64_t;
2821 typedef unsigned char uint8_t;
2922 typedef unsigned short int uint16_t;
3023 typedef unsigned int uint32_t;
31−#if defined(__LP64__) \
32− && !defined(__APPLE__) \
33− && !defined(__OpenBSD__) \
34− && !(defined(__NetBSD__) && defined(__aarch64__))
35−typedef unsigned long int uint64_t;
36−#else
37−typedef unsigned long long int uint64_t;
38−#endif
24+typedef unsigned __INT64_TYPE__ uint64_t;
3925 #endif
4026
4127 #ifndef NULL
include/tccdefs.h+28−22
@@ -1,27 +1,43 @@
11 /* tccdefs.h
2− *
3− * By using native platf�rm macros this file may be included at runtime
4− * just as is.
5− *
6− * If converted to C-strings and included in tccpp.c, these are trahslated
7− * to tcc target macros accordingly.
8− */
2+
3+ Nothing is defined before this file except target machine, target os
4+ and the few things related to option settings in tccpp.c:tcc_predefs().
5+
6+ This file is either included at runtime as is, or converted and
7+ included as C-strings at compile-time (depending on CONFIG_TCC_PREDEFS).
8+
9+ Note that line indent matters:
10+
11+ - in lines starting at column 1, platform macros are replaced by
12+ corresponding TCC target compile-time macros. See conftest.c for
13+ the list of platform macros supported in lines starting at column 1.
14+
15+ - only lines indented >= 4 are actually included into the executable,
16+ check tccdefs_.h.
17+*/
918
1019 #if __SIZEOF_POINTER__ == 4
1120 /* 32bit systems. */
1221 #define __SIZE_TYPE__ unsigned int
1322 #define __PTRDIFF_TYPE__ int
1423 #define __ILP32__ 1
24+ #define __INT64_TYPE__ long long
1525 #elif __SIZEOF_LONG__ == 4
1626 /* 64bit Windows. */
1727 #define __SIZE_TYPE__ unsigned long long
1828 #define __PTRDIFF_TYPE__ long long
1929 #define __LLP64__ 1
30+ #define __INT64_TYPE__ long long
2031 #else
2132 /* Other 64bit systems. */
2233 #define __SIZE_TYPE__ unsigned long
2334 #define __PTRDIFF_TYPE__ long
2435 #define __LP64__ 1
36+# if defined __linux__
37+ #define __INT64_TYPE__ long
38+# else /* APPLE, BSD */
39+ #define __INT64_TYPE__ long long
40+# endif
2541 #endif
2642 #define __SIZEOF_INT__ 4
2743 #define __INT_MAX__ 0x7fffffff
@@ -58,15 +74,10 @@ · 30 unmodified lines
5874 #endif
5975
6076 #if defined _WIN32
61− //#define _WIN32 1
62−# if __SIZEOF_POINTER__ == 8
63− #define _WIN64 1
64−# endif
6577 #define __declspec(x) __attribute__((x))
6678 #define __cdecl
6779
6880 #elif defined __FreeBSD__
69− //#define __FreeBSD__ 12
7081 #define __GNUC__ 9
7182 #define __GNUC_MINOR__ 3
7283 #define __GNUC_PATCHLEVEL__ 0
@@ -78,27 +89,22 @@ · 5 unmodified lines
7889 # endif
7990
8091 #elif defined __FreeBSD_kernel__
81− //#define __FreeBSD_kernel__ 1
8292
8393 #elif defined __NetBSD__
84− //#define __NetBSD__ 1
8594 #define __GNUC__ 4
8695 #define __GNUC_MINOR__ 1
8796 #define __GNUC_PATCHLEVEL__ 0
8897 #define _Pragma(x)
8998 #define __ELF__ 1
90− #if defined(__aarch64__) && defined(__TINYC__) && !defined(_LOCORE)
91− /* avoids usage of __asm which is not yet supported by tcc */
92− #define _LOCORE
93− #endif
99+#if defined __aarch64__
100+ #define _LOCORE /* avoids usage of __asm */
101+#endif
94102
95103 #elif defined __OpenBSD__
96− //#define __OpenBSD__ 1
97104 #define __GNUC__ 4
98105 #define _ANSI_LIBRARY 1
99106
100107 #elif defined __APPLE__
101− //#define __APPLE__ 1
102108 /* emulate APPLE-GCC to make libc's headerfiles compile: */
103109 #define __GNUC__ 4 /* darwin emits warning on GCC<4 */
104110 #define __APPLE_CC__ 1 /* for <TargetConditionals.h> */
@@ -108,8 +114,8 @@ · 3 unmodified lines
108114 #define _FORTIFY_SOURCE 0
109115
110116 #else
111− //#define __linux__ 1
112− //#define __linux 1
117+ /* Linux */
118+
113119 #endif
114120
115121 #if !defined _WIN32
riscv64-gen.c+11−0
@@ -36,6 +36,17 @@ · 35 unmodified lines
3636 #include "tcc.h"
3737 #include <assert.h>
3838
39+ST_DATA const char *target_machine_defs =
40+ "__riscv\0"
41+ "__riscv_xlen 64\0"
42+ "__riscv_flen 64\0"
43+ "__riscv_div\0"
44+ "__riscv_mul\0"
45+ "__riscv_fdiv\0"
46+ "__riscv_fsqrt\0"
47+ "__riscv_float_abi_double\0"
48+ ;
49+
3950 #define XLEN 8
4051
4152 #define TREG_RA 17
tcc.h+6−1
@@ -211,6 +211,11 @@ extern long double strtold (const char *__nptr, char **__endptr); · 210 unmodified lines
211211 # define ELF_OBJ_ONLY /* create elf .o but native executables */
212212 #endif
213213
214+/* No ten-byte long doubles on window except in cross-compilers made by GCC */
215+#if defined TCC_TARGET_PE || (defined _WIN32 && !defined __GNUC__)
216+# define TCC_USING_DOUBLE_FOR_LDOUBLE 1
217+#endif
218+
214219 /* ------------ path configuration ------------ */
215220
216221 #ifndef CONFIG_SYSROOT
@@ -1620,7 +1625,7 @@ ST_FUNC void relocate_plt(TCCState *s1); · 1403 unmodified lines
16201625 ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
16211626
16221627 /* ------------ xxx-gen.c ------------ */
1623−
1628+ST_DATA const char *target_machine_defs;
16241629 ST_DATA const int reg_classes[NB_REGS];
16251630
16261631 ST_FUNC void gsym_addr(int t, int a);
tccgen.c+5−1
@@ -160,7 +160,11 @@ static const struct { · 159 unmodified lines
160160 { VT_BYTE | VT_DEFSIGN | VT_UNSIGNED, "unsigned char:t13=r13;0;255;" },
161161 { VT_FLOAT, "float:t14=r1;4;0;" },
162162 { VT_DOUBLE, "double:t15=r1;8;0;" },
163+#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
164+ { VT_DOUBLE | VT_LONG, "long double:t16=r1;8;0;" },
165+#else
163166 { VT_LDOUBLE, "long double:t16=r1;16;0;" },
167+#endif
164168 { -1, "_Float32:t17=r1;4;0;" },
165169 { -1, "_Float64:t18=r1;8;0;" },
166170 { -1, "_Float128:t19=r1;16;0;" },
@@ -5061,7 +5065,7 @@ the_end: · 4894 unmodified lines
50615065 bt = t & (VT_BTYPE|VT_LONG);
50625066 if (bt == VT_LONG)
50635067 t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT;
5064−#if defined TCC_TARGET_PE || (defined _WIN32 && defined _MSC_VER)
5068+#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
50655069 if (bt == VT_LDOUBLE)
50665070 t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG);
50675071 #endif
tccpp.c+49−71
@@ -1840,8 +1840,6 @@ ST_FUNC void preprocess(int is_bof) · 1839 unmodified lines
18401840
18411841 if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)
18421842 tcc_error("#include recursion too deep");
1843− /* push current file on stack */
1844− *s1->include_stack_ptr++ = file;
18451843 i = tok == TOK_INCLUDE_NEXT ? file->include_next_index + 1 : 0;
18461844 n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;
18471845 for (; i < n; ++i) {
@@ -1884,7 +1882,8 @@ ST_FUNC void preprocess(int is_bof) · 36 unmodified lines
18841882
18851883 if (tcc_open(s1, buf1) < 0)
18861884 continue;
1887−
1885+ /* push previous file on stack */
1886+ *s1->include_stack_ptr++ = file->prev;
18881887 file->include_next_index = i;
18891888 #ifdef INC_DEBUG
18901889 printf("%s: including %s\n", file->prev->filename, file->filename);
@@ -1907,7 +1906,6 @@ ST_FUNC void preprocess(int is_bof) · 16 unmodified lines
19071906 }
19081907 tcc_error("include file '%s' not found", buf);
19091908 include_done:
1910− --s1->include_stack_ptr;
19111909 break;
19121910 case TOK_IFNDEF:
19131911 c = 1;
@@ -3625,97 +3623,77 @@ ST_INLN void unget_tok(int last_tok) · 1711 unmodified lines
36253623 tok = last_tok;
36263624 }
36273625
3628−static void tcc_predefs(TCCState *s1, CString *cs, int is_asm)
3629−{
3630− int a,b,c;
3626+/* ------------------------------------------------------------------------- */
3627+/* init preprocessor */
36313628
3632− sscanf(TCC_VERSION, "%d.%d.%d", &a, &b, &c);
3633− cstr_printf(cs, "#define __TINYC__ %d\n", a*10000 + b*100 + c);
3634− cstr_cat(cs,
3635− /* target machine */
3636−#if defined TCC_TARGET_I386
3637− "#define __i386__ 1\n"
3638− "#define __i386 1\n"
3639−#elif defined TCC_TARGET_X86_64
3640− "#define __x86_64__ 1\n"
3641− "#define __amd64__ 1\n"
3642−#elif defined TCC_TARGET_ARM
3643− "#define __ARM_ARCH_4__ 1\n"
3644− "#define __arm_elf__ 1\n"
3645− "#define __arm_elf 1\n"
3646− "#define arm_elf 1\n"
3647− "#define __arm__ 1\n"
3648− "#define __arm 1\n"
3649− "#define arm 1\n"
3650− "#define __APCS_32__ 1\n"
3651− "#define __ARMEL__ 1\n"
3652−# if defined TCC_ARM_EABI
3653− "#define __ARM_EABI__ 1\n"
3654−# endif
3655−#elif defined TCC_TARGET_ARM64
3656− "#define __aarch64__ 1\n"
3657−#elif defined TCC_TARGET_C67
3658− "#define __C67__ 1\n"
3659−#elif defined TCC_TARGET_RISCV64
3660− "#define __riscv 1\n"
3661− "#define __riscv_xlen 64\n"
3662− "#define __riscv_flen 64\n"
3663− "#define __riscv_div 1\n"
3664− "#define __riscv_mul 1\n"
3665− "#define __riscv_fdiv 1\n"
3666− "#define __riscv_fsqrt 1\n"
3667− "#define __riscv_float_abi_double 1\n"
3668−#endif
3669− , -1);
3670−#ifdef TCC_TARGET_ARM
3671− if (s1->float_abi == ARM_HARD_FLOAT)
3672− cstr_printf(cs, "#define __ARM_PCS_VFP 1\n");
3673−#endif
3674− cstr_cat(cs,
3675− /* target platform */
3629+static const char *target_os_defs =
36763630 #ifdef TCC_TARGET_PE
3677− "#define _WIN32 1\n"
3631+ "_WIN32\0"
3632+# if PTR_SIZE == 8
3633+ "_WIN64\0"
3634+# endif
36783635 #else
3679− "#define __unix__ 1\n"
3680− "#define __unix 1\n"
36813636 # if defined TCC_TARGET_MACHO
3682− "#define __APPLE__ 1\n"
3637+ "__APPLE__\0"
36833638 # elif TARGETOS_FreeBSD
3684− "#define __FreeBSD__ 12\n"
3639+ "__FreeBSD__ 12\0"
36853640 # elif TARGETOS_FreeBSD_kernel
3686− "#define __FreeBSD_kernel__ 1\n"
3641+ "__FreeBSD_kernel__\0"
36873642 # elif TARGETOS_NetBSD
3688− "#define __NetBSD__ 1\n"
3643+ "__NetBSD__\0"
36893644 # elif TARGETOS_OpenBSD
3690− "#define __OpenBSD__ 1\n"
3645+ "__OpenBSD__\0"
36913646 # else
3692− "#define __linux__ 1\n"
3693− "#define __linux 1\n"
3647+ "__linux__\0"
3648+ "__linux\0"
36943649 # endif
3650+ "__unix__\0"
3651+ "__unix\0"
3652+#endif
3653+ ;
3654+
3655+static void putdef(CString *cs, const char *p)
3656+{
3657+ cstr_printf(cs, "#define %s%s\n", p, &" 1"[!!strchr(p, ' ')*2]);
3658+}
3659+
3660+static void tcc_predefs(TCCState *s1, CString *cs, int is_asm)
3661+{
3662+ int a, b, c;
3663+ const char *defs[] = { target_machine_defs, target_os_defs, NULL };
3664+ const char *p;
3665+
3666+ sscanf(TCC_VERSION, "%d.%d.%d", &a, &b, &c);
3667+ cstr_printf(cs, "#define __TINYC__ %d\n", a*10000 + b*100 + c);
3668+ for (a = 0; defs[a]; ++a)
3669+ for (p = defs[a]; *p; p = strchr(p, 0) + 1)
3670+ putdef(cs, p);
3671+#ifdef TCC_TARGET_ARM
3672+ if (s1->float_abi == ARM_HARD_FLOAT)
3673+ putdef(cs, "__ARM_PCS_VFP");
36953674 #endif
3696− , -1);
36973675 if (is_asm)
3698− cstr_printf(cs, "#define __ASSEMBLER__ 1\n");
3676+ putdef(cs, "__ASSEMBLER__");
36993677 if (s1->output_type == TCC_OUTPUT_PREPROCESS)
3700− cstr_printf(cs, "#define __TCC_PP__ 1\n");
3678+ putdef(cs, "__TCC_PP__");
37013679 if (s1->output_type == TCC_OUTPUT_MEMORY)
3702− cstr_printf(cs, "#define __TCC_RUN__ 1\n");
3680+ putdef(cs, "__TCC_RUN__");
37033681 if (s1->char_is_unsigned)
3704− cstr_printf(cs, "#define __CHAR_UNSIGNED__ 1\n");
3682+ putdef(cs, "__CHAR_UNSIGNED__");
37053683 if (s1->optimize > 0)
3706− cstr_printf(cs, "#define __OPTIMIZE__ 1\n");
3684+ putdef(cs, "__OPTIMIZE__");
37073685 if (s1->option_pthread)
3708− cstr_printf(cs, "#define _REENTRANT 1\n");
3686+ putdef(cs, "_REENTRANT");
37093687 if (s1->leading_underscore)
3710− cstr_printf(cs, "#define __leading_underscore 1\n");
3688+ putdef(cs, "__leading_underscore");
37113689 #ifdef CONFIG_TCC_BCHECK
37123690 if (s1->do_bounds_check)
3713− cstr_printf(cs, "#define __BOUNDS_CHECKING_ON 1\n");
3691+ putdef(cs, "__BOUNDS_CHECKING_ON");
37143692 #endif
37153693 cstr_printf(cs, "#define __SIZEOF_POINTER__ %d\n", PTR_SIZE);
37163694 cstr_printf(cs, "#define __SIZEOF_LONG__ %d\n", LONG_SIZE);
37173695 if (!is_asm) {
3718− cstr_printf(cs, "#define __STDC__ 1\n");
3696+ putdef(cs, "__STDC__");
37193697 cstr_printf(cs, "#define __STDC_VERSION__ %dL\n", s1->cversion);
37203698 cstr_cat(cs,
37213699 /* load more predefs and __builtins */
tests/libtcc_test_mt.c+1−1
@@ -269,7 +269,7 @@ int main(int argc, char **argv) · 268 unmodified lines
269269 printf("\n (%u ms)\n", getclock_ms() - t);
270270 #endif
271271 #if 1
272− printf("running tcc.c in threads to run fib\n"), fflush(stdout);
272+ printf("running tcc.c in threads to run fib\n "), fflush(stdout);
273273 t = getclock_ms();
274274 for (n = 0; n < M; ++n)
275275 create_thread(thread_test_complex, n);
tests/misc/c2str.c+0−158
@@ -1,158 +0,0 @@
1−#include <stdio.h>
2−#include <string.h>
3−
4−/* replace native host macros by compile-time versions */
5−const char *platform_macros[] = {
6− "__i386__", "TCC_TARGET_I386",
7− "__x86_64__", "TCC_TARGET_X86_64",
8− "_WIN32", "TCC_TARGET_PE",
9− "__arm__", "TCC_TARGET_ARM",
10− "__ARM_EABI__", "TCC_ARM_EABI",
11− "__aarch64__", "TCC_TARGET_ARM64",
12− "__riscv", "TCC_TARGET_RISCV64",
13− "__APPLE__", "TCC_TARGET_MACHO",
14− "__FreeBSD__", "TARGETOS_FreeBSD",
15− "__FreeBSD_kernel__", "TARGETOS_FreeBSD_kernel",
16− "__OpenBSD__", "TARGETOS_OpenBSD",
17− "__NetBSD__", "TARGETOS_NetBSD",
18− "__linux__", "TARGETOS_Linux",
19− "__SIZEOF_POINTER__", "PTR_SIZE",
20− "__SIZEOF_LONG__", "LONG_SIZE",
21− 0
22−};
23−
24−int isid(int c)
25−{
26− return (c >= 'a' && c <= 'z')
27− || (c >= 'A' && c <= 'Z')
28− || (c >= '0' && c <= '9')
29− || c == '_';
30−}
31−
32−int isspc(int c)
33−{
34− return c == ' ' || c == '\t';
35−}
36−
37−int main(int argc, char **argv)
38−{
39− char l[1000], l2[1000], *p, *q, *p0;
40− FILE *fp, *op;
41− int c, e, f, cmt, cmt_n;
42− const char *r;
43−
44− if (argc < 3)
45− return 1;
46−
47− fp = fopen(argv[1], "rb");
48− op = fopen(argv[2], "wb");
49− if (!fp || !op) {
50− fprintf(stderr, "c2str: file error\n");
51− return 1;
52− }
53−
54− cmt = cmt_n = 0;
55− for (;;) {
56− p = l;
57− append:
58− if (fgets(p, sizeof l - (p - l), fp)) {
59− p = strchr(p, 0);
60− while (p > l && p[-1] <= ' ')
61− --p;
62− *p = 0;
63− } else if (p == l)
64− break;
65−
66− /* check for continuation */
67− if (p > l && p[-1] == '\\') {
68− p[-1] = ' ';
69− goto append;
70− }
71−
72− p = l, q = l2, f = 0;
73− /* count & skip leading spaces */
74− while (*p && isspc(*p))
75− ++p, ++f;
76−
77− /* handle comments */
78− if (p[0] == '/' && cmt == 0) {
79− if (p[1] == '*')
80− cmt = 2;
81− if (p[1] == '/')
82− cmt = 1;
83− }
84− if (cmt) {
85− fprintf(op, "%s", l);
86− if (++cmt_n == 1)
87− fprintf(op, " (converted, do not edit this file)");
88− fprintf(op, "\n");
89− if (cmt == 1)
90− cmt = 0;
91− if (cmt == 2) {
92− p = strchr(l, 0);
93− if (p >= l + 2 && p[-1] == '/' && p[-2] == '*')
94− cmt = 0;
95− }
96− continue;
97− }
98−
99− if (f < 4) {
100− /* less than 4 leading spaces : no quotes but replace macros
101− by compile-time versions */
102− do {
103− for (f = 0; (r = platform_macros[f]); f += 2) {
104− c = strlen(r);
105− e = 0;
106− /*if (memcmp(p, "defined ", 8))
107− e = 8;*/
108− if (0 == memcmp(p + e, r, c)) {
109− p += e + c;
110− q = strchr(strcpy(q, platform_macros[f + 1]), 0);
111− break;
112− }
113−
114− }
115− if (r)
116− continue;
117− } while (!!(*q++ = *p++));
118− fprintf(op, "%s\n", l2);
119− continue;
120−
121− } else {
122− /* output line as C string */
123− e = f = 0, p0 = p;
124− for (;;) {
125− c = *p++;
126−
127− if (c == '/' && (p[0] == '/' || p[0] == '*'))
128− c = 0; /* trailing comment detected */
129−
130− if (isspc(c)) {
131− /* remove spaces if possible */
132− if (q == l2 || isspc(q[-1]))
133− continue;
134− /* keep space after macro identifier */
135− if ((f >= 2 || e) && (!isid(q[-1]) || !isid(*p)))
136− continue;
137− if (f == 1)
138− f = 2;
139− }
140− if (c == '(')
141− ++e;
142− if (c == ')')
143− --e, f += e == 0;
144− if (c == '\\' || c == '\"')
145− *q++ = '\\';
146− *q++ = c;
147− if (c == 0)
148− break;
149− p0 = p;
150− }
151− fprintf(op, " \"%s\\n\"%s\n", l2, p0);
152− }
153− }
154−
155− fclose(fp);
156− fclose(op);
157− return 0;
158−}
win32/include/_mingw.h+1−1
@@ -80,7 +80,6 @@ · 79 unmodified lines
8080 #define __stdcall __attribute__((__stdcall__))
8181 #define _X86_ 1
8282 #define _M_IX86 300 /* Visual Studio */
83−#define WIN32 1
8483 #define _USE_32BIT_TIME_T
8584 #endif
8685
@@ -160,5 +159,6 @@ typedef struct localeinfo_struct _locale_tstruct,*_locale_t; · 73 unmodified lines
160159 #define __MINGW_EXTENSION
161160 #define WINAPI_FAMILY_PARTITION(X) 1
162161 #define MINGW_HAS_SECURE_API
162+#define WIN32 1
163163
164164 #endif /* __MINGW_H */
win32/include/errno.h+1−1
@@ -14,7 +14,7 @@ extern "C" { · 13 unmodified lines
1414
1515 #ifndef _CRT_ERRNO_DEFINED
1616 #define _CRT_ERRNO_DEFINED
17− _CRTIMP extern int *__cdecl _errno(void);
17+ _CRTIMP int *__cdecl _errno(void);
1818 #define errno (*_errno())
1919
2020 errno_t __cdecl _set_errno(int _Value);
win32/include/math.h+1−1
@@ -274,7 +274,7 @@ extern "C" { · 273 unmodified lines
274274 : __signbitl (x))
275275 */
276276 #define signbit(x) \
277− _Generic(x, float: __signbitf, double: __signbit, long double: signbitl)(x)
277+ _Generic(x, float: __signbitf, double: __signbit, long double: __signbitl)(x)
278278
279279 extern double __cdecl exp2(double);
280280 extern float __cdecl exp2f(float);
win32/include/stdlib.h+1−1
@@ -136,7 +136,7 @@ extern "C" { · 135 unmodified lines
136136
137137 #ifndef _CRT_ERRNO_DEFINED
138138 #define _CRT_ERRNO_DEFINED
139− _CRTIMP extern int *__cdecl _errno(void);
139+ _CRTIMP int *__cdecl _errno(void);
140140 #define errno (*_errno())
141141 errno_t __cdecl _set_errno(int _Value);
142142 errno_t __cdecl _get_errno(int *_Value);
win32/include/tcc/tcc_libm.h+1−1
@@ -467,7 +467,7 @@ __CRT_INLINE long double __cdecl hypotl(long double x, long double y) { return h · 466 unmodified lines
467467 __CRT_INLINE long double __cdecl logl(long double x) { return log(x); }
468468 __CRT_INLINE long double __cdecl logbl(long double x) { return logb(x); }
469469 __CRT_INLINE long double __cdecl log10l(long double x) { return log10(x); }
470−__CRT_INLINE long double __cdecl modfl(long double x, long double* y) { return modf(x, y); }
470+__CRT_INLINE long double __cdecl modfl(long double x, long double* y) { double y1 = *y; x = modf(x, &y1); *y = y1; return x; }
471471 __CRT_INLINE long double __cdecl powl(long double x, long double y) { return pow(x, y); }
472472 __CRT_INLINE long double __cdecl sinhl(long double x) { return sinh(x); }
473473 __CRT_INLINE long double __cdecl sinl(long double x) { return sin(x); }
x86_64-gen.c+5−0
@@ -112,6 +112,11 @@ enum { · 111 unmodified lines
112112 #include "tcc.h"
113113 #include <assert.h>
114114
115+ST_DATA const char *target_machine_defs =
116+ "__x86_64__\0"
117+ "__amd64__\0"
118+ ;
119+
115120 ST_DATA const int reg_classes[NB_REGS] = {
116121 /* eax */ RC_INT | RC_RAX,
117122 /* ecx */ RC_INT | RC_RCX,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t