Skip to content

Commit 34b45a6

Browse files
author
grischka
committed
Reverts & cleanups
- include/stddef.h, tcctest.c Revert "tests/tcctest.c: include stdint.h" This reverts commit 8f23997 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 2f88764. - tcc.c: fix formatting of commit e735298 - 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
1 parent ce8b343 commit 34b45a6

File tree

8 files changed

+38
-56
lines changed

8 files changed

+38
-56
lines changed

README

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ Features:
77
- SMALL! You can compile and execute C code everywhere, for example on
88
rescue disks.
99

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'.
1312

1413
- UNLIMITED! Any C dynamic library can be used directly. TCC is
1514
heading toward full ISOC99 compliance. TCC can of course compile
@@ -28,15 +27,14 @@ Features:
2827
Documentation:
2928
-------------
3029

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:
3331

3432
./configure
3533
make
3634
make test
3735
make install
3836

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.
4038
For Windows read tcc-win32.txt.
4139

4240
makeinfo must be installed to compile the doc. By default, tcc is
@@ -83,9 +81,8 @@ when doing 'make test'.
8381

8482
4) Full Documentation
8583

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.
8986

9087
License:
9188
-------

include/stddef.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#ifndef _STDDEF_H
22
#define _STDDEF_H
3-
#define _TINYC_STDDEF
43

54
typedef __SIZE_TYPE__ size_t;
65
typedef __PTRDIFF_TYPE__ ssize_t;

libtcc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ ST_FUNC void libc_free(void *ptr)
257257
free(ptr);
258258
}
259259

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+
260264
/* global so that every tcc_alloc()/tcc_free() call doesn't need to be changed */
261265
static void *(*reallocator)(void*, unsigned long) = default_reallocator;
262266

tcc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ static const char help[] =
8787
#ifdef TCC_TARGET_PE
8888
" create def file : tcc -impdef lib.dll [-v] [-o lib.def]\n"
8989
#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"
9192
;
9293

9394
static const char help2[] =

tcc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extern long double strtold (const char *__nptr, char **__endptr);
5656
# include <io.h> /* open, close etc. */
5757
# include <direct.h> /* getcwd */
5858
# include <malloc.h> /* alloca */
59-
# ifdef __GNUC__
59+
# ifndef _MSC_VER
6060
# include <stdint.h>
6161
# endif
6262
# define inline __inline
@@ -1235,6 +1235,7 @@ PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
12351235
#endif
12361236

12371237
ST_FUNC void libc_free(void *ptr);
1238+
/* defined to be not used */
12381239
#define free(p) use_tcc_free(p)
12391240
#define malloc(s) use_tcc_malloc(s)
12401241
#define realloc(p, s) use_tcc_realloc(p, s)

tccgen.c

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7108,28 +7108,18 @@ static void lblock(int *bsym, int *csym)
71087108
}
71097109
}
71107110

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;
71207119
} 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();
71337123
}
71347124
}
71357125

@@ -7153,7 +7143,7 @@ static void block(int flags)
71537143
if (t == TOK_IF) {
71547144
new_scope_s(&o);
71557145
skip('(');
7156-
condition_expresion();
7146+
gexpr_decl();
71577147
a = gvtst(1, 0);
71587148
skip(')');
71597149
block(0);
@@ -7322,7 +7312,7 @@ static void block(int flags)
73227312

73237313
new_scope_s(&o);
73247314
skip('(');
7325-
condition_expresion();
7315+
gexpr_decl();
73267316
if (!is_integer_btype(vtop->type.t & VT_BTYPE))
73277317
tcc_error("switch value not an integer");
73287318
skip(')');
@@ -8654,9 +8644,7 @@ static void pe_check_linkage(CType *type, AttributeDef *ad)
86548644

86558645
/* 'l' is VT_LOCAL or VT_CONST to define default storage type
86568646
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, ...) */
86608648
static int decl(int l)
86618649
{
86628650
int v, has_init, r, oldint;
@@ -8669,7 +8657,7 @@ static int decl(int l)
86698657

86708658
oldint = 0;
86718659
if (!parse_btype(&btype, &adbase, l == VT_LOCAL)) {
8672-
if (l == VT_JMP || l == VT_JMPI)
8660+
if (l == VT_JMP)
86738661
return 0;
86748662
/* skip redundant ';' if not in old parameter decl scope */
86758663
if (tok == ';' && l != VT_CMP) {
@@ -8896,12 +8884,10 @@ static int decl(int l)
88968884
}
88978885
}
88988886
if (tok != ',') {
8899-
if (l == VT_JMP || l == VT_JMPI)
8887+
if (l == VT_JMP)
89008888
return has_init ? v : 1;
89018889
skip(';');
89028890
break;
8903-
} else if (l == VT_JMPI) {
8904-
tcc_error("declaration in condition can only declare a single object");
89058891
}
89068892
next();
89078893
}

tccpp.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,9 @@ static int parse_include(TCCState *s1, int do_next, int test)
14181418
#ifdef INC_DEBUG
14191419
printf("%s: skipping cached %s\n", file->filename, buf);
14201420
#endif
1421+
if ((s1->verbose | 1) == 3) /* -vv[v] */
1422+
printf("=> %*s%s\n",
1423+
(int)(s1->include_stack_ptr - s1->include_stack), "", buf);
14211424
return 1;
14221425
}
14231426
if (tcc_open(s1, buf) >= 0)
@@ -2740,7 +2743,6 @@ static void next_nomacro(void)
27402743
cstr_cat(&tokcstr, (char *) p1, len);
27412744
p--;
27422745
PEEKC(c, p);
2743-
parse_ident_slow:
27442746
while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
27452747
{
27462748
cstr_ccat(&tokcstr, c);
@@ -2752,21 +2754,15 @@ static void next_nomacro(void)
27522754
break;
27532755
case 'L':
27542756
t = p[1];
2755-
if (t != '\\' && t != '\'' && t != '\"') {
2756-
/* fast case */
2757-
goto parse_ident_fast;
2758-
} else {
2757+
if (t == '\'' || t == '\"' || t == '\\') {
27592758
PEEKC(c, p);
27602759
if (c == '\'' || c == '\"') {
27612760
is_long = 1;
27622761
goto str_const;
2763-
} else {
2764-
cstr_reset(&tokcstr);
2765-
cstr_ccat(&tokcstr, 'L');
2766-
goto parse_ident_slow;
27672762
}
2763+
*--p = c = 'L';
27682764
}
2769-
break;
2765+
goto parse_ident_fast;
27702766

27712767
case '0': case '1': case '2': case '3':
27722768
case '4': case '5': case '6': case '7':

tests/tcctest.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#define LONG_DOUBLE_LITERAL(x) x ## L
4242
#endif
4343

44+
typedef __SIZE_TYPE__ uintptr_t;
45+
4446
/* test various include syntaxes */
4547

4648
#define TCCLIB_INC <tcclib.h>
@@ -62,10 +64,6 @@
6264

6365
#include "tcctest.h"
6466

65-
#ifndef _TINYC_STDDEF
66-
#include <stdint.h>
67-
#endif
68-
6967
/* Test two more ways to include a file named like a pp-number */
7068
#define INC(name) <tests/name.h>
7169
#define funnyname 42test.h

0 commit comments

Comments
 (0)