cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.95k stars 982 forks source link

Chez as a compiler backend alternative to LLVM #672

Open NHALX opened 1 year ago

NHALX commented 1 year ago

Several projects are now using Chez as a compilation target with great success. I'm curious, how difficult would it be for a project to bypass the scheme specific compilation stages, and skip down to a lower level of the pipeline for code generation? What do you have to do to compile higher level virtual assembly instructions in a way that can interact directly with the rest of the runtime?

melted commented 1 year ago

I would be a bit hesitant to do that, as it's not made to be used that way, and it's not guaranteed to help compared to just emitting Scheme. When I wrote my Idris backend, Scheme turned out to be a good fit. On the other hand the nanopass architecture helps in that there is a well-defined language at each compilation step. So the first thing to do would be to understand the nanopass framework used by the compiler. There is a user guide in nanopass/docs. Also, the "Writing a Nanopass Compiler" video is helpful. Chez Scheme uses it mostly in cp0.ss, compile.ss, cpnanopass.ss (for the passes) and np-languages.ss (for the languages).

One reason why it might not be a good idea to hook into later in the compilation process is that quite a few optimizations is done at the very beginning in the cp0 pass.