History

tccpp : "tcc -E -P" : suppress empty lines

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

grischka committed 10 years ago

Commit 71b16f41 parent 78c08899 files · +82 −89Browse files

Unified · Split

9 files
  1. tcc.h +35 −73
  2. tccgen.c +1 −1
  3. tccpp.c +13 −7
  4. tests/pp/02.expect +2 −3
  5. tests/pp/13.expect +0 −3
  6. tests/pp/15.c +18 −0
  7. tests/pp/15.expect +7 −0
  8. tests/pp/Makefile +2 −2
  9. tests/tcctest.c +4 −0
tcc.h+35−73
@@ -324,12 +324,6 @@ · 323 unmodified lines
324324 #define TOK_HASH_SIZE 16384 /* must be a power of two */
325325 #define TOK_ALLOC_INCR 512 /* must be a power of two */
326326 #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
333327
334328 /* token symbol management */
335329 typedef struct TokenSym {
@@ -1021,42 +1015,15 @@ enum tcc_token { · 685 unmodified lines
10211015 #undef DEF
10221016 };
10231017
1018+/* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */
10241019 #define TOK_UIDENT TOK_DEFINE
10251020
1026−/* space exlcuding newline */
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−}
1021+/* -------------------------------------------- */
10511022
1052−#ifndef PUB_FUNC
1023+#ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */
10531024 # define PUB_FUNC
10541025 #endif
10551026
1056−#ifdef TCC_PROFILE /* profile all functions */
1057−# define static
1058−#endif
1059−
10601027 #ifdef ONE_SOURCE
10611028 #define ST_INLN static inline
10621029 #define ST_FUNC static
@@ -1067,6 +1034,10 @@ static inline int toup(int c) · 4 unmodified lines
10671034 #define ST_DATA extern
10681035 #endif
10691036
1037+#ifdef TCC_PROFILE /* profile all functions */
1038+# define static
1039+#endif
1040+
10701041 /* ------------ libtcc.c ------------ */
10711042
10721043 /* use GNU C extensions */
@@ -1240,6 +1211,23 @@ ST_FUNC int tcc_preprocess(TCCState *s1); · 167 unmodified lines
12401211 ST_FUNC void skip(int c);
12411212 ST_FUNC NORETURN void expect(const char *msg);
12421213
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+
12431231 /* ------------ tccgen.c ------------ */
12441232
12451233 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
14221410 ST_FUNC void gen_vla_sp_restore(int addr);
14231411 ST_FUNC void gen_vla_alloc(CType *type, int align);
14241412
1425−static inline uint16_t read16le(unsigned char *p)
1426−{
1413+static inline uint16_t read16le(unsigned char *p) {
14271414 return p[0] | (uint16_t)p[1] << 8;
14281415 }
1429−
1430−static inline void write16le(unsigned char *p, uint16_t x)
1431−{
1432− p[0] = x & 255;
1433− p[1] = x >> 8 & 255;
1416+static inline void write16le(unsigned char *p, uint16_t x) {
1417+ p[0] = x & 255, p[1] = x >> 8 & 255;
14341418 }
1435−
1436−static inline uint32_t read32le(unsigned char *p)
1437−{
1438− return (p[0] | (uint32_t)p[1] << 8 |
1439− (uint32_t)p[2] << 16 | (uint32_t)p[3] << 24);
1419+static inline uint32_t read32le(unsigned char *p) {
1420+ return read16le(p) | (uint32_t)read16le(p + 2) << 16;
14401421 }
1441−
1442−static inline void write32le(unsigned char *p, uint32_t x)
1443−{
1444− p[0] = x & 255;
1445− p[1] = x >> 8 & 255;
1446− p[2] = x >> 16 & 255;
1447− p[3] = x >> 24 & 255;
1422+static inline void write32le(unsigned char *p, uint32_t x) {
1423+ write16le(p, x), write16le(p + 2, x >> 16);
14481424 }
1449−
1450−static inline uint64_t read64le(unsigned char *p)
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);
1425+static inline uint64_t read64le(unsigned char *p) {
1426+ return read32le(p) | (uint64_t)read32le(p + 4) << 32;
14561427 }
1457−
1458−static inline void write64le(unsigned char *p, uint64_t x)
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;
1428+static inline void write64le(unsigned char *p, uint64_t x) {
1429+ write32le(p, x), write32le(p + 4, x >> 32);
14681430 }
14691431
14701432 /* ------------ i386-gen.c ------------ */
tccgen.c+1−1
@@ -6334,7 +6334,7 @@ static int decl0(int l, int is_for_loop_init) · 6333 unmodified lines
63346334 }
63356335 /* special test for old K&R protos without explicit int
63366336 type. Only accepted when defining global data */
6337− if (l == VT_LOCAL || tok < TOK_DEFINE)
6337+ if (l == VT_LOCAL || tok < TOK_UIDENT)
63386338 break;
63396339 btype.t = VT_INT;
63406340 }
tccpp.c+13−7
@@ -127,12 +127,19 @@ ST_FUNC void expect(const char *msg) · 126 unmodified lines
127127 #define TAL_DEBUG_PARAMS
128128 #else
129129 #define TAL_DEBUG 1
130+//#define TAL_INFO 1 /* collect and dump allocators stats */
130131 #define tal_free(al, p) tal_free_impl(al, p, __FILE__, __LINE__)
131132 #define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size, __FILE__, __LINE__)
132133 #define TAL_DEBUG_PARAMS , const char *file, int line
133134 #define TAL_DEBUG_FILE_LEN 15
134135 #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
136143
137144 typedef struct TinyAlloc {
138145 size_t limit;
@@ -3039,7 +3046,8 @@ static int next_argstream(Sym **nested_list, int can_read_stream, TokenString *w · 2900 unmodified lines
30393046 break;
30403047 ch = ' ';
30413048 }
3042− tok_str_add(ws_str, ch);
3049+ if (!(ch == '\f' || ch == '\v' || ch == '\r'))
3050+ tok_str_add(ws_str, ch);
30433051 cinp();
30443052 }
30453053 }
@@ -3569,15 +3577,13 @@ static void tok_print(const char *msg, const int *str) · 523 unmodified lines
35693577 static void pp_line(TCCState *s1, BufferedFile *f, int level)
35703578 {
35713579 int d = f->line_num - f->line_ref;
3580+
35723581 if (s1->dflag & 4)
35733582 return;
3583+
35743584 if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE) {
3575− if (level == 0 && f->line_ref && d) {
3576− d = 1;
3577− goto simple;
3578− }
3585+ ;
35793586 } else if (level == 0 && f->line_ref && d < 8) {
3580−simple:
35813587 while (d > 0)
35823588 fputs("\n", s1->ppfp), --d;
35833589 } else if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) {
tests/pp/02.expect+2−3
@@ -1,6 +1,5 @@
11 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);
3−
2+f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
43 char c[2][6] = { "hello", "" };
54 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);
tests/pp/13.expect+0−3
@@ -1,6 +1,3 @@
11 # `modelist' label. Each video mode record looks like:
2−
3−
4−
52 .text
63 endtext:
tests/pp/15.c+18−0
@@ -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);
tests/pp/15.expect+7−0
@@ -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;
tests/pp/Makefile+2−2
@@ -40,8 +40,8 @@ DIFF_OPTS = -Nu -b -B -I "^\#" · 39 unmodified lines
4040 clean:
4141 rm -vf *.output
4242
43−# 02.test : DIFF_OPTS += -w
44−# 15.test : DIFF_OPTS += -w
43+02.test : DIFF_OPTS += -w
44+15.test : DIFF_OPTS += -I"^XXX:"
4545
4646 # diff options:
4747 # -b ighore space changes
tests/tcctest.c+4−0
@@ -2573,6 +2573,10 @@ void asm_test(void) · 2572 unmodified lines
25732573 unsigned int val;
25742574
25752575 printf("inline asm:\n");
2576+
2577+ // parse 0x1E-1 as 3 tokens in asm mode
2578+ asm volatile ("mov $0x1E-1,%eax");
2579+
25762580 /* test the no operand case */
25772581 asm volatile ("xorl %eax, %eax");
25782582

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