History

fix a preprocessor for .S

* 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

seyko committed 11 years ago

Commit 70dbe161 parent 559675b2 files · +15 −19Browse files

Unified · Split

2 files
  1. libtcc.c +2 −2
  2. tccpp.c +13 −17
libtcc.c+2−2
@@ -1177,13 +1177,13 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 1176 unmodified lines
11771177
11781178 #ifdef CONFIG_TCC_ASM
11791179 if (!strcmp(ext, "S")) {
1180− /* preprocessed assembler */
1180+ /* non preprocessed assembler */
11811181 ret = tcc_assemble(s1, 1);
11821182 goto the_end;
11831183 }
11841184
11851185 if (!strcmp(ext, "s")) {
1186− /* non preprocessed assembler */
1186+ /* preprocessed assembler */
11871187 ret = tcc_assemble(s1, 0);
11881188 goto the_end;
11891189 }
tccpp.c+13−17
@@ -24,20 +24,7 @@ · 23 unmodified lines
2424 /* global variables */
2525
2626 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−
3327 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) */
4128
4229 ST_DATA struct BufferedFile *file;
4330 ST_DATA int ch, tok;
@@ -792,6 +779,8 @@ redo_start: · 748 unmodified lines
792779 in_warn_or_error = 1;
793780 else if (tok == TOK_LINEFEED)
794781 goto redo_start;
782+ else if (parse_flags & PARSE_FLAG_ASM_COMMENTS)
783+ p = parse_line_comment(p);
795784 }
796785 break;
797786 _default:
@@ -1443,6 +1432,7 @@ ST_FUNC void preprocess(int is_bof) · 645 unmodified lines
14431432 saved_parse_flags = parse_flags;
14441433 parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM |
14451434 PARSE_FLAG_LINEFEED;
1435+ parse_flags |= (saved_parse_flags & PARSE_FLAG_ASM_COMMENTS);
14461436 next_nomacro();
14471437 redo:
14481438 switch(tok) {
@@ -1679,11 +1669,17 @@ include_done: · 230 unmodified lines
16791669 char *p = tokc.cstr->data;
16801670 tokc.i = strtoul(p, (char **)&p, 10);
16811671 }
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;
16831674 next();
16841675 if (tok != TOK_LINEFEED) {
1685− if (tok != TOK_STR)
1686− tcc_error("#line");
1676+ if (tok != TOK_STR) {
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+ }
16871683 pstrcpy(file->filename, sizeof(file->filename),
16881684 (char *)tokc.cstr->data);
16891685 }
@@ -1719,7 +1715,7 @@ include_done: · 29 unmodified lines
17191715 /* '!' is ignored to allow C scripts. numbers are ignored
17201716 to emulate cpp behaviour */
17211717 } else {
1722− if (!(saved_parse_flags & PARSE_FLAG_ASM_COMMENTS))
1718+ if (!(parse_flags & PARSE_FLAG_ASM_COMMENTS))
17231719 tcc_warning("Ignoring unknown preprocessing directive #%s", get_tok_str(tok, &tokc));
17241720 else {
17251721 /* this is a gas line comment in an 'S' file. */

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