fix a preprocessor for .S
Lets assume that in *.S files a preprocessor directive
    follow '#' char w/o spaces between. Otherwise there is
    too many problems with the content of the comments.
			
			
This commit is contained in:
		
							parent
							
								
									8037a1ce39
								
							
						
					
					
						commit
						d81611b641
					
				
					 3 changed files with 21 additions and 4 deletions
				
			
		
							
								
								
									
										5
									
								
								libtcc.c
									
										
									
									
									
								
							
							
						
						
									
										5
									
								
								libtcc.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1146,10 +1146,13 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
 | 
			
		|||
    if (ext[0])
 | 
			
		||||
        ext++;
 | 
			
		||||
 | 
			
		||||
    parse_flags = 0;
 | 
			
		||||
#ifdef CONFIG_TCC_ASM
 | 
			
		||||
    /* if .S file, define __ASSEMBLER__ like gcc does */
 | 
			
		||||
    if (!strcmp(ext, "S"))
 | 
			
		||||
    if (!strcmp(ext, "S") || !strcmp(ext, "s")) {
 | 
			
		||||
        tcc_define_symbol(s1, "__ASSEMBLER__", NULL);
 | 
			
		||||
        parse_flags = PARSE_FLAG_ASM_FILE;
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    /* open the file */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								tcc.h
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								tcc.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1149,6 +1149,7 @@ ST_DATA TokenSym **table_ident;
 | 
			
		|||
                                        returned at eof */
 | 
			
		||||
#define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */
 | 
			
		||||
#define PARSE_FLAG_SPACES     0x0010 /* next() returns space tokens (for -E) */
 | 
			
		||||
#define PARSE_FLAG_ASM_FILE 0x0020 /* we processing an asm file */
 | 
			
		||||
 | 
			
		||||
ST_FUNC TokenSym *tok_alloc(const char *str, int len);
 | 
			
		||||
ST_FUNC char *get_tok_str(int v, CValue *cv);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								tccpp.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								tccpp.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -782,6 +782,8 @@ redo_start:
 | 
			
		|||
                else if (parse_flags & PARSE_FLAG_ASM_COMMENTS)
 | 
			
		||||
            	    p = parse_line_comment(p);
 | 
			
		||||
            }
 | 
			
		||||
            else if (parse_flags & PARSE_FLAG_ASM_FILE)
 | 
			
		||||
        	p = parse_line_comment(p);
 | 
			
		||||
            break;
 | 
			
		||||
_default:
 | 
			
		||||
        default:
 | 
			
		||||
| 
						 | 
				
			
			@ -1432,7 +1434,7 @@ ST_FUNC void preprocess(int is_bof)
 | 
			
		|||
    saved_parse_flags = parse_flags;
 | 
			
		||||
    parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM | 
 | 
			
		||||
        PARSE_FLAG_LINEFEED;
 | 
			
		||||
    parse_flags |= (saved_parse_flags & PARSE_FLAG_ASM_COMMENTS);
 | 
			
		||||
    parse_flags |= (saved_parse_flags & (PARSE_FLAG_ASM_FILE | PARSE_FLAG_ASM_COMMENTS));
 | 
			
		||||
    next_nomacro();
 | 
			
		||||
 redo:
 | 
			
		||||
    switch(tok) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2259,6 +2261,11 @@ maybe_newline:
 | 
			
		|||
    case '#':
 | 
			
		||||
        /* XXX: simplify */
 | 
			
		||||
        PEEKC(c, p);
 | 
			
		||||
        if (is_space(c) && (parse_flags & PARSE_FLAG_ASM_FILE)) {
 | 
			
		||||
    	    p = parse_line_comment(p);
 | 
			
		||||
            goto redo_no_start;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        if ((tok_flags & TOK_FLAG_BOL) && 
 | 
			
		||||
            (parse_flags & PARSE_FLAG_PREPROCESS)) {
 | 
			
		||||
            file->buf_ptr = p;
 | 
			
		||||
| 
						 | 
				
			
			@ -2588,7 +2595,12 @@ maybe_newline:
 | 
			
		|||
        p++;
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
	if ((parse_flags & PARSE_FLAG_ASM_FILE) == 0)
 | 
			
		||||
    	    tcc_error("unrecognized character \\x%02x", c);
 | 
			
		||||
    	else {
 | 
			
		||||
    	    tok = ' ';
 | 
			
		||||
    	    p++;
 | 
			
		||||
    	}
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    tok_flags = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -3215,7 +3227,8 @@ ST_FUNC int tcc_preprocess(TCCState *s1)
 | 
			
		|||
    preprocess_init(s1);
 | 
			
		||||
    ch = file->buf_ptr[0];
 | 
			
		||||
    tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
 | 
			
		||||
    parse_flags = PARSE_FLAG_ASM_COMMENTS | PARSE_FLAG_PREPROCESS |
 | 
			
		||||
    parse_flags = (parse_flags & PARSE_FLAG_ASM_FILE);
 | 
			
		||||
    parse_flags |= PARSE_FLAG_ASM_COMMENTS | PARSE_FLAG_PREPROCESS |
 | 
			
		||||
        PARSE_FLAG_LINEFEED | PARSE_FLAG_SPACES;
 | 
			
		||||
    token_seen = 0;
 | 
			
		||||
    file->line_ref = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue