I'm a HUGE fan of TCC -- I've recently added a pretty cool feature to simavr: a way to translate the whole AVR core into 'C' and JIT compile it using libtcc (the backend of tcc).
That's awesome, can you give a quick rundown here, or have you blogged about it? One question I have is around symbol resolution. Can the in memory piece of tcc compiled code see all the symbols in your program (ie the host exe) for example?
I haven't posted about it yet, as I wanted to clean up the branch before I do, and I ran out of time; work to catch up and so on :-)
libtcc is /massively/ clever, it will 'link back' to your (exported) ELF symbols automatically. Basically it links the piece of code to your current running process, with all it's libs etc.
So if you have a function blob(int); in your main program, just call it from the C you generate, and it'll Just Works.
For my own purpose, I decided to trim down the headers I would have to include in the generated C and made some sort of simpler 'trampoline', but it's not strictly necessary.
Tiny C compiler (tcc) is really cool. I used it as a test case in my diverse double-compiling (DDC) work to counter the trusting trust attack: http://www.dwheeler.com/trusting-trust/
There has been some continued development of tcc; the GitHub repository here has changes through April 2016: https://github.com/TinyCC/tinycc
Mob is the main development branch, open to all. Master is the release branch, and as no release has been cut for a couple of years, it is indeed rather stale.
edit: If you want to get an idea about what happens in TCC-land, you should check out the mailing list archives [1], eg a recent-ish status update [2].
Another I found doing research for human-verifiable builds was the LCC compiler. It's specifically designed to be easy to understand despite producing good performance. People that mentioned it said the authors spent around 10 years on it trying to achieve that goal. Full description is in the book they sell to recoup some of that investment. Worth looking into if you hadnt heard of it.
Now there's a fun little Xmas break project: port tinycc to RISC-V. I don't expect it to be too hard. Extra credit for using the compressed instruction where possible.
Related: Based on the Tiny C Compiler, a demo program ('TCCBOOT', also from Fabrice) mentioned in the "News" section in the URL from the OP was part of the QEMU Advent calendar:
I gave it a shot, and it was way above my head. tccboot involves kernel trickery that Belliard himself wrote as not safe at all and just there to make it run a bit. I'm not even kernel developper level, I have no idea how I could migrate this to linux 3.x or 4.x.
/me nods. While preparing that QEMU Advent image, I spent little (admittedly too little) time to see if I can get newer Kernels work with TCC, and quickly came to a somewhat similar conclusion. (While also realizing limits on my abilities - not a Kernel developer either).
At least you gave it a shot! There are loads of things I can't do but I almost always try a couple of times to push myself. Sometimes I find I really love it even though I suck at it and muddle through, sometime I just suck and find no enjoyment so move on quickly. But I always learn something new, either about myself or the technology or whatever it was I was looking into. I don't see any time spent on giving something I don't know a go as time wasted.
Merry Christmas/Happy Holidays my HN-friend! Have a great end of 2016 and a happy and healthy start to 2017 :)
TCC is an amazing project, and very useful, as there are few multiplatorm "C99 enough" compliant compilers. Also, it is suitable for using C as scripting language (!)
I experimented with using TCC as an experimental native code compilation backend for a scripting language. Was pretty impressed how easy it was to embed compared to some other solutions I tried.
The language had a fairly basic AST, was fairly C-Like, and used fairly basic programming constructs (e.g. at most functions are just a call into a dispatcher) so it translates reasonably well to C. Didn't pursue the project too far, so not really anything concrete to show.
@buserror's project sounds like a better example with code.
I used TCC a lot back in 2003 or so for schoolwork. I had an ancient pentium 1 thinkpad someone had given me that I used for all my programming assignments. TCC compile times were basically instantaneous for simple C programs, I remember using the `tcc -run` hasbbang feature too.
Result is amazing speed for emulation!
https://github.com/buserror/simavr/tree/jit-wip