from armchair_progamer@programming.dev to programming_languages@programming.dev on 27 Jul 2024 03:03
https://programming.dev/post/17382161
I created Bril, the Big Red Intermediate Language, to support the class’s implementation projects. Bril isn’t very interesting from a compiler engineering perspective, but I think it’s pretty good for the specific use case of teaching compilers classes. Here’s a factorial program:
@main(input: int) { res: int = call @fact input; print res; } @fact(n: int): int { one: int = const 1; cond: bool = le n one; br cond .then .else; .then: ret one; .else: decr: int = sub n one; rec: int = call @fact decr; prod: int = mul n rec; ret prod; }Bril is the only compiler IL I know of that is specifically designed for education. Focusing on teaching means that Bril prioritizes these goals:
- It is fast to get started working with the IL.
- It is easy to mix and match components that work with the IL, including things that fellow students write.
- The semantics are simple, without too many distractions.
- The syntax is ruthlessly regular.
Bril is different from other ILs because it prioritizes those goals above other, more typical ones: code size, compiler speed, and performance of the generated code.
Aside from that inversion of priorities, Bril looks a lot like any other modern compiler IL. It’s an instruction-based, assembly-like, typed, ANF language. There’s a quote from why the lucky stiff where he introduces Camping, the original web microframework, as “a little white blood cell in the vein of Rails.” If LLVM is an entire circulatory system, Bril is a single blood cell.
threaded - newest