- include/stddef.h, tcctest.c Revert "tests/tcctest.c: include stdint.h" This reverts commit 8f23997ca7c7bd34756bbbae1f5363afec422907 We don't want tcctest.c to rely on system include files - libtcc.c: Revert "libtcc.c: Remove unused defines free and realloc" To be unused is the point why they do exist This reverts commit 2f8876410044b3e8d26c79f1f7dfac5b7700a88c. - tcc.c: fix formatting of commit e73529865d97f7699b6a96fca5ecd0d6affe605b - tccpp.c: parse_include(): print skipped include files too (with tcc -vv[v] file) next_nomacro(): faster L"str" parsing - tccgen.c: fix c2y if declaration: * accept like GCC: if (int a = 0, b, c = x; c) * accept as "TCC extension": if (int a = 0, b, c = x) * "speak tcc" with symbol/function names - README: cleanup
Unified · Split
| @@ -7,9 +7,8 @@ Features: · 6 unmodified lines | ||
| 7 | 7 | - SMALL! You can compile and execute C code everywhere, for example on |
| 8 | 8 | rescue disks. |
| 9 | 9 | |
| 10 | −- FAST! tcc generates optimized x86 code. No byte code | |
| 11 | − overhead. Compile, assemble and link about 7 times faster than 'gcc | |
| 12 | − -O0'. | |
| 10 | +- FAST! tcc generates machine code for i386, x86_64, arm, aarch64 or | |
| 11 | + riscv64. Compiles and links about 10 times faster than 'gcc -O0'. | |
| 13 | 12 | |
| 14 | 13 | - UNLIMITED! Any C dynamic library can be used directly. TCC is |
| 15 | 14 | heading toward full ISOC99 compliance. TCC can of course compile |
| @@ -28,15 +27,14 @@ Features: · 12 unmodified lines | ||
| 28 | 27 | Documentation: |
| 29 | 28 | ------------- |
| 30 | 29 | |
| 31 | −1) Installation on a i386/x86_64/arm/aarch64/riscv64 | |
| 32 | − Linux/macOS/FreeBSD/NetBSD/OpenBSD hosts. | |
| 30 | +1) Installation on Linux, BSD variants or macOS hosts: | |
| 33 | 31 | |
| 34 | 32 | ./configure |
| 35 | 33 | make |
| 36 | 34 | make test |
| 37 | 35 | make install |
| 38 | 36 | |
| 39 | − Notes: For FreeBSD, NetBSD and OpenBSD, gmake should be used instead of make. | |
| 37 | + Notes: On BSD hosts, gmake should be used instead of make. | |
| 40 | 38 | For Windows read tcc-win32.txt. |
| 41 | 39 | |
| 42 | 40 | makeinfo must be installed to compile the doc. By default, tcc is |
| @@ -83,9 +81,8 @@ when doing 'make test'. · 40 unmodified lines | ||
| 83 | 81 | |
| 84 | 82 | 4) Full Documentation |
| 85 | 83 | |
| 86 | −Please read tcc-doc.html to have all the features of TCC. | |
| 87 | − | |
| 88 | −Additional information is available for the Windows port in tcc-win32.txt. | |
| 84 | +Please read tcc-doc.html to have all the features of TCC. Additional | |
| 85 | +information for the Windows port is in tcc-win32.txt. | |
| 89 | 86 | |
| 90 | 87 | License: |
| 91 | 88 | ------- |
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | #ifndef _STDDEF_H |
| 2 | 2 | #define _STDDEF_H |
| 3 | −#define _TINYC_STDDEF | |
| 4 | 3 | |
| 5 | 4 | typedef __SIZE_TYPE__ size_t; |
| 6 | 5 | typedef __PTRDIFF_TYPE__ ssize_t; |
| @@ -257,6 +257,10 @@ ST_FUNC void libc_free(void *ptr) · 256 unmodified lines | ||
| 257 | 257 | free(ptr); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | +/* defined to be not used */ | |
| 261 | +#define free(p) use_tcc_free(p) | |
| 262 | +#define realloc(p, s) use_tcc_realloc(p, s) | |
| 263 | + | |
| 260 | 264 | /* global so that every tcc_alloc()/tcc_free() call doesn't need to be changed */ |
| 261 | 265 | static void *(*reallocator)(void*, unsigned long) = default_reallocator; |
| 262 | 266 | |
| @@ -87,7 +87,8 @@ static const char help[] = · 86 unmodified lines | ||
| 87 | 87 | #ifdef TCC_TARGET_PE |
| 88 | 88 | " create def file : tcc -impdef lib.dll [-v] [-o lib.def]\n" |
| 89 | 89 | #endif |
| 90 | − " report bugs to the mailing list http://lists.nongnu.org/mailman/listinfo/tinycc-devel\n" | |
| 90 | + "Discussion & bug reports:\n" | |
| 91 | + " https://lists.nongnu.org/mailman/listinfo/tinycc-devel\n" | |
| 91 | 92 | ; |
| 92 | 93 | |
| 93 | 94 | static const char help2[] = |
| @@ -56,7 +56,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 55 unmodified lines | ||
| 56 | 56 | # include <io.h> /* open, close etc. */ |
| 57 | 57 | # include <direct.h> /* getcwd */ |
| 58 | 58 | # include <malloc.h> /* alloca */ |
| 59 | −# ifdef __GNUC__ | |
| 59 | +# ifndef _MSC_VER | |
| 60 | 60 | # include <stdint.h> |
| 61 | 61 | # endif |
| 62 | 62 | # define inline __inline |
| @@ -1235,6 +1235,7 @@ PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line); · 1172 unmodified lines | ||
| 1235 | 1235 | #endif |
| 1236 | 1236 | |
| 1237 | 1237 | ST_FUNC void libc_free(void *ptr); |
| 1238 | +/* defined to be not used */ | |
| 1238 | 1239 | #define free(p) use_tcc_free(p) |
| 1239 | 1240 | #define malloc(s) use_tcc_malloc(s) |
| 1240 | 1241 | #define realloc(p, s) use_tcc_realloc(p, s) |
| @@ -7108,28 +7108,18 @@ static void lblock(int *bsym, int *csym) · 7107 unmodified lines | ||
| 7108 | 7108 | } |
| 7109 | 7109 | } |
| 7110 | 7110 | |
| 7111 | −static void condition_expresion(void) | |
| 7112 | −{ | |
| 7113 | − Sym *s; | |
| 7114 | − int decl_ret; | |
| 7115 | − | |
| 7116 | − /* c2y if init decl? */ | |
| 7117 | − if (!(decl_ret = decl(VT_JMPI))) { | |
| 7118 | − /* no, regular if init expr */ | |
| 7119 | − gexpr(); | |
| 7111 | +/* c2y if/switch declaration */ | |
| 7112 | +static void gexpr_decl(void) | |
| 7113 | +{ | |
| 7114 | + int v = decl(VT_JMP); | |
| 7115 | + if (v > 1 && tok != ';') { | |
| 7116 | + Sym *s = sym_find(v); | |
| 7117 | + vset(&s->type, s->r, (s->r & VT_SYM) ? 0 : s->c); | |
| 7118 | + vtop->sym = s; | |
| 7120 | 7119 | } else { |
| 7121 | − if (decl_ret == 1) | |
| 7122 | − tcc_error("declaration in the controlling expression must have an initializer"); | |
| 7123 | − | |
| 7124 | − if (tok == ';') { | |
| 7125 | − /* finish the push */ | |
| 7126 | − next(); | |
| 7127 | − gexpr(); | |
| 7128 | − } else { | |
| 7129 | − s = sym_find(decl_ret); | |
| 7130 | − vset(&s->type, s->r, s->c); | |
| 7131 | − vtop->sym = s; | |
| 7132 | − } | |
| 7120 | + if (v) | |
| 7121 | + skip(';'); | |
| 7122 | + gexpr(); | |
| 7133 | 7123 | } |
| 7134 | 7124 | } |
| 7135 | 7125 | |
| @@ -7153,7 +7143,7 @@ again: · 17 unmodified lines | ||
| 7153 | 7143 | if (t == TOK_IF) { |
| 7154 | 7144 | new_scope_s(&o); |
| 7155 | 7145 | skip('('); |
| 7156 | − condition_expresion(); | |
| 7146 | + gexpr_decl(); | |
| 7157 | 7147 | a = gvtst(1, 0); |
| 7158 | 7148 | skip(')'); |
| 7159 | 7149 | block(0); |
| @@ -7322,7 +7312,7 @@ again: · 162 unmodified lines | ||
| 7322 | 7312 | |
| 7323 | 7313 | new_scope_s(&o); |
| 7324 | 7314 | skip('('); |
| 7325 | − condition_expresion(); | |
| 7315 | + gexpr_decl(); | |
| 7326 | 7316 | if (!is_integer_btype(vtop->type.t & VT_BTYPE)) |
| 7327 | 7317 | tcc_error("switch value not an integer"); |
| 7328 | 7318 | skip(')'); |
| @@ -8654,9 +8644,7 @@ static void pe_check_linkage(CType *type, AttributeDef *ad) · 1325 unmodified lines | ||
| 8654 | 8644 | |
| 8655 | 8645 | /* 'l' is VT_LOCAL or VT_CONST to define default storage type |
| 8656 | 8646 | or VT_CMP if parsing old style parameter list |
| 8657 | − or VT_JMP if parsing c99 for decl: for (int i = 0, ...) | |
| 8658 | − or VT_JMPI if parsing c2y if decl; if (int = 0; ...) | |
| 8659 | −*/ | |
| 8647 | + or VT_JMP if parsing c99 for decl: for (int i = 0, ...) */ | |
| 8660 | 8648 | static int decl(int l) |
| 8661 | 8649 | { |
| 8662 | 8650 | int v, has_init, r, oldint; |
| @@ -8669,7 +8657,7 @@ static int decl(int l) · 6 unmodified lines | ||
| 8669 | 8657 | |
| 8670 | 8658 | oldint = 0; |
| 8671 | 8659 | if (!parse_btype(&btype, &adbase, l == VT_LOCAL)) { |
| 8672 | − if (l == VT_JMP || l == VT_JMPI) | |
| 8660 | + if (l == VT_JMP) | |
| 8673 | 8661 | return 0; |
| 8674 | 8662 | /* skip redundant ';' if not in old parameter decl scope */ |
| 8675 | 8663 | if (tok == ';' && l != VT_CMP) { |
| @@ -8896,12 +8884,10 @@ static int decl(int l) · 220 unmodified lines | ||
| 8896 | 8884 | } |
| 8897 | 8885 | } |
| 8898 | 8886 | if (tok != ',') { |
| 8899 | − if (l == VT_JMP || l == VT_JMPI) | |
| 8887 | + if (l == VT_JMP) | |
| 8900 | 8888 | return has_init ? v : 1; |
| 8901 | 8889 | skip(';'); |
| 8902 | 8890 | break; |
| 8903 | − } else if (l == VT_JMPI) { | |
| 8904 | − tcc_error("declaration in condition can only declare a single object"); | |
| 8905 | 8891 | } |
| 8906 | 8892 | next(); |
| 8907 | 8893 | } |
| @@ -1418,6 +1418,9 @@ static int parse_include(TCCState *s1, int do_next, int test) · 1417 unmodified lines | ||
| 1418 | 1418 | #ifdef INC_DEBUG |
| 1419 | 1419 | printf("%s: skipping cached %s\n", file->filename, buf); |
| 1420 | 1420 | #endif |
| 1421 | + if ((s1->verbose | 1) == 3) /* -vv[v] */ | |
| 1422 | + printf("=> %*s%s\n", | |
| 1423 | + (int)(s1->include_stack_ptr - s1->include_stack), "", buf); | |
| 1421 | 1424 | return 1; |
| 1422 | 1425 | } |
| 1423 | 1426 | if (tcc_open(s1, buf) >= 0) |
| @@ -2740,7 +2743,6 @@ maybe_newline: · 1316 unmodified lines | ||
| 2740 | 2743 | cstr_cat(&tokcstr, (char *) p1, len); |
| 2741 | 2744 | p--; |
| 2742 | 2745 | PEEKC(c, p); |
| 2743 | − parse_ident_slow: | |
| 2744 | 2746 | while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) |
| 2745 | 2747 | { |
| 2746 | 2748 | cstr_ccat(&tokcstr, c); |
| @@ -2752,21 +2754,15 @@ maybe_newline: · 5 unmodified lines | ||
| 2752 | 2754 | break; |
| 2753 | 2755 | case 'L': |
| 2754 | 2756 | t = p[1]; |
| 2755 | − if (t != '\\' && t != '\'' && t != '\"') { | |
| 2756 | − /* fast case */ | |
| 2757 | − goto parse_ident_fast; | |
| 2758 | − } else { | |
| 2757 | + if (t == '\'' || t == '\"' || t == '\\') { | |
| 2759 | 2758 | PEEKC(c, p); |
| 2760 | 2759 | if (c == '\'' || c == '\"') { |
| 2761 | 2760 | is_long = 1; |
| 2762 | 2761 | goto str_const; |
| 2763 | − } else { | |
| 2764 | − cstr_reset(&tokcstr); | |
| 2765 | − cstr_ccat(&tokcstr, 'L'); | |
| 2766 | − goto parse_ident_slow; | |
| 2767 | 2762 | } |
| 2763 | + *--p = c = 'L'; | |
| 2768 | 2764 | } |
| 2769 | − break; | |
| 2765 | + goto parse_ident_fast; | |
| 2770 | 2766 | |
| 2771 | 2767 | case '0': case '1': case '2': case '3': |
| 2772 | 2768 | case '4': case '5': case '6': case '7': |
| @@ -41,6 +41,8 @@ · 40 unmodified lines | ||
| 41 | 41 | #define LONG_DOUBLE_LITERAL(x) x ## L |
| 42 | 42 | #endif |
| 43 | 43 | |
| 44 | +typedef __SIZE_TYPE__ uintptr_t; | |
| 45 | + | |
| 44 | 46 | /* test various include syntaxes */ |
| 45 | 47 | |
| 46 | 48 | #define TCCLIB_INC <tcclib.h> |
| @@ -62,10 +64,6 @@ · 15 unmodified lines | ||
| 62 | 64 | |
| 63 | 65 | #include "tcctest.h" |
| 64 | 66 | |
| 65 | −#ifndef _TINYC_STDDEF | |
| 66 | −#include <stdint.h> | |
| 67 | −#endif | |
| 68 | − | |
| 69 | 67 | /* Test two more ways to include a file named like a pp-number */ |
| 70 | 68 | #define INC(name) <tests/name.h> |
| 71 | 69 | #define funnyname 42test.h |