Introduction

This project is a compiler targeting the linux x86_64 intel architecture for the brainfck programming language written in C++. Allowing to create executables reflecting the content of the brainfck script.

For this project, my main goals were to learn more about assembly for the x86_64 architecture under linux (using intel syntax and ELF format). Explore the tool chain for creating an executable from assembly code (using nasm for assembling and ld for linking). And finally, I wanted to learn and apply the concept of file embedding in a C++ executable.

As a result of my desire to apply file embedding, the project is divided between the cpp code and the pre-written assembly code. These assembly files are then embedded in the cpp code using the xxd tool. When the bf executable is generated, the assembly code is extracted from the cpp code and written to temporary files. These files are then linked with the assembly code generated by the compiler to produce the final executable.

Generate the executable

The project uses CMake to generate the makefile.
The executable is then generated by running make.

Compile a BF script

The compiler takes a brainfck script and output name as inputs.
It generates an executable reflecting the content of the brainfck script.

Run tests

The resulting executables' behaviour are tested using shunit2, a unit testing framework for shell scripts.
They are tested on both correct output, error handling and memory management.

Run manual tests

As the majority of the asm code is written by hand and separated from the cpp code. It is possible to check the correct behavior of the functions by writing to the start.asm file, compiling it and running it by hand. Since it is this code that is used by the compiler, we can be assured that the asm code is correct.