From 78e4ee55b7243e856ad4257bd44564fd6a95bf91 Mon Sep 17 00:00:00 2001 From: seyko Date: Wed, 4 May 2016 16:54:40 +0300 Subject: [PATCH] PP_NUM in ASM mode oxe+1 is parsed as 0xe +1 if (parse_flags & PARSE_FLAG_ASM_FILE) Helps to compile a code: __asm__("mov $0xe" "+1", "%eax\n") --- tccpp.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/tccpp.c b/tccpp.c index 8c8560f..a040de4 100644 --- a/tccpp.c +++ b/tccpp.c @@ -2558,6 +2558,7 @@ static inline void next_nomacro1(void) TokenSym *ts; uint8_t *p, *p1; unsigned int h; + int is_dec; p = file->buf_ptr; redo_no_start: @@ -2752,23 +2753,45 @@ maybe_newline: } break; - case '0': case '1': case '2': case '3': + case '0': + t = c; + cstr_reset(&tokcstr); + cstr_ccat(&tokcstr, c); + PEEKC(c, p); + is_dec = 1; + if ((c == 'x') || (c == 'o') || (c == 'b')) + is_dec = 0; + goto parse_num; + + case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': + is_dec = 1; + t = c; cstr_reset(&tokcstr); - /* after the first digit, accept digits, alpha, '.' or sign if - prefixed by 'eEpP' */ + cstr_ccat(&tokcstr, c); + PEEKC(c, p); parse_num: for(;;) { + if (parse_flags & PARSE_FLAG_ASM_FILE) { + if (!((isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) + || (c == '.') + || ((c == '+' || c == '-') + && (((t == 'e' || t == 'E') && is_dec) || + ((t == 'p' || t == 'P') && !is_dec))) + )) + break; + } else + if (!((isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) + || c == '.' + || ((c == '+' || c == '-') + && (t == 'e' || t == 'E' || t == 'p' || t == 'P') + ))) + break; + t = c; cstr_ccat(&tokcstr, c); PEEKC(c, p); - if (!((isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) - || c == '.' - || ((c == '+' || c == '-') - && (t == 'e' || t == 'E' || t == 'p' || t == 'P') - ))) - break; } /* We add a trailing '\0' to ease parsing */ cstr_ccat(&tokcstr, '\0'); @@ -2782,6 +2805,8 @@ maybe_newline: /* special dot handling because it can also start a number */ PEEKC(c, p); if (isnum(c)) { + t = '.'; + is_dec = 1; cstr_reset(&tokcstr); cstr_ccat(&tokcstr, '.'); goto parse_num;