History

Merge branch 'kirr/tcc-MD' into mob

Hello up there. I'm trying to change gcc to tcc for faster develpment on slow machines, and the first obstacle that turned out was lack of dependency generation on tcc side. Attached patches try to fix that. Thanks, Kirill * tcc-MD: .gitignore += tags tcc: Explicitly require -l<lib> for libraries Document what tcc_fileextension does tcc -E: Let output_default be <file>.o instead of a.out tcc: Draft suppoprt for -MD/-MF options tcc: Refactor "compute default outfile name" into libtcc function Add input files/libs and reloc_output switch to TCCState tcc: Fix typo in error (it's '%s', not '%s) chmod a-x i386-gen.c .gitignore += *.o *.a .cvsignore -> .gitignore

Kirill Smelkov committed 16 years ago

Commit 9775aea2 parents 3ba37e1 2fe52109 files · +150 −34Browse files

Unified · Split

9 files
  1. .gitignore +4 −1
  2. Changelog +4 −0
  3. TODO +0 −1
  4. i386-gen.c +0 −0
  5. libtcc.c +81 −0
  6. libtcc.h +14 −0
  7. tcc.c +32 −31
  8. tcc.h +12 −1
  9. tccpp.c +3 −0
.gitignorerenamed from .cvsignore+4−1
@@ -1,3 +1,5 @@
1*.o
2*.a
1tcc_g3tcc_g
2tcc4tcc
3tc2.c5tc2.c
@@ -34,4 +36,5 @@ tcc.pod · 30 unmodified lines
34config.h36config.h
35config.mak37config.mak
36config.texi38config.texi
37tests39tests
40tags
Changelog+4−0
@@ -1,3 +1,7 @@
1not released:
2
3- Add support for -MD/-MF (automatically generate dependencies for make)
4
1version 0.9.25:5version 0.9.25:
2 6
3- first support for x86-64 target (Shinichiro Hamaji)7- first support for x86-64 target (Shinichiro Hamaji)
TODO+0−1
@@ -46,7 +46,6 @@ Missing features: · 45 unmodified lines
46- disable-asm and disable-bcheck options46- disable-asm and disable-bcheck options
47- __builtin_expect()47- __builtin_expect()
48- improve '-E' option.48- improve '-E' option.
49- add '-MD' option
50- atexit (Nigel Horne)49- atexit (Nigel Horne)
51- packed attribute50- packed attribute
52- C99: add variable size arrays (gcc 3.2 testsuite issue)51- C99: add variable size arrays (gcc 3.2 testsuite issue)
i386-gen.c+0−0

File mode changed from 100755 to 100644.

libtcc.c+81−0
@@ -168,6 +168,10 @@ PUB_FUNC char *tcc_basename(const char *name) · 167 unmodified lines
168 return p;168 return p;
169}169}
170 170
171/* extract extension part of a file
172 *
173 * (if no extension, return pointer to end-of-string)
174 */
171PUB_FUNC char *tcc_fileextension (const char *name)175PUB_FUNC char *tcc_fileextension (const char *name)
172{176{
173 char *b = tcc_basename(name);177 char *b = tcc_basename(name);
@@ -1038,6 +1042,11 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 864 unmodified lines
1038 dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);1042 dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
1039 1043
1040 tcc_free(s1->tcc_lib_path);1044 tcc_free(s1->tcc_lib_path);
1045
1046 dynarray_reset(&s1->input_files, &s1->nb_input_files);
1047 dynarray_reset(&s1->input_libs, &s1->nb_input_libs);
1048 dynarray_reset(&s1->target_deps, &s1->nb_target_deps);
1049
1041#ifdef HAVE_SELINUX1050#ifdef HAVE_SELINUX
1042 munmap (s1->write_mem, s1->mem_size);1051 munmap (s1->write_mem, s1->mem_size);
1043 munmap (s1->runtime_mem, s1->mem_size); 1052 munmap (s1->runtime_mem, s1->mem_size);
@@ -1088,6 +1097,10 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 44 unmodified lines
1088 goto the_end;1097 goto the_end;
1089 }1098 }
1090 1099
1100 /* update target deps */
1101 dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps,
1102 tcc_strdup(filename));
1103
1091 if (flags & AFF_PREPROCESS) {1104 if (flags & AFF_PREPROCESS) {
1092 ret = tcc_preprocess(s1);1105 ret = tcc_preprocess(s1);
1093 goto the_end;1106 goto the_end;
@@ -1184,6 +1197,8 @@ the_end: · 90 unmodified lines
1184 1197
1185LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)1198LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
1186{1199{
1200 dynarray_add((void ***)&s->input_files, &s->nb_input_files, tcc_strdup(filename));
1201
1187 if (s->output_type == TCC_OUTPUT_PREPROCESS)1202 if (s->output_type == TCC_OUTPUT_PREPROCESS)
1188 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);1203 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);
1189 else1204 else
@@ -1220,6 +1235,8 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) · 30 unmodified lines
1220{1235{
1221 char buf[1024];1236 char buf[1024];
1222 int i;1237 int i;
1238
1239 dynarray_add((void ***)&s->input_libs, &s->nb_input_libs, tcc_strdup(libraryname));
1223 1240
1224 /* first we look for the dynamic library if not static linking */1241 /* first we look for the dynamic library if not static linking */
1225 if (!s->static_link) {1242 if (!s->static_link) {
@@ -1549,3 +1566,67 @@ PUB_FUNC void set_num_callers(int n) · 323 unmodified lines
1549 num_callers = n;1566 num_callers = n;
1550#endif1567#endif
1551}1568}
1569
1570
1571LIBTCCAPI const char *tcc_default_target(TCCState *s)
1572{
1573 /* FIXME will break in multithreaded case */
1574 static char outfile_default[1024];
1575
1576 char *ext;
1577 const char *name =
1578 strcmp(s->input_files[0], "-") == 0 ? "a"
1579 : tcc_basename(s->input_files[0]);
1580 pstrcpy(outfile_default, sizeof(outfile_default), name);
1581 ext = tcc_fileextension(outfile_default);
1582#ifdef TCC_TARGET_PE
1583 if (s->output_type == TCC_OUTPUT_DLL)
1584 strcpy(ext, ".dll");
1585 else
1586 if (s->output_type == TCC_OUTPUT_EXE)
1587 strcpy(ext, ".exe");
1588 else
1589#endif
1590 if (( (s->output_type == TCC_OUTPUT_OBJ && !s->reloc_output) ||
1591 (s->output_type == TCC_OUTPUT_PREPROCESS) )
1592 && *ext)
1593 strcpy(ext, ".o");
1594 else
1595 pstrcpy(outfile_default, sizeof(outfile_default), "a.out");
1596
1597 return outfile_default;
1598}
1599
1600
1601LIBTCCAPI void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename)
1602{
1603 FILE *depout;
1604 char buf[1024], *ext;
1605 int i;
1606
1607 if (!target)
1608 target = tcc_default_target(s);
1609
1610 if (!filename) {
1611 /* compute filename automatically
1612 * dir/file.o -> dir/file.d */
1613 pstrcpy(buf, sizeof(buf), target);
1614 ext = tcc_fileextension(buf);
1615 pstrcpy(ext, sizeof(buf) - (ext-buf), ".d");
1616 filename = buf;
1617 }
1618
1619 if (s->verbose)
1620 printf("<- %s\n", filename);
1621
1622 /* XXX return err codes instead of error() ? */
1623 depout = fopen(filename, "w");
1624 if (!depout)
1625 error("could not open '%s'", filename);
1626
1627 fprintf(depout, "%s : \\\n", target);
1628 for (i=0; i<s->nb_target_deps; ++i)
1629 fprintf(depout, "\t%s \\\n", s->target_deps[i]);
1630 fprintf(depout, "\n");
1631 fclose(depout);
1632}
libtcc.h+14−0
@@ -103,6 +103,20 @@ LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name); · 102 unmodified lines
103/* set CONFIG_TCCDIR at runtime */103/* set CONFIG_TCCDIR at runtime */
104LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);104LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
105 105
106
107/*****************************/
108/* Miscellaneous */
109
110/* Get default target filename for this compilation */
111LIBTCCAPI const char *tcc_default_target(TCCState *s);
112
113/* Generate make dependencies for target and store them into file
114 *
115 * !target - use default target name
116 * !filename - use (target.o -> target.d)
117 */
118LIBTCCAPI void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename);
119
106#ifdef __cplusplus120#ifdef __cplusplus
107}121}
108#endif122#endif
tcc.c+32−31
@@ -32,6 +32,8 @@ static int output_type; · 31 unmodified lines
32static int reloc_output;32static int reloc_output;
33static const char *outfile;33static const char *outfile;
34static int do_bench = 0;34static int do_bench = 0;
35static int gen_deps;
36static const char *deps_outfile;
35 37
36#define TCC_OPTION_HAS_ARG 0x000138#define TCC_OPTION_HAS_ARG 0x0001
37#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */39#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */
@@ -74,6 +76,9 @@ static void help(void) · 36 unmodified lines
74#ifdef CONFIG_TCC_BACKTRACE76#ifdef CONFIG_TCC_BACKTRACE
75 " -bt N show N callers in stack traces\n"77 " -bt N show N callers in stack traces\n"
76#endif78#endif
79 "Misc options:\n"
80 " -MD generate target dependencies for make\n"
81 " -MF depfile put generated dependencies here\n"
77 );82 );
78}83}
79 84
@@ -115,6 +120,8 @@ enum { · 35 unmodified lines
115 TCC_OPTION_w,120 TCC_OPTION_w,
116 TCC_OPTION_pipe,121 TCC_OPTION_pipe,
117 TCC_OPTION_E,122 TCC_OPTION_E,
123 TCC_OPTION_MD,
124 TCC_OPTION_MF,
118 TCC_OPTION_x,125 TCC_OPTION_x,
119};126};
120 127
@@ -154,6 +161,8 @@ static const TCCOption tcc_options[] = { · 33 unmodified lines
154 { "w", TCC_OPTION_w, 0 },161 { "w", TCC_OPTION_w, 0 },
155 { "pipe", TCC_OPTION_pipe, 0},162 { "pipe", TCC_OPTION_pipe, 0},
156 { "E", TCC_OPTION_E, 0},163 { "E", TCC_OPTION_E, 0},
164 { "MD", TCC_OPTION_MD, 0},
165 { "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG },
157 { "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG },166 { "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG },
158 { NULL },167 { NULL },
159};168};
@@ -374,6 +383,12 @@ static int parse_args(TCCState *s, int argc, char **argv) · 214 unmodified lines
374 case TCC_OPTION_E:383 case TCC_OPTION_E:
375 output_type = TCC_OUTPUT_PREPROCESS;384 output_type = TCC_OUTPUT_PREPROCESS;
376 break;385 break;
386 case TCC_OPTION_MD:
387 gen_deps = 1;
388 break;
389 case TCC_OPTION_MF:
390 deps_outfile = optarg;
391 break;
377 case TCC_OPTION_x:392 case TCC_OPTION_x:
378 break;393 break;
379 default:394 default:
@@ -393,7 +408,6 @@ int main(int argc, char **argv) · 13 unmodified lines
393 int i;408 int i;
394 TCCState *s;409 TCCState *s;
395 int nb_objfiles, ret, optind;410 int nb_objfiles, ret, optind;
396 char objfilename[1024];
397 int64_t start_time = 0;411 int64_t start_time = 0;
398 412
399 s = tcc_new();413 s = tcc_new();
@@ -444,29 +458,7 @@ int main(int argc, char **argv) · 44 unmodified lines
444 } else {458 } else {
445 s->outfile = fopen(outfile, "w");459 s->outfile = fopen(outfile, "w");
446 if (!s->outfile)460 if (!s->outfile)
447 error("could not open '%s", outfile);461 error("could not open '%s'", outfile);
448 }
449 } else if (output_type != TCC_OUTPUT_MEMORY) {
450 if (!outfile) {
451 /* compute default outfile name */
452 char *ext;
453 const char *name =
454 strcmp(files[0], "-") == 0 ? "a" : tcc_basename(files[0]);
455 pstrcpy(objfilename, sizeof(objfilename), name);
456 ext = tcc_fileextension(objfilename);
457#ifdef TCC_TARGET_PE
458 if (output_type == TCC_OUTPUT_DLL)
459 strcpy(ext, ".dll");
460 else
461 if (output_type == TCC_OUTPUT_EXE)
462 strcpy(ext, ".exe");
463 else
464#endif
465 if (output_type == TCC_OUTPUT_OBJ && !reloc_output && *ext)
466 strcpy(ext, ".o");
467 else
468 pstrcpy(objfilename, sizeof(objfilename), "a.out");
469 outfile = objfilename;
470 }462 }
471 }463 }
472 464
@@ -475,13 +467,14 @@ int main(int argc, char **argv) · 2 unmodified lines
475 }467 }
476 468
477 tcc_set_output_type(s, output_type);469 tcc_set_output_type(s, output_type);
470 s->reloc_output = reloc_output;
478 471
479 /* compile or add each files or library */472 /* compile or add each files or library */
480 for(i = 0; i < nb_files && ret == 0; i++) {473 for(i = 0; i < nb_files && ret == 0; i++) {
481 const char *filename;474 const char *filename;
482 475
483 filename = files[i];476 filename = files[i];
484 if (filename[0] == '-' && filename[1]) {477 if (filename[0] == '-' && filename[1] == 'l') {
485 if (tcc_add_library(s, filename + 2) < 0) {478 if (tcc_add_library(s, filename + 2) < 0) {
486 error_noabort("cannot find %s", filename);479 error_noabort("cannot find %s", filename);
487 ret = 1;480 ret = 1;
@@ -501,13 +494,21 @@ int main(int argc, char **argv) · 13 unmodified lines
501 if (do_bench)494 if (do_bench)
502 tcc_print_stats(s, getclock_us() - start_time);495 tcc_print_stats(s, getclock_us() - start_time);
503 496
504 if (s->output_type == TCC_OUTPUT_PREPROCESS) {497 if (s->output_type == TCC_OUTPUT_MEMORY)
505 if (outfile)
506 fclose(s->outfile);
507 } else if (s->output_type == TCC_OUTPUT_MEMORY)
508 ret = tcc_run(s, argc - optind, argv + optind);498 ret = tcc_run(s, argc - optind, argv + optind);
509 else499 else {
510 ret = tcc_output_file(s, outfile) ? 1 : 0;500 if (s->output_type == TCC_OUTPUT_PREPROCESS) {
501 if (outfile)
502 fclose(s->outfile);
503 } else {
504 ret = tcc_output_file(s, outfile ? outfile : tcc_default_target(s));
505 ret = ret ? 1 : 0;
506 }
507
508 /* dump collected dependencies */
509 if (gen_deps && !ret)
510 tcc_gen_makedeps(s, outfile, deps_outfile);
511 }
511 }512 }
512 513
513 tcc_delete(s);514 tcc_delete(s);
tcc.h+12−1
@@ -397,7 +397,8 @@ typedef struct ASMOperand { · 396 unmodified lines
397#endif397#endif
398 398
399struct TCCState {399struct TCCState {
400 int output_type;400 unsigned output_type : 8;
401 unsigned reloc_output : 1;
401 402
402 BufferedFile **include_stack_ptr;403 BufferedFile **include_stack_ptr;
403 int *ifdef_stack_ptr;404 int *ifdef_stack_ptr;
@@ -518,6 +519,16 @@ struct TCCState { · 114 unmodified lines
518 /* output file for preprocessing */519 /* output file for preprocessing */
519 FILE *outfile;520 FILE *outfile;
520 521
522 /* input files and libraries for this compilation */
523 char **input_files;
524 int nb_input_files;
525 char **input_libs;
526 int nb_input_libs;
527
528 /* automatically collected dependencies for this compilation */
529 char **target_deps;
530 int nb_target_deps;
531
521 /* for tcc_relocate */532 /* for tcc_relocate */
522 int runtime_added;533 int runtime_added;
523 void *runtime_mem;534 void *runtime_mem;
tccpp.c+3−0
@@ -1491,6 +1491,9 @@ ST_FUNC void preprocess(int is_bof) · 1490 unmodified lines
1491#ifdef INC_DEBUG1491#ifdef INC_DEBUG
1492 printf("%s: including %s\n", file->filename, buf1);1492 printf("%s: including %s\n", file->filename, buf1);
1493#endif1493#endif
1494 /* update target deps */
1495 dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps,
1496 tcc_strdup(buf1));
1494 1497
1495 /* XXX: fix current line init */1498 /* XXX: fix current line init */
1496 /* push current file in stack */1499 /* push current file in stack */

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