History

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.

Michael Matz committed 6 years ago

Commit 40671f71 parent de061933 files · +24 −23Browse files

Unified · Split

3 files
  1. libtcc.c +2 −4
  2. tcc.h +1 −1
  3. tccpp.c +21 −18
libtcc.c+2−4
@@ -708,7 +708,6 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 707 unmodified lines
708 tcc_enter_state(s1);708 tcc_enter_state(s1);
709 709
710 if (setjmp(s1->error_jmp_buf) == 0) {710 if (setjmp(s1->error_jmp_buf) == 0) {
711 int is_asm;
712 s1->error_set_jmp_enabled = 1;711 s1->error_set_jmp_enabled = 1;
713 s1->nb_errors = 0;712 s1->nb_errors = 0;
714 713
@@ -721,13 +720,12 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 6 unmodified lines
721 file->fd = fd;720 file->fd = fd;
722 }721 }
723 722
724 is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
725 tccelf_begin_file(s1);723 tccelf_begin_file(s1);
726 preprocess_start(s1, is_asm);724 preprocess_start(s1, filetype);
727 tccgen_init(s1);725 tccgen_init(s1);
728 if (s1->output_type == TCC_OUTPUT_PREPROCESS) {726 if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
729 tcc_preprocess(s1);727 tcc_preprocess(s1);
730 } else if (is_asm) {728 } else if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) {
731#ifdef CONFIG_TCC_ASM729#ifdef CONFIG_TCC_ASM
732 tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP));730 tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP));
733#else731#else
tcc.h+1−1
@@ -1365,7 +1365,7 @@ ST_FUNC void parse_define(void); · 1364 unmodified lines
1365ST_FUNC void preprocess(int is_bof);1365ST_FUNC void preprocess(int is_bof);
1366ST_FUNC void next(void);1366ST_FUNC void next(void);
1367ST_INLN void unget_tok(int last_tok);1367ST_INLN void unget_tok(int last_tok);
1368ST_FUNC void preprocess_start(TCCState *s1, int is_asm);1368ST_FUNC void preprocess_start(TCCState *s1, int filetype);
1369ST_FUNC void preprocess_end(TCCState *s1);1369ST_FUNC void preprocess_end(TCCState *s1);
1370ST_FUNC void tccpp_new(TCCState *s);1370ST_FUNC void tccpp_new(TCCState *s);
1371ST_FUNC void tccpp_delete(TCCState *s);1371ST_FUNC void tccpp_delete(TCCState *s);
tccpp.c+21−18
@@ -3720,8 +3720,9 @@ static void tcc_predefs(CString *cstr) · 3719 unmodified lines
3720 , -1);3720 , -1);
3721}3721}
3722 3722
3723ST_FUNC void preprocess_start(TCCState *s1, int is_asm)3723ST_FUNC void preprocess_start(TCCState *s1, int filetype)
3724{3724{
3725 int is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
3725 CString cstr;3726 CString cstr;
3726 3727
3727 tccpp_new(s1);3728 tccpp_new(s1);
@@ -3739,23 +3740,25 @@ ST_FUNC void preprocess_start(TCCState *s1, int is_asm) · 11 unmodified lines
3739 set_idnum('$', !is_asm && s1->dollars_in_identifiers ? IS_ID : 0);3740 set_idnum('$', !is_asm && s1->dollars_in_identifiers ? IS_ID : 0);
3740 set_idnum('.', is_asm ? IS_ID : 0);3741 set_idnum('.', is_asm ? IS_ID : 0);
3741 3742
3742 cstr_new(&cstr);3743 if (!(filetype & AFF_TYPE_ASM)) {
3743 if (s1->cmdline_defs.size)3744 cstr_new(&cstr);
3744 cstr_cat(&cstr, s1->cmdline_defs.data, s1->cmdline_defs.size);3745 if (s1->cmdline_defs.size)
3745 cstr_printf(&cstr, "#define __BASE_FILE__ \"%s\"\n", file->filename);3746 cstr_cat(&cstr, s1->cmdline_defs.data, s1->cmdline_defs.size);
3746 if (is_asm)3747 cstr_printf(&cstr, "#define __BASE_FILE__ \"%s\"\n", file->filename);
3747 cstr_printf(&cstr, "#define __ASSEMBLER__ 1\n");3748 if (is_asm)
3748 if (s1->output_type == TCC_OUTPUT_MEMORY)3749 cstr_printf(&cstr, "#define __ASSEMBLER__ 1\n");
3749 cstr_printf(&cstr, "#define __TCC_RUN__ 1\n");3750 if (s1->output_type == TCC_OUTPUT_MEMORY)
3750 if (!is_asm && s1->output_type != TCC_OUTPUT_PREPROCESS)3751 cstr_printf(&cstr, "#define __TCC_RUN__ 1\n");
3751 tcc_predefs(&cstr);3752 if (!is_asm && s1->output_type != TCC_OUTPUT_PREPROCESS)
3752 if (s1->cmdline_incl.size)3753 tcc_predefs(&cstr);
3753 cstr_cat(&cstr, s1->cmdline_incl.data, s1->cmdline_incl.size);3754 if (s1->cmdline_incl.size)
3754 //printf("%s\n", (char*)cstr.data);3755 cstr_cat(&cstr, s1->cmdline_incl.data, s1->cmdline_incl.size);
3755 *s1->include_stack_ptr++ = file;3756 //printf("%s\n", (char*)cstr.data);
3756 tcc_open_bf(s1, "<command line>", cstr.size);3757 *s1->include_stack_ptr++ = file;
3757 memcpy(file->buffer, cstr.data, cstr.size);3758 tcc_open_bf(s1, "<command line>", cstr.size);
3758 cstr_free(&cstr);3759 memcpy(file->buffer, cstr.data, cstr.size);
3760 cstr_free(&cstr);
3761 }
3759 3762
3760 parse_flags = is_asm ? PARSE_FLAG_ASM_FILE : 0;3763 parse_flags = is_asm ? PARSE_FLAG_ASM_FILE : 0;
3761 tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;3764 tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;

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