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. :-)
> From: Zden??k Pavlas <zde...@gmail.com>
> Date: Thu, 15 Sep 2016 11:09:30 +0200
> To: firstname.lastname@example.org
> Subject: [Tinycc-devel] Patch for review - duplicate case label checking in
> 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
> 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.
Tinycc-devel mailing list