Currently used only with 'tcc_compile_sem' to protect tcc_compile(), but can be used with other semaphores Also fix deadlock when tcc_enter_state() is called recursively for the same state, for example with tcc_warning() from #pragma comment(option,"...") Also: - libtcc.c: error1(): use cstr_[v]printf() - tcc.h: set TCC_USING_DOUBLE_FOR_LDOUBLE for macho-arm64 (rather than for macho-X86_64) - tcc.h: define TCC_TARGET_MACHO on __APPLE__ by default - tcc.h: cleanup TCCState, move DEFASM token stuff to tcctok.h - tccgen.c: more static - Makefile/tcc.c: review githash - tccpe/tcctools: use read() instead of fgets() in pe_load_def() (all files opened by tcc for reading are now read via 'int fd') - configure/win32: don't preset CONFIG_TCCDIR (to allow to override it) - tcc.c -bench: do not include output/run-time
Unified · Split
| @@ -134,7 +134,7 @@ all: $(PROGS) $(TCCLIBS) $(TCCDOCS) · 133 unmodified lines | |||
| 134 | 134 | ||
| 135 | # cross compiler targets to build | 135 | # cross compiler targets to build |
| 136 | TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67 | 136 | TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67 |
| 137 | TCC_X += riscv64 | 137 | TCC_X += riscv64 arm64-osx |
| 138 | # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi | 138 | # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi |
| 139 | 139 | ||
| 140 | # cross libtcc1.a targets to build | 140 | # cross libtcc1.a targets to build |
| @@ -222,10 +222,9 @@ $(TCC_FILES) : DEFINES += -DONE_SOURCE=0 · 81 unmodified lines | |||
| 222 | $(X)tccpp.o : $(TCCDEFS_H) | 222 | $(X)tccpp.o : $(TCCDEFS_H) |
| 223 | endif | 223 | endif |
| 224 | 224 | ||
| 225 | TCC_GIT_HASH=$(shell git rev-parse > /dev/null 2>&1 && git rev-parse --short HEAD || echo no) | 225 | GITHASH := $(shell git rev-parse >/dev/null 2>&1 && git rev-parse --short HEAD || echo no) |
| 226 | ifneq ($(TCC_GIT_HASH),no) | 226 | ifneq ($(GITHASH),no) |
| 227 | MODIFIED = $(shell git diff | grep -q +++ && echo "modified ") | 227 | DEF_GITHASH := -DTCC_GITHASH="\"$(GITHASH)$(shell git diff --quiet || echo '-mod')\"" |
| 228 | $(X)tcc.o : DEFINES += -DTCC_GIT_HASH="\"$(MODIFIED)$(TCC_GIT_HASH)\"" | ||
| 229 | endif | 228 | endif |
| 230 | 229 | ||
| 231 | ifeq ($(CONFIG_debug),yes) | 230 | ifeq ($(CONFIG_debug),yes) |
| @@ -247,6 +246,7 @@ $(X)%.o : %.c $(LIBTCC_INC) · 15 unmodified lines | |||
| 247 | 246 | ||
| 248 | # additional dependencies | 247 | # additional dependencies |
| 249 | $(X)tcc.o : tcctools.c | 248 | $(X)tcc.o : tcctools.c |
| 249 | $(X)tcc.o : DEFINES += $(DEF_GITHASH) | ||
| 250 | 250 | ||
| 251 | # Host Tiny C Compiler | 251 | # Host Tiny C Compiler |
| 252 | tcc$(EXESUF): tcc.o $(LIBTCC) | 252 | tcc$(EXESUF): tcc.o $(LIBTCC) |
| @@ -238,7 +238,7 @@ if test "$mingw32" = "yes" ; then · 237 unmodified lines | |||
| 238 | source_path="." | 238 | source_path="." |
| 239 | fi | 239 | fi |
| 240 | test -z "$prefix" && prefix="C:/Program Files/tcc" | 240 | test -z "$prefix" && prefix="C:/Program Files/tcc" |
| 241 | test -z "$tccdir" && tccdir="${prefix}" | 241 | test -z "$tccdir" && tccdir="${prefix}" && tccdir_auto="yes" |
| 242 | test -z "$bindir" && bindir="${tccdir}" | 242 | test -z "$bindir" && bindir="${tccdir}" |
| 243 | test -z "$docdir" && docdir="${tccdir}/doc" | 243 | test -z "$docdir" && docdir="${tccdir}/doc" |
| 244 | test -z "$libdir" && libdir="${tccdir}/libtcc" | 244 | test -z "$libdir" && libdir="${tccdir}/libtcc" |
| @@ -483,7 +483,7 @@ print_mak() { · 238 unmodified lines | |||
| 483 | echo "/* Automatically generated by configure - do not modify */" > $TMPH | 483 | echo "/* Automatically generated by configure - do not modify */" > $TMPH |
| 484 | 484 | ||
| 485 | print_inc CONFIG_SYSROOT "$sysroot" | 485 | print_inc CONFIG_SYSROOT "$sysroot" |
| 486 | print_inc CONFIG_TCCDIR "$tccdir" | 486 | test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir" |
| 487 | print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude" | 487 | print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude" |
| 488 | print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths" | 488 | print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths" |
| 489 | print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths" | 489 | print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths" |
| @@ -1,6 +1,82 @@ | |||
| 1 | /* ------------------------------------------------------------------ */ | 1 | /* ------------------------------------------------------------------ */ |
| 2 | /* WARNING: relative order of tokens is important. */ | 2 | /* WARNING: relative order of tokens is important. */ |
| 3 | 3 | ||
| 4 | #define DEF_BWL(x) \ | ||
| 5 | DEF(TOK_ASM_ ## x ## b, #x "b") \ | ||
| 6 | DEF(TOK_ASM_ ## x ## w, #x "w") \ | ||
| 7 | DEF(TOK_ASM_ ## x ## l, #x "l") \ | ||
| 8 | DEF(TOK_ASM_ ## x, #x) | ||
| 9 | #define DEF_WL(x) \ | ||
| 10 | DEF(TOK_ASM_ ## x ## w, #x "w") \ | ||
| 11 | DEF(TOK_ASM_ ## x ## l, #x "l") \ | ||
| 12 | DEF(TOK_ASM_ ## x, #x) | ||
| 13 | #ifdef TCC_TARGET_X86_64 | ||
| 14 | # define DEF_BWLQ(x) \ | ||
| 15 | DEF(TOK_ASM_ ## x ## b, #x "b") \ | ||
| 16 | DEF(TOK_ASM_ ## x ## w, #x "w") \ | ||
| 17 | DEF(TOK_ASM_ ## x ## l, #x "l") \ | ||
| 18 | DEF(TOK_ASM_ ## x ## q, #x "q") \ | ||
| 19 | DEF(TOK_ASM_ ## x, #x) | ||
| 20 | # define DEF_WLQ(x) \ | ||
| 21 | DEF(TOK_ASM_ ## x ## w, #x "w") \ | ||
| 22 | DEF(TOK_ASM_ ## x ## l, #x "l") \ | ||
| 23 | DEF(TOK_ASM_ ## x ## q, #x "q") \ | ||
| 24 | DEF(TOK_ASM_ ## x, #x) | ||
| 25 | # define DEF_BWLX DEF_BWLQ | ||
| 26 | # define DEF_WLX DEF_WLQ | ||
| 27 | /* number of sizes + 1 */ | ||
| 28 | # define NBWLX 5 | ||
| 29 | #else | ||
| 30 | # define DEF_BWLX DEF_BWL | ||
| 31 | # define DEF_WLX DEF_WL | ||
| 32 | /* number of sizes + 1 */ | ||
| 33 | # define NBWLX 4 | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #define DEF_FP1(x) \ | ||
| 37 | DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \ | ||
| 38 | DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \ | ||
| 39 | DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \ | ||
| 40 | DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s") | ||
| 41 | |||
| 42 | #define DEF_FP(x) \ | ||
| 43 | DEF(TOK_ASM_ ## f ## x, "f" #x ) \ | ||
| 44 | DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \ | ||
| 45 | DEF_FP1(x) | ||
| 46 | |||
| 47 | #define DEF_ASMTEST(x,suffix) \ | ||
| 48 | DEF_ASM(x ## o ## suffix) \ | ||
| 49 | DEF_ASM(x ## no ## suffix) \ | ||
| 50 | DEF_ASM(x ## b ## suffix) \ | ||
| 51 | DEF_ASM(x ## c ## suffix) \ | ||
| 52 | DEF_ASM(x ## nae ## suffix) \ | ||
| 53 | DEF_ASM(x ## nb ## suffix) \ | ||
| 54 | DEF_ASM(x ## nc ## suffix) \ | ||
| 55 | DEF_ASM(x ## ae ## suffix) \ | ||
| 56 | DEF_ASM(x ## e ## suffix) \ | ||
| 57 | DEF_ASM(x ## z ## suffix) \ | ||
| 58 | DEF_ASM(x ## ne ## suffix) \ | ||
| 59 | DEF_ASM(x ## nz ## suffix) \ | ||
| 60 | DEF_ASM(x ## be ## suffix) \ | ||
| 61 | DEF_ASM(x ## na ## suffix) \ | ||
| 62 | DEF_ASM(x ## nbe ## suffix) \ | ||
| 63 | DEF_ASM(x ## a ## suffix) \ | ||
| 64 | DEF_ASM(x ## s ## suffix) \ | ||
| 65 | DEF_ASM(x ## ns ## suffix) \ | ||
| 66 | DEF_ASM(x ## p ## suffix) \ | ||
| 67 | DEF_ASM(x ## pe ## suffix) \ | ||
| 68 | DEF_ASM(x ## np ## suffix) \ | ||
| 69 | DEF_ASM(x ## po ## suffix) \ | ||
| 70 | DEF_ASM(x ## l ## suffix) \ | ||
| 71 | DEF_ASM(x ## nge ## suffix) \ | ||
| 72 | DEF_ASM(x ## nl ## suffix) \ | ||
| 73 | DEF_ASM(x ## ge ## suffix) \ | ||
| 74 | DEF_ASM(x ## le ## suffix) \ | ||
| 75 | DEF_ASM(x ## ng ## suffix) \ | ||
| 76 | DEF_ASM(x ## nle ## suffix) \ | ||
| 77 | DEF_ASM(x ## g ## suffix) | ||
| 78 | |||
| 79 | /* ------------------------------------------------------------------ */ | ||
| 4 | /* register */ | 80 | /* register */ |
| 5 | DEF_ASM(al) | 81 | DEF_ASM(al) |
| 6 | DEF_ASM(cl) | 82 | DEF_ASM(cl) |
| @@ -21,6 +21,7 @@ · 20 unmodified lines | |||
| 21 | #if !defined ONE_SOURCE || ONE_SOURCE | 21 | #if !defined ONE_SOURCE || ONE_SOURCE |
| 22 | #include "tccpp.c" | 22 | #include "tccpp.c" |
| 23 | #include "tccgen.c" | 23 | #include "tccgen.c" |
| 24 | #include "tccasm.c" | ||
| 24 | #include "tccelf.c" | 25 | #include "tccelf.c" |
| 25 | #include "tccrun.c" | 26 | #include "tccrun.c" |
| 26 | #ifdef TCC_TARGET_I386 | 27 | #ifdef TCC_TARGET_I386 |
| @@ -50,9 +51,6 @@ · 23 unmodified lines | |||
| 50 | #else | 51 | #else |
| 51 | #error unknown target | 52 | #error unknown target |
| 52 | #endif | 53 | #endif |
| 53 | #ifdef CONFIG_TCC_ASM | ||
| 54 | #include "tccasm.c" | ||
| 55 | #endif | ||
| 56 | #ifdef TCC_TARGET_PE | 54 | #ifdef TCC_TARGET_PE |
| 57 | #include "tccpe.c" | 55 | #include "tccpe.c" |
| 58 | #endif | 56 | #endif |
| @@ -68,6 +66,7 @@ · 9 unmodified lines | |||
| 68 | 66 | ||
| 69 | /* XXX: get rid of this ASAP (or maybe not) */ | 67 | /* XXX: get rid of this ASAP (or maybe not) */ |
| 70 | ST_DATA struct TCCState *tcc_state; | 68 | ST_DATA struct TCCState *tcc_state; |
| 69 | TCC_SEM(static tcc_compile_sem); | ||
| 71 | 70 | ||
| 72 | #ifdef MEM_DEBUG | 71 | #ifdef MEM_DEBUG |
| 73 | static int nb_states; | 72 | static int nb_states; |
| @@ -84,19 +83,23 @@ ST_FUNC char *normalize_slashes(char *path) · 10 unmodified lines | |||
| 84 | return path; | 83 | return path; |
| 85 | } | 84 | } |
| 86 | 85 | ||
| 86 | /* NULL if this is tcc.exe, HINSTANCE if this is libtcc.dll */ | ||
| 87 | static HMODULE tcc_module; | 87 | static HMODULE tcc_module; |
| 88 | 88 | ||
| 89 | #ifndef CONFIG_TCCDIR | ||
| 89 | /* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */ | 90 | /* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */ |
| 90 | static void tcc_set_lib_path_w32(TCCState *s) | 91 | static inline char *config_tccdir_w32(char *path) |
| 91 | { | 92 | { |
| 92 | char path[1024], *p; | 93 | char *p; |
| 93 | GetModuleFileNameA(tcc_module, path, sizeof path); | 94 | GetModuleFileName(tcc_module, path, MAX_PATH); |
| 94 | p = tcc_basename(normalize_slashes(strlwr(path))); | 95 | p = tcc_basename(normalize_slashes(strlwr(path))); |
| 95 | if (p > path) | 96 | if (p > path) |
| 96 | --p; | 97 | --p; |
| 97 | *p = 0; | 98 | *p = 0; |
| 98 | tcc_set_lib_path(s, path); | 99 | return path; |
| 99 | } | 100 | } |
| 101 | #define CONFIG_TCCDIR config_tccdir_w32(alloca(MAX_PATH)) | ||
| 102 | #endif | ||
| 100 | 103 | ||
| 101 | #ifdef TCC_TARGET_PE | 104 | #ifdef TCC_TARGET_PE |
| 102 | static void tcc_add_systemdir(TCCState *s) | 105 | static void tcc_add_systemdir(TCCState *s) |
| @@ -118,47 +121,60 @@ BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) · 15 unmodified lines | |||
| 118 | #endif | 121 | #endif |
| 119 | 122 | ||
| 120 | /********************************************************/ | 123 | /********************************************************/ |
| 121 | #if CONFIG_TCC_SEMLOCK == 0 | 124 | #if CONFIG_TCC_SEMLOCK |
| 122 | #define WAIT_SEM() | 125 | #if defined _WIN32 |
| 123 | #define POST_SEM() | 126 | ST_FUNC void wait_sem(TCCSem *p) |
| 124 | #elif defined _WIN32 | 127 | { |
| 125 | static int tcc_sem_init; | 128 | if (!p->init) |
| 126 | static CRITICAL_SECTION tcc_cr; | 129 | InitializeCriticalSection(&p->cr), p->init = 1; |
| 127 | static void wait_sem(void) | 130 | EnterCriticalSection(&p->cr); |
| 128 | { | 131 | } |
| 129 | if (!tcc_sem_init) | 132 | ST_FUNC void post_sem(TCCSem *p) |
| 130 | InitializeCriticalSection(&tcc_cr), tcc_sem_init = 1; | 133 | { |
| 131 | EnterCriticalSection(&tcc_cr); | 134 | LeaveCriticalSection(&p->cr); |
| 132 | } | 135 | } |
| 133 | #define WAIT_SEM() wait_sem() | ||
| 134 | #define POST_SEM() LeaveCriticalSection(&tcc_cr); | ||
| 135 | #elif defined __APPLE__ | 136 | #elif defined __APPLE__ |
| 136 | /* Half-compatible MacOS doesn't have non-shared (process local) | 137 | /* Half-compatible MacOS doesn't have non-shared (process local) |
| 137 | semaphores. Use the dispatch framework for lightweight locks. */ | 138 | semaphores. Use the dispatch framework for lightweight locks. */ |
| 138 | #include <dispatch/dispatch.h> | 139 | ST_FUNC void wait_sem(TCCSem *p) |
| 139 | static int tcc_sem_init; | ||
| 140 | static dispatch_semaphore_t tcc_sem; | ||
| 141 | static void wait_sem(void) | ||
| 142 | { | 140 | { |
| 143 | if (!tcc_sem_init) | 141 | if (!p->init) |
| 144 | tcc_sem = dispatch_semaphore_create(1), tcc_sem_init = 1; | 142 | p->sem = dispatch_semaphore_create(1), p->init = 1; |
| 145 | dispatch_semaphore_wait(tcc_sem, DISPATCH_TIME_FOREVER); | 143 | dispatch_semaphore_wait(p->sem, DISPATCH_TIME_FOREVER); |
| 144 | } | ||
| 145 | ST_FUNC void post_sem(TCCSem *p) | ||
| 146 | { | ||
| 147 | dispatch_semaphore_signal(p->sem); | ||
| 146 | } | 148 | } |
| 147 | #define WAIT_SEM() wait_sem() | ||
| 148 | #define POST_SEM() dispatch_semaphore_signal(tcc_sem) | ||
| 149 | #else | 149 | #else |
| 150 | #include <semaphore.h> | 150 | ST_FUNC void wait_sem(TCCSem *p) |
| 151 | static int tcc_sem_init; | 151 | { |
| 152 | static sem_t tcc_sem; | 152 | if (!p->init) |
| 153 | static void wait_sem(void) | 153 | sem_init(&p->sem, 0, 1), p->init = 1; |
| 154 | while (sem_wait(&p->sem) < 0 && errno == EINTR); | ||
| 155 | } | ||
| 156 | ST_FUNC void post_sem(TCCSem *p) | ||
| 154 | { | 157 | { |
| 155 | if (!tcc_sem_init) | 158 | sem_post(&p->sem); |
| 156 | sem_init(&tcc_sem, 0, 1), tcc_sem_init = 1; | ||
| 157 | while (sem_wait (&tcc_sem) < 0 && errno == EINTR); | ||
| 158 | } | 159 | } |
| 159 | #define WAIT_SEM() wait_sem() | ||
| 160 | #define POST_SEM() sem_post(&tcc_sem) | ||
| 161 | #endif | 160 | #endif |
| 161 | #endif | ||
| 162 | |||
| 163 | PUB_FUNC void tcc_enter_state(TCCState *s1) | ||
| 164 | { | ||
| 165 | if (s1->error_set_jmp_enabled) | ||
| 166 | return; | ||
| 167 | WAIT_SEM(&tcc_compile_sem); | ||
| 168 | tcc_state = s1; | ||
| 169 | } | ||
| 170 | |||
| 171 | PUB_FUNC void tcc_exit_state(TCCState *s1) | ||
| 172 | { | ||
| 173 | if (s1->error_set_jmp_enabled) | ||
| 174 | return; | ||
| 175 | tcc_state = NULL; | ||
| 176 | POST_SEM(&tcc_compile_sem); | ||
| 177 | } | ||
| 162 | 178 | ||
| 163 | /********************************************************/ | 179 | /********************************************************/ |
| 164 | /* copy a string and truncate it. */ | 180 | /* copy a string and truncate it. */ |
| @@ -494,52 +510,29 @@ static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char * · 329 unmodified lines | |||
| 494 | } | 510 | } |
| 495 | 511 | ||
| 496 | /********************************************************/ | 512 | /********************************************************/ |
| 513 | /* warning / error */ | ||
| 497 | 514 | ||
| 498 | static void strcat_vprintf(char *buf, int buf_size, const char *fmt, va_list ap) | 515 | /* warn_... option bits */ |
| 499 | { | 516 | #define WARN_ON 1 /* warning is on (-Woption) */ |
| 500 | int len; | 517 | #define WARN_ERR 2 /* warning is an error (-Werror=option) */ |
| 501 | len = strlen(buf); | 518 | #define WARN_NOE 4 /* warning is not an error (-Wno-error=option) */ |
| 502 | vsnprintf(buf + len, buf_size - len, fmt, ap); | ||
| 503 | } | ||
| 504 | |||
| 505 | static void strcat_printf(char *buf, int buf_size, const char *fmt, ...) | ||
| 506 | { | ||
| 507 | va_list ap; | ||
| 508 | va_start(ap, fmt); | ||
| 509 | strcat_vprintf(buf, buf_size, fmt, ap); | ||
| 510 | va_end(ap); | ||
| 511 | } | ||
| 512 | 519 | ||
| 513 | PUB_FUNC void tcc_enter_state(TCCState *s1) | 520 | /* error1() modes */ |
| 514 | { | 521 | enum { ERROR_WARN, ERROR_NOABORT, ERROR_ERROR }; |
| 515 | WAIT_SEM(); | ||
| 516 | tcc_state = s1; | ||
| 517 | } | ||
| 518 | |||
| 519 | PUB_FUNC void tcc_exit_state(void) | ||
| 520 | { | ||
| 521 | tcc_state = NULL; | ||
| 522 | POST_SEM(); | ||
| 523 | } | ||
| 524 | |||
| 525 | #define ERROR_WARN 0 | ||
| 526 | #define ERROR_NOABORT 1 | ||
| 527 | #define ERROR_ERROR 2 | ||
| 528 | 522 | ||
| 529 | static void error1(int mode, const char *fmt, va_list ap) | 523 | static void error1(int mode, const char *fmt, va_list ap) |
| 530 | { | 524 | { |
| 531 | char buf[2048]; | ||
| 532 | BufferedFile **pf, *f; | 525 | BufferedFile **pf, *f; |
| 533 | TCCState *s1 = tcc_state; | 526 | TCCState *s1 = tcc_state; |
| 527 | CString cs; | ||
| 528 | |||
| 529 | cstr_new(&cs); | ||
| 534 | 530 | ||
| 535 | buf[0] = '\0'; | ||
| 536 | if (s1 == NULL) | 531 | if (s1 == NULL) |
| 537 | /* can happen only if called from tcc_malloc(): 'out of memory' */ | 532 | /* can happen only if called from tcc_malloc(): 'out of memory' */ |
| 538 | goto no_file; | 533 | goto no_file; |
| 539 | 534 | ||
| 540 | if (!s1->error_set_jmp_enabled) | 535 | tcc_exit_state(s1); |
| 541 | /* tcc_state just was set by tcc_enter_state() */ | ||
| 542 | tcc_exit_state(); | ||
| 543 | 536 | ||
| 544 | if (mode == ERROR_WARN) { | 537 | if (mode == ERROR_WARN) { |
| 545 | if (s1->warn_error) | 538 | if (s1->warn_error) |
| @@ -567,33 +560,30 @@ static void error1(int mode, const char *fmt, va_list ap) · 21 unmodified lines | |||
| 567 | } | 560 | } |
| 568 | if (f) { | 561 | if (f) { |
| 569 | for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++) | 562 | for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++) |
| 570 | strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n", | 563 | cstr_printf(&cs, "In file included from %s:%d:\n", |
| 571 | (*pf)->filename, (*pf)->line_num); | 564 | (*pf)->filename, (*pf)->line_num); |
| 572 | strcat_printf(buf, sizeof(buf), "%s:%d: ", | 565 | cstr_printf(&cs, "%s:%d: ", |
| 573 | f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL)); | 566 | f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL)); |
| 574 | } else if (s1->current_filename) { | 567 | } else if (s1->current_filename) { |
| 575 | strcat_printf(buf, sizeof(buf), "%s: ", s1->current_filename); | 568 | cstr_printf(&cs, "%s: ", s1->current_filename); |
| 576 | } | 569 | } |
| 577 | 570 | ||
| 578 | no_file: | 571 | no_file: |
| 579 | if (0 == buf[0]) | 572 | if (0 == cs.size) |
| 580 | strcat_printf(buf, sizeof(buf), "tcc: "); | 573 | cstr_printf(&cs, "tcc: "); |
| 581 | if (mode == ERROR_WARN) | 574 | cstr_printf(&cs, mode == ERROR_WARN ? "warning: " : "error: "); |
| 582 | strcat_printf(buf, sizeof(buf), "warning: "); | 575 | cstr_vprintf(&cs, fmt, ap); |
| 583 | else | ||
| 584 | strcat_printf(buf, sizeof(buf), "error: "); | ||
| 585 | strcat_vprintf(buf, sizeof(buf), fmt, ap); | ||
| 586 | if (!s1 || !s1->error_func) { | 576 | if (!s1 || !s1->error_func) { |
| 587 | /* default case: stderr */ | 577 | /* default case: stderr */ |
| 588 | if (s1 && s1->output_type == TCC_OUTPUT_PREPROCESS && s1->ppfp == stdout) | 578 | if (s1 && s1->output_type == TCC_OUTPUT_PREPROCESS && s1->ppfp == stdout) |
| 589 | /* print a newline during tcc -E */ | 579 | printf("\n"); /* print a newline during tcc -E */ |
| 590 | printf("\n"), fflush(stdout); | ||
| 591 | fflush(stdout); /* flush -v output */ | 580 | fflush(stdout); /* flush -v output */ |
| 592 | fprintf(stderr, "%s\n", buf); | 581 | fprintf(stderr, "%s\n", (char*)cs.data); |
| 593 | fflush(stderr); /* print error/warning now (win32) */ | 582 | fflush(stderr); /* print error/warning now (win32) */ |
| 594 | } else { | 583 | } else { |
| 595 | s1->error_func(s1->error_opaque, buf); | 584 | s1->error_func(s1->error_opaque, (char*)cs.data); |
| 596 | } | 585 | } |
| 586 | cstr_free(&cs); | ||
| 597 | if (s1) { | 587 | if (s1) { |
| 598 | if (mode != ERROR_WARN) | 588 | if (mode != ERROR_WARN) |
| 599 | s1->nb_errors++; | 589 | s1->nb_errors++; |
| @@ -718,9 +708,9 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 118 unmodified lines | |||
| 718 | variables, which may or may not have advantages */ | 708 | variables, which may or may not have advantages */ |
| 719 | 709 | ||
| 720 | tcc_enter_state(s1); | 710 | tcc_enter_state(s1); |
| 711 | s1->error_set_jmp_enabled = 1; | ||
| 721 | 712 | ||
| 722 | if (setjmp(s1->error_jmp_buf) == 0) { | 713 | if (setjmp(s1->error_jmp_buf) == 0) { |
| 723 | s1->error_set_jmp_enabled = 1; | ||
| 724 | s1->nb_errors = 0; | 714 | s1->nb_errors = 0; |
| 725 | 715 | ||
| 726 | if (fd == -1) { | 716 | if (fd == -1) { |
| @@ -738,19 +728,16 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 11 unmodified lines | |||
| 738 | if (s1->output_type == TCC_OUTPUT_PREPROCESS) { | 728 | if (s1->output_type == TCC_OUTPUT_PREPROCESS) { |
| 739 | tcc_preprocess(s1); | 729 | tcc_preprocess(s1); |
| 740 | } else if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) { | 730 | } else if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) { |
| 741 | #ifdef CONFIG_TCC_ASM | ||
| 742 | tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP)); | 731 | tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP)); |
| 743 | #else | ||
| 744 | tcc_error_noabort("asm not supported"); | ||
| 745 | #endif | ||
| 746 | } else { | 732 | } else { |
| 747 | tccgen_compile(s1); | 733 | tccgen_compile(s1); |
| 748 | } | 734 | } |
| 749 | } | 735 | } |
| 750 | s1->error_set_jmp_enabled = 0; | ||
| 751 | tccgen_finish(s1); | 736 | tccgen_finish(s1); |
| 752 | preprocess_end(s1); | 737 | preprocess_end(s1); |
| 753 | tcc_exit_state(); | 738 | |
| 739 | s1->error_set_jmp_enabled = 0; | ||
| 740 | tcc_exit_state(s1); | ||
| 754 | 741 | ||
| 755 | tccelf_end_file(s1); | 742 | tccelf_end_file(s1); |
| 756 | return s1->nb_errors != 0 ? -1 : 0; | 743 | return s1->nb_errors != 0 ? -1 : 0; |
| @@ -821,11 +808,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 64 unmodified lines | |||
| 821 | 808 | ||
| 822 | tccelf_new(s); | 809 | tccelf_new(s); |
| 823 | 810 | ||
| 824 | #ifdef _WIN32 | ||
| 825 | tcc_set_lib_path_w32(s); | ||
| 826 | #else | ||
| 827 | tcc_set_lib_path(s, CONFIG_TCCDIR); | 811 | tcc_set_lib_path(s, CONFIG_TCCDIR); |
| 828 | #endif | ||
| 829 | return s; | 812 | return s; |
| 830 | } | 813 | } |
| 831 | 814 | ||
| @@ -154,10 +154,8 @@ static const char help2[] = · 153 unmodified lines | |||
| 154 | 154 | ||
| 155 | static const char version[] = | 155 | static const char version[] = |
| 156 | "tcc version "TCC_VERSION | 156 | "tcc version "TCC_VERSION |
| 157 | #ifdef TCC_GIT_HASH | 157 | #ifdef TCC_GITHASH |
| 158 | " - " TCC_GIT_HASH | 158 | " "TCC_GITHASH |
| 159 | #else | ||
| 160 | " - unknown hash" | ||
| 161 | #endif | 159 | #endif |
| 162 | " (" | 160 | " (" |
| 163 | #ifdef TCC_TARGET_I386 | 161 | #ifdef TCC_TARGET_I386 |
| @@ -276,7 +274,7 @@ int main(int argc0, char **argv0) · 112 unmodified lines | |||
| 276 | { | 274 | { |
| 277 | TCCState *s, *s1; | 275 | TCCState *s, *s1; |
| 278 | int ret, opt, n = 0, t = 0, done; | 276 | int ret, opt, n = 0, t = 0, done; |
| 279 | unsigned start_time = 0; | 277 | unsigned start_time = 0, end_time = 0; |
| 280 | const char *first_file; | 278 | const char *first_file; |
| 281 | int argc; char **argv; | 279 | int argc; char **argv; |
| 282 | FILE *ppfp = stdout; | 280 | FILE *ppfp = stdout; |
| @@ -372,6 +370,9 @@ redo: · 89 unmodified lines | |||
| 372 | done = ret || ++n >= s->nb_files; | 370 | done = ret || ++n >= s->nb_files; |
| 373 | } while (!done && (s->output_type != TCC_OUTPUT_OBJ || s->option_r)); | 371 | } while (!done && (s->output_type != TCC_OUTPUT_OBJ || s->option_r)); |
| 374 | 372 | ||
| 373 | if (s->do_bench) | ||
| 374 | end_time = getclock_ms(); | ||
| 375 | |||
| 375 | if (s->run_test) { | 376 | if (s->run_test) { |
| 376 | t = 0; | 377 | t = 0; |
| 377 | } else if (s->output_type == TCC_OUTPUT_PREPROCESS) { | 378 | } else if (s->output_type == TCC_OUTPUT_PREPROCESS) { |
| @@ -391,13 +392,15 @@ redo: · 13 unmodified lines | |||
| 391 | } | 392 | } |
| 392 | } | 393 | } |
| 393 | 394 | ||
| 394 | if (s->do_bench && done && !(t | ret)) | 395 | if (done && 0 == t && 0 == ret && s->do_bench) |
| 395 | tcc_print_stats(s, getclock_ms() - start_time); | 396 | tcc_print_stats(s, end_time - start_time); |
| 397 | |||
| 396 | tcc_delete(s); | 398 | tcc_delete(s); |
| 397 | if (!done) | 399 | if (!done) |
| 398 | goto redo; /* compile more files with -c */ | 400 | goto redo; /* compile more files with -c */ |
| 399 | if (t) | 401 | if (t) |
| 400 | goto redo; /* run more tests with -dt -run */ | 402 | goto redo; /* run more tests with -dt -run */ |
| 403 | |||
| 401 | if (ppfp && ppfp != stdout) | 404 | if (ppfp && ppfp != stdout) |
| 402 | fclose(ppfp); | 405 | fclose(ppfp); |
| 403 | return ret; | 406 | return ret; |
| @@ -55,6 +55,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 54 unmodified lines | |||
| 55 | # include <windows.h> | 55 | # include <windows.h> |
| 56 | # include <io.h> /* open, close etc. */ | 56 | # include <io.h> /* open, close etc. */ |
| 57 | # include <direct.h> /* getcwd */ | 57 | # include <direct.h> /* getcwd */ |
| 58 | # include <malloc.h> /* alloca */ | ||
| 58 | # ifdef __GNUC__ | 59 | # ifdef __GNUC__ |
| 59 | # include <stdint.h> | 60 | # include <stdint.h> |
| 60 | # endif | 61 | # endif |
| @@ -91,6 +92,9 @@ extern long double strtold (const char *__nptr, char **__endptr); · 30 unmodified lines | |||
| 91 | # define __x86_64__ 1 | 92 | # define __x86_64__ 1 |
| 92 | # endif | 93 | # endif |
| 93 | # endif | 94 | # endif |
| 95 | # ifndef va_copy | ||
| 96 | # define va_copy(a,b) a = b | ||
| 97 | # endif | ||
| 94 | # undef CONFIG_TCC_STATIC | 98 | # undef CONFIG_TCC_STATIC |
| 95 | #endif | 99 | #endif |
| 96 | 100 | ||
| @@ -124,7 +128,6 @@ extern long double strtold (const char *__nptr, char **__endptr); · 27 unmodified lines | |||
| 124 | # define PRINTF_LIKE(x,y) __attribute__ ((format (printf, (x), (y)))) | 128 | # define PRINTF_LIKE(x,y) __attribute__ ((format (printf, (x), (y)))) |
| 125 | #endif | 129 | #endif |
| 126 | 130 | ||
| 127 | |||
| 128 | #ifdef _WIN32 | 131 | #ifdef _WIN32 |
| 129 | # define IS_DIRSEP(c) (c == '/' || c == '\\') | 132 | # define IS_DIRSEP(c) (c == '/' || c == '\\') |
| 130 | # define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2]))) | 133 | # define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2]))) |
| @@ -179,6 +182,9 @@ extern long double strtold (const char *__nptr, char **__endptr); · 48 unmodified lines | |||
| 179 | # ifdef _WIN32 | 182 | # ifdef _WIN32 |
| 180 | # define TCC_TARGET_PE 1 | 183 | # define TCC_TARGET_PE 1 |
| 181 | # endif | 184 | # endif |
| 185 | # ifdef __APPLE__ | ||
| 186 | # define TCC_TARGET_MACHO 1 | ||
| 187 | # endif | ||
| 182 | #endif | 188 | #endif |
| 183 | 189 | ||
| 184 | /* only native compiler supports -run */ | 190 | /* only native compiler supports -run */ |
| @@ -226,7 +232,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 41 unmodified lines | |||
| 226 | /* No ten-byte long doubles on window and macos except in | 232 | /* No ten-byte long doubles on window and macos except in |
| 227 | cross-compilers made by a mingw-GCC */ | 233 | cross-compilers made by a mingw-GCC */ |
| 228 | #if defined TCC_TARGET_PE \ | 234 | #if defined TCC_TARGET_PE \ |
| 229 | || (defined TCC_TARGET_MACHO && defined TCC_TARGET_X86_64) \ | 235 | || (defined TCC_TARGET_MACHO && defined TCC_TARGET_ARM64) \ |
| 230 | || (defined _WIN32 && !defined __GNUC__) | 236 | || (defined _WIN32 && !defined __GNUC__) |
| 231 | # define TCC_USING_DOUBLE_FOR_LDOUBLE 1 | 237 | # define TCC_USING_DOUBLE_FOR_LDOUBLE 1 |
| 232 | #endif | 238 | #endif |
| @@ -236,7 +242,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 3 unmodified lines | |||
| 236 | #ifndef CONFIG_SYSROOT | 242 | #ifndef CONFIG_SYSROOT |
| 237 | # define CONFIG_SYSROOT "" | 243 | # define CONFIG_SYSROOT "" |
| 238 | #endif | 244 | #endif |
| 239 | #ifndef CONFIG_TCCDIR | 245 | #if !defined CONFIG_TCCDIR && !defined _WIN32 |
| 240 | # define CONFIG_TCCDIR "/usr/local/lib/tcc" | 246 | # define CONFIG_TCCDIR "/usr/local/lib/tcc" |
| 241 | #endif | 247 | #endif |
| 242 | #ifndef CONFIG_LDDIR | 248 | #ifndef CONFIG_LDDIR |
| @@ -751,15 +757,6 @@ struct TCCState { · 508 unmodified lines | |||
| 751 | unsigned char enable_new_dtags; /* -Wl,--enable-new-dtags */ | 757 | unsigned char enable_new_dtags; /* -Wl,--enable-new-dtags */ |
| 752 | unsigned int cversion; /* supported C ISO version, 199901 (the default), 201112, ... */ | 758 | unsigned int cversion; /* supported C ISO version, 199901 (the default), 201112, ... */ |
| 753 | 759 | ||
| 754 | char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */ | ||
| 755 | char *soname; /* as specified on the command line (-soname) */ | ||
| 756 | char *rpath; /* as specified on the command line (-Wl,-rpath=) */ | ||
| 757 | |||
| 758 | /* output type, see TCC_OUTPUT_XXX */ | ||
| 759 | int output_type; | ||
| 760 | /* output format, see TCC_OUTPUT_FORMAT_xxx */ | ||
| 761 | int output_format; | ||
| 762 | |||
| 763 | /* C language options */ | 760 | /* C language options */ |
| 764 | unsigned char char_is_unsigned; | 761 | unsigned char char_is_unsigned; |
| 765 | unsigned char leading_underscore; | 762 | unsigned char leading_underscore; |
| @@ -776,10 +773,14 @@ struct TCCState { · 10 unmodified lines | |||
| 776 | unsigned char warn_implicit_function_declaration; | 773 | unsigned char warn_implicit_function_declaration; |
| 777 | unsigned char warn_discarded_qualifiers; | 774 | unsigned char warn_discarded_qualifiers; |
| 778 | #define WARN_ON 1 /* warning is on (-Woption) */ | 775 | #define WARN_ON 1 /* warning is on (-Woption) */ |
| 779 | #define WARN_ERR 2 /* warning is an error (-Werror=option) */ | ||
| 780 | #define WARN_NOE 4 /* warning is not an error (-Wno-error=option) */ | ||
| 781 | unsigned char warn_num; /* temp var for tcc_warning_c() */ | 776 | unsigned char warn_num; /* temp var for tcc_warning_c() */ |
| 782 | 777 | ||
| 778 | unsigned char option_r; /* option -r */ | ||
| 779 | unsigned char do_bench; /* option -bench */ | ||
| 780 | unsigned char just_deps; /* option -M */ | ||
| 781 | unsigned char gen_deps; /* option -MD */ | ||
| 782 | unsigned char include_sys_deps; /* option -MD */ | ||
| 783 | |||
| 783 | /* compile with debug symbol (and use them if error during execution) */ | 784 | /* compile with debug symbol (and use them if error during execution) */ |
| 784 | unsigned char do_debug; | 785 | unsigned char do_debug; |
| 785 | unsigned char do_backtrace; | 786 | unsigned char do_backtrace; |
| @@ -789,30 +790,41 @@ struct TCCState { · 3 unmodified lines | |||
| 789 | #endif | 790 | #endif |
| 790 | unsigned char test_coverage; /* generate test coverage code */ | 791 | unsigned char test_coverage; /* generate test coverage code */ |
| 791 | 792 | ||
| 793 | /* use GNU C extensions */ | ||
| 794 | unsigned char gnu_ext; | ||
| 795 | /* use TinyCC extensions */ | ||
| 796 | unsigned char tcc_ext; | ||
| 797 | |||
| 798 | unsigned char dflag; /* -dX value */ | ||
| 799 | unsigned char Pflag; /* -P switch (LINE_MACRO_OUTPUT_FORMAT) */ | ||
| 800 | |||
| 801 | #ifdef TCC_TARGET_X86_64 | ||
| 802 | unsigned char nosse; /* For -mno-sse support. */ | ||
| 803 | #endif | ||
| 792 | #ifdef TCC_TARGET_ARM | 804 | #ifdef TCC_TARGET_ARM |
| 793 | enum float_abi float_abi; /* float ABI of the generated code*/ | 805 | unsigned char float_abi; /* float ABI of the generated code*/ |
| 794 | #endif | 806 | #endif |
| 795 | int run_test; /* nth test to run with -dt -run */ | ||
| 796 | 807 | ||
| 797 | addr_t text_addr; /* address of text section */ | ||
| 798 | unsigned char has_text_addr; | 808 | unsigned char has_text_addr; |
| 799 | 809 | addr_t text_addr; /* address of text section */ | |
| 800 | unsigned section_align; /* section alignment */ | 810 | unsigned section_align; /* section alignment */ |
| 811 | #ifdef TCC_TARGET_I386 | ||
| 812 | int seg_size; /* 32. Can be 16 with i386 assembler (.code16) */ | ||
| 813 | #endif | ||
| 801 | 814 | ||
| 802 | /* use GNU C extensions */ | 815 | char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */ |
| 803 | unsigned char gnu_ext; | 816 | char *soname; /* as specified on the command line (-soname) */ |
| 804 | /* use TinyCC extensions */ | 817 | char *rpath; /* as specified on the command line (-Wl,-rpath=) */ |
| 805 | unsigned char tcc_ext; | ||
| 806 | 818 | ||
| 807 | char *init_symbol; /* symbols to call at load-time (not used currently) */ | 819 | char *init_symbol; /* symbols to call at load-time (not used currently) */ |
| 808 | char *fini_symbol; /* symbols to call at unload-time (not used currently) */ | 820 | char *fini_symbol; /* symbols to call at unload-time (not used currently) */ |
| 809 | 821 | ||
| 810 | #ifdef TCC_TARGET_I386 | 822 | /* output type, see TCC_OUTPUT_XXX */ |
| 811 | int seg_size; /* 32. Can be 16 with i386 assembler (.code16) */ | 823 | int output_type; |
| 812 | #endif | 824 | /* output format, see TCC_OUTPUT_FORMAT_xxx */ |
| 813 | #ifdef TCC_TARGET_X86_64 | 825 | int output_format; |
| 814 | unsigned char nosse; /* For -mno-sse support. */ | 826 | /* nth test to run with -dt -run */ |
| 815 | #endif | 827 | int run_test; |
| 816 | 828 | ||
| 817 | /* array of all loaded dlls (including those referenced by loaded dlls) */ | 829 | /* array of all loaded dlls (including those referenced by loaded dlls) */ |
| 818 | DLLReference **loaded_dlls; | 830 | DLLReference **loaded_dlls; |
| @@ -847,13 +859,6 @@ struct TCCState { · 28 unmodified lines | |||
| 847 | 859 | ||
| 848 | /* output file for preprocessing (-E) */ | 860 | /* output file for preprocessing (-E) */ |
| 849 | FILE *ppfp; | 861 | FILE *ppfp; |
| 850 | enum { | ||
| 851 | LINE_MACRO_OUTPUT_FORMAT_GCC, | ||
| 852 | LINE_MACRO_OUTPUT_FORMAT_NONE, | ||
| 853 | LINE_MACRO_OUTPUT_FORMAT_STD, | ||
| 854 | LINE_MACRO_OUTPUT_FORMAT_P10 = 11 | ||
| 855 | } Pflag; /* -P switch */ | ||
| 856 | char dflag; /* -dX value */ | ||
| 857 | 862 | ||
| 858 | /* for -MD/-MF: collected dependencies for this compilation */ | 863 | /* for -MD/-MF: collected dependencies for this compilation */ |
| 859 | char **target_deps; | 864 | char **target_deps; |
| @@ -922,11 +927,11 @@ struct TCCState { · 62 unmodified lines | |||
| 922 | int nb_sym_attrs; | 927 | int nb_sym_attrs; |
| 923 | /* ptr to next reloc entry reused */ | 928 | /* ptr to next reloc entry reused */ |
| 924 | ElfW_Rel *qrel; | 929 | ElfW_Rel *qrel; |
| 925 | # define qrel s1->qrel | 930 | #define qrel s1->qrel |
| 926 | 931 | ||
| 927 | #ifdef TCC_TARGET_RISCV64 | 932 | #ifdef TCC_TARGET_RISCV64 |
| 928 | struct pcrel_hi { addr_t addr, val; } last_hi; | 933 | struct pcrel_hi { addr_t addr, val; } last_hi; |
| 929 | # define last_hi s1->last_hi | 934 | #define last_hi s1->last_hi |
| 930 | #endif | 935 | #endif |
| 931 | 936 | ||
| 932 | #ifdef TCC_TARGET_PE | 937 | #ifdef TCC_TARGET_PE |
| @@ -963,8 +968,6 @@ struct TCCState { · 30 unmodified lines | |||
| 963 | int rt_num_callers; | 968 | int rt_num_callers; |
| 964 | #endif | 969 | #endif |
| 965 | 970 | ||
| 966 | int fd, cc; /* used by tcc_load_ldscript */ | ||
| 967 | |||
| 968 | /* benchmark info */ | 971 | /* benchmark info */ |
| 969 | int total_idents; | 972 | int total_idents; |
| 970 | int total_lines; | 973 | int total_lines; |
| @@ -974,7 +977,10 @@ struct TCCState { · 3 unmodified lines | |||
| 974 | /* option -dnum (for general development purposes) */ | 977 | /* option -dnum (for general development purposes) */ |
| 975 | int g_debug; | 978 | int g_debug; |
| 976 | 979 | ||
| 977 | /* for warnings/errors for object files*/ | 980 | /* used by tcc_load_ldscript */ |
| 981 | int fd, cc; | ||
| 982 | |||
| 983 | /* for warnings/errors for object files */ | ||
| 978 | const char *current_filename; | 984 | const char *current_filename; |
| 979 | 985 | ||
| 980 | /* used by main and tcc_parse_args only */ | 986 | /* used by main and tcc_parse_args only */ |
| @@ -982,11 +988,6 @@ struct TCCState { · 1 unmodified line | |||
| 982 | int nb_files; /* number thereof */ | 988 | int nb_files; /* number thereof */ |
| 983 | int nb_libraries; /* number of libs thereof */ | 989 | int nb_libraries; /* number of libs thereof */ |
| 984 | char *outfile; /* output filename */ | 990 | char *outfile; /* output filename */ |
| 985 | unsigned char option_r; /* option -r */ | ||
| 986 | unsigned char do_bench; /* option -bench */ | ||
| 987 | int just_deps; /* option -M */ | ||
| 988 | int gen_deps; /* option -MD */ | ||
| 989 | int include_sys_deps; /* option -MD */ | ||
| 990 | char *deps_outfile; /* option -MF */ | 991 | char *deps_outfile; /* option -MF */ |
| 991 | int argc; | 992 | int argc; |
| 992 | char **argv; | 993 | char **argv; |
| @@ -1161,91 +1162,6 @@ struct filespec { · 168 unmodified lines | |||
| 1161 | /* all identifiers and strings have token above that */ | 1162 | /* all identifiers and strings have token above that */ |
| 1162 | #define TOK_IDENT 256 | 1163 | #define TOK_IDENT 256 |
| 1163 | 1164 | ||
| 1164 | #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x) | ||
| 1165 | #define TOK_ASM_int TOK_INT | ||
| 1166 | #define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x) | ||
| 1167 | #define TOK_ASMDIR_FIRST TOK_ASMDIR_byte | ||
| 1168 | #define TOK_ASMDIR_LAST TOK_ASMDIR_section | ||
| 1169 | |||
| 1170 | #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 | ||
| 1171 | /* only used for i386 asm opcodes definitions */ | ||
| 1172 | #define DEF_BWL(x) \ | ||
| 1173 | DEF(TOK_ASM_ ## x ## b, #x "b") \ | ||
| 1174 | DEF(TOK_ASM_ ## x ## w, #x "w") \ | ||
| 1175 | DEF(TOK_ASM_ ## x ## l, #x "l") \ | ||
| 1176 | DEF(TOK_ASM_ ## x, #x) | ||
| 1177 | #define DEF_WL(x) \ | ||
| 1178 | DEF(TOK_ASM_ ## x ## w, #x "w") \ | ||
| 1179 | DEF(TOK_ASM_ ## x ## l, #x "l") \ | ||
| 1180 | DEF(TOK_ASM_ ## x, #x) | ||
| 1181 | #ifdef TCC_TARGET_X86_64 | ||
| 1182 | # define DEF_BWLQ(x) \ | ||
| 1183 | DEF(TOK_ASM_ ## x ## b, #x "b") \ | ||
| 1184 | DEF(TOK_ASM_ ## x ## w, #x "w") \ | ||
| 1185 | DEF(TOK_ASM_ ## x ## l, #x "l") \ | ||
| 1186 | DEF(TOK_ASM_ ## x ## q, #x "q") \ | ||
| 1187 | DEF(TOK_ASM_ ## x, #x) | ||
| 1188 | # define DEF_WLQ(x) \ | ||
| 1189 | DEF(TOK_ASM_ ## x ## w, #x "w") \ | ||
| 1190 | DEF(TOK_ASM_ ## x ## l, #x "l") \ | ||
| 1191 | DEF(TOK_ASM_ ## x ## q, #x "q") \ | ||
| 1192 | DEF(TOK_ASM_ ## x, #x) | ||
| 1193 | # define DEF_BWLX DEF_BWLQ | ||
| 1194 | # define DEF_WLX DEF_WLQ | ||
| 1195 | /* number of sizes + 1 */ | ||
| 1196 | # define NBWLX 5 | ||
| 1197 | #else | ||
| 1198 | # define DEF_BWLX DEF_BWL | ||
| 1199 | # define DEF_WLX DEF_WL | ||
| 1200 | /* number of sizes + 1 */ | ||
| 1201 | # define NBWLX 4 | ||
| 1202 | #endif | ||
| 1203 | |||
| 1204 | #define DEF_FP1(x) \ | ||
| 1205 | DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \ | ||
| 1206 | DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \ | ||
| 1207 | DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \ | ||
| 1208 | DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s") | ||
| 1209 | |||
| 1210 | #define DEF_FP(x) \ | ||
| 1211 | DEF(TOK_ASM_ ## f ## x, "f" #x ) \ | ||
| 1212 | DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \ | ||
| 1213 | DEF_FP1(x) | ||
| 1214 | |||
| 1215 | #define DEF_ASMTEST(x,suffix) \ | ||
| 1216 | DEF_ASM(x ## o ## suffix) \ | ||
| 1217 | DEF_ASM(x ## no ## suffix) \ | ||
| 1218 | DEF_ASM(x ## b ## suffix) \ | ||
| 1219 | DEF_ASM(x ## c ## suffix) \ | ||
| 1220 | DEF_ASM(x ## nae ## suffix) \ | ||
| 1221 | DEF_ASM(x ## nb ## suffix) \ | ||
| 1222 | DEF_ASM(x ## nc ## suffix) \ | ||
| 1223 | DEF_ASM(x ## ae ## suffix) \ | ||
| 1224 | DEF_ASM(x ## e ## suffix) \ | ||
| 1225 | DEF_ASM(x ## z ## suffix) \ | ||
| 1226 | DEF_ASM(x ## ne ## suffix) \ | ||
| 1227 | DEF_ASM(x ## nz ## suffix) \ | ||
| 1228 | DEF_ASM(x ## be ## suffix) \ | ||
| 1229 | DEF_ASM(x ## na ## suffix) \ | ||
| 1230 | DEF_ASM(x ## nbe ## suffix) \ | ||
| 1231 | DEF_ASM(x ## a ## suffix) \ | ||
| 1232 | DEF_ASM(x ## s ## suffix) \ | ||
| 1233 | DEF_ASM(x ## ns ## suffix) \ | ||
| 1234 | DEF_ASM(x ## p ## suffix) \ | ||
| 1235 | DEF_ASM(x ## pe ## suffix) \ | ||
| 1236 | DEF_ASM(x ## np ## suffix) \ | ||
| 1237 | DEF_ASM(x ## po ## suffix) \ | ||
| 1238 | DEF_ASM(x ## l ## suffix) \ | ||
| 1239 | DEF_ASM(x ## nge ## suffix) \ | ||
| 1240 | DEF_ASM(x ## nl ## suffix) \ | ||
| 1241 | DEF_ASM(x ## ge ## suffix) \ | ||
| 1242 | DEF_ASM(x ## le ## suffix) \ | ||
| 1243 | DEF_ASM(x ## ng ## suffix) \ | ||
| 1244 | DEF_ASM(x ## nle ## suffix) \ | ||
| 1245 | DEF_ASM(x ## g ## suffix) | ||
| 1246 | |||
| 1247 | #endif /* defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 */ | ||
| 1248 | |||
| 1249 | enum tcc_token { | 1165 | enum tcc_token { |
| 1250 | TOK_LAST = TOK_IDENT - 1 | 1166 | TOK_LAST = TOK_IDENT - 1 |
| 1251 | #define DEF(id, str) ,id | 1167 | #define DEF(id, str) ,id |
| @@ -1306,6 +1222,7 @@ ST_FUNC void cstr_wccat(CString *cstr, int ch); · 54 unmodified lines | |||
| 1306 | ST_FUNC void cstr_new(CString *cstr); | 1222 | ST_FUNC void cstr_new(CString *cstr); |
| 1307 | ST_FUNC void cstr_free(CString *cstr); | 1223 | ST_FUNC void cstr_free(CString *cstr); |
| 1308 | ST_FUNC int cstr_printf(CString *cs, const char *fmt, ...) PRINTF_LIKE(2,3); | 1224 | ST_FUNC int cstr_printf(CString *cs, const char *fmt, ...) PRINTF_LIKE(2,3); |
| 1225 | ST_FUNC int cstr_vprintf(CString *cstr, const char *fmt, va_list ap); | ||
| 1309 | ST_FUNC void cstr_reset(CString *cstr); | 1226 | ST_FUNC void cstr_reset(CString *cstr); |
| 1310 | 1227 | ||
| 1311 | ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen); | 1228 | ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen); |
| @@ -1397,6 +1314,13 @@ ST_DATA TokenSym **table_ident; · 85 unmodified lines | |||
| 1397 | #define IS_ID 2 | 1314 | #define IS_ID 2 |
| 1398 | #define IS_NUM 4 | 1315 | #define IS_NUM 4 |
| 1399 | 1316 | ||
| 1317 | enum line_macro_output_format { | ||
| 1318 | LINE_MACRO_OUTPUT_FORMAT_GCC, | ||
| 1319 | LINE_MACRO_OUTPUT_FORMAT_NONE, | ||
| 1320 | LINE_MACRO_OUTPUT_FORMAT_STD, | ||
| 1321 | LINE_MACRO_OUTPUT_FORMAT_P10 = 11 | ||
| 1322 | }; | ||
| 1323 | |||
| 1400 | ST_FUNC TokenSym *tok_alloc(const char *str, int len); | 1324 | ST_FUNC TokenSym *tok_alloc(const char *str, int len); |
| 1401 | ST_FUNC int tok_alloc_const(const char *str); | 1325 | ST_FUNC int tok_alloc_const(const char *str); |
| 1402 | ST_FUNC const char *get_tok_str(int v, CValue *cv); | 1326 | ST_FUNC const char *get_tok_str(int v, CValue *cv); |
| @@ -1770,12 +1694,12 @@ ST_FUNC int tcc_load_coff(TCCState * s1, int fd); · 367 unmodified lines | |||
| 1770 | /* ------------ tccasm.c ------------ */ | 1694 | /* ------------ tccasm.c ------------ */ |
| 1771 | ST_FUNC void asm_instr(void); | 1695 | ST_FUNC void asm_instr(void); |
| 1772 | ST_FUNC void asm_global_instr(void); | 1696 | ST_FUNC void asm_global_instr(void); |
| 1697 | ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess); | ||
| 1773 | #ifdef CONFIG_TCC_ASM | 1698 | #ifdef CONFIG_TCC_ASM |
| 1774 | ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp); | 1699 | ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp); |
| 1775 | ST_FUNC Sym* get_asm_sym(int name, Sym *csym); | 1700 | ST_FUNC Sym* get_asm_sym(int name, Sym *csym); |
| 1776 | ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe); | 1701 | ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe); |
| 1777 | ST_FUNC int asm_int_expr(TCCState *s1); | 1702 | ST_FUNC int asm_int_expr(TCCState *s1); |
| 1778 | ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess); | ||
| 1779 | /* ------------ i386-asm.c ------------ */ | 1703 | /* ------------ i386-asm.c ------------ */ |
| 1780 | ST_FUNC void gen_expr32(ExprValue *pe); | 1704 | ST_FUNC void gen_expr32(ExprValue *pe); |
| 1781 | #ifdef TCC_TARGET_X86_64 | 1705 | #ifdef TCC_TARGET_X86_64 |
| @@ -1844,6 +1768,28 @@ ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option); · 62 unmodified lines | |||
| 1844 | ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename); | 1768 | ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename); |
| 1845 | #endif | 1769 | #endif |
| 1846 | 1770 | ||
| 1771 | /********************************************************/ | ||
| 1772 | #if CONFIG_TCC_SEMLOCK | ||
| 1773 | #if defined _WIN32 | ||
| 1774 | typedef struct { int init; CRITICAL_SECTION cr; } TCCSem; | ||
| 1775 | #elif defined __APPLE__ | ||
| 1776 | #include <dispatch/dispatch.h> | ||
| 1777 | typedef struct { int init; dispatch_semaphore_t sem; } TCCSem; | ||
| 1778 | #else | ||
| 1779 | #include <semaphore.h> | ||
| 1780 | typedef struct { int init; sem_t sem; } TCCSem; | ||
| 1781 | #endif | ||
| 1782 | ST_FUNC void wait_sem(TCCSem *p); | ||
| 1783 | ST_FUNC void post_sem(TCCSem *p); | ||
| 1784 | #define TCC_SEM(s) TCCSem s | ||
| 1785 | #define WAIT_SEM wait_sem | ||
| 1786 | #define POST_SEM post_sem | ||
| 1787 | #else | ||
| 1788 | #define TCC_SEM(s) | ||
| 1789 | #define WAIT_SEM(p) | ||
| 1790 | #define POST_SEM(p) | ||
| 1791 | #endif | ||
| 1792 | |||
| 1847 | /********************************************************/ | 1793 | /********************************************************/ |
| 1848 | #undef ST_DATA | 1794 | #undef ST_DATA |
| 1849 | #if ONE_SOURCE | 1795 | #if ONE_SOURCE |
| @@ -1875,7 +1821,7 @@ ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename) · 25 unmodified lines | |||
| 1875 | #define total_bytes TCC_STATE_VAR(total_bytes) | 1821 | #define total_bytes TCC_STATE_VAR(total_bytes) |
| 1876 | 1822 | ||
| 1877 | PUB_FUNC void tcc_enter_state(TCCState *s1); | 1823 | PUB_FUNC void tcc_enter_state(TCCState *s1); |
| 1878 | PUB_FUNC void tcc_exit_state(void); | 1824 | PUB_FUNC void tcc_exit_state(TCCState *s1); |
| 1879 | 1825 | ||
| 1880 | /* conditional warning depending on switch */ | 1826 | /* conditional warning depending on switch */ |
| 1881 | #define tcc_warning_c(sw) TCC_SET_STATE((\ | 1827 | #define tcc_warning_c(sw) TCC_SET_STATE((\ |
| @@ -1298,4 +1298,21 @@ ST_FUNC void asm_global_instr(void) · 1297 unmodified lines | |||
| 1298 | cstr_free(&astr); | 1298 | cstr_free(&astr); |
| 1299 | nocode_wanted = saved_nocode_wanted; | 1299 | nocode_wanted = saved_nocode_wanted; |
| 1300 | } | 1300 | } |
| 1301 | |||
| 1302 | /********************************************************/ | ||
| 1303 | #else | ||
| 1304 | ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess) | ||
| 1305 | { | ||
| 1306 | tcc_error("asm not supported"); | ||
| 1307 | } | ||
| 1308 | |||
| 1309 | ST_FUNC void asm_instr(void) | ||
| 1310 | { | ||
| 1311 | tcc_error("inline asm() not supported"); | ||
| 1312 | } | ||
| 1313 | |||
| 1314 | ST_FUNC void asm_global_instr(void) | ||
| 1315 | { | ||
| 1316 | tcc_error("inline asm() not supported"); | ||
| 1317 | } | ||
| 1301 | #endif /* CONFIG_TCC_ASM */ | 1318 | #endif /* CONFIG_TCC_ASM */ |
| @@ -97,7 +97,7 @@ static CString initstr; · 96 unmodified lines | |||
| 97 | #define VT_PTRDIFF_T (VT_LONG | VT_LLONG) | 97 | #define VT_PTRDIFF_T (VT_LONG | VT_LLONG) |
| 98 | #endif | 98 | #endif |
| 99 | 99 | ||
| 100 | ST_DATA struct switch_t { | 100 | static struct switch_t { |
| 101 | struct case_t { | 101 | struct case_t { |
| 102 | int64_t v1, v2; | 102 | int64_t v1, v2; |
| 103 | int sym; | 103 | int sym; |
| @@ -111,12 +111,12 @@ ST_DATA struct switch_t { · 7 unmodified lines | |||
| 111 | 111 | ||
| 112 | #define MAX_TEMP_LOCAL_VARIABLE_NUMBER 8 | 112 | #define MAX_TEMP_LOCAL_VARIABLE_NUMBER 8 |
| 113 | /*list of temporary local variables on the stack in current function. */ | 113 | /*list of temporary local variables on the stack in current function. */ |
| 114 | ST_DATA struct temp_local_variable { | 114 | static struct temp_local_variable { |
| 115 | int location; //offset on stack. Svalue.c.i | 115 | int location; //offset on stack. Svalue.c.i |
| 116 | short size; | 116 | short size; |
| 117 | short align; | 117 | short align; |
| 118 | } arr_temp_local_vars[MAX_TEMP_LOCAL_VARIABLE_NUMBER]; | 118 | } arr_temp_local_vars[MAX_TEMP_LOCAL_VARIABLE_NUMBER]; |
| 119 | short nb_temp_local_vars; | 119 | static int nb_temp_local_vars; |
| 120 | 120 | ||
| 121 | static struct scope { | 121 | static struct scope { |
| 122 | struct scope *prev; | 122 | struct scope *prev; |
| @@ -132,6 +132,11 @@ typedef struct { · 9 unmodified lines | |||
| 132 | Sym *flex_array_ref; | 132 | Sym *flex_array_ref; |
| 133 | } init_params; | 133 | } init_params; |
| 134 | 134 | ||
| 135 | #if 1 | ||
| 136 | #define precedence_parser | ||
| 137 | static void init_prec(void); | ||
| 138 | #endif | ||
| 139 | |||
| 135 | /********************************************************/ | 140 | /********************************************************/ |
| 136 | /* stab debug support */ | 141 | /* stab debug support */ |
| 137 | 142 | ||
| @@ -215,23 +220,6 @@ static struct { · 77 unmodified lines | |||
| 215 | } tcov_data; | 220 | } tcov_data; |
| 216 | 221 | ||
| 217 | /********************************************************/ | 222 | /********************************************************/ |
| 218 | #if 1 | ||
| 219 | #define precedence_parser | ||
| 220 | static void init_prec(void); | ||
| 221 | #endif | ||
| 222 | /********************************************************/ | ||
| 223 | #ifndef CONFIG_TCC_ASM | ||
| 224 | ST_FUNC void asm_instr(void) | ||
| 225 | { | ||
| 226 | tcc_error("inline asm() not supported"); | ||
| 227 | } | ||
| 228 | ST_FUNC void asm_global_instr(void) | ||
| 229 | { | ||
| 230 | tcc_error("inline asm() not supported"); | ||
| 231 | } | ||
| 232 | #endif | ||
| 233 | |||
| 234 | /* ------------------------------------------------------------------------- */ | ||
| 235 | static void gen_cast(CType *type); | 223 | static void gen_cast(CType *type); |
| 236 | static void gen_cast_s(int t); | 224 | static void gen_cast_s(int t); |
| 237 | static inline CType *pointed_type(CType *type); | 225 | static inline CType *pointed_type(CType *type); |
| @@ -7247,7 +7235,7 @@ static void vla_leave(struct scope *o) · 7009 unmodified lines | |||
| 7247 | /* ------------------------------------------------------------------------- */ | 7235 | /* ------------------------------------------------------------------------- */ |
| 7248 | /* local scopes */ | 7236 | /* local scopes */ |
| 7249 | 7237 | ||
| 7250 | void new_scope(struct scope *o) | 7238 | static void new_scope(struct scope *o) |
| 7251 | { | 7239 | { |
| 7252 | /* copy and link previous scope */ | 7240 | /* copy and link previous scope */ |
| 7253 | *o = *cur_scope; | 7241 | *o = *cur_scope; |
| @@ -7264,7 +7252,7 @@ void new_scope(struct scope *o) · 10 unmodified lines | |||
| 7264 | tcc_debug_stabn(tcc_state, N_LBRAC, ind - func_ind); | 7252 | tcc_debug_stabn(tcc_state, N_LBRAC, ind - func_ind); |
| 7265 | } | 7253 | } |
| 7266 | 7254 | ||
| 7267 | void prev_scope(struct scope *o, int is_expr) | 7255 | static void prev_scope(struct scope *o, int is_expr) |
| 7268 | { | 7256 | { |
| 7269 | vla_leave(o->prev); | 7257 | vla_leave(o->prev); |
| 7270 | 7258 | ||
| @@ -7292,7 +7280,7 @@ void prev_scope(struct scope *o, int is_expr) · 21 unmodified lines | |||
| 7292 | } | 7280 | } |
| 7293 | 7281 | ||
| 7294 | /* leave a scope via break/continue(/goto) */ | 7282 | /* leave a scope via break/continue(/goto) */ |
| 7295 | void leave_scope(struct scope *o) | 7283 | static void leave_scope(struct scope *o) |
| 7296 | { | 7284 | { |
| 7297 | if (!o) | 7285 | if (!o) |
| 7298 | return; | 7286 | return; |
| @@ -517,7 +517,7 @@ static void create_symtab(TCCState *s1, struct macho *mo) · 516 unmodified lines | |||
| 517 | } | 517 | } |
| 518 | tcc_enter_state(s1); /* qsort needs global state */ | 518 | tcc_enter_state(s1); /* qsort needs global state */ |
| 519 | qsort(pn, sym_end - 1, sizeof(*pn), machosymcmp); | 519 | qsort(pn, sym_end - 1, sizeof(*pn), machosymcmp); |
| 520 | tcc_exit_state(); | 520 | tcc_exit_state(s1); |
| 521 | mo->e2msym = tcc_malloc(sym_end * sizeof(*mo->e2msym)); | 521 | mo->e2msym = tcc_malloc(sym_end * sizeof(*mo->e2msym)); |
| 522 | mo->e2msym[0] = -1; | 522 | mo->e2msym[0] = -1; |
| 523 | for (sym_index = 1; sym_index < sym_end; ++sym_index) { | 523 | for (sym_index = 1; sym_index < sym_end; ++sym_index) { |
| @@ -1543,8 +1543,6 @@ static int pe_add_dllref(TCCState *s1, const char *dllname) · 1542 unmodified lines | |||
| 1543 | return s1->nb_loaded_dlls; | 1543 | return s1->nb_loaded_dlls; |
| 1544 | } | 1544 | } |
| 1545 | 1545 | ||
| 1546 | /* ------------------------------------------------------------- */ | ||
| 1547 | |||
| 1548 | static int read_mem(int fd, unsigned offset, void *buffer, unsigned len) | 1546 | static int read_mem(int fd, unsigned offset, void *buffer, unsigned len) |
| 1549 | { | 1547 | { |
| 1550 | lseek(fd, offset, SEEK_SET); | 1548 | lseek(fd, offset, SEEK_SET); |
| @@ -1553,11 +1551,10 @@ static int read_mem(int fd, unsigned offset, void *buffer, unsigned len) · 2 unmodified lines | |||
| 1553 | 1551 | ||
| 1554 | /* ------------------------------------------------------------- */ | 1552 | /* ------------------------------------------------------------- */ |
| 1555 | 1553 | ||
| 1556 | PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp) | 1554 | static int get_dllexports(int fd, char **pp) |
| 1557 | { | 1555 | { |
| 1558 | int l, i, n, n0, ret; | 1556 | int l, i, n, n0, ret; |
| 1559 | char *p; | 1557 | char *p; |
| 1560 | int fd; | ||
| 1561 | 1558 | ||
| 1562 | IMAGE_SECTION_HEADER ish; | 1559 | IMAGE_SECTION_HEADER ish; |
| 1563 | IMAGE_EXPORT_DIRECTORY ied; | 1560 | IMAGE_EXPORT_DIRECTORY ied; |
| @@ -1569,11 +1566,6 @@ PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp) · 5 unmodified lines | |||
| 1569 | 1566 | ||
| 1570 | n = n0 = 0; | 1567 | n = n0 = 0; |
| 1571 | p = NULL; | 1568 | p = NULL; |
| 1572 | ret = -1; | ||
| 1573 | |||
| 1574 | fd = open(filename, O_RDONLY | O_BINARY); | ||
| 1575 | if (fd < 0) | ||
| 1576 | goto the_end_1; | ||
| 1577 | ret = 1; | 1569 | ret = 1; |
| 1578 | if (!read_mem(fd, 0, &dh, sizeof dh)) | 1570 | if (!read_mem(fd, 0, &dh, sizeof dh)) |
| 1579 | goto the_end; | 1571 | goto the_end; |
| @@ -1640,8 +1632,6 @@ found: · 60 unmodified lines | |||
| 1640 | the_end_0: | 1632 | the_end_0: |
| 1641 | ret = 0; | 1633 | ret = 0; |
| 1642 | the_end: | 1634 | the_end: |
| 1643 | close(fd); | ||
| 1644 | the_end_1: | ||
| 1645 | *pp = p; | 1635 | *pp = p; |
| 1646 | return ret; | 1636 | return ret; |
| 1647 | } | 1637 | } |
| @@ -1694,47 +1684,53 @@ quit: · 46 unmodified lines | |||
| 1694 | 1684 | ||
| 1695 | static char *trimfront(char *p) | 1685 | static char *trimfront(char *p) |
| 1696 | { | 1686 | { |
| 1697 | while (*p && (unsigned char)*p <= ' ') | 1687 | while ((unsigned char)*p <= ' ' && *p && *p != '\n') |
| 1698 | ++p; | 1688 | ++p; |
| 1699 | return p; | 1689 | return p; |
| 1700 | } | 1690 | } |
| 1701 | 1691 | ||
| 1692 | /* | ||
| 1702 | static char *trimback(char *a, char *e) | 1693 | static char *trimback(char *a, char *e) |
| 1703 | { | 1694 | { |
| 1704 | while (e > a && (unsigned char)e[-1] <= ' ') | 1695 | while (e > a && (unsigned char)e[-1] <= ' ') |
| 1705 | --e; | 1696 | --e; |
| 1706 | *e = 0;; | 1697 | *e = 0;; |
| 1707 | return a; | 1698 | return a; |
| 1699 | }*/ | ||
| 1700 | |||
| 1701 | static char *get_token(char **s, char *f) | ||
| 1702 | { | ||
| 1703 | char *p = *s, *e; | ||
| 1704 | p = e = trimfront(p); | ||
| 1705 | while ((unsigned char)*e > ' ') | ||
| 1706 | ++e; | ||
| 1707 | *s = trimfront(e); | ||
| 1708 | *f = **s; *e = 0; | ||
| 1709 | return p; | ||
| 1708 | } | 1710 | } |
| 1709 | 1711 | ||
| 1710 | /* ------------------------------------------------------------- */ | ||
| 1711 | static int pe_load_def(TCCState *s1, int fd) | 1712 | static int pe_load_def(TCCState *s1, int fd) |
| 1712 | { | 1713 | { |
| 1713 | int state = 0, ret = -1, dllindex = 0, ord; | 1714 | int state = 0, ret = -1, dllindex = 0, ord; |
| 1714 | char line[400], dllname[80], *p, *x; | 1715 | char dllname[80], *buf, *line, *p, *x, next; |
| 1715 | FILE *fp; | ||
| 1716 | |||
| 1717 | fp = fdopen(dup(fd), "rb"); | ||
| 1718 | while (fgets(line, sizeof line, fp)) | ||
| 1719 | { | ||
| 1720 | p = trimfront(trimback(line, strchr(line, 0))); | ||
| 1721 | if (0 == *p || ';' == *p) | ||
| 1722 | continue; | ||
| 1723 | 1716 | ||
| 1717 | buf = tcc_load_text(fd); | ||
| 1718 | for (line = buf;; ++line) { | ||
| 1719 | p = get_token(&line, &next); | ||
| 1720 | if (!(*p && *p != ';')) | ||
| 1721 | goto skip; | ||
| 1724 | switch (state) { | 1722 | switch (state) { |
| 1725 | case 0: | 1723 | case 0: |
| 1726 | if (0 != strnicmp(p, "LIBRARY", 7)) | 1724 | if (0 != stricmp(p, "LIBRARY") || next == '\n') |
| 1727 | goto quit; | 1725 | goto quit; |
| 1728 | pstrcpy(dllname, sizeof dllname, trimfront(p+7)); | 1726 | pstrcpy(dllname, sizeof dllname, get_token(&line, &next)); |
| 1729 | ++state; | 1727 | ++state; |
| 1730 | continue; | 1728 | break; |
| 1731 | |||
| 1732 | case 1: | 1729 | case 1: |
| 1733 | if (0 != stricmp(p, "EXPORTS")) | 1730 | if (0 != stricmp(p, "EXPORTS")) |
| 1734 | goto quit; | 1731 | goto quit; |
| 1735 | ++state; | 1732 | ++state; |
| 1736 | continue; | 1733 | break; |
| 1737 | |||
| 1738 | case 2: | 1734 | case 2: |
| 1739 | dllindex = pe_add_dllref(s1, dllname); | 1735 | dllindex = pe_add_dllref(s1, dllname); |
| 1740 | ++state; | 1736 | ++state; |
| @@ -1742,33 +1738,34 @@ static int pe_load_def(TCCState *s1, int fd) · 1 unmodified line | |||
| 1742 | default: | 1738 | default: |
| 1743 | /* get ordinal and will store in sym->st_value */ | 1739 | /* get ordinal and will store in sym->st_value */ |
| 1744 | ord = 0; | 1740 | ord = 0; |
| 1745 | x = strchr(p, ' '); | 1741 | if (next == '@') { |
| 1746 | if (x) { | 1742 | x = get_token(&line, &next); |
| 1747 | *x = 0, x = strrchr(x + 1, '@'); | 1743 | ord = (int)strtol(x + 1, &x, 10); |
| 1748 | if (x) { | ||
| 1749 | char *d; | ||
| 1750 | ord = (int)strtol(x + 1, &d, 10); | ||
| 1751 | if (*d) | ||
| 1752 | ord = 0; | ||
| 1753 | } | ||
| 1754 | } | 1744 | } |
| 1745 | //printf("token %s ; %s : %d\n", dllname, p, ord); | ||
| 1755 | pe_putimport(s1, dllindex, p, ord); | 1746 | pe_putimport(s1, dllindex, p, ord); |
| 1756 | continue; | 1747 | break; |
| 1757 | } | 1748 | } |
| 1749 | skip: | ||
| 1750 | while ((unsigned char)next > ' ') | ||
| 1751 | get_token(&line, &next); | ||
| 1752 | if (next != '\n') | ||
| 1753 | break; | ||
| 1758 | } | 1754 | } |
| 1759 | ret = 0; | 1755 | ret = 0; |
| 1760 | quit: | 1756 | quit: |
| 1761 | fclose(fp); | 1757 | tcc_free(buf); |
| 1762 | return ret; | 1758 | return ret; |
| 1763 | } | 1759 | } |
| 1764 | 1760 | ||
| 1765 | /* ------------------------------------------------------------- */ | 1761 | /* ------------------------------------------------------------- */ |
| 1766 | static int pe_load_dll(TCCState *s1, const char *filename) | 1762 | |
| 1763 | static int pe_load_dll(TCCState *s1, int fd, const char *filename) | ||
| 1767 | { | 1764 | { |
| 1768 | char *p, *q; | 1765 | char *p, *q; |
| 1769 | int index, ret; | 1766 | int index, ret; |
| 1770 | 1767 | ||
| 1771 | ret = tcc_get_dllexports(filename, &p); | 1768 | ret = get_dllexports(fd, &p); |
| 1772 | if (ret) { | 1769 | if (ret) { |
| 1773 | return -1; | 1770 | return -1; |
| 1774 | } else if (p) { | 1771 | } else if (p) { |
| @@ -1780,7 +1777,6 @@ static int pe_load_dll(TCCState *s1, const char *filename) · 5 unmodified lines | |||
| 1780 | return 0; | 1777 | return 0; |
| 1781 | } | 1778 | } |
| 1782 | 1779 | ||
| 1783 | /* ------------------------------------------------------------- */ | ||
| 1784 | ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename) | 1780 | ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename) |
| 1785 | { | 1781 | { |
| 1786 | int ret = -1; | 1782 | int ret = -1; |
| @@ -1790,7 +1786,17 @@ ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename) · 3 unmodified lines | |||
| 1790 | else if (pe_load_res(s1, fd) == 0) | 1786 | else if (pe_load_res(s1, fd) == 0) |
| 1791 | ret = 0; | 1787 | ret = 0; |
| 1792 | else if (read_mem(fd, 0, buf, 4) && 0 == memcmp(buf, "MZ", 2)) | 1788 | else if (read_mem(fd, 0, buf, 4) && 0 == memcmp(buf, "MZ", 2)) |
| 1793 | ret = pe_load_dll(s1, filename); | 1789 | ret = pe_load_dll(s1, fd, filename); |
| 1790 | return ret; | ||
| 1791 | } | ||
| 1792 | |||
| 1793 | PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp) | ||
| 1794 | { | ||
| 1795 | int ret, fd = open(filename, O_RDONLY | O_BINARY); | ||
| 1796 | if (fd < 0) | ||
| 1797 | return -1; | ||
| 1798 | ret = get_dllexports(fd, pp); | ||
| 1799 | close(fd); | ||
| 1794 | return ret; | 1800 | return ret; |
| 1795 | } | 1801 | } |
| 1796 | 1802 | ||
| @@ -404,7 +404,7 @@ ST_FUNC void cstr_reset(CString *cstr) · 403 unmodified lines | |||
| 404 | cstr->size = 0; | 404 | cstr->size = 0; |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | ST_FUNC int cstr_printf(CString *cstr, const char *fmt, ...) | 407 | ST_FUNC int cstr_vprintf(CString *cstr, const char *fmt, va_list ap) |
| 408 | { | 408 | { |
| 409 | va_list v; | 409 | va_list v; |
| 410 | int len, size = 80; | 410 | int len, size = 80; |
| @@ -413,7 +413,7 @@ ST_FUNC int cstr_printf(CString *cstr, const char *fmt, ...) · 2 unmodified lines | |||
| 413 | if (size > cstr->size_allocated) | 413 | if (size > cstr->size_allocated) |
| 414 | cstr_realloc(cstr, size); | 414 | cstr_realloc(cstr, size); |
| 415 | size = cstr->size_allocated - cstr->size; | 415 | size = cstr->size_allocated - cstr->size; |
| 416 | va_start(v, fmt); | 416 | va_copy(v, ap); |
| 417 | len = vsnprintf((char*)cstr->data + cstr->size, size, fmt, v); | 417 | len = vsnprintf((char*)cstr->data + cstr->size, size, fmt, v); |
| 418 | va_end(v); | 418 | va_end(v); |
| 419 | if (len > 0 && len < size) | 419 | if (len > 0 && len < size) |
| @@ -424,6 +424,15 @@ ST_FUNC int cstr_printf(CString *cstr, const char *fmt, ...) · 4 unmodified lines | |||
| 424 | return len; | 424 | return len; |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | ST_FUNC int cstr_printf(CString *cstr, const char *fmt, ...) | ||
| 428 | { | ||
| 429 | va_list ap; int len; | ||
| 430 | va_start(ap, fmt); | ||
| 431 | len = cstr_vprintf(cstr, fmt, ap); | ||
| 432 | va_end(ap); | ||
| 433 | return len; | ||
| 434 | } | ||
| 435 | |||
| 427 | /* XXX: unicode ? */ | 436 | /* XXX: unicode ? */ |
| 428 | static void add_char(CString *cstr, int c) | 437 | static void add_char(CString *cstr, int c) |
| 429 | { | 438 | { |
| @@ -1,3 +1,4 @@ | |||
| 1 | /*********************************************************************/ | ||
| 1 | /* keywords */ | 2 | /* keywords */ |
| 2 | DEF(TOK_INT, "int") | 3 | DEF(TOK_INT, "int") |
| 3 | DEF(TOK_VOID, "void") | 4 | DEF(TOK_VOID, "void") |
| @@ -343,8 +344,17 @@ · 339 unmodified lines | |||
| 343 | DEF(TOK_longjmp, "longjmp") | 344 | DEF(TOK_longjmp, "longjmp") |
| 344 | #endif | 345 | #endif |
| 345 | 346 | ||
| 347 | |||
| 348 | /*********************************************************************/ | ||
| 346 | /* Tiny Assembler */ | 349 | /* Tiny Assembler */ |
| 347 | DEF_ASMDIR(byte) /* must be first directive */ | 350 | #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x) |
| 351 | #define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x) | ||
| 352 | #define TOK_ASM_int TOK_INT | ||
| 353 | |||
| 354 | #define TOK_ASMDIR_FIRST TOK_ASMDIR_byte | ||
| 355 | #define TOK_ASMDIR_LAST TOK_ASMDIR_section | ||
| 356 | |||
| 357 | DEF_ASMDIR(byte) /* must be first directive */ | ||
| 348 | DEF_ASMDIR(word) | 358 | DEF_ASMDIR(word) |
| 349 | DEF_ASMDIR(align) | 359 | DEF_ASMDIR(align) |
| 350 | DEF_ASMDIR(balign) | 360 | DEF_ASMDIR(balign) |
| @@ -383,14 +393,16 @@ · 32 unmodified lines | |||
| 383 | DEF_ASMDIR(short) | 393 | DEF_ASMDIR(short) |
| 384 | DEF_ASMDIR(long) | 394 | DEF_ASMDIR(long) |
| 385 | DEF_ASMDIR(int) | 395 | DEF_ASMDIR(int) |
| 386 | DEF_ASMDIR(section) /* must be last directive */ | 396 | DEF_ASMDIR(section) /* must be last directive */ |
| 387 | 397 | ||
| 388 | #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 | 398 | #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 |
| 389 | #include "i386-tok.h" | 399 | #include "i386-tok.h" |
| 390 | #endif | 400 | #endif |
| 401 | |||
| 391 | #if defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64 | 402 | #if defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64 |
| 392 | #include "arm-tok.h" | 403 | #include "arm-tok.h" |
| 393 | #endif | 404 | #endif |
| 405 | |||
| 394 | #if defined TCC_TARGET_RISCV64 | 406 | #if defined TCC_TARGET_RISCV64 |
| 395 | #include "riscv64-tok.h" | 407 | #include "riscv64-tok.h" |
| 396 | #endif | 408 | #endif |
| @@ -385,10 +385,8 @@ usage: · 384 unmodified lines | |||
| 385 | ret = 0; | 385 | ret = 0; |
| 386 | 386 | ||
| 387 | the_end: | 387 | the_end: |
| 388 | /* cannot free memory received from tcc_get_dllexports | 388 | if (p) |
| 389 | if it came from a dll */ | 389 | tcc_free(p); |
| 390 | /* if (p) | ||
| 391 | tcc_free(p); */ | ||
| 392 | if (fp) | 390 | if (fp) |
| 393 | fclose(fp); | 391 | fclose(fp); |
| 394 | if (op) | 392 | if (op) |
| @@ -220,9 +220,10 @@ TF_TYPE(thread_test_complex, vn) · 219 unmodified lines | |||
| 220 | void time_tcc(int n, const char *src) | 220 | void time_tcc(int n, const char *src) |
| 221 | { | 221 | { |
| 222 | TCCState *s; | 222 | TCCState *s; |
| 223 | int ret; | 223 | int ret, i = 0; |
| 224 | while (--n >= 0) { | 224 | while (i++ < n) { |
| 225 | s = new_state(1); | 225 | s = new_state(1); |
| 226 | printf(" %d", i), fflush(stdout); | ||
| 226 | ret = tcc_add_file(s, src); | 227 | ret = tcc_add_file(s, src); |
| 227 | tcc_delete(s); | 228 | tcc_delete(s); |
| 228 | if (ret < 0) | 229 | if (ret < 0) |
| @@ -277,10 +278,10 @@ int main(int argc, char **argv) · 48 unmodified lines | |||
| 277 | printf("\n (%u ms)\n", getclock_ms() - t); | 278 | printf("\n (%u ms)\n", getclock_ms() - t); |
| 278 | #endif | 279 | #endif |
| 279 | #if 1 | 280 | #if 1 |
| 280 | printf("compiling tcc.c 10 times\n"), fflush(stdout); | 281 | printf("compiling tcc.c 10 times\n "), fflush(stdout); |
| 281 | t = getclock_ms(); | 282 | t = getclock_ms(); |
| 282 | time_tcc(10, argv[1]); | 283 | time_tcc(10, argv[1]); |
| 283 | printf(" (%u ms)\n", getclock_ms() - t), fflush(stdout); | 284 | printf("\n (%u ms)\n", getclock_ms() - t), fflush(stdout); |
| 284 | #endif | 285 | #endif |
| 285 | return 0; | 286 | return 0; |
| 286 | } | 287 | } |