Path: csiph.com!weretis.net!feeder9.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Michael Lehn Newsgroups: comp.compilers Subject: A tiny self-hosting compiler used for teaching Date: Mon, 24 Aug 2026 18:32:50 +0200 Organization: Compilers Central Sender: johnl%iecc.com Approved: comp.compilers@iecc.com Message-ID: <26-08-003@comp.compilers> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="43387"; mail-complaints-to="abuse@iecc.com" Keywords: courses, available Posted-Date: 24 Aug 2026 13:17:24 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:3740 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: I thought the result was a nice small example of bootstrapping that students can actually follow from beginning to end. Best, Michael