Unified · Split
| @@ -508,15 +508,13 @@ static void error1(int mode, const char *fmt, va_list ap) · 507 unmodified lines | |||
| 508 | BufferedFile **pf, *f; | 508 | BufferedFile **pf, *f; |
| 509 | TCCState *s1 = tcc_state; | 509 | TCCState *s1 = tcc_state; |
| 510 | 510 | ||
| 511 | /* 's1->error_set_jmp_enabled' means that we're called from | 511 | buf[0] = '\0'; |
| 512 | within the parser/generator and 'tcc_state' was already | 512 | if (s1 == NULL) |
| 513 | set (i.e. not by the function above). | 513 | /* can happen only if called from tcc_malloc(): 'out of memory' */ |
| 514 | 514 | goto no_file; | |
| 515 | Otherwise, 's1 = NULL' means we're called because of severe | ||
| 516 | problems from tcc_malloc() which under normal conditions | ||
| 517 | should never happen. */ | ||
| 518 | 515 | ||
| 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() */ | ||
| 520 | tcc_state = NULL; | 518 | tcc_state = NULL; |
| 521 | POST_SEM(); | 519 | POST_SEM(); |
| 522 | } | 520 | } |
| @@ -528,24 +526,25 @@ static void error1(int mode, const char *fmt, va_list ap) · 5 unmodified lines | |||
| 528 | mode = ERROR_ERROR; | 526 | mode = ERROR_ERROR; |
| 529 | } | 527 | } |
| 530 | 528 | ||
| 531 | buf[0] = '\0'; | 529 | f = NULL; |
| 532 | /* use upper file if inline ":asm:" or token ":paste:" */ | 530 | if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */ |
| 533 | for (f = file; f && f->filename[0] == ':'; f = f->prev) | 531 | /* use upper file if inline ":asm:" or token ":paste:" */ |
| 534 | ; | 532 | for (f = file; f && f->filename[0] == ':'; f = f->prev) |
| 533 | ; | ||
| 534 | } | ||
| 535 | if (f) { | 535 | if (f) { |
| 536 | for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++) | 536 | for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++) |
| 537 | strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n", | 537 | strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n", |
| 538 | (*pf)->filename, (*pf)->line_num); | 538 | (*pf)->filename, (*pf)->line_num); |
| 539 | if (s1->error_set_jmp_enabled) { | 539 | strcat_printf(buf, sizeof(buf), "%s:%d: ", |
| 540 | strcat_printf(buf, sizeof(buf), "%s:%d: ", | 540 | f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL)); |
| 541 | f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL)); | 541 | } else if (s1->current_filename) { |
| 542 | } else { | 542 | strcat_printf(buf, sizeof(buf), "%s: ", s1->current_filename); |
| 543 | strcat_printf(buf, sizeof(buf), "%s: ", | ||
| 544 | f->filename); | ||
| 545 | } | ||
| 546 | } else { | ||
| 547 | strcat_printf(buf, sizeof(buf), "tcc: "); | ||
| 548 | } | 543 | } |
| 544 | |||
| 545 | no_file: | ||
| 546 | if (0 == buf[0]) | ||
| 547 | strcat_printf(buf, sizeof(buf), "tcc: "); | ||
| 549 | if (mode == ERROR_WARN) | 548 | if (mode == ERROR_WARN) |
| 550 | strcat_printf(buf, sizeof(buf), "warning: "); | 549 | strcat_printf(buf, sizeof(buf), "warning: "); |
| 551 | else | 550 | else |
| @@ -1071,10 +1070,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 519 unmodified lines | |||
| 1071 | return -1; | 1070 | return -1; |
| 1072 | } | 1071 | } |
| 1073 | 1072 | ||
| 1074 | /* update target deps */ | 1073 | s1->current_filename = filename; |
| 1075 | dynarray_add(&s1->target_deps, &s1->nb_target_deps, | ||
| 1076 | tcc_strdup(filename)); | ||
| 1077 | |||
| 1078 | if (flags & AFF_TYPE_BIN) { | 1074 | if (flags & AFF_TYPE_BIN) { |
| 1079 | ElfW(Ehdr) ehdr; | 1075 | ElfW(Ehdr) ehdr; |
| 1080 | int obj_type; | 1076 | int obj_type; |
| @@ -1126,8 +1122,11 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 45 unmodified lines | |||
| 1126 | } | 1122 | } |
| 1127 | close(fd); | 1123 | close(fd); |
| 1128 | } else { | 1124 | } else { |
| 1125 | /* update target deps */ | ||
| 1126 | dynarray_add(&s1->target_deps, &s1->nb_target_deps, tcc_strdup(filename)); | ||
| 1129 | ret = tcc_compile(s1, flags, filename, fd); | 1127 | ret = tcc_compile(s1, flags, filename, fd); |
| 1130 | } | 1128 | } |
| 1129 | s1->current_filename = NULL; | ||
| 1131 | return ret; | 1130 | return ret; |
| 1132 | } | 1131 | } |
| 1133 | 1132 | ||
| @@ -911,6 +911,9 @@ struct TCCState { · 910 unmodified lines | |||
| 911 | /* option -dnum (for general development purposes) */ | 911 | /* option -dnum (for general development purposes) */ |
| 912 | int g_debug; | 912 | int g_debug; |
| 913 | 913 | ||
| 914 | /* for warnings/errors for object files*/ | ||
| 915 | const char *current_filename; | ||
| 916 | |||
| 914 | /* used by main and tcc_parse_args only */ | 917 | /* used by main and tcc_parse_args only */ |
| 915 | struct filespec **files; /* files seen on command line */ | 918 | struct filespec **files; /* files seen on command line */ |
| 916 | int nb_files; /* number thereof */ | 919 | int nb_files; /* number thereof */ |
| @@ -3125,7 +3125,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 3124 unmodified lines | |||
| 3125 | /* test CPU specific stuff */ | 3125 | /* test CPU specific stuff */ |
| 3126 | if (ehdr.e_ident[5] != ELFDATA2LSB || | 3126 | if (ehdr.e_ident[5] != ELFDATA2LSB || |
| 3127 | ehdr.e_machine != EM_TCC_TARGET) { | 3127 | ehdr.e_machine != EM_TCC_TARGET) { |
| 3128 | tcc_error_noabort("bad architecture: %s", filename); | 3128 | tcc_error_noabort("bad architecture"); |
| 3129 | return -1; | 3129 | return -1; |
| 3130 | } | 3130 | } |
| 3131 | 3131 | ||
| @@ -861,7 +861,7 @@ static void pe_build_imports(struct pe_info *pe) · 860 unmodified lines | |||
| 861 | v = (ADDR3264)GetProcAddress(dllref->handle, ordinal?(char*)0+ordinal:name); | 861 | v = (ADDR3264)GetProcAddress(dllref->handle, ordinal?(char*)0+ordinal:name); |
| 862 | } | 862 | } |
| 863 | if (!v) | 863 | if (!v) |
| 864 | tcc_error_noabort("can't build symbol '%s'", name); | 864 | tcc_error_noabort("could not resolve symbol '%s'", name); |
| 865 | } else | 865 | } else |
| 866 | #endif | 866 | #endif |
| 867 | if (ordinal) { | 867 | if (ordinal) { |
| @@ -1808,7 +1808,7 @@ ST_FUNC void preprocess(int is_bof) · 1807 unmodified lines | |||
| 1808 | tcc_error("#include recursion too deep"); | 1808 | tcc_error("#include recursion too deep"); |
| 1809 | /* push current file on stack */ | 1809 | /* push current file on stack */ |
| 1810 | *s1->include_stack_ptr++ = file; | 1810 | *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; |
| 1812 | n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths; | 1812 | n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths; |
| 1813 | for (; i < n; ++i) { | 1813 | for (; i < n; ++i) { |
| 1814 | char buf1[sizeof file->filename]; | 1814 | char buf1[sizeof file->filename]; |
| @@ -1851,14 +1851,19 @@ ST_FUNC void preprocess(int is_bof) · 36 unmodified lines | |||
| 1851 | if (tcc_open(s1, buf1) < 0) | 1851 | if (tcc_open(s1, buf1) < 0) |
| 1852 | continue; | 1852 | continue; |
| 1853 | 1853 | ||
| 1854 | file->include_next_index = i + 1; | 1854 | file->include_next_index = i; |
| 1855 | #ifdef INC_DEBUG | 1855 | #ifdef INC_DEBUG |
| 1856 | printf("%s: including %s\n", file->prev->filename, file->filename); | 1856 | printf("%s: including %s\n", file->prev->filename, file->filename); |
| 1857 | #endif | 1857 | #endif |
| 1858 | /* update target deps */ | 1858 | /* update target deps */ |
| 1859 | if (s1->gen_deps) { | 1859 | if (s1->gen_deps) { |
| 1860 | dynarray_add(&s1->target_deps, &s1->nb_target_deps, | 1860 | BufferedFile *bf = file; |
| 1861 | tcc_strdup(buf1)); | 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)); | ||
| 1862 | } | 1867 | } |
| 1863 | /* add include file debug info */ | 1868 | /* add include file debug info */ |
| 1864 | tcc_debug_bincl(tcc_state); | 1869 | tcc_debug_bincl(tcc_state); |
| @@ -3866,8 +3871,10 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 2001 unmodified lines | |||
| 3866 | s1->dflag &= ~1; | 3871 | s1->dflag &= ~1; |
| 3867 | } | 3872 | } |
| 3868 | 3873 | ||
| 3869 | token_seen = TOK_LINEFEED, spcs = 0; | 3874 | token_seen = TOK_LINEFEED, spcs = 0, level = 0; |
| 3870 | pp_line(s1, file, 0); | 3875 | if (file->prev) |
| 3876 | pp_line(s1, file->prev, level++); | ||
| 3877 | pp_line(s1, file, level); | ||
| 3871 | for (;;) { | 3878 | for (;;) { |
| 3872 | iptr = s1->include_stack_ptr; | 3879 | iptr = s1->include_stack_ptr; |
| 3873 | next(); | 3880 | next(); |
| @@ -519,7 +519,7 @@ ST_FUNC void gen_makedeps(TCCState *s1, const char *target, const char *filename · 518 unmodified lines | |||
| 519 | { | 519 | { |
| 520 | FILE *depout; | 520 | FILE *depout; |
| 521 | char buf[1024]; | 521 | char buf[1024]; |
| 522 | int i; | 522 | int i, k; |
| 523 | 523 | ||
| 524 | if (!filename) { | 524 | if (!filename) { |
| 525 | /* compute filename automatically: dir/file.o -> dir/file.d */ | 525 | /* 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 | |||
| 535 | depout = fopen(filename, "w"); | 535 | depout = fopen(filename, "w"); |
| 536 | if (!depout) | 536 | if (!depout) |
| 537 | tcc_error("could not open '%s'", filename); | 537 | tcc_error("could not open '%s'", filename); |
| 538 | 538 | fprintf(depout, "%s:", target); | |
| 539 | fprintf(depout, "%s: \\\n", target); | 539 | for (i = 0; i<s1->nb_target_deps; ++i) { |
| 540 | for (i=0; i<s1->nb_target_deps; ++i) | 540 | for (k = 0; k < i; ++k) |
| 541 | fprintf(depout, " %s \\\n", s1->target_deps[i]); | 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 | } | ||
| 542 | fprintf(depout, "\n"); | 546 | fprintf(depout, "\n"); |
| 543 | fclose(depout); | 547 | fclose(depout); |
| 544 | } | 548 | } |