[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] [RFC] tinycc and rock compiler
From: |
Jared Maddox |
Subject: |
Re: [Tinycc-devel] [RFC] tinycc and rock compiler |
Date: |
Sun, 30 Aug 2015 20:11:40 -0500 |
> Date: Sun, 30 Aug 2015 04:53:49 +0300
> From: Sergey Korshunoff <address@hidden>
> To: address@hidden
> Subject: [Tinycc-devel] [RFC] tinycc and rock compiler
> Message-ID:
> <address@hidden>
> Content-Type: text/plain; charset=UTF-8
>
> Hi all!
> I think there is a problem wiith using tcc for compiling a rock parser
> sources. Some snippet (NagaQueen.c):
>
> if (!yymatchClass(G, (const unsigned char
> *)"\000\000\000\000\000\000\377\003\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
> "a-zA-Z0-9_")) goto l920;
>
> l921:;
> { int yypos922= G->pos, yythunkpos922= G->thunkpos;
> if (!yymatchClass(G, (const unsigned char
> *)"\000\000\000\000\000\000\377\003\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
> "a-zA-Z0-9_")) goto l922;
>
> And a test program:
>
> #include <stdio.h>
> int main()
> {
> const char *const p1 = "1234567890qwertyuiopasdfghjklzxcvbnm";
> const char *const p2 = "1234567890qwertyuiopasdfghjklzxcvbnm";
> if (p1 == p2 )
> printf("OK\n");
> else
> printf("There is a problem\n");
> }
>
> A gcc output: OK
> A tcc output: There is a problem
>
> A proposal: introduce a string constant cache in a function scope
> level (like this is done for the identifers). Would this help for a
> general purpose programs? How often this programming style is used?
>
> PS: this is only a size of the produced exe problem
>
If Rock depends on this, then Rock should be re-written to not depend
on this. Assuming that the strings originate from whatever Rock parses
instead of being from the code actually doing that parsing, then
allocating a global or static const char* for each string, merging
duplicates, sticking these const char* variables in a different file,
using their names instead of the strings themselves, and then
outputting the string file ahead of the rest of the translated code
should do the trick.
> Date: Sun, 30 Aug 2015 08:22:52 +0200
> From: "Christian Jullien" <address@hidden>
> To: <address@hidden>
> Subject: Re: [Tinycc-devel] [RFC] tinycc and rock compiler
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset="iso-8859-1"
>
> This is not a BUG but a feature that C compliers often propose (for example,
> VC++ has: /GF enable read-only string pooling)
> Strictly speaking, tcc is right with this behavior and no portable programs
> should rely on this feature.
>
> If you want a faster code when this feature exists you should write:
>
> if ((p1 == p2) || strcmp(p1,p2) == 0 )
> printf("OK\n");
> else
> printf("There is a problem\n");
> }
>
> IMHO having this feature with tcc should be with a new option.
>
> C.
>
Ideally a linker option. Does TCC default to putting each string in a
distinct portion of it's output object files?