A compiler frontend for the Brainf*ck language that outputs code in LLVM Intermediate Representation (IR), which can then be compiled to any desired target architecture with clang.
You can interact with it online here, or in a self-hosted web interface accessed at http://localhost:8080 after running
$ docker compose upThe input validation and parsing functionality is formally verified to be memory safe for inputs up to thirteen commands long. Details are in MODELCHECKING.md.
$ sudo apt-get install cmake llvm-dev check expect clang-format cpplint$ brew install cmake llvm check expect clang-format cpplint$ cmake -B build
$ cmake --build buildAfter building, the bfc (compiler) and bfi (interpreter) executables will be in the build directory.
To compile a bf program to a binary executable:
# Generate LLVM IR
$ bfc test/res/helloworld.b > main.ll
# Compile IR to binary
$ clang main.ll -o main
$ ./main
Hello, World!To execute a bf program with the interpreter:
$ bfi test/res/helloworld.b
Hello, World!$ cmake --build build --target fmt lintCode docs can be accessed online at benmandrew.com/docs/bf/, or built locally with
$ cmake --build build --target docsDepends on Doxygen and Sphinx. The generated HTML site is written to build/docs/html/index.html.
$ cmake --build build --target testsYou can fuzz test with AFL:
$ docker run -ti -v .:/src benmandrew/bf:fuzzIf there are crashes, the offending inputs will be located in build-fuzz/fuzz_output/default/crashes.
Why does ASan fail with
malloc: nano zone abandoned due to inability to reserve vm space.?
On MacOS, every ASan-built binary prints this error. This is not an issue with the program, and can be fixed by setting the environment variable MallocNanoZone=0. See google/sanitizers#1666.
Compiling to the LLVM IR is a niche topic, and it is hard to find resources for learning. Here are a few useful ones I found:
