Unified · Split
| @@ -17,7 +17,12 @@ · 16 unmodified lines | |||
| 17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ | 19 | */ |
| 20 | #include <tcclib.h> | 20 | #include <stdlib.h> |
| 21 | #include <stdio.h> | ||
| 22 | #include <string.h> | ||
| 23 | #ifndef CONFIG_TCC_STATIC | ||
| 24 | #include <dlfcn.h> | ||
| 25 | #endif | ||
| 21 | 26 | ||
| 22 | //#define DEBUG | 27 | //#define DEBUG |
| 23 | /* preprocessor debug */ | 28 | /* preprocessor debug */ |
| @@ -103,6 +108,10 @@ typedef struct { · 79 unmodified lines | |||
| 103 | int line_num; | 108 | int line_num; |
| 104 | } IncludeFile; | 109 | } IncludeFile; |
| 105 | 110 | ||
| 111 | /* parser */ | ||
| 112 | FILE *file; | ||
| 113 | int ch, ch1, tok, tokc, tok1, tok1c; | ||
| 114 | |||
| 106 | /* loc : local variable index | 115 | /* loc : local variable index |
| 107 | glo : global variable index | 116 | glo : global variable index |
| 108 | ind : output code ptr | 117 | ind : output code ptr |
| @@ -110,8 +119,7 @@ typedef struct { · 1 unmodified line | |||
| 110 | prog: output code | 119 | prog: output code |
| 111 | anon_sym: anonymous symbol index | 120 | anon_sym: anonymous symbol index |
| 112 | */ | 121 | */ |
| 113 | FILE *file; | 122 | int rsym, anon_sym, |
| 114 | int tok, tokc, tok1, tok1c, rsym, anon_sym, | ||
| 115 | prog, ind, loc, glo, vt, vc, const_wanted, line_num; | 123 | prog, ind, loc, glo, vt, vc, const_wanted, line_num; |
| 116 | int global_expr; /* true if compound literals must be allocated | 124 | int global_expr; /* true if compound literals must be allocated |
| 117 | globally (used during initializers parsing */ | 125 | globally (used during initializers parsing */ |
| @@ -309,20 +317,49 @@ int pointed_size(int t); · 191 unmodified lines | |||
| 309 | int ist(void); | 317 | int ist(void); |
| 310 | int type_decl(int *v, int t, int td); | 318 | int type_decl(int *v, int t, int td); |
| 311 | 319 | ||
| 312 | #ifdef PROFILE | 320 | #ifdef CONFIG_TCC_STATIC |
| 321 | |||
| 322 | #define RTLD_LAZY 0x001 | ||
| 323 | #define RTLD_NOW 0x002 | ||
| 324 | #define RTLD_GLOBAL 0x100 | ||
| 325 | |||
| 313 | /* dummy function for profiling */ | 326 | /* dummy function for profiling */ |
| 314 | void *dlopen(const char *filename, int flag) | 327 | void *dlopen(const char *filename, int flag) |
| 315 | { | 328 | { |
| 316 | return (void *)1; | 329 | return NULL; |
| 317 | } | 330 | } |
| 331 | |||
| 318 | const char *dlerror(void) | 332 | const char *dlerror(void) |
| 319 | { | 333 | { |
| 320 | return "error"; | 334 | return "error"; |
| 321 | } | 335 | } |
| 322 | 336 | ||
| 337 | typedef struct TCCSyms { | ||
| 338 | char *str; | ||
| 339 | void *ptr; | ||
| 340 | } TCCSyms; | ||
| 341 | |||
| 342 | #define TCCSYM(a) { #a, &a, }, | ||
| 343 | |||
| 344 | /* add the symbol you want here if no dynamic linking is done */ | ||
| 345 | static TCCSyms tcc_syms[] = { | ||
| 346 | TCCSYM(printf) | ||
| 347 | TCCSYM(fprintf) | ||
| 348 | TCCSYM(fopen) | ||
| 349 | TCCSYM(fclose) | ||
| 350 | { NULL, NULL }, | ||
| 351 | }; | ||
| 352 | |||
| 323 | void *dlsym(void *handle, char *symbol) | 353 | void *dlsym(void *handle, char *symbol) |
| 324 | { | 354 | { |
| 325 | return (void *)1; | 355 | TCCSyms *p; |
| 356 | p = tcc_syms; | ||
| 357 | while (p->str != NULL) { | ||
| 358 | if (!strcmp(p->str, symbol)) | ||
| 359 | return p->ptr; | ||
| 360 | p++; | ||
| 361 | } | ||
| 362 | return NULL; | ||
| 326 | } | 363 | } |
| 327 | 364 | ||
| 328 | #endif | 365 | #endif |
| @@ -576,13 +613,12 @@ void sym_pop(SymStack *st, Sym *b) · 247 unmodified lines | |||
| 576 | st->top = b; | 613 | st->top = b; |
| 577 | } | 614 | } |
| 578 | 615 | ||
| 579 | int ch, ch1; | ||
| 580 | |||
| 581 | /* read next char from current input file */ | 616 | /* read next char from current input file */ |
| 582 | void inp() | 617 | void inp(void) |
| 583 | { | 618 | { |
| 584 | redo: | 619 | redo: |
| 585 | ch1 = fgetc(file); | 620 | /* faster than fgetc */ |
| 621 | ch1 = getc_unlocked(file); | ||
| 586 | if (ch1 == -1) { | 622 | if (ch1 == -1) { |
| 587 | if (include_stack_ptr == include_stack) | 623 | if (include_stack_ptr == include_stack) |
| 588 | return; | 624 | return; |
| @@ -3887,10 +3923,6 @@ int main(int argc, char **argv) · 3298 unmodified lines | |||
| 3887 | if (!s) | 3923 | if (!s) |
| 3888 | error("main() not defined"); | 3924 | error("main() not defined"); |
| 3889 | t = (int (*)())s->c; | 3925 | t = (int (*)())s->c; |
| 3890 | #ifdef PROFILE | ||
| 3891 | return 1; | ||
| 3892 | #else | ||
| 3893 | return (*t)(argc - optind, argv + optind); | 3926 | return (*t)(argc - optind, argv + optind); |
| 3894 | #endif | ||
| 3895 | } | 3927 | } |
| 3896 | } | 3928 | } |