A Brainfuck to binary compiler using LLVM, written in OCaml

Taddeus Kroes d1d5c13d26 Added Python script to generate naive text programs há 11 anos atrás
.gitignore 541164a238 First working version of compiler -> llvm há 11 anos atrás
Makefile 2eafc343a2 Switched to LLVM 3.4 há 11 anos atrás
README.md 8117b3b42c Typo há 11 anos atrás
bf.ml 50b028d2a0 Code + makefile cleanup há 11 anos atrás
hello.b 7b66f09168 Removed undocumented Hello World program and added rot13 program há 11 anos atrás
rot13.b 7b66f09168 Removed undocumented Hello World program and added rot13 program há 11 anos atrás
run.sh 2eafc343a2 Switched to LLVM 3.4 há 11 anos atrás
text.py d1d5c13d26 Added Python script to generate naive text programs há 11 anos atrás

README.md

About

This is a minimal compiler for the Brainfuck language, written for the purpose of practicing OCaml LLVM bindings and seeing how well LLVM optimizes arrays. Brainfuck commands are transformed to LLVM IR, which is generated in such a way that it is easy to optimize for LLVM's opt utility.

Building and usage

Building the bf compiler (Debian dependencies):

$ sudo apt-get install ocaml llvm-3.4 libllvm-3.4-ocaml-dev
$ make

Building a brainfuck program (plain and optimized):

$ make hello hello-opt  # compile file "hello.b" to binaries
$ ./hello
Hello World!
$ ./hello-opt
Hello World!

Quick compilation and running (deletes temporary binary after running):

$ echo ++++++++++++. | ./run.sh
$ ./run.sh < hello.b
Hello World!

Examining generated LLVM:

$ echo ++++++++++++. | ./bf
...
$ echo ++++++++++++. | ./bf | opt -O3 -S
...