Fix parsing of .s files

those aren't preprocessed, but our use of a fake file in
preprocess_start requires inline stack processing (which isn't done
without preprocessing).  Just don't try to setup anything requiring
preprocessing at all in this case.
This commit is contained in:
Michael Matz 2020-07-06 18:12:35 +02:00
parent de06193d88
commit 40671f76e4
3 changed files with 24 additions and 23 deletions

View File

@ -708,7 +708,6 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
tcc_enter_state(s1);
if (setjmp(s1->error_jmp_buf) == 0) {
int is_asm;
s1->error_set_jmp_enabled = 1;
s1->nb_errors = 0;
@ -721,13 +720,12 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
file->fd = fd;
}
is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
tccelf_begin_file(s1);
preprocess_start(s1, is_asm);
preprocess_start(s1, filetype);
tccgen_init(s1);
if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
tcc_preprocess(s1);
} else if (is_asm) {
} else if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) {
#ifdef CONFIG_TCC_ASM
tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP));
#else

2
tcc.h
View File

@ -1365,7 +1365,7 @@ ST_FUNC void parse_define(void);
ST_FUNC void preprocess(int is_bof);
ST_FUNC void next(void);
ST_INLN void unget_tok(int last_tok);
ST_FUNC void preprocess_start(TCCState *s1, int is_asm);
ST_FUNC void preprocess_start(TCCState *s1, int filetype);
ST_FUNC void preprocess_end(TCCState *s1);
ST_FUNC void tccpp_new(TCCState *s);
ST_FUNC void tccpp_delete(TCCState *s);

39
tccpp.c
View File

@ -3720,8 +3720,9 @@ static void tcc_predefs(CString *cstr)
, -1);
}
ST_FUNC void preprocess_start(TCCState *s1, int is_asm)
ST_FUNC void preprocess_start(TCCState *s1, int filetype)
{
int is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
CString cstr;
tccpp_new(s1);
@ -3739,23 +3740,25 @@ ST_FUNC void preprocess_start(TCCState *s1, int is_asm)
set_idnum('$', !is_asm && s1->dollars_in_identifiers ? IS_ID : 0);
set_idnum('.', is_asm ? IS_ID : 0);
cstr_new(&cstr);
if (s1->cmdline_defs.size)
cstr_cat(&cstr, s1->cmdline_defs.data, s1->cmdline_defs.size);
cstr_printf(&cstr, "#define __BASE_FILE__ \"%s\"\n", file->filename);
if (is_asm)
cstr_printf(&cstr, "#define __ASSEMBLER__ 1\n");
if (s1->output_type == TCC_OUTPUT_MEMORY)
cstr_printf(&cstr, "#define __TCC_RUN__ 1\n");
if (!is_asm && s1->output_type != TCC_OUTPUT_PREPROCESS)
tcc_predefs(&cstr);
if (s1->cmdline_incl.size)
cstr_cat(&cstr, s1->cmdline_incl.data, s1->cmdline_incl.size);
//printf("%s\n", (char*)cstr.data);
*s1->include_stack_ptr++ = file;
tcc_open_bf(s1, "<command line>", cstr.size);
memcpy(file->buffer, cstr.data, cstr.size);
cstr_free(&cstr);
if (!(filetype & AFF_TYPE_ASM)) {
cstr_new(&cstr);
if (s1->cmdline_defs.size)
cstr_cat(&cstr, s1->cmdline_defs.data, s1->cmdline_defs.size);
cstr_printf(&cstr, "#define __BASE_FILE__ \"%s\"\n", file->filename);
if (is_asm)
cstr_printf(&cstr, "#define __ASSEMBLER__ 1\n");
if (s1->output_type == TCC_OUTPUT_MEMORY)
cstr_printf(&cstr, "#define __TCC_RUN__ 1\n");
if (!is_asm && s1->output_type != TCC_OUTPUT_PREPROCESS)
tcc_predefs(&cstr);
if (s1->cmdline_incl.size)
cstr_cat(&cstr, s1->cmdline_incl.data, s1->cmdline_incl.size);
//printf("%s\n", (char*)cstr.data);
*s1->include_stack_ptr++ = file;
tcc_open_bf(s1, "<command line>", cstr.size);
memcpy(file->buffer, cstr.data, cstr.size);
cstr_free(&cstr);
}
parse_flags = is_asm ? PARSE_FLAG_ASM_FILE : 0;
tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;