udem-dlteam / pnut

🥜 A Self-Compiling C Transpiler Targeting Human-Readable POSIX Shell
https://pnut.sh
BSD 2-Clause "Simplified" License
378 stars 9 forks source link

Building tcc with pnut #63

Open cosinusoidally opened 1 month ago

cosinusoidally commented 1 month ago

In the readme file it indicates that pnut.exe is capable of building tcc. I can't seem to figure out how to actually do that though. Can you please advise whether this is possible? Simply passing --cc=pnut.exe to the tcc configure script won't work:

configure: error: 'pnut.exe' failed to compile conftest.c

If I try this (which works with gcc after the configure script has been run):

pnut.exe tcc.c

I get the following error:

codegen_glo_decl: unexpected declaration

I'm using a stock tcc 0.9.27 release from 2017 (rather than a random version of their mob branch). Same issue when i use the i386 backend.

laurenthuberdeau commented 4 weeks ago

We're still working on TCC support. ~I'll update the README because pnut-exe is not yet able to compile TCC.~ I've updated the README.

cosinusoidally commented 2 weeks ago

Thanks, it's good to know that tcc is one of your aims. It will be good to have another C compiler that is capable of bootstrapping tcc.

Are you aware of the live-bootstrap project (https://github.com/fosslinux/live-bootstrap/)? They bootstrap from a couple of hundred bytes of commented machine code all the way up to modern versions of GCC. tcc is part of their bootstrap chain. They use a "bootstrapable" version of tcc 0.9.26 (https://gitlab.com/janneke/tinycc (mes-0.27 branch I think) which is actually closer to 0.9.27 than 26). This version of tcc can be built by mescc (which is a C compiler written in scheme). I mention this because their bootstrapable version can be built by simplified C compilers and is used as a stepping stone to a stock 2017 era tcc-0.9.27 release (and then on to modern versions of gcc).

Live Bootstrap actually goes through several C compilers on its way to tcc:

cc_x86 (a C compiler written in a simple macro assembly language. There are also other arch versions) M2-Planet (a C compiler written in the cc_x86 dialect) mescc (a C compiler written in scheme that is run in a scheme interpreter (mes.c) written in the M2-Planet dialect of C)

I have also been working on a means of bootstrapping tcc but replacing mescc with a chain of previous versions of tcc (plus some cut down versions of tcc). My project is very i386 specific, but it can bootstrap from nothing up to tcc 0.9.27 much more quickly than a stock live-bootstrap can. https://github.com/cosinusoidally/tcc_bootstrap_alt . The thing that got me interested in pnut is potentially allowing me to eliminate some intermediate versions of tcc from my project.

feeley commented 2 weeks ago

@cosinusoidally We should definitely talk some more about how we can combine our efforts. We see pnut as a more practical seed than used by live bootstrap (depends only on the shell, more maintainable source, and fewer steps to get TCC built). We could add more C language features to pnut as needed and you could simplify TCC to avoid "advanced" features.