Brainfuck compiler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Přemysl Eric Janouch 18d9dc6e2f
Name change
1 year ago
dwarf Move Go to a subdir 4 years ago
interpreters Fix interpreter portability 5 years ago
.gitignore gdb-experiment.go: add DWARF debugging information 5 years ago
LICENSE Name change 1 year ago
Makefile Add support for OpenBSD 5 years ago
README.adoc Update README 3 years ago
bfc-amd64.c Remember to truncate the output file 5 years ago
gdb-experiment.png gdb-experiment.go: add a screenshot 5 years ago



bfc is a small, fast, self-contained, optimizing Brainfuck compiler for *nix on Intel x86-64.

Also included are several interpreters in various states of sophistication that document my progress as I was writing this, from the simplest approach to an optimizing JIT compiler.

It’s pretty easy to retarget the compiler, it just means redoing half the work. Thanks to the unified ABI, adding support for another flavour of *nix only means changing the syscall numbers. The compiler itself is platform agnostic.


Build dependencies: a C99 compiler
Runtime dependencies: Linux or OpenBSD

$ git clone
$ cd bfc
$ make

To obtain dumps of the intermediate representation, compile with -DDEBUG:



$ ./bfc-amd64-linux [INPUT-FILE] [OUTPUT-FILE]
$ ./bfc-amd64-openbsd [INPUT-FILE] [OUTPUT-FILE]

When no input file is specified, standard input is used. Similarly, the default output filename is a.out. After the compilation, the resulting file can be run on the target platform.


You may have noticed the dwarf directory. simple.go is a non-optimizing version of the compiler targeting Linux only that adds DWARF debugging information mapping code locations onto lines in the ir-dump.txt byproduct output file. It’s been rewritten in Go since managing all those binary buffers required to build the symbol table proved to be too painful in C.

$ go run dwarf/simple.go [INPUT-FILE] [OUTPUT-FILE]

Type break *0x4000b7 into gdb to get a breakpoint at the first Brainfuck instruction.


There is also object-file.go that generates an object file that can be statically linked with ld, and object-file-libc.go that generates an OS-independent binary that can be linked against the libc with the C compiler:

$ go run dwarf/object-file-libc.go program.o
$ cc program.o -o program

Contributing and Support

Use to report any bugs, request features, or submit pull requests. git send-email is tolerated. If you want to discuss the project, feel free to join me at ircs://, channel #dev.

Bitcoin donations are accepted at: 12r5uEWEgcHC46xd64tt3hHt9EUvYYDHe9


This software is released under the terms of the 0BSD license, the text of which is included within the package along with the list of authors.