Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

alpluspluss/bfc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bfc: A Brainfuck Compiler from Scratch

Note

The system call number is currently for OSX/XNU Darwin. More OS may or may not be supported at later date.

bfc is a fully-made-from-scratch with its custom ARM64 code generation backend. bfc is developed as a testament to my learning of ARM64 instructions encoding and decoding.

The codebase is written with simplicity in mind with a fair share of comments in most files. Readers should have some ideas about basic instruction encoding as well as how a typical compiler optimizes your code.

Status

bfc is able to compile and optimize all Brainfuck instructions into native binary with naive optimizations enabled. Currently, -O3 breaks all the program.

Essentials

  • Tokenizing
  • Parsing
  • IR generation
  • Naive optimization (#1 pass)
  • Peephole optimization (#2 pass)
  • Native ARM64 instruction encoding
  • JIT runtime

bfc will not be implementing other related toolchains such as linker, assembler, or anything that is beyond the scope of a "compiler" does.

Building

Requirements

Before building bfc, there are several required dependencies:

  • GNU Make
  • Clang (both Apple and LLVM works)

Optional

To ensure the generated binary is compiled correctly, you may want to install capstone to disassemble the machine code for correctness. You can download capstone by simply typing:

pip install capstone

Commands

Type:

make

to compile the source code.

About

Brainfuck Compiler from Scratch with Custom ARM64 Backend and JIT Runtime

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors