Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #3740

A tiny self-hosting compiler used for teaching

From Michael Lehn <michael.lehn@uni-ulm.de>
Newsgroups comp.compilers
Subject A tiny self-hosting compiler used for teaching
Date 2026-08-24 18:32 +0200
Organization Compilers Central
Message-ID <26-08-003@comp.compilers> (permalink)

Show all headers | View raw


Hi,

I thought this might be of interest to readers of comp.compilers.

I teach a high-performance computing course at Ulm University. For this course
I developed a small C-like language called ABC, which we use to teach some of
the basics of programming and compiler construction.

As a course project, the students wrote a compiler in ABC for an even smaller,
somewhat BCPL-like language which we called not-abc. Code generation is a
separate module (or, more precisely, a separate translation unit containing
the code generation functions), so that different backends can be used without
changing the rest of the compiler.

During the course, the students generated code for a simple RISC architecture
called ULM (Ulm Lecture Machine), which exists both as a virtual machine and
as an FPGA implementation.

At the end of the semester, I wanted to demonstrate that essentially the same
compiler could also generate code for the computers they were actually using.
So I gave them another code-generator translation unit which emits LLVM IR.
The resulting IR can simply be passed to clang to produce native code.

This also led to a little experiment in self-hosting. The not-abc compiler
originally written in ABC can itself be rewritten in not-abc. That version is
about 2,000 lines of code and can be found here:

https://github.com/michael-lehn/not-abc

`not-abc.ll` in the repository is LLVM IR for the compiler and can be compiled
with clang to obtain the initial `not-abc`executable. `examples/not-abc.abc`
is the same compiler written in not-abc.

It can then compile itself:

    ./not-abc < examples/not-abc.abc > not-abc-compare.ll
    diff not-abc.ll not-abc-compare.ll

The second command produces no output: the compiler reproduces its own LLVM
IR.

Getting from the students' ABC implementation to the not-abc implementation
was mostly a matter of combining the translation units into a single source
file and downgrading the language features. not-abc deliberately has only one
data type: a 64-bit integer, which can also be interpreted as a pointer. The
compiler reads its source from stdin and writes LLVM IR to stdout, so the
complete compiler can live in one small source file.

The ABC compiler and language I developed for the course are here:

<https://github.com/michael-lehn/abc-llvm>

I thought the result was a nice small example of bootstrapping that students
can actually follow from beginning to end.

Best,
Michael

Back to comp.compilers | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

A tiny self-hosting compiler used for teaching Michael Lehn <michael.lehn@uni-ulm.de> - 2026-08-24 18:32 +0200
  Re: A tiny self-hosting compiler used for teaching Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-08-24 13:39 -0700

csiph-web