Also: - regenerate all tests/pp/*.expect with gcc - test "insert one space" feature - test "0x1E-1" in asm mode case - PARSE_FLAG_SPACES: ignore \f\v\r better - tcc.h: move some things
Unified · Split
| @@ -324,12 +324,6 @@ · 323 unmodified lines | |||
| 324 | #define TOK_HASH_SIZE 16384 /* must be a power of two */ | 324 | #define TOK_HASH_SIZE 16384 /* must be a power of two */ |
| 325 | #define TOK_ALLOC_INCR 512 /* must be a power of two */ | 325 | #define TOK_ALLOC_INCR 512 /* must be a power of two */ |
| 326 | #define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */ | 326 | #define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */ |
| 327 | #define TOKSYM_TAL_SIZE (768 * 1024) /* allocator for tiny TokenSym in table_ident */ | ||
| 328 | #define TOKSTR_TAL_SIZE (768 * 1024) /* allocator for tiny TokenString instances */ | ||
| 329 | #define CSTR_TAL_SIZE (256 * 1024) /* allocator for tiny CString instances */ | ||
| 330 | #define TOKSYM_TAL_LIMIT 256 /* prefer unique limits to distinguish allocators debug msgs */ | ||
| 331 | #define TOKSTR_TAL_LIMIT 128 /* 32 * sizeof(int) */ | ||
| 332 | #define CSTR_TAL_LIMIT 1024 | ||
| 333 | 327 | ||
| 334 | /* token symbol management */ | 328 | /* token symbol management */ |
| 335 | typedef struct TokenSym { | 329 | typedef struct TokenSym { |
| @@ -1021,42 +1015,15 @@ enum tcc_token { · 685 unmodified lines | |||
| 1021 | #undef DEF | 1015 | #undef DEF |
| 1022 | }; | 1016 | }; |
| 1023 | 1017 | ||
| 1018 | /* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */ | ||
| 1024 | #define TOK_UIDENT TOK_DEFINE | 1019 | #define TOK_UIDENT TOK_DEFINE |
| 1025 | 1020 | ||
| 1026 | /* space exlcuding newline */ | 1021 | /* -------------------------------------------- */ |
| 1027 | static inline int is_space(int ch) | ||
| 1028 | { | ||
| 1029 | return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r'; | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | static inline int isid(int c) | ||
| 1033 | { | ||
| 1034 | return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; | ||
| 1035 | } | ||
| 1036 | |||
| 1037 | static inline int isnum(int c) | ||
| 1038 | { | ||
| 1039 | return c >= '0' && c <= '9'; | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | static inline int isoct(int c) | ||
| 1043 | { | ||
| 1044 | return c >= '0' && c <= '7'; | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | static inline int toup(int c) | ||
| 1048 | { | ||
| 1049 | return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; | ||
| 1050 | } | ||
| 1051 | 1022 | ||
| 1052 | #ifndef PUB_FUNC | 1023 | #ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */ |
| 1053 | # define PUB_FUNC | 1024 | # define PUB_FUNC |
| 1054 | #endif | 1025 | #endif |
| 1055 | 1026 | ||
| 1056 | #ifdef TCC_PROFILE /* profile all functions */ | ||
| 1057 | # define static | ||
| 1058 | #endif | ||
| 1059 | |||
| 1060 | #ifdef ONE_SOURCE | 1027 | #ifdef ONE_SOURCE |
| 1061 | #define ST_INLN static inline | 1028 | #define ST_INLN static inline |
| 1062 | #define ST_FUNC static | 1029 | #define ST_FUNC static |
| @@ -1067,6 +1034,10 @@ static inline int toup(int c) · 4 unmodified lines | |||
| 1067 | #define ST_DATA extern | 1034 | #define ST_DATA extern |
| 1068 | #endif | 1035 | #endif |
| 1069 | 1036 | ||
| 1037 | #ifdef TCC_PROFILE /* profile all functions */ | ||
| 1038 | # define static | ||
| 1039 | #endif | ||
| 1040 | |||
| 1070 | /* ------------ libtcc.c ------------ */ | 1041 | /* ------------ libtcc.c ------------ */ |
| 1071 | 1042 | ||
| 1072 | /* use GNU C extensions */ | 1043 | /* use GNU C extensions */ |
| @@ -1240,6 +1211,23 @@ ST_FUNC int tcc_preprocess(TCCState *s1); · 167 unmodified lines | |||
| 1240 | ST_FUNC void skip(int c); | 1211 | ST_FUNC void skip(int c); |
| 1241 | ST_FUNC NORETURN void expect(const char *msg); | 1212 | ST_FUNC NORETURN void expect(const char *msg); |
| 1242 | 1213 | ||
| 1214 | /* space exlcuding newline */ | ||
| 1215 | static inline int is_space(int ch) { | ||
| 1216 | return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r'; | ||
| 1217 | } | ||
| 1218 | static inline int isid(int c) { | ||
| 1219 | return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; | ||
| 1220 | } | ||
| 1221 | static inline int isnum(int c) { | ||
| 1222 | return c >= '0' && c <= '9'; | ||
| 1223 | } | ||
| 1224 | static inline int isoct(int c) { | ||
| 1225 | return c >= '0' && c <= '7'; | ||
| 1226 | } | ||
| 1227 | static inline int toup(int c) { | ||
| 1228 | return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; | ||
| 1229 | } | ||
| 1230 | |||
| 1243 | /* ------------ tccgen.c ------------ */ | 1231 | /* ------------ tccgen.c ------------ */ |
| 1244 | 1232 | ||
| 1245 | ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */ | 1233 | ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */ |
| @@ -1422,49 +1410,23 @@ ST_FUNC void gen_vla_sp_save(int addr); · 176 unmodified lines | |||
| 1422 | ST_FUNC void gen_vla_sp_restore(int addr); | 1410 | ST_FUNC void gen_vla_sp_restore(int addr); |
| 1423 | ST_FUNC void gen_vla_alloc(CType *type, int align); | 1411 | ST_FUNC void gen_vla_alloc(CType *type, int align); |
| 1424 | 1412 | ||
| 1425 | static inline uint16_t read16le(unsigned char *p) | 1413 | static inline uint16_t read16le(unsigned char *p) { |
| 1426 | { | ||
| 1427 | return p[0] | (uint16_t)p[1] << 8; | 1414 | return p[0] | (uint16_t)p[1] << 8; |
| 1428 | } | 1415 | } |
| 1429 | 1416 | static inline void write16le(unsigned char *p, uint16_t x) { | |
| 1430 | static inline void write16le(unsigned char *p, uint16_t x) | 1417 | p[0] = x & 255, p[1] = x >> 8 & 255; |
| 1431 | { | ||
| 1432 | p[0] = x & 255; | ||
| 1433 | p[1] = x >> 8 & 255; | ||
| 1434 | } | 1418 | } |
| 1435 | 1419 | static inline uint32_t read32le(unsigned char *p) { | |
| 1436 | static inline uint32_t read32le(unsigned char *p) | 1420 | return read16le(p) | (uint32_t)read16le(p + 2) << 16; |
| 1437 | { | ||
| 1438 | return (p[0] | (uint32_t)p[1] << 8 | | ||
| 1439 | (uint32_t)p[2] << 16 | (uint32_t)p[3] << 24); | ||
| 1440 | } | 1421 | } |
| 1441 | 1422 | static inline void write32le(unsigned char *p, uint32_t x) { | |
| 1442 | static inline void write32le(unsigned char *p, uint32_t x) | 1423 | write16le(p, x), write16le(p + 2, x >> 16); |
| 1443 | { | ||
| 1444 | p[0] = x & 255; | ||
| 1445 | p[1] = x >> 8 & 255; | ||
| 1446 | p[2] = x >> 16 & 255; | ||
| 1447 | p[3] = x >> 24 & 255; | ||
| 1448 | } | 1424 | } |
| 1449 | 1425 | static inline uint64_t read64le(unsigned char *p) { | |
| 1450 | static inline uint64_t read64le(unsigned char *p) | 1426 | return read32le(p) | (uint64_t)read32le(p + 4) << 32; |
| 1451 | { | ||
| 1452 | return (p[0] | (uint64_t)p[1] << 8 | | ||
| 1453 | (uint64_t)p[2] << 16 | (uint64_t)p[3] << 24 | | ||
| 1454 | (uint64_t)p[4] << 32 | (uint64_t)p[5] << 40 | | ||
| 1455 | (uint64_t)p[6] << 48 | (uint64_t)p[7] << 56); | ||
| 1456 | } | 1427 | } |
| 1457 | 1428 | static inline void write64le(unsigned char *p, uint64_t x) { | |
| 1458 | static inline void write64le(unsigned char *p, uint64_t x) | 1429 | write32le(p, x), write32le(p + 4, x >> 32); |
| 1459 | { | ||
| 1460 | p[0] = x & 255; | ||
| 1461 | p[1] = x >> 8 & 255; | ||
| 1462 | p[2] = x >> 16 & 255; | ||
| 1463 | p[3] = x >> 24 & 255; | ||
| 1464 | p[4] = x >> 32 & 255; | ||
| 1465 | p[5] = x >> 40 & 255; | ||
| 1466 | p[6] = x >> 48 & 255; | ||
| 1467 | p[7] = x >> 56 & 255; | ||
| 1468 | } | 1430 | } |
| 1469 | 1431 | ||
| 1470 | /* ------------ i386-gen.c ------------ */ | 1432 | /* ------------ i386-gen.c ------------ */ |
| @@ -6334,7 +6334,7 @@ static int decl0(int l, int is_for_loop_init) · 6333 unmodified lines | |||
| 6334 | } | 6334 | } |
| 6335 | /* special test for old K&R protos without explicit int | 6335 | /* special test for old K&R protos without explicit int |
| 6336 | type. Only accepted when defining global data */ | 6336 | type. Only accepted when defining global data */ |
| 6337 | if (l == VT_LOCAL || tok < TOK_DEFINE) | 6337 | if (l == VT_LOCAL || tok < TOK_UIDENT) |
| 6338 | break; | 6338 | break; |
| 6339 | btype.t = VT_INT; | 6339 | btype.t = VT_INT; |
| 6340 | } | 6340 | } |
| @@ -127,12 +127,19 @@ ST_FUNC void expect(const char *msg) · 126 unmodified lines | |||
| 127 | #define TAL_DEBUG_PARAMS | 127 | #define TAL_DEBUG_PARAMS |
| 128 | #else | 128 | #else |
| 129 | #define TAL_DEBUG 1 | 129 | #define TAL_DEBUG 1 |
| 130 | //#define TAL_INFO 1 /* collect and dump allocators stats */ | ||
| 130 | #define tal_free(al, p) tal_free_impl(al, p, __FILE__, __LINE__) | 131 | #define tal_free(al, p) tal_free_impl(al, p, __FILE__, __LINE__) |
| 131 | #define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size, __FILE__, __LINE__) | 132 | #define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size, __FILE__, __LINE__) |
| 132 | #define TAL_DEBUG_PARAMS , const char *file, int line | 133 | #define TAL_DEBUG_PARAMS , const char *file, int line |
| 133 | #define TAL_DEBUG_FILE_LEN 15 | 134 | #define TAL_DEBUG_FILE_LEN 15 |
| 134 | #endif | 135 | #endif |
| 135 | //#define TAL_INFO 1 /* collect and dump allocators stats */ | 136 | |
| 137 | #define TOKSYM_TAL_SIZE (768 * 1024) /* allocator for tiny TokenSym in table_ident */ | ||
| 138 | #define TOKSTR_TAL_SIZE (768 * 1024) /* allocator for tiny TokenString instances */ | ||
| 139 | #define CSTR_TAL_SIZE (256 * 1024) /* allocator for tiny CString instances */ | ||
| 140 | #define TOKSYM_TAL_LIMIT 256 /* prefer unique limits to distinguish allocators debug msgs */ | ||
| 141 | #define TOKSTR_TAL_LIMIT 128 /* 32 * sizeof(int) */ | ||
| 142 | #define CSTR_TAL_LIMIT 1024 | ||
| 136 | 143 | ||
| 137 | typedef struct TinyAlloc { | 144 | typedef struct TinyAlloc { |
| 138 | size_t limit; | 145 | size_t limit; |
| @@ -3039,7 +3046,8 @@ static int next_argstream(Sym **nested_list, int can_read_stream, TokenString *w · 2900 unmodified lines | |||
| 3039 | break; | 3046 | break; |
| 3040 | ch = ' '; | 3047 | ch = ' '; |
| 3041 | } | 3048 | } |
| 3042 | tok_str_add(ws_str, ch); | 3049 | if (!(ch == '\f' || ch == '\v' || ch == '\r')) |
| 3050 | tok_str_add(ws_str, ch); | ||
| 3043 | cinp(); | 3051 | cinp(); |
| 3044 | } | 3052 | } |
| 3045 | } | 3053 | } |
| @@ -3569,15 +3577,13 @@ static void tok_print(const char *msg, const int *str) · 523 unmodified lines | |||
| 3569 | static void pp_line(TCCState *s1, BufferedFile *f, int level) | 3577 | static void pp_line(TCCState *s1, BufferedFile *f, int level) |
| 3570 | { | 3578 | { |
| 3571 | int d = f->line_num - f->line_ref; | 3579 | int d = f->line_num - f->line_ref; |
| 3580 | |||
| 3572 | if (s1->dflag & 4) | 3581 | if (s1->dflag & 4) |
| 3573 | return; | 3582 | return; |
| 3583 | |||
| 3574 | if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE) { | 3584 | if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE) { |
| 3575 | if (level == 0 && f->line_ref && d) { | 3585 | ; |
| 3576 | d = 1; | ||
| 3577 | goto simple; | ||
| 3578 | } | ||
| 3579 | } else if (level == 0 && f->line_ref && d < 8) { | 3586 | } else if (level == 0 && f->line_ref && d < 8) { |
| 3580 | simple: | ||
| 3581 | while (d > 0) | 3587 | while (d > 0) |
| 3582 | fputs("\n", s1->ppfp), --d; | 3588 | fputs("\n", s1->ppfp), --d; |
| 3583 | } else if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) { | 3589 | } else if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) { |
| @@ -1,6 +1,5 @@ | |||
| 1 | f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); | 1 | f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); |
| 2 | f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); | 2 | f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); |
| 3 | |||
| 4 | char c[2][6] = { "hello", "" }; | 3 | char c[2][6] = { "hello", "" }; |
| 5 | f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); | 4 | f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1); |
| 6 | f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); | 5 | f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1); |
| @@ -1,6 +1,3 @@ | |||
| 1 | # `modelist' label. Each video mode record looks like: | 1 | # `modelist' label. Each video mode record looks like: |
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | .text | 2 | .text |
| 6 | endtext: | 3 | endtext: |
| @@ -0,0 +1,18 @@ | |||
| 1 | // insert a space between two tokens if otherwise they | ||
| 2 | // would form a single token when read back | ||
| 3 | |||
| 4 | #define n(x) x | ||
| 5 | |||
| 6 | return (n(long)n(double))d; | ||
| 7 | return n(A)n(++)n(+)n(B); | ||
| 8 | return n(A)n(+)n(++)n(B); | ||
| 9 | return n(A)n(++)n(+)n(+)n(B); | ||
| 10 | |||
| 11 | // not a hex float | ||
| 12 | return n(0x1E)n(-1); | ||
| 13 | |||
| 14 | // unlike gcc but correct | ||
| 15 | XXX: return n(x)+n(x)-n(1)+n(1)-2; | ||
| 16 | |||
| 17 | // unlile gcc, but cannot appear in valid C | ||
| 18 | XXX: return n(x)n(x)n(1)n(2)n(x); | ||
| @@ -0,0 +1,7 @@ | |||
| 1 | return (long double)d; | ||
| 2 | return A+++B; | ||
| 3 | return A+ ++B; | ||
| 4 | return A+++ +B; | ||
| 5 | return 0x1E -1; | ||
| 6 | XXX: return x+x-1 +1 -2; | ||
| 7 | XXX: return x x 1 2 x; | ||
| @@ -40,8 +40,8 @@ DIFF_OPTS = -Nu -b -B -I "^\#" · 39 unmodified lines | |||
| 40 | clean: | 40 | clean: |
| 41 | rm -vf *.output | 41 | rm -vf *.output |
| 42 | 42 | ||
| 43 | # 02.test : DIFF_OPTS += -w | 43 | 02.test : DIFF_OPTS += -w |
| 44 | # 15.test : DIFF_OPTS += -w | 44 | 15.test : DIFF_OPTS += -I"^XXX:" |
| 45 | 45 | ||
| 46 | # diff options: | 46 | # diff options: |
| 47 | # -b ighore space changes | 47 | # -b ighore space changes |
| @@ -2573,6 +2573,10 @@ void asm_test(void) · 2572 unmodified lines | |||
| 2573 | unsigned int val; | 2573 | unsigned int val; |
| 2574 | 2574 | ||
| 2575 | printf("inline asm:\n"); | 2575 | printf("inline asm:\n"); |
| 2576 | |||
| 2577 | // parse 0x1E-1 as 3 tokens in asm mode | ||
| 2578 | asm volatile ("mov $0x1E-1,%eax"); | ||
| 2579 | |||
| 2576 | /* test the no operand case */ | 2580 | /* test the no operand case */ |
| 2577 | asm volatile ("xorl %eax, %eax"); | 2581 | asm volatile ("xorl %eax, %eax"); |
| 2578 | 2582 | ||