tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Get a token from char *


From: Thomas Preud'homme
Subject: Re: [Tinycc-devel] Get a token from char *
Date: Tue, 8 Feb 2011 14:53:33 +0100
User-agent: KMail/1.13.5 (Linux/2.6.32-5-amd64; KDE/4.4.5; x86_64; ; )

Le mardi 08 février 2011 14:29:04, grischka a écrit :
> Thomas Preud'homme wrote:
> > Hello all,
> > 
> > Is there a function to get the token from a supplied string, something
> > whose prototype would be: int get_tok_from_str(char *str)?
> > I made an improvement of my commit about assembly function label (commit
> > 9b09fc3) but when I wanted to push it a conflict made me realize another
> > attempt has been made which handle more pattern but just ignore label for
> > the moment (cf commit 264a1036). This commit parse the asm label as 2
> > distincts string: one user defined and one "API". So I'd need to create
> > a token for the concatenation in order to merge both code and do the
> > redirection.
> 
> This might be a misunderstanding.  String concatenation is nothing
> special with asm labels.  It is part of the normal C parsing rules:
>      puts("1" "2" "3");
> Accordingly
>     int bar() asm ("foo_" "bar" "_9");
> is eqivalent to
>     int bar() asm ("foo_bar_9");
> 
> parse_asm_str already does that.

I thought about it being equal to a normal string in C but I wasn't sure of 
the function which handle the concatenation. Anyway, that's precisely the 
function I used in my own patch but as the other patch used another method I 
thought there might be a reason, like the two part of the string needing to be 
handled seperately.

So I will drop that concatening code and just use parse_asm_str instead.
> 
> However I'm not sure that converting the asm label into a C token is
> the right thing.  For example, tcc already can use "__bound_malloc"
> instead of "malloc",  where "malloc" is the C token and "__bound_malloc"
> is the elf-symbol name.
Yes but IIRW it's done by a switch/case on a few known token. Here the list is 
dynamic as it depends on the asm label defined in the source so this would 
require some kind of hashtable and each time we find a token we must check 
whether it is in this table and use its asm label instead.

The scheme used in my patch is to only use the C token while compiling and 
then linking against the asm label at link time. Basically everything happen 
in external_sym and put_extern_sym2. There is just one line in external_sym to 
register the association between asm token and C token, and then 3 lines added 
in put_extern_sym2 to use the asm label if it exist. It may not be the cleaner 
way to do it, but at least it's a very short patch.
> 
> Btw. gnu asm labels can be used not only with functions but with data
> as well:  http://gcc.gnu.org/onlinedocs/gcc-4.5.2/gcc/Asm-Labels.html
I know, I also have a patch for this. Basically it works the same except that 
in the case of variable asm label it also works with non-extern declaration. 
I'll push the patch tonight.
> 
> --- grischka

Thomas Preud'homme

P.S. I drop the CC address I got from the commit entry as it is invalid.
> 
> > I looked at
> > tccpp.c but no function is used to get a token, it's done inside a rather
> > big function. Would it make sense to create a function for this? If so,
> > I don't feel confortable to do it myself, could someone who knows this
> > code well do it if it doesn't take too much time?
> > 
> > Best regards,
> > 
> > Thomas

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]