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
1217 1217
1218 tcc_cleanup();1218 tcc_cleanup();
1219 1219
1220 /* close a preprocessor output */
1221 if (s1->ppfp && s1->ppfp != stdout)
1222 fclose(s1->ppfp);
1223
1220 /* free all sections */1224 /* free all sections */
1221 for(i = 1; i < s1->nb_sections; i++)1225 for(i = 1; i < s1->nb_sections; i++)
1222 free_section(s1->sections[i]);1226 free_section(s1->sections[i]);
tcc.c+9−17
@@ -247,7 +247,6 @@ int main(int argc, char **argv) · 246 unmodified lines
247 TCCState *s;247 TCCState *s;
248 int ret, optind, i, bench;248 int ret, optind, i, bench;
249 int64_t start_time = 0;249 int64_t start_time = 0;
250 const char *first_file = NULL;
251 250
252 s = tcc_new();251 s = tcc_new();
253 252
@@ -286,7 +285,7 @@ int main(int argc, char **argv) · 32 unmodified lines
286 tcc_error("cannot specify multiple files with -c and -o");285 tcc_error("cannot specify multiple files with -c and -o");
287 }286 }
288 }287 }
289 288
290 if (s->output_type == TCC_OUTPUT_PREPROCESS) {289 if (s->output_type == TCC_OUTPUT_PREPROCESS) {
291 if (!s->outfile) {290 if (!s->outfile) {
292 s->ppfp = stdout;291 s->ppfp = stdout;
@@ -315,17 +314,16 @@ int main(int argc, char **argv) · 22 unmodified lines
315 } else {314 } else {
316 if (1 == s->verbose)315 if (1 == s->verbose)
317 printf("-> %s\n", filename);316 printf("-> %s\n", filename);
317 if (!s->outfile)
318 s->outfile = default_outputfile(s, filename);
318 if (tcc_add_file(s, filename, filetype) < 0)319 if (tcc_add_file(s, filename, filetype) < 0)
319 ret = 1;320 ret = 1;
320 else321 else
321 if (s->output_type == TCC_OUTPUT_OBJ) {322 if (s->output_type == TCC_OUTPUT_OBJ) {
322 if (!s->outfile)
323 s->outfile = default_outputfile(s, filename);
324 ret = !!tcc_output_file(s, s->outfile);323 ret = !!tcc_output_file(s, s->outfile);
324 if (s->gen_deps && !ret)
325 gen_makedeps(s, s->outfile, s->deps_outfile);
325 if (!ret) {326 if (!ret) {
326 /* dump collected dependencies */
327 if (s->gen_deps)
328 gen_makedeps(s, s->outfile, s->deps_outfile);
329 if ((i+1) < s->nb_files) {327 if ((i+1) < s->nb_files) {
330 tcc_delete(s);328 tcc_delete(s);
331 s = tcc_new();329 s = tcc_new();
@@ -337,9 +335,6 @@ int main(int argc, char **argv) · 5 unmodified lines
337 }335 }
338 }336 }
339 }337 }
340 else
341 if (!first_file)
342 first_file = filename;
343 }338 }
344 }339 }
345 340
@@ -354,14 +349,11 @@ int main(int argc, char **argv) · 8 unmodified lines
354 tcc_error_noabort("-run is not available in a cross compiler");349 tcc_error_noabort("-run is not available in a cross compiler");
355 ret = 1;350 ret = 1;
356#endif351#endif
357 } else if (s->output_type == TCC_OUTPUT_PREPROCESS) {352 } else
358 if (s->outfile)353 if (s->output_type == TCC_OUTPUT_EXE ||
359 fclose(s->ppfp);354 s->output_type == TCC_OUTPUT_DLL)
360 } else if (s->output_type != TCC_OUTPUT_OBJ) {355 {
361 if (!s->outfile)
362 s->outfile = default_outputfile(s, first_file);
363 ret = !!tcc_output_file(s, s->outfile);356 ret = !!tcc_output_file(s, s->outfile);
364 /* dump collected dependencies */
365 if (s->gen_deps && !ret)357 if (s->gen_deps && !ret)
366 gen_makedeps(s, s->outfile, s->deps_outfile);358 gen_makedeps(s, s->outfile, s->deps_outfile);
367 }359 }
tccpp.c+0−3
@@ -3332,12 +3332,10 @@ static void pp_line(TCCState *s1, BufferedFile *f, int level) · 3331 unmodified lines
3332/* Preprocess the current file */3332/* Preprocess the current file */
3333ST_FUNC int tcc_preprocess(TCCState *s1)3333ST_FUNC int tcc_preprocess(TCCState *s1)
3334{3334{
3335 Sym *define_start;
3336 BufferedFile **iptr;3335 BufferedFile **iptr;
3337 int token_seen, spcs, level;3336 int token_seen, spcs, level;
3338 3337
3339 preprocess_init(s1);3338 preprocess_init(s1);
3340 define_start = define_stack;
3341 ch = file->buf_ptr[0];3339 ch = file->buf_ptr[0];
3342 tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;3340 tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
3343 parse_flags = PARSE_FLAG_PREPROCESS3341 parse_flags = PARSE_FLAG_PREPROCESS
@@ -3388,6 +3386,5 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 44 unmodified lines
3388 fputs(get_tok_str(tok, &tokc), s1->ppfp);3386 fputs(get_tok_str(tok, &tokc), s1->ppfp);
3389 }3387 }
3390 3388
3391 free_defines(define_start);
3392 return 0;3389 return 0;
3393}3390}

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