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
221endif221endif
222 222
223# convert "include/tccdefs.h" to "tccdefs_.h"223# convert "include/tccdefs.h" to "tccdefs_.h"
224%_.h : include/%.h tests/misc/c2str.c224%_.h : include/%.h conftest.c
225 $S$(CC) -o c2str.exe $(filter %.c,$^) && ./c2str.exe $< $@225 $S$(CC) -DC2STR $(filter %.c,$^) -o c2str.exe && ./c2str.exe $< $@
226 226
227# target specific object rule227# target specific object rule
228$(X)%.o : %.c $(LIBTCC_INC)228$(X)%.o : %.c $(LIBTCC_INC)
arm-gen.c+15−0
@@ -141,6 +141,21 @@ enum { · 140 unmodified lines
141#define USING_GLOBALS141#define USING_GLOBALS
142#include "tcc.h"142#include "tcc.h"
143 143
144ST_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
144enum float_abi float_abi;159enum float_abi float_abi;
145 160
146ST_DATA const int reg_classes[NB_REGS] = {161ST_DATA const int reg_classes[NB_REGS] = {
arm64-gen.c+4−0
@@ -50,6 +50,10 @@ · 49 unmodified lines
50#include "tcc.h"50#include "tcc.h"
51#include <assert.h>51#include <assert.h>
52 52
53ST_DATA const char *target_machine_defs =
54 "__aarch64__\0"
55 ;
56
53ST_DATA const int reg_classes[NB_REGS] = {57ST_DATA const int reg_classes[NB_REGS] = {
54 RC_INT | RC_R(0),58 RC_INT | RC_R(0),
55 RC_INT | RC_R(1),59 RC_INT | RC_R(1),
c67-gen.c+5−1
@@ -114,8 +114,12 @@ enum { · 113 unmodified lines
114#define USING_GLOBALS114#define USING_GLOBALS
115#include "tcc.h"115#include "tcc.h"
116 116
117ST_DATA const char *target_machine_defs =
118 "__C67__\0"
119 ;
120
117ST_DATA const int reg_classes[NB_REGS] = {121ST_DATA const int reg_classes[NB_REGS] = {
118 /* eax */ RC_INT | RC_FLOAT | RC_EAX, 122 /* eax */ RC_INT | RC_FLOAT | RC_EAX,
119 // only allow even regs for floats (allow for doubles)123 // only allow even regs for floats (allow for doubles)
120 /* ecx */ RC_INT | RC_ECX,124 /* ecx */ RC_INT | RC_ECX,
121 /* edx */ RC_INT | RC_INT_BSIDE | RC_FLOAT | RC_EDX,125 /* 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 */
10const 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
29int isid(int c)
30{
31 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
32 || (c >= '0' && c <= '9') || c == '_';
33}
34
35int isspc(int c)
36{
37 return (unsigned char)c <= ' ' && c != 0;
38}
39
40int 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
1#include <stdio.h>171#include <stdio.h>
2 172
3#if defined(_WIN32)173#if defined(_WIN32)
@@ -123,3 +293,6 @@ int main(int argc, char *argv[]) · 119 unmodified lines
123 }293 }
124 return 0;294 return 0;
125}295}
296
297/* ----------------------------------------------------------------------- */
298#endif
i386-gen.c+5−0
@@ -81,6 +81,11 @@ enum { · 80 unmodified lines
81#define USING_GLOBALS81#define USING_GLOBALS
82#include "tcc.h"82#include "tcc.h"
83 83
84ST_DATA const char *target_machine_defs =
85 "__i386__\0"
86 "__i386\0"
87 ;
88
84/* define to 1/0 to [not] have EBX as 4th register */89/* define to 1/0 to [not] have EBX as 4th register */
85#define USE_EBX 090#define USE_EBX 0
86 91
include/stddef.h+2−16
@@ -17,25 +17,11 @@ typedef union { long long __ll; long double __ld; } max_align_t; · 16 unmodified lines
17typedef signed char int8_t;17typedef signed char int8_t;
18typedef signed short int int16_t;18typedef signed short int int16_t;
19typedef signed int int32_t;19typedef signed int int32_t;
20#if defined(__LP64__) \20typedef signed __INT64_TYPE__ int64_t;
21 && !defined(__APPLE__) \
22 && !defined(__OpenBSD__) \
23 && !(defined(__NetBSD__) && defined(__aarch64__))
24typedef signed long int int64_t;
25#else
26typedef signed long long int int64_t;
27#endif
28typedef unsigned char uint8_t;21typedef unsigned char uint8_t;
29typedef unsigned short int uint16_t;22typedef unsigned short int uint16_t;
30typedef unsigned int uint32_t;23typedef unsigned int uint32_t;
31#if defined(__LP64__) \24typedef unsigned __INT64_TYPE__ uint64_t;
32 && !defined(__APPLE__) \
33 && !defined(__OpenBSD__) \
34 && !(defined(__NetBSD__) && defined(__aarch64__))
35typedef unsigned long int uint64_t;
36#else
37typedef unsigned long long int uint64_t;
38#endif
39#endif25#endif
40 26
41#ifndef NULL27#ifndef NULL
include/tccdefs.h+28−22
@@ -1,27 +1,43 @@
1/* tccdefs.h1/* tccdefs.h
2 *2
3 * By using native platf�rm macros this file may be included at runtime3 Nothing is defined before this file except target machine, target os
4 * just as is.4 and the few things related to option settings in tccpp.c:tcc_predefs().
5 *5
6 * If converted to C-strings and included in tccpp.c, these are trahslated6 This file is either included at runtime as is, or converted and
7 * to tcc target macros accordingly.7 included as C-strings at compile-time (depending on CONFIG_TCC_PREDEFS).
8 */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*/
9 18
10#if __SIZEOF_POINTER__ == 419#if __SIZEOF_POINTER__ == 4
11 /* 32bit systems. */20 /* 32bit systems. */
12 #define __SIZE_TYPE__ unsigned int21 #define __SIZE_TYPE__ unsigned int
13 #define __PTRDIFF_TYPE__ int22 #define __PTRDIFF_TYPE__ int
14 #define __ILP32__ 123 #define __ILP32__ 1
24 #define __INT64_TYPE__ long long
15#elif __SIZEOF_LONG__ == 425#elif __SIZEOF_LONG__ == 4
16 /* 64bit Windows. */26 /* 64bit Windows. */
17 #define __SIZE_TYPE__ unsigned long long27 #define __SIZE_TYPE__ unsigned long long
18 #define __PTRDIFF_TYPE__ long long28 #define __PTRDIFF_TYPE__ long long
19 #define __LLP64__ 129 #define __LLP64__ 1
30 #define __INT64_TYPE__ long long
20#else31#else
21 /* Other 64bit systems. */32 /* Other 64bit systems. */
22 #define __SIZE_TYPE__ unsigned long33 #define __SIZE_TYPE__ unsigned long
23 #define __PTRDIFF_TYPE__ long34 #define __PTRDIFF_TYPE__ long
24 #define __LP64__ 135 #define __LP64__ 1
36# if defined __linux__
37 #define __INT64_TYPE__ long
38# else /* APPLE, BSD */
39 #define __INT64_TYPE__ long long
40# endif
25#endif41#endif
26 #define __SIZEOF_INT__ 442 #define __SIZEOF_INT__ 4
27 #define __INT_MAX__ 0x7fffffff43 #define __INT_MAX__ 0x7fffffff
@@ -58,15 +74,10 @@ · 30 unmodified lines
58 #endif74 #endif
59 75
60#if defined _WIN3276#if defined _WIN32
61 //#define _WIN32 1
62# if __SIZEOF_POINTER__ == 8
63 #define _WIN64 1
64# endif
65 #define __declspec(x) __attribute__((x))77 #define __declspec(x) __attribute__((x))
66 #define __cdecl78 #define __cdecl
67 79
68#elif defined __FreeBSD__80#elif defined __FreeBSD__
69 //#define __FreeBSD__ 12
70 #define __GNUC__ 981 #define __GNUC__ 9
71 #define __GNUC_MINOR__ 382 #define __GNUC_MINOR__ 3
72 #define __GNUC_PATCHLEVEL__ 083 #define __GNUC_PATCHLEVEL__ 0
@@ -78,27 +89,22 @@ · 5 unmodified lines
78# endif89# endif
79 90
80#elif defined __FreeBSD_kernel__91#elif defined __FreeBSD_kernel__
81 //#define __FreeBSD_kernel__ 1
82 92
83#elif defined __NetBSD__93#elif defined __NetBSD__
84 //#define __NetBSD__ 1
85 #define __GNUC__ 494 #define __GNUC__ 4
86 #define __GNUC_MINOR__ 195 #define __GNUC_MINOR__ 1
87 #define __GNUC_PATCHLEVEL__ 096 #define __GNUC_PATCHLEVEL__ 0
88 #define _Pragma(x)97 #define _Pragma(x)
89 #define __ELF__ 198 #define __ELF__ 1
90 #if defined(__aarch64__) && defined(__TINYC__) && !defined(_LOCORE)99#if defined __aarch64__
91 /* avoids usage of __asm which is not yet supported by tcc */100 #define _LOCORE /* avoids usage of __asm */
92 #define _LOCORE101#endif
93 #endif
94 102
95#elif defined __OpenBSD__103#elif defined __OpenBSD__
96 //#define __OpenBSD__ 1
97 #define __GNUC__ 4104 #define __GNUC__ 4
98 #define _ANSI_LIBRARY 1105 #define _ANSI_LIBRARY 1
99 106
100#elif defined __APPLE__107#elif defined __APPLE__
101 //#define __APPLE__ 1
102 /* emulate APPLE-GCC to make libc's headerfiles compile: */108 /* emulate APPLE-GCC to make libc's headerfiles compile: */
103 #define __GNUC__ 4 /* darwin emits warning on GCC<4 */109 #define __GNUC__ 4 /* darwin emits warning on GCC<4 */
104 #define __APPLE_CC__ 1 /* for <TargetConditionals.h> */110 #define __APPLE_CC__ 1 /* for <TargetConditionals.h> */
@@ -108,8 +114,8 @@ · 3 unmodified lines
108 #define _FORTIFY_SOURCE 0114 #define _FORTIFY_SOURCE 0
109 115
110#else116#else
111 //#define __linux__ 1117 /* Linux */
112 //#define __linux 1118
113#endif119#endif
114 120
115#if !defined _WIN32121#if !defined _WIN32
riscv64-gen.c+11−0
@@ -36,6 +36,17 @@ · 35 unmodified lines
36#include "tcc.h"36#include "tcc.h"
37#include <assert.h>37#include <assert.h>
38 38
39ST_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
39#define XLEN 850#define XLEN 8
40 51
41#define TREG_RA 1752#define TREG_RA 17
tcc.h+6−1
@@ -211,6 +211,11 @@ extern long double strtold (const char *__nptr, char **__endptr); · 210 unmodified lines
211# define ELF_OBJ_ONLY /* create elf .o but native executables */211# define ELF_OBJ_ONLY /* create elf .o but native executables */
212#endif212#endif
213 213
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
214/* ------------ path configuration ------------ */219/* ------------ path configuration ------------ */
215 220
216#ifndef CONFIG_SYSROOT221#ifndef CONFIG_SYSROOT
@@ -1620,7 +1625,7 @@ ST_FUNC void relocate_plt(TCCState *s1); · 1403 unmodified lines
1620ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);1625ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
1621 1626
1622/* ------------ xxx-gen.c ------------ */1627/* ------------ xxx-gen.c ------------ */
1623 1628ST_DATA const char *target_machine_defs;
1624ST_DATA const int reg_classes[NB_REGS];1629ST_DATA const int reg_classes[NB_REGS];
1625 1630
1626ST_FUNC void gsym_addr(int t, int a);1631ST_FUNC void gsym_addr(int t, int a);
tccgen.c+5−1
@@ -160,7 +160,11 @@ static const struct { · 159 unmodified lines
160 { VT_BYTE | VT_DEFSIGN | VT_UNSIGNED, "unsigned char:t13=r13;0;255;" },160 { VT_BYTE | VT_DEFSIGN | VT_UNSIGNED, "unsigned char:t13=r13;0;255;" },
161 { VT_FLOAT, "float:t14=r1;4;0;" },161 { VT_FLOAT, "float:t14=r1;4;0;" },
162 { VT_DOUBLE, "double:t15=r1;8;0;" },162 { 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
163 { VT_LDOUBLE, "long double:t16=r1;16;0;" },166 { VT_LDOUBLE, "long double:t16=r1;16;0;" },
167#endif
164 { -1, "_Float32:t17=r1;4;0;" },168 { -1, "_Float32:t17=r1;4;0;" },
165 { -1, "_Float64:t18=r1;8;0;" },169 { -1, "_Float64:t18=r1;8;0;" },
166 { -1, "_Float128:t19=r1;16;0;" },170 { -1, "_Float128:t19=r1;16;0;" },
@@ -5061,7 +5065,7 @@ the_end: · 4894 unmodified lines
5061 bt = t & (VT_BTYPE|VT_LONG);5065 bt = t & (VT_BTYPE|VT_LONG);
5062 if (bt == VT_LONG)5066 if (bt == VT_LONG)
5063 t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT;5067 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
5065 if (bt == VT_LDOUBLE)5069 if (bt == VT_LDOUBLE)
5066 t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG);5070 t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG);
5067#endif5071#endif
tccpp.c+49−71
@@ -1840,8 +1840,6 @@ ST_FUNC void preprocess(int is_bof) · 1839 unmodified lines
1840 1840
1841 if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)1841 if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)
1842 tcc_error("#include recursion too deep");1842 tcc_error("#include recursion too deep");
1843 /* push current file on stack */
1844 *s1->include_stack_ptr++ = file;
1845 i = tok == TOK_INCLUDE_NEXT ? file->include_next_index + 1 : 0;1843 i = tok == TOK_INCLUDE_NEXT ? file->include_next_index + 1 : 0;
1846 n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;1844 n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;
1847 for (; i < n; ++i) {1845 for (; i < n; ++i) {
@@ -1884,7 +1882,8 @@ ST_FUNC void preprocess(int is_bof) · 36 unmodified lines
1884 1882
1885 if (tcc_open(s1, buf1) < 0)1883 if (tcc_open(s1, buf1) < 0)
1886 continue;1884 continue;
1887 1885 /* push previous file on stack */
1886 *s1->include_stack_ptr++ = file->prev;
1888 file->include_next_index = i;1887 file->include_next_index = i;
1889#ifdef INC_DEBUG1888#ifdef INC_DEBUG
1890 printf("%s: including %s\n", file->prev->filename, file->filename);1889 printf("%s: including %s\n", file->prev->filename, file->filename);
@@ -1907,7 +1906,6 @@ ST_FUNC void preprocess(int is_bof) · 16 unmodified lines
1907 }1906 }
1908 tcc_error("include file '%s' not found", buf);1907 tcc_error("include file '%s' not found", buf);
1909include_done:1908include_done:
1910 --s1->include_stack_ptr;
1911 break;1909 break;
1912 case TOK_IFNDEF:1910 case TOK_IFNDEF:
1913 c = 1;1911 c = 1;
@@ -3625,97 +3623,77 @@ ST_INLN void unget_tok(int last_tok) · 1711 unmodified lines
3625 tok = last_tok;3623 tok = last_tok;
3626}3624}
3627 3625
3628static void tcc_predefs(TCCState *s1, CString *cs, int is_asm)3626/* ------------------------------------------------------------------------- */
3629{3627/* init preprocessor */
3630 int a,b,c;
3631 3628
3632 sscanf(TCC_VERSION, "%d.%d.%d", &a, &b, &c);3629static const char *target_os_defs =
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 */
3676#ifdef TCC_TARGET_PE3630#ifdef TCC_TARGET_PE
3677 "#define _WIN32 1\n"3631 "_WIN32\0"
3632# if PTR_SIZE == 8
3633 "_WIN64\0"
3634# endif
3678#else3635#else
3679 "#define __unix__ 1\n"
3680 "#define __unix 1\n"
3681# if defined TCC_TARGET_MACHO3636# if defined TCC_TARGET_MACHO
3682 "#define __APPLE__ 1\n"3637 "__APPLE__\0"
3683# elif TARGETOS_FreeBSD3638# elif TARGETOS_FreeBSD
3684 "#define __FreeBSD__ 12\n"3639 "__FreeBSD__ 12\0"
3685# elif TARGETOS_FreeBSD_kernel3640# elif TARGETOS_FreeBSD_kernel
3686 "#define __FreeBSD_kernel__ 1\n"3641 "__FreeBSD_kernel__\0"
3687# elif TARGETOS_NetBSD3642# elif TARGETOS_NetBSD
3688 "#define __NetBSD__ 1\n"3643 "__NetBSD__\0"
3689# elif TARGETOS_OpenBSD3644# elif TARGETOS_OpenBSD
3690 "#define __OpenBSD__ 1\n"3645 "__OpenBSD__\0"
3691# else3646# else
3692 "#define __linux__ 1\n"3647 "__linux__\0"
3693 "#define __linux 1\n"3648 "__linux\0"
3694# endif3649# endif
3650 "__unix__\0"
3651 "__unix\0"
3652#endif
3653 ;
3654
3655static void putdef(CString *cs, const char *p)
3656{
3657 cstr_printf(cs, "#define %s%s\n", p, &" 1"[!!strchr(p, ' ')*2]);
3658}
3659
3660static 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");
3695#endif3674#endif
3696 , -1);
3697 if (is_asm)3675 if (is_asm)
3698 cstr_printf(cs, "#define __ASSEMBLER__ 1\n");3676 putdef(cs, "__ASSEMBLER__");
3699 if (s1->output_type == TCC_OUTPUT_PREPROCESS)3677 if (s1->output_type == TCC_OUTPUT_PREPROCESS)
3700 cstr_printf(cs, "#define __TCC_PP__ 1\n");3678 putdef(cs, "__TCC_PP__");
3701 if (s1->output_type == TCC_OUTPUT_MEMORY)3679 if (s1->output_type == TCC_OUTPUT_MEMORY)
3702 cstr_printf(cs, "#define __TCC_RUN__ 1\n");3680 putdef(cs, "__TCC_RUN__");
3703 if (s1->char_is_unsigned)3681 if (s1->char_is_unsigned)
3704 cstr_printf(cs, "#define __CHAR_UNSIGNED__ 1\n");3682 putdef(cs, "__CHAR_UNSIGNED__");
3705 if (s1->optimize > 0)3683 if (s1->optimize > 0)
3706 cstr_printf(cs, "#define __OPTIMIZE__ 1\n");3684 putdef(cs, "__OPTIMIZE__");
3707 if (s1->option_pthread)3685 if (s1->option_pthread)
3708 cstr_printf(cs, "#define _REENTRANT 1\n");3686 putdef(cs, "_REENTRANT");
3709 if (s1->leading_underscore)3687 if (s1->leading_underscore)
3710 cstr_printf(cs, "#define __leading_underscore 1\n");3688 putdef(cs, "__leading_underscore");
3711#ifdef CONFIG_TCC_BCHECK3689#ifdef CONFIG_TCC_BCHECK
3712 if (s1->do_bounds_check)3690 if (s1->do_bounds_check)
3713 cstr_printf(cs, "#define __BOUNDS_CHECKING_ON 1\n");3691 putdef(cs, "__BOUNDS_CHECKING_ON");
3714#endif3692#endif
3715 cstr_printf(cs, "#define __SIZEOF_POINTER__ %d\n", PTR_SIZE);3693 cstr_printf(cs, "#define __SIZEOF_POINTER__ %d\n", PTR_SIZE);
3716 cstr_printf(cs, "#define __SIZEOF_LONG__ %d\n", LONG_SIZE);3694 cstr_printf(cs, "#define __SIZEOF_LONG__ %d\n", LONG_SIZE);
3717 if (!is_asm) {3695 if (!is_asm) {
3718 cstr_printf(cs, "#define __STDC__ 1\n");3696 putdef(cs, "__STDC__");
3719 cstr_printf(cs, "#define __STDC_VERSION__ %dL\n", s1->cversion);3697 cstr_printf(cs, "#define __STDC_VERSION__ %dL\n", s1->cversion);
3720 cstr_cat(cs,3698 cstr_cat(cs,
3721 /* load more predefs and __builtins */3699 /* 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
269 printf("\n (%u ms)\n", getclock_ms() - t);269 printf("\n (%u ms)\n", getclock_ms() - t);
270#endif270#endif
271#if 1271#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);
273 t = getclock_ms();273 t = getclock_ms();
274 for (n = 0; n < M; ++n)274 for (n = 0; n < M; ++n)
275 create_thread(thread_test_complex, n);275 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 */
5const 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
24int isid(int c)
25{
26 return (c >= 'a' && c <= 'z')
27 || (c >= 'A' && c <= 'Z')
28 || (c >= '0' && c <= '9')
29 || c == '_';
30}
31
32int isspc(int c)
33{
34 return c == ' ' || c == '\t';
35}
36
37int 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
80#define __stdcall __attribute__((__stdcall__))80#define __stdcall __attribute__((__stdcall__))
81#define _X86_ 181#define _X86_ 1
82#define _M_IX86 300 /* Visual Studio */82#define _M_IX86 300 /* Visual Studio */
83#define WIN32 1
84#define _USE_32BIT_TIME_T83#define _USE_32BIT_TIME_T
85#endif84#endif
86 85
@@ -160,5 +159,6 @@ typedef struct localeinfo_struct _locale_tstruct,*_locale_t; · 73 unmodified lines
160#define __MINGW_EXTENSION159#define __MINGW_EXTENSION
161#define WINAPI_FAMILY_PARTITION(X) 1160#define WINAPI_FAMILY_PARTITION(X) 1
162#define MINGW_HAS_SECURE_API161#define MINGW_HAS_SECURE_API
162#define WIN32 1
163 163
164#endif /* __MINGW_H */164#endif /* __MINGW_H */
win32/include/errno.h+1−1
@@ -14,7 +14,7 @@ extern "C" { · 13 unmodified lines
14 14
15#ifndef _CRT_ERRNO_DEFINED15#ifndef _CRT_ERRNO_DEFINED
16#define _CRT_ERRNO_DEFINED16#define _CRT_ERRNO_DEFINED
17 _CRTIMP extern int *__cdecl _errno(void);17 _CRTIMP int *__cdecl _errno(void);
18#define errno (*_errno())18#define errno (*_errno())
19 19
20 errno_t __cdecl _set_errno(int _Value);20 errno_t __cdecl _set_errno(int _Value);
win32/include/math.h+1−1
@@ -274,7 +274,7 @@ extern "C" { · 273 unmodified lines
274 : __signbitl (x))274 : __signbitl (x))
275*/275*/
276#define signbit(x) \276#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)
278 278
279 extern double __cdecl exp2(double);279 extern double __cdecl exp2(double);
280 extern float __cdecl exp2f(float);280 extern float __cdecl exp2f(float);
win32/include/stdlib.h+1−1
@@ -136,7 +136,7 @@ extern "C" { · 135 unmodified lines
136 136
137#ifndef _CRT_ERRNO_DEFINED137#ifndef _CRT_ERRNO_DEFINED
138#define _CRT_ERRNO_DEFINED138#define _CRT_ERRNO_DEFINED
139 _CRTIMP extern int *__cdecl _errno(void);139 _CRTIMP int *__cdecl _errno(void);
140#define errno (*_errno())140#define errno (*_errno())
141 errno_t __cdecl _set_errno(int _Value);141 errno_t __cdecl _set_errno(int _Value);
142 errno_t __cdecl _get_errno(int *_Value);142 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
467__CRT_INLINE long double __cdecl logl(long double x) { return log(x); }467__CRT_INLINE long double __cdecl logl(long double x) { return log(x); }
468__CRT_INLINE long double __cdecl logbl(long double x) { return logb(x); }468__CRT_INLINE long double __cdecl logbl(long double x) { return logb(x); }
469__CRT_INLINE long double __cdecl log10l(long double x) { return log10(x); }469__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; }
471__CRT_INLINE long double __cdecl powl(long double x, long double y) { return pow(x, y); }471__CRT_INLINE long double __cdecl powl(long double x, long double y) { return pow(x, y); }
472__CRT_INLINE long double __cdecl sinhl(long double x) { return sinh(x); }472__CRT_INLINE long double __cdecl sinhl(long double x) { return sinh(x); }
473__CRT_INLINE long double __cdecl sinl(long double x) { return sin(x); }473__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
112#include "tcc.h"112#include "tcc.h"
113#include <assert.h>113#include <assert.h>
114 114
115ST_DATA const char *target_machine_defs =
116 "__x86_64__\0"
117 "__amd64__\0"
118 ;
119
115ST_DATA const int reg_classes[NB_REGS] = {120ST_DATA const int reg_classes[NB_REGS] = {
116 /* eax */ RC_INT | RC_RAX,121 /* eax */ RC_INT | RC_RAX,
117 /* ecx */ RC_INT | RC_RCX,122 /* 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