Optimizing Brainfuck Compiler
This optimizing Brainfuck compiler runs entirely in the browser and targets WebAssembly as its output format. The generated WebAssembly is executed by the same browser runtime that hosts the compiler itself. I wrote it for John Regehr’s advanced compilers course (source code).
The optimizer uses an IR to recognize Brainfuck idioms, including:
-
clearing a cell with a decrement loop
[-] -
using a loop to multiply and transfer values
[- > + <] -
using SIMD to scan for zero cells more quickly
[>]