A port of the earliest C compiler to x86. The compiler generates 32-bit code and works on modern Linux with a current libc. It follows the architectur

vegesm / c72

submited by
Style Pass
2021-06-13 15:30:12

A port of the earliest C compiler to x86. The compiler generates 32-bit code and works on modern Linux with a current libc. It follows the architecture of the original implementation closely, keeping the bugs and missing features.

I've also attached an early implementation of cp from UNIX v5. It worked with minor modifications with this compiler, on my Ubuntu 18.04. It's pretty neat, to have a nearly 50 years old code compile with a nearly 50 years old compiler and run on a modern OS!

This version of C is from around 1972. While the general syntax is pretty much the same as today, there are tons of missing features:

The compiler has two stages: c0 and c1. c0 parses the input C file and generates a half-assembly half-parsed syntax tree temporary file. It is not meant to make the second stage easily portable, rather the memory restrictions of the PDP-11 made the split necessary. Then c1 generates the final assembly, translating the syntax trees to actual code.

c0 is a fairly straightforward parser. One interesting bit is that a[b] is parsed and then converted to *(a+b) already in this very early version of C (if you are not familiar with the C standard, a[b] is defined to be equivalent to *((a)+(b))).

Leave a Comment
Related Posts