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
708708 tcc_enter_state(s1);
709709
710710 if (setjmp(s1->error_jmp_buf) == 0) {
711− int is_asm;
712711 s1->error_set_jmp_enabled = 1;
713712 s1->nb_errors = 0;
714713
@@ -721,13 +720,12 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd) · 6 unmodified lines
721720 file->fd = fd;
722721 }
723722
724− is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
725723 tccelf_begin_file(s1);
726− preprocess_start(s1, is_asm);
724+ preprocess_start(s1, filetype);
727725 tccgen_init(s1);
728726 if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
729727 tcc_preprocess(s1);
730− } else if (is_asm) {
728+ } else if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) {
731729 #ifdef CONFIG_TCC_ASM
732730 tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP));
733731 #else
tcc.h+1−1
@@ -1365,7 +1365,7 @@ ST_FUNC void parse_define(void); · 1364 unmodified lines
13651365 ST_FUNC void preprocess(int is_bof);
13661366 ST_FUNC void next(void);
13671367 ST_INLN void unget_tok(int last_tok);
1368−ST_FUNC void preprocess_start(TCCState *s1, int is_asm);
1368+ST_FUNC void preprocess_start(TCCState *s1, int filetype);
13691369 ST_FUNC void preprocess_end(TCCState *s1);
13701370 ST_FUNC void tccpp_new(TCCState *s);
13711371 ST_FUNC void tccpp_delete(TCCState *s);
tccpp.c+21−18
@@ -3720,8 +3720,9 @@ static void tcc_predefs(CString *cstr) · 3719 unmodified lines
37203720 , -1);
37213721 }
37223722
3723−ST_FUNC void preprocess_start(TCCState *s1, int is_asm)
3723+ST_FUNC void preprocess_start(TCCState *s1, int filetype)
37243724 {
3725+ int is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
37253726 CString cstr;
37263727
37273728 tccpp_new(s1);
@@ -3739,23 +3740,25 @@ ST_FUNC void preprocess_start(TCCState *s1, int is_asm) · 11 unmodified lines
37393740 set_idnum('$', !is_asm && s1->dollars_in_identifiers ? IS_ID : 0);
37403741 set_idnum('.', is_asm ? IS_ID : 0);
37413742
3742− cstr_new(&cstr);
3743− if (s1->cmdline_defs.size)
3744− cstr_cat(&cstr, s1->cmdline_defs.data, s1->cmdline_defs.size);
3745− cstr_printf(&cstr, "#define __BASE_FILE__ \"%s\"\n", file->filename);
3746− if (is_asm)
3747− cstr_printf(&cstr, "#define __ASSEMBLER__ 1\n");
3748− if (s1->output_type == TCC_OUTPUT_MEMORY)
3749− cstr_printf(&cstr, "#define __TCC_RUN__ 1\n");
3750− if (!is_asm && s1->output_type != TCC_OUTPUT_PREPROCESS)
3751− tcc_predefs(&cstr);
3752− if (s1->cmdline_incl.size)
3753− cstr_cat(&cstr, s1->cmdline_incl.data, s1->cmdline_incl.size);
3754− //printf("%s\n", (char*)cstr.data);
3755− *s1->include_stack_ptr++ = file;
3756− tcc_open_bf(s1, "<command line>", cstr.size);
3757− memcpy(file->buffer, cstr.data, cstr.size);
3758− cstr_free(&cstr);
3743+ if (!(filetype & AFF_TYPE_ASM)) {
3744+ cstr_new(&cstr);
3745+ if (s1->cmdline_defs.size)
3746+ cstr_cat(&cstr, s1->cmdline_defs.data, s1->cmdline_defs.size);
3747+ cstr_printf(&cstr, "#define __BASE_FILE__ \"%s\"\n", file->filename);
3748+ if (is_asm)
3749+ cstr_printf(&cstr, "#define __ASSEMBLER__ 1\n");
3750+ if (s1->output_type == TCC_OUTPUT_MEMORY)
3751+ cstr_printf(&cstr, "#define __TCC_RUN__ 1\n");
3752+ if (!is_asm && s1->output_type != TCC_OUTPUT_PREPROCESS)
3753+ tcc_predefs(&cstr);
3754+ if (s1->cmdline_incl.size)
3755+ cstr_cat(&cstr, s1->cmdline_incl.data, s1->cmdline_incl.size);
3756+ //printf("%s\n", (char*)cstr.data);
3757+ *s1->include_stack_ptr++ = file;
3758+ tcc_open_bf(s1, "<command line>", cstr.size);
3759+ memcpy(file->buffer, cstr.data, cstr.size);
3760+ cstr_free(&cstr);
3761+ }
37593762
37603763 parse_flags = is_asm ? PARSE_FLAG_ASM_FILE : 0;
37613764 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