bfc/README.adoc

76 lines
2.5 KiB
Plaintext
Raw Permalink Normal View History

2016-12-22 22:58:20 +01:00
bfc
===
'bfc' is a small, fast, self-contained, optimizing Brainfuck compiler for *nix
2016-12-24 22:42:21 +01:00
on Intel x86-64.
2016-12-22 22:58:20 +01:00
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.
2016-12-24 22:42:21 +01:00
Thanks to the unified ABI, adding support for another flavour of *nix only means
changing the syscall numbers. The compiler itself is platform agnostic.
2016-12-22 22:58:20 +01:00
Building
--------
Build dependencies: a C99 compiler +
Runtime dependencies: Linux or OpenBSD
2016-12-22 22:58:20 +01:00
2018-06-24 03:06:14 +02:00
$ git clone https://git.janouch.name/p/bfc.git
2016-12-22 22:58:20 +01:00
$ cd bfc
$ make
To obtain dumps of the intermediate representation, compile with `-DDEBUG`:
$ make CPPFLAGS=-DDEBUG
Usage
-----
2016-12-24 22:42:21 +01:00
$ ./bfc-amd64-linux [INPUT-FILE] [OUTPUT-FILE]
$ ./bfc-amd64-openbsd [INPUT-FILE] [OUTPUT-FILE]
2016-12-22 22:58:20 +01:00
2016-12-22 23:40:30 +01:00
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.
2016-12-22 22:58:20 +01:00
2017-07-03 07:47:13 +02:00
DWARF
-----
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.
2017-07-03 07:47:13 +02:00
$ go run dwarf/simple.go [INPUT-FILE] [OUTPUT-FILE]
2017-07-03 07:47:13 +02:00
Type `break *0x4000b7` into gdb to get a breakpoint at the first Brainfuck
instruction.
2017-01-21 23:49:16 +01:00
image::gdb-experiment.png[align="center"]
2017-07-03 07:47:13 +02:00
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
2017-06-25 22:22:00 +02:00
OS-independent binary that can be linked against the libc with the C compiler:
2017-06-20 19:30:00 +02:00
2017-07-03 07:47:13 +02:00
$ go run dwarf/object-file-libc.go program.bf program.o
2017-06-20 19:30:00 +02:00
$ cc program.o -o program
2022-10-11 02:09:19 +02:00
Similar software
----------------
https://github.com/skeeto/bf-x86 is perhaps an easier-to-make-sense-of project.
2016-12-22 22:58:20 +01:00
Contributing and Support
------------------------
2018-06-24 03:06:14 +02:00
Use https://git.janouch.name/p/bfc 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://irc.janouch.name, channel #dev.
2016-12-22 22:58:20 +01:00
2018-06-24 03:06:14 +02:00
Bitcoin donations are accepted at: 12r5uEWEgcHC46xd64tt3hHt9EUvYYDHe9
2017-06-20 19:30:00 +02:00
2016-12-22 22:58:20 +01:00
License
-------
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.