Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #3740 > unrolled thread
| Started by | Michael Lehn <michael.lehn@uni-ulm.de> |
|---|---|
| First post | 2026-08-24 18:32 +0200 |
| Last post | 2026-08-24 13:39 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.compilers
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
| From | Michael Lehn <michael.lehn@uni-ulm.de> |
|---|---|
| Date | 2026-08-24 18:32 +0200 |
| Subject | A tiny self-hosting compiler used for teaching |
| Message-ID | <26-08-003@comp.compilers> |
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
[toc] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2026-08-24 13:39 -0700 |
| Message-ID | <26-08-006@comp.compilers> |
| In reply to | #3740 |
Michael Lehn <michael.lehn@uni-ulm.de> writes:
> 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.
FYI, there's an existing language called ABC. It influenced Python.
https://en.wikipedia.org/wiki/ABC_(programming_language)
I understand it's difficult to avoid name collisions, and it probably
doesn't hurt anything in this case.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
[ABC was also the Atanasoff–Berry computer built in 1939-42. There
aren't enough letters to go around. -John]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.compilers
csiph-web