stuff & etc..

- tccpp.c: rename ... to __TCC_BCHECK__/__TCC_BACKTRACE__
- libtcc.c: correct total line count
- libtcc.c: support -run -- args... (instead of -run @ args ...)
- Makefile/build-tcc.bat: streamline GITHASH string somewhat
- bt-exe.c: avoid redef of pstrcpy() with 'tcc -bt tcc.c ...'
This commit is contained in:
grischka 2023-03-31 18:20:49 +02:00
parent a045400501
commit bb93bf8cd2
8 changed files with 36 additions and 32 deletions

View file

@ -243,12 +243,10 @@ $(TCC_FILES) : DEFINES += -DONE_SOURCE=0
$(X)tccpp.o : $(TCCDEFS_H) $(X)tccpp.o : $(TCCDEFS_H)
endif endif
FROM_GIT := $(shell git rev-parse >/dev/null 2>&1 && echo yes || echo no) GITHASH:=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo no)
ifneq ($(GITHASH),no)
ifeq ($(FROM_GIT),yes) GITHASH:=$(shell git log -1 --pretty='format:%cs $(GITHASH)@%h')$(shell git diff --quiet || echo '*')
GITHASH:=$(shell git rev-parse --abbrev-ref HEAD):$(shell git rev-parse --short HEAD) $(shell git log -1 --pretty='format:%cI') DEF_GITHASH:= -DTCC_GITHASH="\"$(GITHASH)\""
GITLOCAL:=$(shell git diff --quiet || echo ' locally modified')
DEF_GITHASH:= -DTCC_GITHASH="\"$(GITHASH)$(GITLOCAL)\""
endif endif
ifeq ($(CONFIG_debug),yes) ifeq ($(CONFIG_debug),yes)
@ -270,7 +268,7 @@ $(X)%.o : %.c $(LIBTCC_INC)
# additional dependencies # additional dependencies
$(X)tcc.o : tcctools.c $(X)tcc.o : tcctools.c
$(X)tcc.o : DEFINES += $(DEF_GITHASH) $(DEF_GITDATE) $(X)tcc.o : DEFINES += $(DEF_GITHASH)
# Host Tiny C Compiler # Host Tiny C Compiler
tcc$(EXESUF): tcc.o $(LIBTCC) tcc$(EXESUF): tcc.o $(LIBTCC)

View file

@ -245,7 +245,7 @@
# define __RENAME(X) __asm__(X) # define __RENAME(X) __asm__(X)
#endif #endif
#ifdef __BOUNDS_CHECKING_ON #ifdef __TCC_BCHECK__
# define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME("__bound_"#name); # define __BUILTINBC(ret,name,params) ret __builtin_##name params __RENAME("__bound_"#name);
# define __BOUND(ret,name,params) ret name params __RENAME("__bound_"#name); # define __BOUND(ret,name,params) ret name params __RENAME("__bound_"#name);
#else #else

View file

@ -3,7 +3,8 @@
from tccrun.c into executables. */ from tccrun.c into executables. */
#define CONFIG_TCC_BACKTRACE_ONLY #define CONFIG_TCC_BACKTRACE_ONLY
#define ONE_SOURCE 0 #define ONE_SOURCE 1
#define pstrcpy tcc_pstrcpy
#include "../tccrun.c" #include "../tccrun.c"
int (*__rt_error)(void*, void*, const char *, va_list); int (*__rt_error)(void*, void*, const char *, va_list);

View file

@ -695,7 +695,7 @@ ST_FUNC void tcc_close(void)
BufferedFile *bf = file; BufferedFile *bf = file;
if (bf->fd > 0) { if (bf->fd > 0) {
close(bf->fd); close(bf->fd);
total_lines += bf->line_num; total_lines += bf->line_num - 1;
} }
if (bf->true_filename != bf->filename) if (bf->true_filename != bf->filename)
tcc_free(bf->true_filename); tcc_free(bf->true_filename);
@ -1867,9 +1867,9 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv, int optind)
} }
reparse: reparse:
if (r[0] != '-' || r[1] == '\0') { if (r[0] != '-' || r[1] == '\0') {
if (r[0] != '@') /* allow "tcc file(s) -run @ args ..." */ args_parser_add_file(s, r, s->filetype);
args_parser_add_file(s, r, s->filetype);
if (run) { if (run) {
dorun:
if (tcc_set_options(s, run)) if (tcc_set_options(s, run))
return -1; return -1;
arg_start = optind - 1; arg_start = optind - 1;
@ -1878,6 +1878,10 @@ reparse:
continue; continue;
} }
/* allow "tcc files... -run -- args ..." */
if (r[1] == '-' && r[2] == '\0' && run)
goto dorun;
/* find option in table */ /* find option in table */
for(popt = tcc_options; ; ++popt) { for(popt = tcc_options; ; ++popt) {
const char *p1 = popt->name; const char *p1 = popt->name;

2
tcc.c
View file

@ -27,7 +27,7 @@
static const char help[] = static const char help[] =
"Tiny C Compiler "TCC_VERSION" - Copyright (C) 2001-2006 Fabrice Bellard\n" "Tiny C Compiler "TCC_VERSION" - Copyright (C) 2001-2006 Fabrice Bellard\n"
"Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n" "Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n"
" tcc [options...] -run infile [arguments...]\n" " tcc [options...] -run infile (or --) [arguments...]\n"
"General options:\n" "General options:\n"
" -c compile only - generate an object file\n" " -c compile only - generate an object file\n"
" -o outfile set output filename\n" " -o outfile set output filename\n"

16
tccpp.c
View file

@ -3588,6 +3588,14 @@ static void tcc_predefs(TCCState *s1, CString *cs, int is_asm)
putdef(cs, "__TCC_PP__"); putdef(cs, "__TCC_PP__");
if (s1->output_type == TCC_OUTPUT_MEMORY) if (s1->output_type == TCC_OUTPUT_MEMORY)
putdef(cs, "__TCC_RUN__"); putdef(cs, "__TCC_RUN__");
#ifdef CONFIG_TCC_BACKTRACE
if (s1->do_backtrace)
putdef(cs, "__TCC_BACKTRACE__");
#endif
#ifdef CONFIG_TCC_BCHECK
if (s1->do_bounds_check)
putdef(cs, "__TCC_BCHECK__");
#endif
if (s1->char_is_unsigned) if (s1->char_is_unsigned)
putdef(cs, "__CHAR_UNSIGNED__"); putdef(cs, "__CHAR_UNSIGNED__");
if (s1->optimize > 0) if (s1->optimize > 0)
@ -3596,14 +3604,6 @@ static void tcc_predefs(TCCState *s1, CString *cs, int is_asm)
putdef(cs, "_REENTRANT"); putdef(cs, "_REENTRANT");
if (s1->leading_underscore) if (s1->leading_underscore)
putdef(cs, "__leading_underscore"); putdef(cs, "__leading_underscore");
#ifdef CONFIG_TCC_BCHECK
if (s1->do_bounds_check)
putdef(cs, "__BOUNDS_CHECKING_ON");
#endif
#ifdef CONFIG_TCC_BACKTRACE
if (s1->do_backtrace)
putdef(cs, "__TCC_BACKTRACE_ENABLED__");
#endif
cstr_printf(cs, "#define __SIZEOF_POINTER__ %d\n", PTR_SIZE); cstr_printf(cs, "#define __SIZEOF_POINTER__ %d\n", PTR_SIZE);
cstr_printf(cs, "#define __SIZEOF_LONG__ %d\n", LONG_SIZE); cstr_printf(cs, "#define __SIZEOF_LONG__ %d\n", LONG_SIZE);
if (!is_asm) { if (!is_asm) {

View file

@ -11,7 +11,7 @@ main (void)
char tmp[100]; char tmp[100];
int r = 0; int r = 0;
#if defined __BOUNDS_CHECKING_ON || defined BC_ON #if defined __TCC_BCHECK__
printf("BOUNDS ON:\n"); printf("BOUNDS ON:\n");
#else #else
printf("BOUNDS OFF:\n"); printf("BOUNDS OFF:\n");

View file

@ -7,14 +7,6 @@ setlocal
if (%1)==(-clean) goto :cleanup if (%1)==(-clean) goto :cleanup
set CC=gcc set CC=gcc
set /p VERSION= < ..\VERSION set /p VERSION= < ..\VERSION
git.exe --version 2>nul
if not %ERRORLEVEL%==0 goto :git_done
for /f %%b in ('git.exe rev-parse --abbrev-ref HEAD') do set GITHASH=%%b
for /f %%h in ('git.exe rev-parse --short HEAD') do set GITHASH=%GITHASH%:%%h
git.exe diff --quiet
if %ERRORLEVEL%==1 set GITHASH=%GITHASH%-mod
set DEF_GITHASH=-DTCC_GITHASH="""%GITHASH%"""
:git_done
set INST= set INST=
set DOC=no set DOC=no
set EXES_ONLY=no set EXES_ONLY=no
@ -94,7 +86,7 @@ set T=32
if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64 if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64 if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
:p2 :p2
if "%CC:~-3%"=="gcc" set CC=%CC% -O2 -s -static %DEF_GITHASH% if "%CC:~-3%"=="gcc" set CC=%CC% -O2 -s -static
set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386 set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64 set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
set P32=i386-win32 set P32=i386-win32
@ -113,6 +105,15 @@ set TX=32
goto :p3 goto :p3
:p3 :p3
git.exe --version 2>nul
if not %ERRORLEVEL%==0 goto :git_done
for /f %%b in ('git.exe rev-parse --abbrev-ref HEAD') do set GITHASH=%%b
for /f %%b in ('git.exe log -1 "--pretty=format:%%cs_%GITHASH%@%%h"') do set GITHASH=%%b
git.exe diff --quiet
if %ERRORLEVEL%==1 set GITHASH=%GITHASH%*
set DEF_GITHASH=-DTCC_GITHASH="""%GITHASH%"""
:git_done
@echo on @echo on
:config.h :config.h
@ -134,7 +135,7 @@ for %%f in (*tcc.exe *tcc.dll) do @del %%f
@if _%LIBTCC_C%_==__ set LIBTCC_C=..\libtcc.c @if _%LIBTCC_C%_==__ set LIBTCC_C=..\libtcc.c
%CC% -o libtcc.dll -shared %LIBTCC_C% %D% -DLIBTCC_AS_DLL %CC% -o libtcc.dll -shared %LIBTCC_C% %D% -DLIBTCC_AS_DLL
@if errorlevel 1 goto :the_end @if errorlevel 1 goto :the_end
%CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0" %CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0" %DEF_GITHASH%
%CC% -o %PX%-tcc.exe ..\tcc.c %DX% %CC% -o %PX%-tcc.exe ..\tcc.c %DX%
:compiler_done :compiler_done
@if (%EXES_ONLY%)==(yes) goto :files_done @if (%EXES_ONLY%)==(yes) goto :files_done