Reverts & cleanups

- include/stddef.h, tcctest.c
  Revert "tests/tcctest.c: include stdint.h"
  This reverts commit 8f23997ca7
  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 2f88764100.

- tcc.c:
  fix formatting of commit e73529865d

- 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
This commit is contained in:
grischka
2025-09-21 14:47:46 +02:00
parent ce8b3432bf
commit 34b45a69ff
8 changed files with 37 additions and 55 deletions

15
README
View File

@@ -7,9 +7,8 @@ Features:
- SMALL! You can compile and execute C code everywhere, for example on
rescue disks.
- FAST! tcc generates optimized x86 code. No byte code
overhead. Compile, assemble and link about 7 times faster than 'gcc
-O0'.
- FAST! tcc generates machine code for i386, x86_64, arm, aarch64 or
riscv64. Compiles and links about 10 times faster than 'gcc -O0'.
- UNLIMITED! Any C dynamic library can be used directly. TCC is
heading toward full ISOC99 compliance. TCC can of course compile
@@ -28,15 +27,14 @@ Features:
Documentation:
-------------
1) Installation on a i386/x86_64/arm/aarch64/riscv64
Linux/macOS/FreeBSD/NetBSD/OpenBSD hosts.
1) Installation on Linux, BSD variants or macOS hosts:
./configure
make
make test
make install
Notes: For FreeBSD, NetBSD and OpenBSD, gmake should be used instead of make.
Notes: On BSD hosts, gmake should be used instead of make.
For Windows read tcc-win32.txt.
makeinfo must be installed to compile the doc. By default, tcc is
@@ -83,9 +81,8 @@ when doing 'make test'.
4) Full Documentation
Please read tcc-doc.html to have all the features of TCC.
Additional information is available for the Windows port in tcc-win32.txt.
Please read tcc-doc.html to have all the features of TCC. Additional
information for the Windows port is in tcc-win32.txt.
License:
-------

View File

@@ -1,6 +1,5 @@
#ifndef _STDDEF_H
#define _STDDEF_H
#define _TINYC_STDDEF
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;

View File

@@ -257,6 +257,10 @@ ST_FUNC void libc_free(void *ptr)
free(ptr);
}
/* defined to be not used */
#define free(p) use_tcc_free(p)
#define realloc(p, s) use_tcc_realloc(p, s)
/* global so that every tcc_alloc()/tcc_free() call doesn't need to be changed */
static void *(*reallocator)(void*, unsigned long) = default_reallocator;

3
tcc.c
View File

@@ -87,7 +87,8 @@ static const char help[] =
#ifdef TCC_TARGET_PE
" create def file : tcc -impdef lib.dll [-v] [-o lib.def]\n"
#endif
" report bugs to the mailing list http://lists.nongnu.org/mailman/listinfo/tinycc-devel\n"
"Discussion & bug reports:\n"
" https://lists.nongnu.org/mailman/listinfo/tinycc-devel\n"
;
static const char help2[] =

3
tcc.h
View File

@@ -56,7 +56,7 @@ extern long double strtold (const char *__nptr, char **__endptr);
# include <io.h> /* open, close etc. */
# include <direct.h> /* getcwd */
# include <malloc.h> /* alloca */
# ifdef __GNUC__
# ifndef _MSC_VER
# include <stdint.h>
# endif
# define inline __inline
@@ -1235,6 +1235,7 @@ PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
#endif
ST_FUNC void libc_free(void *ptr);
/* defined to be not used */
#define free(p) use_tcc_free(p)
#define malloc(s) use_tcc_malloc(s)
#define realloc(p, s) use_tcc_realloc(p, s)

View File

@@ -7108,28 +7108,18 @@ static void lblock(int *bsym, int *csym)
}
}
static void condition_expresion(void)
/* c2y if/switch declaration */
static void gexpr_decl(void)
{
Sym *s;
int decl_ret;
/* c2y if init decl? */
if (!(decl_ret = decl(VT_JMPI))) {
/* no, regular if init expr */
gexpr();
int v = decl(VT_JMP);
if (v > 1 && tok != ';') {
Sym *s = sym_find(v);
vset(&s->type, s->r, (s->r & VT_SYM) ? 0 : s->c);
vtop->sym = s;
} else {
if (decl_ret == 1)
tcc_error("declaration in the controlling expression must have an initializer");
if (tok == ';') {
/* finish the push */
next();
gexpr();
} else {
s = sym_find(decl_ret);
vset(&s->type, s->r, s->c);
vtop->sym = s;
}
if (v)
skip(';');
gexpr();
}
}
@@ -7153,7 +7143,7 @@ again:
if (t == TOK_IF) {
new_scope_s(&o);
skip('(');
condition_expresion();
gexpr_decl();
a = gvtst(1, 0);
skip(')');
block(0);
@@ -7322,7 +7312,7 @@ again:
new_scope_s(&o);
skip('(');
condition_expresion();
gexpr_decl();
if (!is_integer_btype(vtop->type.t & VT_BTYPE))
tcc_error("switch value not an integer");
skip(')');
@@ -8654,9 +8644,7 @@ static void pe_check_linkage(CType *type, AttributeDef *ad)
/* 'l' is VT_LOCAL or VT_CONST to define default storage type
or VT_CMP if parsing old style parameter list
or VT_JMP if parsing c99 for decl: for (int i = 0, ...)
or VT_JMPI if parsing c2y if decl; if (int = 0; ...)
*/
or VT_JMP if parsing c99 for decl: for (int i = 0, ...) */
static int decl(int l)
{
int v, has_init, r, oldint;
@@ -8669,7 +8657,7 @@ static int decl(int l)
oldint = 0;
if (!parse_btype(&btype, &adbase, l == VT_LOCAL)) {
if (l == VT_JMP || l == VT_JMPI)
if (l == VT_JMP)
return 0;
/* skip redundant ';' if not in old parameter decl scope */
if (tok == ';' && l != VT_CMP) {
@@ -8896,12 +8884,10 @@ static int decl(int l)
}
}
if (tok != ',') {
if (l == VT_JMP || l == VT_JMPI)
if (l == VT_JMP)
return has_init ? v : 1;
skip(';');
break;
} else if (l == VT_JMPI) {
tcc_error("declaration in condition can only declare a single object");
}
next();
}

16
tccpp.c
View File

@@ -1418,6 +1418,9 @@ static int parse_include(TCCState *s1, int do_next, int test)
#ifdef INC_DEBUG
printf("%s: skipping cached %s\n", file->filename, buf);
#endif
if ((s1->verbose | 1) == 3) /* -vv[v] */
printf("=> %*s%s\n",
(int)(s1->include_stack_ptr - s1->include_stack), "", buf);
return 1;
}
if (tcc_open(s1, buf) >= 0)
@@ -2740,7 +2743,6 @@ maybe_newline:
cstr_cat(&tokcstr, (char *) p1, len);
p--;
PEEKC(c, p);
parse_ident_slow:
while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
{
cstr_ccat(&tokcstr, c);
@@ -2752,21 +2754,15 @@ maybe_newline:
break;
case 'L':
t = p[1];
if (t != '\\' && t != '\'' && t != '\"') {
/* fast case */
goto parse_ident_fast;
} else {
if (t == '\'' || t == '\"' || t == '\\') {
PEEKC(c, p);
if (c == '\'' || c == '\"') {
is_long = 1;
goto str_const;
} else {
cstr_reset(&tokcstr);
cstr_ccat(&tokcstr, 'L');
goto parse_ident_slow;
}
*--p = c = 'L';
}
break;
goto parse_ident_fast;
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':

View File

@@ -41,6 +41,8 @@
#define LONG_DOUBLE_LITERAL(x) x ## L
#endif
typedef __SIZE_TYPE__ uintptr_t;
/* test various include syntaxes */
#define TCCLIB_INC <tcclib.h>
@@ -62,10 +64,6 @@
#include "tcctest.h"
#ifndef _TINYC_STDDEF
#include <stdint.h>
#endif
/* Test two more ways to include a file named like a pp-number */
#define INC(name) <tests/name.h>
#define funnyname 42test.h