Brainfuck compiler
Go to file
Přemysl Eric Janouch d1d43387e5
Word the README better
2017-06-25 22:22:00 +02:00
interpreters Fix interpreter portability 2016-12-25 01:56:42 +01:00
.gitignore gdb-experiment.go: add DWARF debugging information 2017-01-22 00:01:01 +01:00
LICENSE Fix and update LICENSE 2017-06-25 22:18:17 +02:00
Makefile Add support for OpenBSD 2016-12-24 22:29:29 +01:00
README.adoc Word the README better 2017-06-25 22:22:00 +02:00
bfc-amd64.c Remember to truncate the output file 2016-12-25 01:56:42 +01:00
gdb-experiment.go gdb-experiment.go: fix .text section header 2017-06-25 22:18:17 +02:00
gdb-experiment.png gdb-experiment.go: add a screenshot 2017-01-22 00:01:01 +01:00
gdb-object-file-libc.go Add gdb-object-file-libc.go 2017-06-25 22:18:17 +02:00
gdb-object-file.go gdb-object-file.go: discard program headers 2017-06-25 22:18:17 +02:00

README.adoc

bfc

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.

Its 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.

Building

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

$ git clone https://github.com/pjanouch/bfc.git
$ cd bfc
$ make

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

$ make CPPFLAGS=-DDEBUG

Usage

$ ./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.

gdb

You may have noticed the gdb-experiment.go file. It 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. Its 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 gdb-experiment.go [INPUT-FILE] [OUTPUT-FILE]

Use break *0x4000b7 to get a breakpoint at the first Brainfuck instruction.

gdb experiment

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

$ go run gdb-object-file-libc.go program.bf program.o
$ cc program.o -o program

Contributing and Support

Use this projects GitHub to report any bugs, request features, or submit pull requests. If you want to discuss this project, or maybe just hang out with the developer, feel free to join me at irc://irc.janouch.name, channel #dev.

Bitcoin donations: 12r5uEWEgcHC46xd64tt3hHt9EUvYYDHe9

License

bfc is written by Přemysl Janouch <p.janouch@gmail.com>.

You may use the software under the terms of the ISC license, the text of which is included within the package, or, at your option, you may relicense the work under the MIT or the Modified BSD License, as listed at the following site: