This is a Brainfuck compiler that translates Brainfuck code into LLVM Intermediate Representation (IR) and compiles it into an executable. The compiler follows a multi-stage process where Brainfuck code is first translated into a custom Intermediate Representation (IR) before being converted into LLVM IR. I was inspired by Tsoding's JIT compiler. I originally wanted to write it to compile directly into ASM, however, that would require a compiler for every architecture.
- Translates Brainfuck code into custom Intermediate Representation (IR)
- Converts custom IR into LLVM IR
- Generates executable from LLVM IR
Before using the compiler, make sure you have the following installed:
- LLVM
- Python33
-
Clone this repository to your local machine:
git clone https://github.com/yourusername/brainfuck-compiler.git
-
Write your brainfuck code, or use the hello world example:
cd brainfuck-compiler touch code.bf
-
Compile into IR
python ir.py -f code.bf -o code.ir
-
Compile into LLVM IR
python compile.py -f code.ir -o main.ll
-
Compile and link into executable
make && ./main
- Implement more optimization passes for generated LLVM IR
- Add a linked list struct instead of a static array on the heap (dynamic resizing)
- Add support for more instructions, ie * for multiply, / for divide
- Add support for libc function calls and/or direct syscalls