Merry Christmas 🎄

At about 1 a.m. on Christmas morning, I finished x86-64 code generation for Linux and BSD in credence.

If you subtract the hours at work, you can see exactly when I started on my GitHub contribution graph:

Credence has been the culmination of a lot of professional and hobby work since the idea was first conceived. The first commit in the parser is about 7 years old. Since then, I've designed languages and built compilers at my workplace.

It is my Magnum Opus

As of last night, I am wholly content with the machine code it generates for x64. ARM64 work has started, and it's shaping up to be much more exciting.

The final test was the translation of switch control structures from my IR, the JMP_E ITA statement.

If you're interested in what the machine code looks like, you should peek at the test suite. The code coverage is impressively exhaustive, with about 80% of all functions and lines covered, according to llvm-lcov.


So far, the most challenging part has been designing the Intermediate Representation. Unlike other sections, its design was purely academic - there is no specification to follow. The last time I was in this position was when I needed to re-create left-recursion in a PEG grammar for work, for which I needed a Microsoft paper to complete.

I am very thankful for this lecture at Stanford - it gave me a lot of inspiration. Here is a snippet of the IR for the switch program above:

__main():
 BeginFunc ;
    LOCL x;
    LOCL y;
    x = (10:int:4);
_L2:
    _t5 = x >= (5:int:4);
    IF _t5 GOTO _L4;
...
_L1:
    LEAVE;
_L4:
    _t6 = CMP x;
    JMP_E _t6 (10:int:4) _L8;
    JMP_E _t6 (6:int:4) _L16;
...

_L18:
    x = (5:int:4);
    GOTO _L17;
 EndFunc ;

Support for ARM64 will be much quicker, and I've already finished the template classes and pure virtual methods for platform-agnostic code generation.

Until then, catch you soon 🤘