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
6464 /* XXX: get rid of this ASAP (or maybe not) */
6565 ST_DATA struct TCCState *tcc_state;
6666
67+#ifdef MEM_DEBUG
6768 static int nb_states;
69+#endif
6870
6971 /********************************************************/
7072 #ifdef _WIN32
@@ -245,10 +247,6 @@ PUB_FUNC char *tcc_strdup(const char *str) · 174 unmodified lines
245247 return ptr;
246248 }
247249
248−PUB_FUNC void tcc_memcheck(void)
249−{
250−}
251−
252250 #else
253251
254252 #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
631629
632630 ST_FUNC void tcc_close(void)
633631 {
632+ TCCState *s1 = tcc_state;
634633 BufferedFile *bf = file;
635634 if (bf->fd > 0) {
636635 close(bf->fd);
@@ -668,15 +667,10 @@ ST_FUNC int tcc_open(TCCState *s1, const char *filename) · 31 unmodified lines
668667 /* compile the file opened in 'file'. Return non zero if errors. */
669668 static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
670669 {
671− tccelf_begin_file(s1);
672−
673670 /* Here we enter the code section where we use the global variables for
674671 parsing and code generation (tccpp.c, tccgen.c, <target>-gen.c).
675672 Other threads need to wait until we're done.
676673
677− Alternatively we could of course pass TCCState *s1 everwhere
678− except that it would look extremly ugly.
679−
680674 Alternatively we could use thread local storage for those global
681675 variables, which may or may not have advantages */
682676
@@ -698,7 +692,9 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 15 unmodified lines
698692 }
699693
700694 is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
695+ tccelf_begin_file(s1);
701696 preprocess_start(s1, is_asm);
697+ tccgen_init(s1);
702698 if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
703699 tcc_preprocess(s1);
704700 } else if (is_asm) {
@@ -712,13 +708,12 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 7 unmodified lines
712708 }
713709 }
714710 s1->error_set_jmp_enabled = 0;
715− tccgen_finish(s1, 1);
711+ tccgen_finish(s1);
716712 preprocess_end(s1);
717− tccgen_finish(s1, 2);
713+ tccelf_end_file(s1);
718714
719715 tcc_state = NULL;
720716 POST_SEM();
721− tccelf_end_file(s1);
722717 return s1->nb_errors != 0 ? -1 : 0;
723718 }
724719
@@ -749,9 +744,9 @@ LIBTCCAPI TCCState *tcc_new(void) · 24 unmodified lines
749744 s = tcc_mallocz(sizeof(TCCState));
750745 if (!s)
751746 return NULL;
752− WAIT_SEM();
747+#ifdef MEM_DEBUG
753748 ++nb_states;
754− POST_SEM();
749+#endif
755750
756751 #undef gnu_ext
757752
@@ -960,10 +955,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 202 unmodified lines
960955 #endif
961956
962957 tcc_free(s1);
963− WAIT_SEM();
958+#ifdef MEM_DEBUG
964959 if (0 == --nb_states)
965960 tcc_memcheck();
966− POST_SEM();
961+#endif
967962 }
968963
969964 LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
@@ -1824,7 +1819,7 @@ reparse: · 854 unmodified lines
18241819 else if (*optarg == 't')
18251820 s->dflag = 16;
18261821 else if (isnum(*optarg))
1827− g_debug = atoi(optarg);
1822+ s->g_debug |= atoi(optarg);
18281823 else
18291824 goto unsupported_option;
18301825 break;
@@ -1925,7 +1920,7 @@ reparse: · 94 unmodified lines
19251920 tcc_add_sysinclude_path(s, optarg);
19261921 break;
19271922 case TCC_OPTION_include:
1928− cstr_printf(&s->cmdline_defs, "#include \"%s\"\n", optarg);
1923+ cstr_printf(&s->cmdline_incl, "#include \"%s\"\n", optarg);
19291924 break;
19301925 case TCC_OPTION_nostdinc:
19311926 s->nostdinc = 1;
@@ -2077,7 +2072,7 @@ LIBTCCAPI void tcc_set_options(TCCState *s, const char *r) · 145 unmodified lines
20772072 dynarray_reset(&argv, &argc);
20782073 }
20792074
2080−PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time)
2075+PUB_FUNC void tcc_print_stats(TCCState *s1, unsigned total_time)
20812076 {
20822077 if (total_time < 1)
20832078 total_time = 1;
@@ -2085,7 +2080,7 @@ PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time) · 1 unmodified line
20852080 total_bytes = 1;
20862081 fprintf(stderr, "* %d idents, %d lines, %d bytes\n"
20872082 "* %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,
20892084 (double)total_time/1000,
20902085 (unsigned)total_lines*1000/total_time,
20912086 (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