I'm happy to report that I have a very rough cut at a vCPU backend for the `lcc` C compiler. I chose this compiler for retargeting because of its simplicity and the clarity of the interface between its front- and back-ends. Though I'm certain that there are many, many sharp edges, I have been able to build and run several small programs. Here are a couple of videos of programs I've compiled:
- A port of the "dots" demo: https://www.youtube.com/watch?v=rYGS7Zpkm1c
- An implementation of Conway's Game of Life: https://www.youtube.com/watch?v=avnhPTUZ5E8
Apologies for the low resolution; Youtube won't seem to allow me to upload at the original quality.
The source code for the compiler is here: https://github.com/pgavlin/lcc/tree/pgavlin/gt1
The vCPU backend is mostly contained in https://raw.githubusercontent.com/pgavl ... src/gt1.md. The assembler/linker and runtime may also be of interest: https://github.com/pgavlin/lcc/blob/pgavlin/gt1/asm.py https://github.com/pgavlin/lcc/blob/pgavlin/gt1/rt.py
Needless to say that authoring software in C is not terribly practical on a 32k system: the fragmented memory map limits the amount of stack that is easily available and essentially precludes a heap. I will probably code something up for a 64k memory model that is a bit more capable.
I'm slowly working on putting together a write-up of the design of the compiler, the retargeting process, and the challenges unique to generating code for the vCPU. In the meantime, I'm happy to answer any questions you all have.
Happy hacking!
