History

tcc -MD: drop system includes and duplicates

grischka committed 6 years ago

Commit cbef5461 parent e7a41406 files · +51 −38Browse files

Unified · Split

6 files
  1. libtcc.c +24 −25
  2. tcc.h +3 −0
  3. tccelf.c +1 −1
  4. tccpe.c +1 −1
  5. tccpp.c +13 −6
  6. tcctools.c +9 −5
libtcc.c+24−25
@@ -508,15 +508,13 @@ static void error1(int mode, const char *fmt, va_list ap) · 507 unmodified lines
508508 BufferedFile **pf, *f;
509509 TCCState *s1 = tcc_state;
510510
511− /* 's1->error_set_jmp_enabled' means that we're called from
512− within the parser/generator and 'tcc_state' was already
513− set (i.e. not by the function above).
514−
515− Otherwise, 's1 = NULL' means we're called because of severe
516− problems from tcc_malloc() which under normal conditions
517− should never happen. */
511+ buf[0] = '\0';
512+ if (s1 == NULL)
513+ /* can happen only if called from tcc_malloc(): 'out of memory' */
514+ goto no_file;
518515
519− if (s1 && !s1->error_set_jmp_enabled) {
516+ if (!s1->error_set_jmp_enabled) {
517+ /* tcc_state just was set by tcc_enter_state() */
520518 tcc_state = NULL;
521519 POST_SEM();
522520 }
@@ -528,24 +526,25 @@ static void error1(int mode, const char *fmt, va_list ap) · 5 unmodified lines
528526 mode = ERROR_ERROR;
529527 }
530528
531− buf[0] = '\0';
532− /* use upper file if inline ":asm:" or token ":paste:" */
533− for (f = file; f && f->filename[0] == ':'; f = f->prev)
534− ;
529+ f = NULL;
530+ if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */
531+ /* use upper file if inline ":asm:" or token ":paste:" */
532+ for (f = file; f && f->filename[0] == ':'; f = f->prev)
533+ ;
534+ }
535535 if (f) {
536536 for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++)
537537 strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n",
538538 (*pf)->filename, (*pf)->line_num);
539− if (s1->error_set_jmp_enabled) {
540− strcat_printf(buf, sizeof(buf), "%s:%d: ",
541− f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL));
542− } else {
543− strcat_printf(buf, sizeof(buf), "%s: ",
544− f->filename);
545− }
546− } else {
547− strcat_printf(buf, sizeof(buf), "tcc: ");
539+ strcat_printf(buf, sizeof(buf), "%s:%d: ",
540+ f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL));
541+ } else if (s1->current_filename) {
542+ strcat_printf(buf, sizeof(buf), "%s: ", s1->current_filename);
548543 }
544+
545+no_file:
546+ if (0 == buf[0])
547+ strcat_printf(buf, sizeof(buf), "tcc: ");
549548 if (mode == ERROR_WARN)
550549 strcat_printf(buf, sizeof(buf), "warning: ");
551550 else
@@ -1071,10 +1070,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 519 unmodified lines
10711070 return -1;
10721071 }
10731072
1074− /* update target deps */
1075− dynarray_add(&s1->target_deps, &s1->nb_target_deps,
1076− tcc_strdup(filename));
1077−
1073+ s1->current_filename = filename;
10781074 if (flags & AFF_TYPE_BIN) {
10791075 ElfW(Ehdr) ehdr;
10801076 int obj_type;
@@ -1126,8 +1122,11 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 45 unmodified lines
11261122 }
11271123 close(fd);
11281124 } else {
1125+ /* update target deps */
1126+ dynarray_add(&s1->target_deps, &s1->nb_target_deps, tcc_strdup(filename));
11291127 ret = tcc_compile(s1, flags, filename, fd);
11301128 }
1129+ s1->current_filename = NULL;
11311130 return ret;
11321131 }
11331132
tcc.h+3−0
@@ -911,6 +911,9 @@ struct TCCState { · 910 unmodified lines
911911 /* option -dnum (for general development purposes) */
912912 int g_debug;
913913
914+ /* for warnings/errors for object files*/
915+ const char *current_filename;
916+
914917 /* used by main and tcc_parse_args only */
915918 struct filespec **files; /* files seen on command line */
916919 int nb_files; /* number thereof */
tccelf.c+1−1
@@ -3125,7 +3125,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 3124 unmodified lines
31253125 /* test CPU specific stuff */
31263126 if (ehdr.e_ident[5] != ELFDATA2LSB ||
31273127 ehdr.e_machine != EM_TCC_TARGET) {
3128− tcc_error_noabort("bad architecture: %s", filename);
3128+ tcc_error_noabort("bad architecture");
31293129 return -1;
31303130 }
31313131
tccpe.c+1−1
@@ -861,7 +861,7 @@ static void pe_build_imports(struct pe_info *pe) · 860 unmodified lines
861861 v = (ADDR3264)GetProcAddress(dllref->handle, ordinal?(char*)0+ordinal:name);
862862 }
863863 if (!v)
864− tcc_error_noabort("can't build symbol '%s'", name);
864+ tcc_error_noabort("could not resolve symbol '%s'", name);
865865 } else
866866 #endif
867867 if (ordinal) {
tccpp.c+13−6
@@ -1808,7 +1808,7 @@ ST_FUNC void preprocess(int is_bof) · 1807 unmodified lines
18081808 tcc_error("#include recursion too deep");
18091809 /* push current file on stack */
18101810 *s1->include_stack_ptr++ = file;
1811− i = tok == TOK_INCLUDE_NEXT ? file->include_next_index: 0;
1811+ i = tok == TOK_INCLUDE_NEXT ? file->include_next_index + 1 : 0;
18121812 n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;
18131813 for (; i < n; ++i) {
18141814 char buf1[sizeof file->filename];
@@ -1851,14 +1851,19 @@ ST_FUNC void preprocess(int is_bof) · 36 unmodified lines
18511851 if (tcc_open(s1, buf1) < 0)
18521852 continue;
18531853
1854− file->include_next_index = i + 1;
1854+ file->include_next_index = i;
18551855 #ifdef INC_DEBUG
18561856 printf("%s: including %s\n", file->prev->filename, file->filename);
18571857 #endif
18581858 /* update target deps */
18591859 if (s1->gen_deps) {
1860− dynarray_add(&s1->target_deps, &s1->nb_target_deps,
1861− tcc_strdup(buf1));
1860+ BufferedFile *bf = file;
1861+ while (i == 1 && (bf = bf->prev))
1862+ i = bf->include_next_index;
1863+ /* skip system include files */
1864+ if (n - i > s1->nb_sysinclude_paths)
1865+ dynarray_add(&s1->target_deps, &s1->nb_target_deps,
1866+ tcc_strdup(buf1));
18621867 }
18631868 /* add include file debug info */
18641869 tcc_debug_bincl(tcc_state);
@@ -3866,8 +3871,10 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 2001 unmodified lines
38663871 s1->dflag &= ~1;
38673872 }
38683873
3869− token_seen = TOK_LINEFEED, spcs = 0;
3870− pp_line(s1, file, 0);
3874+ token_seen = TOK_LINEFEED, spcs = 0, level = 0;
3875+ if (file->prev)
3876+ pp_line(s1, file->prev, level++);
3877+ pp_line(s1, file, level);
38713878 for (;;) {
38723879 iptr = s1->include_stack_ptr;
38733880 next();
tcctools.c+9−5
@@ -519,7 +519,7 @@ ST_FUNC void gen_makedeps(TCCState *s1, const char *target, const char *filename · 518 unmodified lines
519519 {
520520 FILE *depout;
521521 char buf[1024];
522− int i;
522+ int i, k;
523523
524524 if (!filename) {
525525 /* compute filename automatically: dir/file.o -> dir/file.d */
@@ -535,10 +535,14 @@ ST_FUNC void gen_makedeps(TCCState *s1, const char *target, const char *filename · 9 unmodified lines
535535 depout = fopen(filename, "w");
536536 if (!depout)
537537 tcc_error("could not open '%s'", filename);
538−
539− fprintf(depout, "%s: \\\n", target);
540− for (i=0; i<s1->nb_target_deps; ++i)
541− fprintf(depout, " %s \\\n", s1->target_deps[i]);
538+ fprintf(depout, "%s:", target);
539+ for (i = 0; i<s1->nb_target_deps; ++i) {
540+ for (k = 0; k < i; ++k)
541+ if (0 == strcmp(s1->target_deps[i], s1->target_deps[k]))
542+ goto next;
543+ fprintf(depout, " \\\n %s", s1->target_deps[i]);
544+ next:;
545+ }
542546 fprintf(depout, "\n");
543547 fclose(depout);
544548 }

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