History

-bench fix

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)

grischka committed 6 years ago

Commit ff3b5ee1 parent b476a5f8 files · +83 −75Browse files

Showing the changes to libtcc.c (1 of 8 files). Show all

Unified · Split

libtcc.c+15−20
@@ -64,7 +64,9 @@ · 63 unmodified lines
64/* XXX: get rid of this ASAP (or maybe not) */64/* XXX: get rid of this ASAP (or maybe not) */
65ST_DATA struct TCCState *tcc_state;65ST_DATA struct TCCState *tcc_state;
66 66
67#ifdef MEM_DEBUG
67static int nb_states;68static int nb_states;
69#endif
68 70
69/********************************************************/71/********************************************************/
70#ifdef _WIN3272#ifdef _WIN32
@@ -245,10 +247,6 @@ PUB_FUNC char *tcc_strdup(const char *str) · 174 unmodified lines
245 return ptr;247 return ptr;
246}248}
247 249
248PUB_FUNC void tcc_memcheck(void)
249{
250}
251
252#else250#else
253 251
254#define MEM_DEBUG_MAGIC1 0xFEEDDEB1252#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
632ST_FUNC void tcc_close(void)630ST_FUNC void tcc_close(void)
633{631{
632 TCCState *s1 = tcc_state;
634 BufferedFile *bf = file;633 BufferedFile *bf = file;
635 if (bf->fd > 0) {634 if (bf->fd > 0) {
636 close(bf->fd);635 close(bf->fd);
@@ -668,15 +667,10 @@ ST_FUNC int tcc_open(TCCState *s1, const char *filename) · 31 unmodified lines
668/* compile the file opened in 'file'. Return non zero if errors. */667/* compile the file opened in 'file'. Return non zero if errors. */
669static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)668static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
670{669{
671 tccelf_begin_file(s1);
672
673 /* Here we enter the code section where we use the global variables for670 /* Here we enter the code section where we use the global variables for
674 parsing and code generation (tccpp.c, tccgen.c, <target>-gen.c).671 parsing and code generation (tccpp.c, tccgen.c, <target>-gen.c).
675 Other threads need to wait until we're done.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 Alternatively we could use thread local storage for those global674 Alternatively we could use thread local storage for those global
681 variables, which may or may not have advantages */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 is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));694 is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
695 tccelf_begin_file(s1);
701 preprocess_start(s1, is_asm);696 preprocess_start(s1, is_asm);
697 tccgen_init(s1);
702 if (s1->output_type == TCC_OUTPUT_PREPROCESS) {698 if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
703 tcc_preprocess(s1);699 tcc_preprocess(s1);
704 } else if (is_asm) {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 s1->error_set_jmp_enabled = 0;710 s1->error_set_jmp_enabled = 0;
715 tccgen_finish(s1, 1);711 tccgen_finish(s1);
716 preprocess_end(s1);712 preprocess_end(s1);
717 tccgen_finish(s1, 2);713 tccelf_end_file(s1);
718 714
719 tcc_state = NULL;715 tcc_state = NULL;
720 POST_SEM();716 POST_SEM();
721 tccelf_end_file(s1);
722 return s1->nb_errors != 0 ? -1 : 0;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 s = tcc_mallocz(sizeof(TCCState));744 s = tcc_mallocz(sizeof(TCCState));
750 if (!s)745 if (!s)
751 return NULL;746 return NULL;
752 WAIT_SEM();747#ifdef MEM_DEBUG
753 ++nb_states;748 ++nb_states;
754 POST_SEM();749#endif
755 750
756#undef gnu_ext751#undef gnu_ext
757 752
@@ -960,10 +955,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 202 unmodified lines
960#endif955#endif
961 956
962 tcc_free(s1);957 tcc_free(s1);
963 WAIT_SEM();958#ifdef MEM_DEBUG
964 if (0 == --nb_states)959 if (0 == --nb_states)
965 tcc_memcheck();960 tcc_memcheck();
966 POST_SEM();961#endif
967}962}
968 963
969LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)964LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
@@ -1824,7 +1819,7 @@ reparse: · 854 unmodified lines
1824 else if (*optarg == 't')1819 else if (*optarg == 't')
1825 s->dflag = 16;1820 s->dflag = 16;
1826 else if (isnum(*optarg))1821 else if (isnum(*optarg))
1827 g_debug = atoi(optarg);1822 s->g_debug |= atoi(optarg);
1828 else1823 else
1829 goto unsupported_option;1824 goto unsupported_option;
1830 break;1825 break;
@@ -1925,7 +1920,7 @@ reparse: · 94 unmodified lines
1925 tcc_add_sysinclude_path(s, optarg);1920 tcc_add_sysinclude_path(s, optarg);
1926 break;1921 break;
1927 case TCC_OPTION_include: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 break;1924 break;
1930 case TCC_OPTION_nostdinc:1925 case TCC_OPTION_nostdinc:
1931 s->nostdinc = 1;1926 s->nostdinc = 1;
@@ -2077,7 +2072,7 @@ LIBTCCAPI void tcc_set_options(TCCState *s, const char *r) · 145 unmodified lines
2077 dynarray_reset(&argv, &argc);2072 dynarray_reset(&argv, &argc);
2078}2073}
2079 2074
2080PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time)2075PUB_FUNC void tcc_print_stats(TCCState *s1, unsigned total_time)
2081{2076{
2082 if (total_time < 1)2077 if (total_time < 1)
2083 total_time = 1;2078 total_time = 1;
@@ -2085,7 +2080,7 @@ PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time) · 1 unmodified line
2085 total_bytes = 1;2080 total_bytes = 1;
2086 fprintf(stderr, "* %d idents, %d lines, %d bytes\n"2081 fprintf(stderr, "* %d idents, %d lines, %d bytes\n"
2087 "* %0.3f s, %u lines/s, %0.1f MB/s\n",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 (double)total_time/1000,2084 (double)total_time/1000,
2090 (unsigned)total_lines*1000/total_time,2085 (unsigned)total_lines*1000/total_time,
2091 (double)total_bytes/1000/total_time);2086 (double)total_bytes/1000/total_time);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t