I tried creating a TinyCC target for asm.js and never really found a clean way to do it because of lack of goto. My goal was to build an in-browser compiler for cheap wifi microcontrollers, the ESP8266 which could let you write code, compile it and run it without the need for a development system like Arduino. There isn't xtensa support, but that wouldn't be hard to add.
It turned all functions into whiles with complicated switch states. I got most of the control flow stuff working but it was AWFUL... And I ran into the same issue with WebAssembly. There was an interesting thread here: https://github.com/WebAssembly/design/issues/796 which has been one heck of a revealing thread between the two camps, where the general argument goes:
(1) But Goto. No, really goto. (2) Eh, we don't need goto and there's this boogyman we're worried about with it and it's dirty and makes us feel dirty. (3) But really, this is paaainful for compiler writers. (4) Use relooper. (5) There's literally only one implementation and it's in C++. (6) Use the C++ implementation. (7) see 1.
I urge any person who is thinking about getting into languages to read that thread to see how wild and dogmatic these things can get.
On Wed, Feb 12, 2020 at 9:21 PM Christian Jullien <[hidden email]> wrote:
I’m not aware of any efforts to create a wasm backend for tinycc but this is something very interesting to consider.
On Fri, Feb 14, 2020 at 03:58:09AM -0800, Charles Lohr wrote:
> There isn't xtensa support, but that wouldn't be hard to add.
Adding support for a specific Xtensa chip wouldn't be hard, but Xtensa
allows the instruction set to be modified in various different ways when
the cpu core is synthesized. GCC had support for Xtensa for several years
before the ESP8266 came along, but it took some time until GCC learnt how
to deal with the call0 calling conventions necessary for this chip.
The tools provided by Tensilica to chipmakers spit out header files with
lots of defines that you have to use in a compiler to know how to
generate code for a particular chip.