Implementing a LLVM Micro C compiler in Haskell
blog.josephmorag.com
blog.josephmorag.com
I especially love the fact that instead of implementing a novel language like Kaleidoscope (which the official LLVM does), it implements a subset of C (a language that's low-level enough and widely understood). C has all of the basic constructs, which if you understand how to write a compiler (to LLVM) for, would allow you to implement far more advanced languages.
Thank you Joseph Morag for this wok, and Théophile Choutri, Moritz Kiefer, et al for making it possible.
The code is still on my github. I recently took a look at it and I was surprised how readable it was. It's a shame that in my professional career I didn't get the chance to use neither Haskell nor any of the PL skills that I picked up in uni, because I really had fun with that project. Though maybe that's for the best. If you have to do it for work, you sometimes end up hating it.
For those interested in tutorials like this, I'd also recommend a very literate Haskell compiler for the PCF language to C[1], which is essentially lambda calculus with some primitives and pattern matching. It details a number of transformations such as closure conversion and lambda lifting.
https://www.amazon.com/Retargetable-Compiler-Design-Implemen...
During the early 80's, the best home computers could get was Small-C.
"A book on C"
https://link.springer.com/book/10.1007/978-1-349-10233-4
It uses a K&R C subset with bytecodes and a bytecode-> machine language translation.
I just never bothered to type it in though.