This repository contains two implementations of a Brainfuck language processor one in C++ and other in Python. The Python interpreter is way slow! Switched to C++ then.
- C++ Compiler: A C++17 compliant compiler.
git clone https://github.com/Sameeranjoshi/brainfuck_toolchain.git
cd brainfuck_toolchain/
-
Brainfuck Interpreter
clang++ -std=c++17 -O3 -o bfi inter_cpp.cpp
Run the interpreter: This runs all the benchmarks
./bfi
Run the interpreter with profiling enabled:
./bfi -p
This generates a profiling_output.txt
file in the current directory.
Run the compiler:
- Generates the driver binary
- runs assembler (
as
) - Links with C library using
gcc
- Executes the binary
bash runassembler.sh
Above command runs the compiler and generates assembly with and without using optimization flags and generates the timing results in timing_results/ folder.
To control the optimization flags use
clang++ -std=c++17 -O3 -o compiler compiler_x86_64.cpp
./compiler <input_file> [--optimize-simple-loops] [--optimize-memory-scans]
Run the compiler:
- Generates the LLVM
output.ll
file from BF code. - runs llc
- Links with C library using
gcc
- Executes the binary
Note: This command will also run AOT compiler for benchmarking and store results in timing_results_llvm
bash runllvm.sh
To manually build and run a single test:
mkdir -p build
cd build
cmake -DLLVM_DIR=/usr/lib64/cmake/llvm/ -G Ninja ..
ninja
./aot_llvm ../benches/hello.b
llc -march=x86-64 output.ll -o output.s
gcc output.s -o out
./out