1 /* ----------------------------------------------------------------------- */
4 /* with -D C2STR: convert tccdefs.h to C-strings */
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 "__ANDROID__", "TARGETOS_ANDROID",
26 "__SIZEOF_POINTER__", "PTR_SIZE",
27 "__SIZEOF_LONG__", "LONG_SIZE",
33 return (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z')
34 || (c
>= '0' && c
<= '9') || c
== '_';
39 return (unsigned char)c
<= ' ' && c
!= 0;
42 int main(int argc
, char **argv
)
44 char l
[1000], l2
[1000], *p
, *q
, *p0
;
46 int c
, e
, f
, s
, cmt
, cmt_n
;
52 fp
= fopen(argv
[1], "rb");
53 op
= fopen(argv
[2], "wb");
55 fprintf(stderr
, "c2str: file error\n");
63 if (fgets(p
, sizeof l
- (p
- l
), fp
)) {
65 while (p
> l
&& isspc(p
[-1]))
71 /* check for continuation */
72 if (p
> l
&& p
[-1] == '\\') {
77 /* count & skip leading spaces */
79 while (*p
&& isspc(*p
))
83 if (p
[0] == '/' && cmt
== 0) {
92 fprintf(op
, " (converted, do not edit this file)");
98 if (p
>= l
+ 2 && p
[-1] == '/' && p
[-2] == '*')
106 /* replace machine/os macros by compile-time counterparts */
107 for (e
= f
= 0; (r
= platform_macros
[f
]); f
+= 2) {
109 /* remove 'defined' */
110 //e = memcmp(p, "defined ", 8) ? 0 : 8;
111 if (0 == memcmp(p
+ e
, r
, c
)) {
113 q
= strchr(strcpy(q
, platform_macros
[f
+ 1]), 0);
120 } while (!!(*q
++ = *p
++));
122 fprintf(op
, "%s\n", l2
);
126 s
= e
= f
= 0, p0
= p
;
134 if (c
== '/' && (p
[0] == '/' || p
[0] == '*'))
135 c
= 0; /* trailing comment detected */
137 && ((isid(q
[-1]) && isid(c
))
138 // keep space after macro name
151 if (c
== '\\' || c
== '\"')
158 /* output with quotes */
159 fprintf(op
, " \"%s\\n\"%s\n", l2
, p0
);
168 /* ----------------------------------------------------------------------- */
171 /* get some information from the host compiler for configure */
179 /* Define architecture */
180 #if defined(__i386__) || defined _M_IX86
181 # define TRIPLET_ARCH "i386"
182 #elif defined(__x86_64__) || defined _M_AMD64
183 # define TRIPLET_ARCH "x86_64"
184 #elif defined(__arm__)
185 # define TRIPLET_ARCH "arm"
186 #elif defined(__aarch64__)
187 # define TRIPLET_ARCH "aarch64"
188 #elif defined(__riscv) && defined(__LP64__)
189 # define TRIPLET_ARCH "riscv64"
191 # define TRIPLET_ARCH "unknown"
195 #if defined (__linux__)
196 # define TRIPLET_OS "linux"
197 #elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
198 # define TRIPLET_OS "kfreebsd"
199 #elif defined(__NetBSD__)
200 # define TRIPLET_OS "netbsd"
201 #elif defined(__OpenBSD__)
202 # define TRIPLET_OS "openbsd"
203 #elif defined(_WIN32)
204 # define TRIPLET_OS "win32"
205 #elif defined(__APPLE__)
206 # define TRIPLET_OS "darwin"
207 #elif !defined (__GNU__)
208 # define TRIPLET_OS "unknown"
211 #if defined __ANDROID__
212 # define ABI_PREFIX "android"
214 # define ABI_PREFIX "gnu"
217 /* Define calling convention and ABI */
218 #if defined (__ARM_EABI__)
219 # if defined (__ARM_PCS_VFP)
220 # define TRIPLET_ABI ABI_PREFIX"eabihf"
222 # define TRIPLET_ABI ABI_PREFIX"eabi"
225 # define TRIPLET_ABI ABI_PREFIX
229 # define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS
230 #elif defined __GNU__
231 # define TRIPLET TRIPLET_ARCH "-" TRIPLET_ABI
233 # define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS "-" TRIPLET_ABI
240 int main(int argc
, char *argv
[])
243 _setmode(_fileno(stdout
), _O_BINARY
); /* don't translate \n to \r\n */
245 switch(argc
== 2 ? argv
[1][0] : 0) {
248 volatile unsigned foo
= 0x01234567;
249 puts(*(unsigned char*)&foo
== 0x67 ? "no" : "yes");
252 #if defined(__clang__)
254 printf("%d\n", __clang_minor__
);
257 printf("%d\n", __clang_major__
);
259 #elif defined(__TINYC__)
264 printf("%d\n", __TINYC__
);
266 #elif defined(_MSC_VER)
271 printf("%d\n", _MSC_VER
);
273 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
274 /* GNU comes last as other compilers may add 'GNU' compatibility */
276 printf("%d\n", __GNUC_MINOR__
);
279 printf("%d\n", __GNUC__
);
291 #if defined(__clang__)
293 #elif defined(__TINYC__)
295 #elif defined(_MSC_VER)
297 #elif defined(__GNUC__)
309 /* ----------------------------------------------------------------------- */