* tell a right line number in error message if a #line directive is wrong * don't print an error message if we preprocess a .S file and #line directive is wrong. This is the case of the # 4026 bytes comment in *.S file. * preprocess_skip: skip a line with if (parse_flags & PARSE_FLAG_ASM_COMMENTS) p = parse_line_comment(p); if line starts with # and a preprocessor command not found. A test program: #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) # This repeats until either a device doesn't exist, or until #endif * remove a second definition of the TOK_FLAG_* and PARSE_FLAG_* from the tccpp.c
Unified · Split
| @@ -1177,13 +1177,13 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 1176 unmodified lines | |||
| 1177 | 1177 | ||
| 1178 | #ifdef CONFIG_TCC_ASM | 1178 | #ifdef CONFIG_TCC_ASM |
| 1179 | if (!strcmp(ext, "S")) { | 1179 | if (!strcmp(ext, "S")) { |
| 1180 | /* preprocessed assembler */ | 1180 | /* non preprocessed assembler */ |
| 1181 | ret = tcc_assemble(s1, 1); | 1181 | ret = tcc_assemble(s1, 1); |
| 1182 | goto the_end; | 1182 | goto the_end; |
| 1183 | } | 1183 | } |
| 1184 | 1184 | ||
| 1185 | if (!strcmp(ext, "s")) { | 1185 | if (!strcmp(ext, "s")) { |
| 1186 | /* non preprocessed assembler */ | 1186 | /* preprocessed assembler */ |
| 1187 | ret = tcc_assemble(s1, 0); | 1187 | ret = tcc_assemble(s1, 0); |
| 1188 | goto the_end; | 1188 | goto the_end; |
| 1189 | } | 1189 | } |
| @@ -24,20 +24,7 @@ · 23 unmodified lines | |||
| 24 | /* global variables */ | 24 | /* global variables */ |
| 25 | 25 | ||
| 26 | ST_DATA int tok_flags; | 26 | ST_DATA int tok_flags; |
| 27 | /* additional informations about token */ | ||
| 28 | #define TOK_FLAG_BOL 0x0001 /* beginning of line before */ | ||
| 29 | #define TOK_FLAG_BOF 0x0002 /* beginning of file before */ | ||
| 30 | #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */ | ||
| 31 | #define TOK_FLAG_EOF 0x0008 /* end of file */ | ||
| 32 | |||
| 33 | ST_DATA int parse_flags; | 27 | ST_DATA int parse_flags; |
| 34 | #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */ | ||
| 35 | #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */ | ||
| 36 | #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a | ||
| 37 | token. line feed is also | ||
| 38 | returned at eof */ | ||
| 39 | #define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */ | ||
| 40 | #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */ | ||
| 41 | 28 | ||
| 42 | ST_DATA struct BufferedFile *file; | 29 | ST_DATA struct BufferedFile *file; |
| 43 | ST_DATA int ch, tok; | 30 | ST_DATA int ch, tok; |
| @@ -792,6 +779,8 @@ redo_start: · 748 unmodified lines | |||
| 792 | in_warn_or_error = 1; | 779 | in_warn_or_error = 1; |
| 793 | else if (tok == TOK_LINEFEED) | 780 | else if (tok == TOK_LINEFEED) |
| 794 | goto redo_start; | 781 | goto redo_start; |
| 782 | else if (parse_flags & PARSE_FLAG_ASM_COMMENTS) | ||
| 783 | p = parse_line_comment(p); | ||
| 795 | } | 784 | } |
| 796 | break; | 785 | break; |
| 797 | _default: | 786 | _default: |
| @@ -1443,6 +1432,7 @@ ST_FUNC void preprocess(int is_bof) · 645 unmodified lines | |||
| 1443 | saved_parse_flags = parse_flags; | 1432 | saved_parse_flags = parse_flags; |
| 1444 | parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM | | 1433 | parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM | |
| 1445 | PARSE_FLAG_LINEFEED; | 1434 | PARSE_FLAG_LINEFEED; |
| 1435 | parse_flags |= (saved_parse_flags & PARSE_FLAG_ASM_COMMENTS); | ||
| 1446 | next_nomacro(); | 1436 | next_nomacro(); |
| 1447 | redo: | 1437 | redo: |
| 1448 | switch(tok) { | 1438 | switch(tok) { |
| @@ -1679,11 +1669,17 @@ include_done: · 230 unmodified lines | |||
| 1679 | char *p = tokc.cstr->data; | 1669 | char *p = tokc.cstr->data; |
| 1680 | tokc.i = strtoul(p, (char **)&p, 10); | 1670 | tokc.i = strtoul(p, (char **)&p, 10); |
| 1681 | } | 1671 | } |
| 1682 | file->line_num = tokc.i - 1; /* the line number will be incremented after */ | 1672 | i = file->line_num; |
| 1673 | file->line_num = tokc.i - 1; | ||
| 1683 | next(); | 1674 | next(); |
| 1684 | if (tok != TOK_LINEFEED) { | 1675 | if (tok != TOK_LINEFEED) { |
| 1685 | if (tok != TOK_STR) | 1676 | if (tok != TOK_STR) { |
| 1686 | tcc_error("#line"); | 1677 | if ((parse_flags & PARSE_FLAG_ASM_COMMENTS) == 0) { |
| 1678 | file->line_num = i; | ||
| 1679 | tcc_error("#line format is wrong"); | ||
| 1680 | } | ||
| 1681 | break; | ||
| 1682 | } | ||
| 1687 | pstrcpy(file->filename, sizeof(file->filename), | 1683 | pstrcpy(file->filename, sizeof(file->filename), |
| 1688 | (char *)tokc.cstr->data); | 1684 | (char *)tokc.cstr->data); |
| 1689 | } | 1685 | } |
| @@ -1719,7 +1715,7 @@ include_done: · 29 unmodified lines | |||
| 1719 | /* '!' is ignored to allow C scripts. numbers are ignored | 1715 | /* '!' is ignored to allow C scripts. numbers are ignored |
| 1720 | to emulate cpp behaviour */ | 1716 | to emulate cpp behaviour */ |
| 1721 | } else { | 1717 | } else { |
| 1722 | if (!(saved_parse_flags & PARSE_FLAG_ASM_COMMENTS)) | 1718 | if (!(parse_flags & PARSE_FLAG_ASM_COMMENTS)) |
| 1723 | tcc_warning("Ignoring unknown preprocessing directive #%s", get_tok_str(tok, &tokc)); | 1719 | tcc_warning("Ignoring unknown preprocessing directive #%s", get_tok_str(tok, &tokc)); |
| 1724 | else { | 1720 | else { |
| 1725 | /* this is a gas line comment in an 'S' file. */ | 1721 | /* this is a gas line comment in an 'S' file. */ |