Re: [Tinycc-devel] Inserting spaces in output from -E

2016-05-04 Thread Michael Matz

Hi,

On Wed, 4 May 2016, Edmund Grimley Evans wrote:


Proposed patch attached. Proposed log message:

   Insert spaces between certain tokens when tcc is invoked with -E.

   Insert a space when it is required to prevent mistokenisation of
   the output, and also in a few cases where it is not strictly
   required, imitating GCC's behaviour.

Comments?


Yes: I like it much better than the previous attempt, it's changing the 
right place, the routine that actually writes stuff, instead of inside the 
tokenizer.  One remark: I believe in the tcc_preprocess routine s1->ppfp 
is always set, otherwise it wouldn't have been called.



Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] TOK_PPNUM for asm

2016-05-04 Thread Edmund Grimley Evans
> > Proposed patch: handle 0x1e+1 as 0x1e +1 if (parse_flags & 
> > PARSE_FLAG_ASM_FILE)
> 
> Please explain and justify exactly what you're trying to do. What do
> you believe the correct definition of a pp-number is when tokenising
> assembly? What definition does the GNU toolchain use?

Also, presumably there's a good reason why your patch modified 43
lines, rather than just one, as below. What is that reason?

diff --git a/tccpp.c b/tccpp.c
index ad35687..7dd6d36 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -2766,6 +2766,7 @@ maybe_newline:
   || c == '.'
   || ((c == '+' || c == '-')
   && (t == 'e' || t == 'E' || t == 'p' || t == 'P')
+  && !(parse_flags & PARSE_FLAG_ASM_FILE)
   )))
 break;
 }

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] Inserting spaces in output from -E

2016-05-04 Thread Edmund Grimley Evans
Proposed patch attached. Proposed log message:

Insert spaces between certain tokens when tcc is invoked with -E.

Insert a space when it is required to prevent mistokenisation of
the output, and also in a few cases where it is not strictly
required, imitating GCC's behaviour.

Comments?
diff --git a/TODO b/TODO
index bc7fb8b..e6e5b07 100644
--- a/TODO
+++ b/TODO
@@ -31,7 +31,6 @@ Bugs:
 - make libtcc fully reentrant (except for the compilation stage itself).
 - struct/union/enum definitions in nested scopes (see also Debian bug #770657)
 - __STDC_IEC_559__: float f(void) { static float x = 0.0 / 0.0; return x; }
-- preprocessor: #define Y(x) Z(x) {newline} #define X Y {newline} X(X(1))
 
 Portability:
 
@@ -94,7 +93,6 @@ Not critical:
 - handle void (__attribute__() *ptr)()
 - VLAs are implemented in a way that is not compatible with signals:
   http://lists.gnu.org/archive/html/tinycc-devel/2015-11/msg00018.html
-- output with -E should include spaces: #define n 0xe {newline} n+1
 
 Fixed (probably):
 
diff --git a/tccpp.c b/tccpp.c
index 94f0b5f..ad35687 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -3670,6 +3670,8 @@ ST_FUNC int tcc_preprocess(TCCState *s1)
 {
 BufferedFile **iptr;
 int token_seen, spcs, level;
+const char *sp_chars = ""; /* insert space before any of these */
+int prev_tok = 0;
 
 preprocess_init(s1);
 ch = file->buf_ptr[0];
@@ -3719,8 +3721,57 @@ ST_FUNC int tcc_preprocess(TCCState *s1)
 ++file->line_ref;
 token_seen = 0;
 }
-if (s1->ppfp)
-fputs(get_tok_str(tok, ), s1->ppfp);
+if (s1->ppfp) {
+const char *t = get_tok_str(tok, );
+if (strchr(sp_chars, t[0]) ||
+((tok >= TOK_IDENT || tok == TOK_PPNUM) &&
+ (prev_tok >= TOK_IDENT || prev_tok == TOK_PPNUM)))
+fputs(" ", s1->ppfp);
+fputs(t, s1->ppfp);
+prev_tok = tok;
+switch (tok) {
+case '+':
+sp_chars = "+=";
+break;
+case '-':
+sp_chars = "-=>";
+break;
+case '*':
+case '/':
+case '%':
+case '^':
+case '=':
+case '!':
+case TOK_A_SHL:
+case TOK_A_SAR:
+sp_chars = "=";
+break;
+case '&':
+sp_chars = "&=";
+break;
+case '|':
+sp_chars = "|=";
+break;
+case '<':
+sp_chars = "<=";
+break;
+case '>':
+sp_chars = ">=";
+break;
+case '.':
+sp_chars = ".";
+break;
+case '#':
+sp_chars = "#";
+break;
+case TOK_PPNUM:
+sp_chars = "+-";
+break;
+default:
+sp_chars = "";
+break;
+}
+}
 }
 
 return 0;
diff --git a/tests/pp/15.c b/tests/pp/15.c
index 28a12bd..dc2b8d1 100644
--- a/tests/pp/15.c
+++ b/tests/pp/15.c
@@ -19,3 +19,8 @@ return A + B;
 #define B1 C1+2
 #define C1 A1+3
 return A1 + B1;
+
+#define i() x
+#define n() 1
+i()i()n()n()i()
+i()+i()-n()+n()-
diff --git a/tests/pp/15.expect b/tests/pp/15.expect
index 7ccee4a..d3d3dd5 100644
--- a/tests/pp/15.expect
+++ b/tests/pp/15.expect
@@ -1,6 +1,26 @@
+
+
 Z(1)
 Z(Z(1))
 Z(Z(Z(Z(Z(1)
+
+
+
 return A + B;
+
+
+
+
+
+
 return A+1 + B+1;
+
+
+
+
 return A1+3 +2 +1 + B1+1 +3 +2;
+
+
+
+x x 1 1 x
+x+x-1 +1 -
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] TOK_PPNUM for asm

2016-05-04 Thread Edmund Grimley Evans
Sergey Korshunoff :

> Proposed patch: handle 0x1e+1 as 0x1e +1 if (parse_flags & 
> PARSE_FLAG_ASM_FILE)

Please explain and justify exactly what you're trying to do. What do
you believe the correct definition of a pp-number is when tokenising
assembly? What definition does the GNU toolchain use?

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] 85-asm-outside-function.c on non Intel

2016-05-04 Thread Edmund Grimley Evans
> There is SKIP variable in test/test2/Makefile which holds test to skip.
> You can test modifications and I not.

Probably no one can test on every architecture and OS, but you could
at least make a reasonable effort not to break it on all systems apart
from your own.

I'm going to attempt a patch, but I can't test it either... and you
haven't even told us whether that test is supposed to work on both
i386 and x86-64...

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] 85-asm-outside-function.c on non Intel

2016-05-04 Thread Sergey Korshunoff
> Can you please check processor and adapt this test otherwise I get:

There is SKIP variable in test/test2/Makefile which holds test to skip.
You can test modifications and I not.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] 85-asm-outside-function.c on non Intel

2016-05-04 Thread Christian Jullien
Hi,

 

TinyCC works on different architecture, among them is ARM I especially care
about for my RPi.

 

85-asm-outside-function.c now includes test that fails on this architecture.

 

Can you please check processor and adapt this test otherwise I get:

 

Test: 85-asm-outside-function...

--- 85-asm-outside-function.expect  2016-05-04 08:06:10.407398268 +0200

+++ 85-asm-outside-function.output  2016-05-04 08:06:34.727274286 +0200

@@ -0,0 +1 @@

+85-asm-outside-function.c:2: error: inline asm() not supported

 

The same is true for many months with test 78:

Test: 78_vla_label...

--- 78_vla_label.expect 2016-05-04 08:06:10.397398319 +0200

+++ 78_vla_label.output 2016-05-04 08:06:34.577275051 +0200

@@ -1,6 +1 @@

-boom!

-boom!

-11

-12

-0

-1

+78_vla_label.c:6: error: variable length arrays unsupported for this target

Makefile:60: recipe for target '78_vla_label.test' failed

make[2]: *** [78_vla_label.test] Error 1

Test: 79_vla_continue...

--- 79_vla_continue.expect  2016-05-04 08:06:10.397398319 +0200

+++ 79_vla_continue.output  2016-05-04 08:06:34.597274949 +0200

@@ -1,5 +1 @@

-OK

-OK

-OK

-OK

-OK

+79_vla_continue.c:13: error: variable length arrays unsupported for this
target

Makefile:60: recipe for target '79_vla_continue.test' failed

make[2]: *** [79_vla_continue.test] Error 1

 

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel