
I made a brainfuck optimizing compile which takes brainfuck code from a .b or .bf file and outputs an assembly file, which can be "linked" to a provided runtime using a C++ compiler.
BOCBWN - Brainfuck Optimizing Compiler Because Why Not
Note: if you're downloading the repo, the examples folder named bf/ is 2.2MiB (36x the size of everything else combined), so consider only downloading src/, bfbpl and the README.md if that's a problem.
It allows compilation to a *.bfvm intermediate file, and also outputs the intermediate in a more human-redable *.bfasm file. Its optimizations include first converting the brainfuck to an intermediate representation (IR) which is stored in a tree (AST) a conservative dry run over the program in which constant folding, some strength reduction, and dead code elimination occur, and more passes for liveness checking and more strength reduction. The AST is then converted back to a linear IR, which is converted to assembly by the (currently unoptimized) compiler.
The code for optimization is heavily commended (mostly because I needed to mentally lay everything out before doing it), so it should be (more-or-less) simple to understand the code.
Planned optimizations on the assembly backend with adding support for Windows in the near future, and further optimizations (check the `main` branch) and a debugger in the future.