tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Patch for review - duplicate case label checking in s


From: Aharon Robbins
Subject: Re: [Tinycc-devel] Patch for review - duplicate case label checking in switches
Date: Fri, 16 Sep 2016 15:02:07 +0300
User-agent: Heirloom mailx 12.5 6/20/10

Hello.

Thanks for this note and for looking at my patch.

I'm sure that all the stuff you suggest is doable and worth doing.
But I'm afraid it won't be done by me.

I invested less than 2 hours total in my patch and it meets my needs.

I don't have the time or cycles to invest in learning enough about tcc
internals to do what you suggest.  Nor does tcc's code quality make that
much difference to me; I use tcc for development where I need fast
compiles and correct code, not for production.

We can hope that someone else will take up the challenge. :-)

Thanks,

Arnold

> From: Zden??k Pavlas <address@hidden>
> Date: Thu, 15 Sep 2016 11:09:30 +0200
> Message-ID: <address@hidden>
> To: address@hidden
> Subject: [Tinycc-devel] Patch for review - duplicate case label checking in
>  switches
>
> Hi Arnold,
>
> The current TOK_SWITCH/TOK_CASE code clearly prefers simplicity over
> performance and features. It was just fine for OTCC but I agree with
> you it should be improved.
>
> However, I don't like this patch, because it adds time+space complexity
> without improving generated code in any way. Also, case ranges are not
> handled properly (eg 1..3 + 2 are incorrectly accepted).
>
> With just a little bit more effort, you can do much better.
>
> - switch_start: generate code that loads a reference to the case table
>   and calls a function in libtcc.
>
> - TOK_CASE: add a literal (or literal range) to the table. Don't generate
>   any code, just gather current code offsets.
>
> - switch_end: sort the table. Check for duplicates (now that's for free).
>   Emit the table to some section (if it's not the current code section
>   you don't have to generate extra jumps), and fix up the symbol reference
>   taken in switch_start.
>
> The runtime function performs a binary search over the sorted array and
> jumps
> to the corresponding code block. Things as defaults and case ranges make it
> a bit more complex. Also, note that switch statements can be nested..
>
> Still, even with all this in place, I believe it probably should not be
> significantly more difficult than this.
>
> regards,
> Zdenek



reply via email to

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