Put total_lines etc. into TCCState. Also, initialize the predefined compiler types for the preprocessor too. tccpe.c: fix BaseOfCode if .init section present (with tcc -b)
Showing the changes to libtcc.c (1 of 8 files). Show all
Unified · Split
| @@ -64,7 +64,9 @@ · 63 unmodified lines | ||
| 64 | 64 | /* XXX: get rid of this ASAP (or maybe not) */ |
| 65 | 65 | ST_DATA struct TCCState *tcc_state; |
| 66 | 66 | |
| 67 | +#ifdef MEM_DEBUG | |
| 67 | 68 | static int nb_states; |
| 69 | +#endif | |
| 68 | 70 | |
| 69 | 71 | /********************************************************/ |
| 70 | 72 | #ifdef _WIN32 |
| @@ -245,10 +247,6 @@ PUB_FUNC char *tcc_strdup(const char *str) · 174 unmodified lines | ||
| 245 | 247 | return ptr; |
| 246 | 248 | } |
| 247 | 249 | |
| 248 | −PUB_FUNC void tcc_memcheck(void) | |
| 249 | −{ | |
| 250 | −} | |
| 251 | − | |
| 252 | 250 | #else |
| 253 | 251 | |
| 254 | 252 | #define MEM_DEBUG_MAGIC1 0xFEEDDEB1 |
| @@ -631,6 +629,7 @@ ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen) · 376 unmodified lines | ||
| 631 | 629 | |
| 632 | 630 | ST_FUNC void tcc_close(void) |
| 633 | 631 | { |
| 632 | + TCCState *s1 = tcc_state; | |
| 634 | 633 | BufferedFile *bf = file; |
| 635 | 634 | if (bf->fd > 0) { |
| 636 | 635 | close(bf->fd); |
| @@ -668,15 +667,10 @@ ST_FUNC int tcc_open(TCCState *s1, const char *filename) · 31 unmodified lines | ||
| 668 | 667 | /* compile the file opened in 'file'. Return non zero if errors. */ |
| 669 | 668 | static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) |
| 670 | 669 | { |
| 671 | − tccelf_begin_file(s1); | |
| 672 | − | |
| 673 | 670 | /* Here we enter the code section where we use the global variables for |
| 674 | 671 | parsing and code generation (tccpp.c, tccgen.c, <target>-gen.c). |
| 675 | 672 | Other threads need to wait until we're done. |
| 676 | 673 | |
| 677 | − Alternatively we could of course pass TCCState *s1 everwhere | |
| 678 | − except that it would look extremly ugly. | |
| 679 | − | |
| 680 | 674 | Alternatively we could use thread local storage for those global |
| 681 | 675 | variables, which may or may not have advantages */ |
| 682 | 676 | |
| @@ -698,7 +692,9 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 15 unmodified lines | ||
| 698 | 692 | } |
| 699 | 693 | |
| 700 | 694 | is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP)); |
| 695 | + tccelf_begin_file(s1); | |
| 701 | 696 | preprocess_start(s1, is_asm); |
| 697 | + tccgen_init(s1); | |
| 702 | 698 | if (s1->output_type == TCC_OUTPUT_PREPROCESS) { |
| 703 | 699 | tcc_preprocess(s1); |
| 704 | 700 | } else if (is_asm) { |
| @@ -712,13 +708,12 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 7 unmodified lines | ||
| 712 | 708 | } |
| 713 | 709 | } |
| 714 | 710 | s1->error_set_jmp_enabled = 0; |
| 715 | − tccgen_finish(s1, 1); | |
| 711 | + tccgen_finish(s1); | |
| 716 | 712 | preprocess_end(s1); |
| 717 | − tccgen_finish(s1, 2); | |
| 713 | + tccelf_end_file(s1); | |
| 718 | 714 | |
| 719 | 715 | tcc_state = NULL; |
| 720 | 716 | POST_SEM(); |
| 721 | − tccelf_end_file(s1); | |
| 722 | 717 | return s1->nb_errors != 0 ? -1 : 0; |
| 723 | 718 | } |
| 724 | 719 | |
| @@ -749,9 +744,9 @@ LIBTCCAPI TCCState *tcc_new(void) · 24 unmodified lines | ||
| 749 | 744 | s = tcc_mallocz(sizeof(TCCState)); |
| 750 | 745 | if (!s) |
| 751 | 746 | return NULL; |
| 752 | − WAIT_SEM(); | |
| 747 | +#ifdef MEM_DEBUG | |
| 753 | 748 | ++nb_states; |
| 754 | − POST_SEM(); | |
| 749 | +#endif | |
| 755 | 750 | |
| 756 | 751 | #undef gnu_ext |
| 757 | 752 | |
| @@ -960,10 +955,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 202 unmodified lines | ||
| 960 | 955 | #endif |
| 961 | 956 | |
| 962 | 957 | tcc_free(s1); |
| 963 | − WAIT_SEM(); | |
| 958 | +#ifdef MEM_DEBUG | |
| 964 | 959 | if (0 == --nb_states) |
| 965 | 960 | tcc_memcheck(); |
| 966 | − POST_SEM(); | |
| 961 | +#endif | |
| 967 | 962 | } |
| 968 | 963 | |
| 969 | 964 | LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) |
| @@ -1824,7 +1819,7 @@ reparse: · 854 unmodified lines | ||
| 1824 | 1819 | else if (*optarg == 't') |
| 1825 | 1820 | s->dflag = 16; |
| 1826 | 1821 | else if (isnum(*optarg)) |
| 1827 | − g_debug = atoi(optarg); | |
| 1822 | + s->g_debug |= atoi(optarg); | |
| 1828 | 1823 | else |
| 1829 | 1824 | goto unsupported_option; |
| 1830 | 1825 | break; |
| @@ -1925,7 +1920,7 @@ reparse: · 94 unmodified lines | ||
| 1925 | 1920 | tcc_add_sysinclude_path(s, optarg); |
| 1926 | 1921 | break; |
| 1927 | 1922 | case TCC_OPTION_include: |
| 1928 | − cstr_printf(&s->cmdline_defs, "#include \"%s\"\n", optarg); | |
| 1923 | + cstr_printf(&s->cmdline_incl, "#include \"%s\"\n", optarg); | |
| 1929 | 1924 | break; |
| 1930 | 1925 | case TCC_OPTION_nostdinc: |
| 1931 | 1926 | s->nostdinc = 1; |
| @@ -2077,7 +2072,7 @@ LIBTCCAPI void tcc_set_options(TCCState *s, const char *r) · 145 unmodified lines | ||
| 2077 | 2072 | dynarray_reset(&argv, &argc); |
| 2078 | 2073 | } |
| 2079 | 2074 | |
| 2080 | −PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time) | |
| 2075 | +PUB_FUNC void tcc_print_stats(TCCState *s1, unsigned total_time) | |
| 2081 | 2076 | { |
| 2082 | 2077 | if (total_time < 1) |
| 2083 | 2078 | total_time = 1; |
| @@ -2085,7 +2080,7 @@ PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time) · 1 unmodified line | ||
| 2085 | 2080 | total_bytes = 1; |
| 2086 | 2081 | fprintf(stderr, "* %d idents, %d lines, %d bytes\n" |
| 2087 | 2082 | "* %0.3f s, %u lines/s, %0.1f MB/s\n", |
| 2088 | − tok_ident - TOK_IDENT, total_lines, total_bytes, | |
| 2083 | + total_idents, total_lines, total_bytes, | |
| 2089 | 2084 | (double)total_time/1000, |
| 2090 | 2085 | (unsigned)total_lines*1000/total_time, |
| 2091 | 2086 | (double)total_bytes/1000/total_time); |