History

minor pp optimizations

* remove free_defines() from tcc_preprocess() all cleanup will be done in tcc_delete * move a preprocessor file closing to tcc_delete too

seyko committed 11 years ago

Commit 06e07531 parent 1234bec3 files · +13 −20Browse files

Unified · Split

3 files
  1. libtcc.c +4 −0
  2. tcc.c +9 −17
  3. tccpp.c +0 −3
libtcc.c+4−0
@@ -1217,6 +1217,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 1216 unmodified lines
12171217
12181218 tcc_cleanup();
12191219
1220+ /* close a preprocessor output */
1221+ if (s1->ppfp && s1->ppfp != stdout)
1222+ fclose(s1->ppfp);
1223+
12201224 /* free all sections */
12211225 for(i = 1; i < s1->nb_sections; i++)
12221226 free_section(s1->sections[i]);
tcc.c+9−17
@@ -247,7 +247,6 @@ int main(int argc, char **argv) · 246 unmodified lines
247247 TCCState *s;
248248 int ret, optind, i, bench;
249249 int64_t start_time = 0;
250− const char *first_file = NULL;
251250
252251 s = tcc_new();
253252
@@ -286,7 +285,7 @@ int main(int argc, char **argv) · 32 unmodified lines
286285 tcc_error("cannot specify multiple files with -c and -o");
287286 }
288287 }
289−
288+
290289 if (s->output_type == TCC_OUTPUT_PREPROCESS) {
291290 if (!s->outfile) {
292291 s->ppfp = stdout;
@@ -315,17 +314,16 @@ int main(int argc, char **argv) · 22 unmodified lines
315314 } else {
316315 if (1 == s->verbose)
317316 printf("-> %s\n", filename);
317+ if (!s->outfile)
318+ s->outfile = default_outputfile(s, filename);
318319 if (tcc_add_file(s, filename, filetype) < 0)
319320 ret = 1;
320321 else
321322 if (s->output_type == TCC_OUTPUT_OBJ) {
322− if (!s->outfile)
323− s->outfile = default_outputfile(s, filename);
324323 ret = !!tcc_output_file(s, s->outfile);
324+ if (s->gen_deps && !ret)
325+ gen_makedeps(s, s->outfile, s->deps_outfile);
325326 if (!ret) {
326− /* dump collected dependencies */
327− if (s->gen_deps)
328− gen_makedeps(s, s->outfile, s->deps_outfile);
329327 if ((i+1) < s->nb_files) {
330328 tcc_delete(s);
331329 s = tcc_new();
@@ -337,9 +335,6 @@ int main(int argc, char **argv) · 5 unmodified lines
337335 }
338336 }
339337 }
340− else
341− if (!first_file)
342− first_file = filename;
343338 }
344339 }
345340
@@ -354,14 +349,11 @@ int main(int argc, char **argv) · 8 unmodified lines
354349 tcc_error_noabort("-run is not available in a cross compiler");
355350 ret = 1;
356351 #endif
357− } else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
358− if (s->outfile)
359− fclose(s->ppfp);
360− } else if (s->output_type != TCC_OUTPUT_OBJ) {
361− if (!s->outfile)
362− s->outfile = default_outputfile(s, first_file);
352+ } else
353+ if (s->output_type == TCC_OUTPUT_EXE ||
354+ s->output_type == TCC_OUTPUT_DLL)
355+ {
363356 ret = !!tcc_output_file(s, s->outfile);
364− /* dump collected dependencies */
365357 if (s->gen_deps && !ret)
366358 gen_makedeps(s, s->outfile, s->deps_outfile);
367359 }
tccpp.c+0−3
@@ -3332,12 +3332,10 @@ static void pp_line(TCCState *s1, BufferedFile *f, int level) · 3331 unmodified lines
33323332 /* Preprocess the current file */
33333333 ST_FUNC int tcc_preprocess(TCCState *s1)
33343334 {
3335− Sym *define_start;
33363335 BufferedFile **iptr;
33373336 int token_seen, spcs, level;
33383337
33393338 preprocess_init(s1);
3340− define_start = define_stack;
33413339 ch = file->buf_ptr[0];
33423340 tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
33433341 parse_flags = PARSE_FLAG_PREPROCESS
@@ -3388,6 +3386,5 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 44 unmodified lines
33883386 fputs(get_tok_str(tok, &tokc), s1->ppfp);
33893387 }
33903388
3391− free_defines(define_start);
33923389 return 0;
33933390 }

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