mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-26 03:50:07 +08:00
tcc -MD: drop system includes and duplicates
Also: - print filenames in errors for binary input files (was lost with the thread support recently)
This commit is contained in:
parent
e7a4140d28
commit
cbef54653a
49
libtcc.c
49
libtcc.c
@ -508,15 +508,13 @@ static void error1(int mode, const char *fmt, va_list ap)
|
||||
BufferedFile **pf, *f;
|
||||
TCCState *s1 = tcc_state;
|
||||
|
||||
/* 's1->error_set_jmp_enabled' means that we're called from
|
||||
within the parser/generator and 'tcc_state' was already
|
||||
set (i.e. not by the function above).
|
||||
buf[0] = '\0';
|
||||
if (s1 == NULL)
|
||||
/* can happen only if called from tcc_malloc(): 'out of memory' */
|
||||
goto no_file;
|
||||
|
||||
Otherwise, 's1 = NULL' means we're called because of severe
|
||||
problems from tcc_malloc() which under normal conditions
|
||||
should never happen. */
|
||||
|
||||
if (s1 && !s1->error_set_jmp_enabled) {
|
||||
if (!s1->error_set_jmp_enabled) {
|
||||
/* tcc_state just was set by tcc_enter_state() */
|
||||
tcc_state = NULL;
|
||||
POST_SEM();
|
||||
}
|
||||
@ -528,24 +526,25 @@ static void error1(int mode, const char *fmt, va_list ap)
|
||||
mode = ERROR_ERROR;
|
||||
}
|
||||
|
||||
buf[0] = '\0';
|
||||
/* use upper file if inline ":asm:" or token ":paste:" */
|
||||
for (f = file; f && f->filename[0] == ':'; f = f->prev)
|
||||
;
|
||||
f = NULL;
|
||||
if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */
|
||||
/* use upper file if inline ":asm:" or token ":paste:" */
|
||||
for (f = file; f && f->filename[0] == ':'; f = f->prev)
|
||||
;
|
||||
}
|
||||
if (f) {
|
||||
for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++)
|
||||
strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n",
|
||||
(*pf)->filename, (*pf)->line_num);
|
||||
if (s1->error_set_jmp_enabled) {
|
||||
strcat_printf(buf, sizeof(buf), "%s:%d: ",
|
||||
f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL));
|
||||
} else {
|
||||
strcat_printf(buf, sizeof(buf), "%s: ",
|
||||
f->filename);
|
||||
}
|
||||
} else {
|
||||
strcat_printf(buf, sizeof(buf), "tcc: ");
|
||||
strcat_printf(buf, sizeof(buf), "%s:%d: ",
|
||||
f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL));
|
||||
} else if (s1->current_filename) {
|
||||
strcat_printf(buf, sizeof(buf), "%s: ", s1->current_filename);
|
||||
}
|
||||
|
||||
no_file:
|
||||
if (0 == buf[0])
|
||||
strcat_printf(buf, sizeof(buf), "tcc: ");
|
||||
if (mode == ERROR_WARN)
|
||||
strcat_printf(buf, sizeof(buf), "warning: ");
|
||||
else
|
||||
@ -1071,10 +1070,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* update target deps */
|
||||
dynarray_add(&s1->target_deps, &s1->nb_target_deps,
|
||||
tcc_strdup(filename));
|
||||
|
||||
s1->current_filename = filename;
|
||||
if (flags & AFF_TYPE_BIN) {
|
||||
ElfW(Ehdr) ehdr;
|
||||
int obj_type;
|
||||
@ -1126,8 +1122,11 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
|
||||
}
|
||||
close(fd);
|
||||
} else {
|
||||
/* update target deps */
|
||||
dynarray_add(&s1->target_deps, &s1->nb_target_deps, tcc_strdup(filename));
|
||||
ret = tcc_compile(s1, flags, filename, fd);
|
||||
}
|
||||
s1->current_filename = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
3
tcc.h
3
tcc.h
@ -911,6 +911,9 @@ struct TCCState {
|
||||
/* option -dnum (for general development purposes) */
|
||||
int g_debug;
|
||||
|
||||
/* for warnings/errors for object files*/
|
||||
const char *current_filename;
|
||||
|
||||
/* used by main and tcc_parse_args only */
|
||||
struct filespec **files; /* files seen on command line */
|
||||
int nb_files; /* number thereof */
|
||||
|
2
tccelf.c
2
tccelf.c
@ -3125,7 +3125,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
|
||||
/* test CPU specific stuff */
|
||||
if (ehdr.e_ident[5] != ELFDATA2LSB ||
|
||||
ehdr.e_machine != EM_TCC_TARGET) {
|
||||
tcc_error_noabort("bad architecture: %s", filename);
|
||||
tcc_error_noabort("bad architecture");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
2
tccpe.c
2
tccpe.c
@ -861,7 +861,7 @@ static void pe_build_imports(struct pe_info *pe)
|
||||
v = (ADDR3264)GetProcAddress(dllref->handle, ordinal?(char*)0+ordinal:name);
|
||||
}
|
||||
if (!v)
|
||||
tcc_error_noabort("can't build symbol '%s'", name);
|
||||
tcc_error_noabort("could not resolve symbol '%s'", name);
|
||||
} else
|
||||
#endif
|
||||
if (ordinal) {
|
||||
|
19
tccpp.c
19
tccpp.c
@ -1808,7 +1808,7 @@ ST_FUNC void preprocess(int is_bof)
|
||||
tcc_error("#include recursion too deep");
|
||||
/* push current file on stack */
|
||||
*s1->include_stack_ptr++ = file;
|
||||
i = tok == TOK_INCLUDE_NEXT ? file->include_next_index: 0;
|
||||
i = tok == TOK_INCLUDE_NEXT ? file->include_next_index + 1 : 0;
|
||||
n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;
|
||||
for (; i < n; ++i) {
|
||||
char buf1[sizeof file->filename];
|
||||
@ -1851,14 +1851,19 @@ ST_FUNC void preprocess(int is_bof)
|
||||
if (tcc_open(s1, buf1) < 0)
|
||||
continue;
|
||||
|
||||
file->include_next_index = i + 1;
|
||||
file->include_next_index = i;
|
||||
#ifdef INC_DEBUG
|
||||
printf("%s: including %s\n", file->prev->filename, file->filename);
|
||||
#endif
|
||||
/* update target deps */
|
||||
if (s1->gen_deps) {
|
||||
dynarray_add(&s1->target_deps, &s1->nb_target_deps,
|
||||
tcc_strdup(buf1));
|
||||
BufferedFile *bf = file;
|
||||
while (i == 1 && (bf = bf->prev))
|
||||
i = bf->include_next_index;
|
||||
/* skip system include files */
|
||||
if (n - i > s1->nb_sysinclude_paths)
|
||||
dynarray_add(&s1->target_deps, &s1->nb_target_deps,
|
||||
tcc_strdup(buf1));
|
||||
}
|
||||
/* add include file debug info */
|
||||
tcc_debug_bincl(tcc_state);
|
||||
@ -3866,8 +3871,10 @@ ST_FUNC int tcc_preprocess(TCCState *s1)
|
||||
s1->dflag &= ~1;
|
||||
}
|
||||
|
||||
token_seen = TOK_LINEFEED, spcs = 0;
|
||||
pp_line(s1, file, 0);
|
||||
token_seen = TOK_LINEFEED, spcs = 0, level = 0;
|
||||
if (file->prev)
|
||||
pp_line(s1, file->prev, level++);
|
||||
pp_line(s1, file, level);
|
||||
for (;;) {
|
||||
iptr = s1->include_stack_ptr;
|
||||
next();
|
||||
|
14
tcctools.c
14
tcctools.c
@ -519,7 +519,7 @@ ST_FUNC void gen_makedeps(TCCState *s1, const char *target, const char *filename
|
||||
{
|
||||
FILE *depout;
|
||||
char buf[1024];
|
||||
int i;
|
||||
int i, k;
|
||||
|
||||
if (!filename) {
|
||||
/* 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
|
||||
depout = fopen(filename, "w");
|
||||
if (!depout)
|
||||
tcc_error("could not open '%s'", filename);
|
||||
|
||||
fprintf(depout, "%s: \\\n", target);
|
||||
for (i=0; i<s1->nb_target_deps; ++i)
|
||||
fprintf(depout, " %s \\\n", s1->target_deps[i]);
|
||||
fprintf(depout, "%s:", target);
|
||||
for (i = 0; i<s1->nb_target_deps; ++i) {
|
||||
for (k = 0; k < i; ++k)
|
||||
if (0 == strcmp(s1->target_deps[i], s1->target_deps[k]))
|
||||
goto next;
|
||||
fprintf(depout, " \\\n %s", s1->target_deps[i]);
|
||||
next:;
|
||||
}
|
||||
fprintf(depout, "\n");
|
||||
fclose(depout);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user