rcc – Retargetable C Compiler
I’ve recently been doing projects such as porting CP/M-86 to C, and the porting MP/M to C. I decided to take a look at UnixV0 and TOPS-10 the same way and quickly discovered that I would like to have a compiler that consumes C and emits… whatever back-end instruction set I want. So I decided, with the help of the LLM’s to write rcc (RCC on Github)
If you want to just use the binaries they are here:
The structure of RCC is simple. It consumes as “pretty close to complete” dialect of C, documented here. The front-end compiler emits IR, documented here. The IR is compiled to assembler for the specific processor, in an assembler format described here. The assembler is then assembled to binary output, usually in COFF format (other options are available). The COFF is then consumed by the rcc linker and/or emitted to a chosen file format such as a PE, or maybe Apple][ PRODOS executable.
Optimizations are applied at the IR level and therefore benefit all target platforms.
For example, these two commands compile a main.c to 8086 COFF and then emit a MS-DOS .com file (source)
rcc --platform=8086-dos-raw --out=main.raw main.c
rcc --link --platform=8086-dos-raw --out=main.com main.o" msdos.lib
Here are commands to create a pdp7 rim file (source)
rcc --platform=pdp7-rim --dump-ir --dump-asm --out=main.o main.c
rcc --link --platform=pdp7-rim --out=main.rim main.o
You might notice that the MS-DOS build includes msdos.lib. Where it’s appropriate, rcc provides C wrappers around the ROM/PROM in the host. You can see them here.
The full list of processors, file formats and platforms is growing however at the time of writing this there are currently 189 combinations of processor and platform supported. The current list is here.