Architecture · Backend guide · CLI reference · API documentation
BFC is a Brainfuck compiler written in C23. It parses Brainfuck source code, builds and optimizes an intermediate representation, and emits target-specific assembly.
The project is intentionally small and self-contained. It uses only the C standard library and platform toolchains; no third-party runtime libraries are required.
BFC currently supports assembly generation for:
aarch64-apple-darwinx86_64-apple-darwin
The target parser also recognizes Linux and Windows target triples, but those backends are not yet implemented.
The compiler currently emits assembly with -S. The final assemble-and-link stage that produces a native executable is planned but not yet complete.
- C23 implementation
- Clang-style command-line interface
- Brainfuck tokenization with source locations
- Optional semicolon line comments
- Bracket validation and diagnostics
- Nested intermediate representation
- Repeated-operation optimization
- Repeated pointer-movement optimization
- Clear-loop optimization for
[-]and[+] - Target-triple selection
- macOS AArch64 backend
- macOS x86-64 backend
- AddressSanitizer-enabled debug builds
- Doxygen-compatible source documentation
To build BFC:
- A C23-capable compiler
- Clang is currently the primary tested compiler
- GCC may work if it supports the required C23 and GNU attribute features
- GNU Make or a compatible
make - macOS for executing and linking the currently implemented backends
Optional:
- Doxygen, for generating HTML documentation
- clang-format, for
make formatandmake format-check - clang-tidy, for
make tidy
The default configuration is debug:
makeExplicit debug build:
make debugRelease build:
make releaseGenerated binaries are placed under:
build/debug/bfc
build/release/bfc
Clean build output:
make cleanFormat all C sources and headers using .clang-format:
make formatCheck formatting without changing files:
make format-checkRun the checks configured in .clang-tidy:
make tidyThese targets are optional developer tools and are not part of the normal compiler build.
The repository includes a GitHub Actions workflow at:
.github/workflows/build.yml
The workflow builds release binaries on native GitHub-hosted runners for:
| Platform | Architecture |
|---|---|
| Linux | x86-64 |
| Linux | AArch64 |
| macOS | x86-64 |
| macOS | AArch64 |
| Windows | x86-64 |
| Windows | ARM64 |
The cross-platform build workflow runs when:
- a commit is pushed to
main - a pull request targets
main - it is started manually
Tags matching v* trigger the separate release workflow.
Each successful job uploads a packaged build artifact containing the compiler
binary, LICENSE, and VERSION. Workflow artifacts are retained for 14 days.
The workflow builds the bfc compiler executable for each host platform. This
is separate from code-generation backend support. A Linux or Windows build of
bfc does not imply that BFC can emit Linux or Windows assembly; only the
targets listed as implemented under Supported target triples
are currently usable for code generation.
bfc [options] <file.bf>
./build/debug/bfc -S hello.bfDefault output:
hello.bf.s
./build/debug/bfc -S hello.bf -o hello.s./build/debug/bfc \
--target aarch64-apple-darwin \
-S \
hello.bf \
-o hello-aarch64.s./build/debug/bfc \
--target x86_64-apple-darwin \
-S \
hello.bf \
-o hello-x86_64.s./build/debug/bfc --help./build/debug/bfc --versionThe examples/ directory contains small Brainfuck programs demonstrating
compiler behavior:
| File | Behavior |
|---|---|
hello.bf |
Prints Hello World! |
echo.bf |
Echoes input until EOF |
comments.bf |
Demonstrates semicolon line comments |
multiply.bf |
Uses a loop to compute 6 × 7 and prints * |
nested_loops.bf |
Uses nested loops to compute and print A |
Generate assembly for an example:
./build/debug/bfc -S examples/hello.bf -o hello.s| Option | Description |
|---|---|
-h, --help |
Display help |
-v, --version |
Display the compiler version |
-S, --assembly |
Emit assembly and stop |
-o, --output <file> |
Set the output path |
-t, --target <triple> |
Select the target triple |
--fno-comments |
Disable semicolon line-comment handling |
-- |
Stop parsing command-line options |
For complete CLI documentation, see docs/cli.md.
| Target triple | Status |
|---|---|
aarch64-apple-darwin |
Implemented |
x86_64-apple-darwin |
Implemented |
aarch64-unknown-linux-gnu |
Recognized; backend not implemented |
x86_64-unknown-linux-gnu |
Recognized; backend not implemented |
aarch64-pc-windows-msvc |
Recognized; backend not implemented |
x86_64-pc-windows-msvc |
Recognized; backend not implemented |
i386-pc-windows-msvc |
Recognized; backend not implemented |
If no target is supplied, BFC selects the host architecture and operating system.
BFC currently uses:
- 30,000 cells
- 8-bit wrapping cells
- One byte per cell
- EOF input converted to zero
- Nested loop blocks in the IR
Semicolon comments are enabled by default:
+++++ ; this text is ignored
.Use --fno-comments to disable that extension.
Implemented optimizations include:
- Coalescing adjacent cell operations
- Coalescing adjacent pointer movements
- Clear-loop recognition for
[-]and[+]
Project documentation is available under docs/:
Generate Doxygen HTML documentation with:
make docsGenerated documentation is written to:
docs/doxygen/html/
The generated HTML is not committed to the repository.
.
├── .github/
│ └── workflows/
│ ├── build.yml
│ ├── docs.yml
│ └── release.yml
├── docs/
├── examples/
├── include/
├── src/
├── tests/
├── .clang-format
├── .clang-tidy
├── Doxyfile
├── LICENSE
├── Makefile
├── README.md
└── VERSION
- Add the assemble-and-link stage
- Add Linux x86-64 code generation
- Add Linux AArch64 code generation
- Add Windows code-generation backends
- Expand integration and regression tests
- Add additional Brainfuck-specific optimizations
- Add target-aware external toolchain selection
BFC is licensed under the GNU General Public License v3.0.
See LICENSE for the complete license text.