| Related articles |
|---|
| A tiny self-hosting compiler used for teaching michael.lehn@uni-ulm.de (Michael Lehn) (2026-08-24) |
| Re: A tiny self-hosting compiler used for teaching Keith.S.Thompson+u@gmail.com (Keith Thompson) (2026-08-24) |
| Re: A tiny self-hosting compiler used for teaching michael.lehn@uni-ulm.de (Michael Lehn) (2026-08-25) |
| Re: A tiny self-hosting compiler used for teaching thanks-to@Taf.com (CóilínNioclásínGlostéir) (2026-09-04) |
| Re: A tiny self-hosting compiler used for teaching ram@zedat.fu-berlin.de (2026-09-05) |
| Re: A tiny self-hosting compiler used for teaching gneuner2@comcast.net (George Neuner) (2026-09-05) |
| Re: A tiny self-hosting compiler used for teaching ram@zedat.fu-berlin.de (2026-09-05) |
| [8 later articles] |
| From: | Michael Lehn <michael.lehn@uni-ulm.de> |
| Newsgroups: | comp.compilers |
| Date: | Mon, 24 Aug 2026 18:32:50 +0200 |
| Organization: | Compilers Central |
| 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 |
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
Return to the
comp.compilers page.
Search the
comp.compilers archives again.