Giter VIP home page Giter VIP logo

bfc's Introduction

bfc

A simple optimizing brainfuck compiler written in C

Olle Lögdahl, 25 December 2021

build licence


bfc is a simple brainfuck compiler (or assembly generator), able to produce x86_64 assembly. The compiler may also call as to compile the assembly into a linkable object. Written as a one day project, it's purely for educational purposes.

The compiler also implements some (albeit very simple) optimizations using patterns ([-] can be optimized as a set 0 for example).

Building & Usage

The only requirements to build are a C99+ POSIX compliant compiler and GNU make. bfc can be built and installed by:

make build
sudo make install

Compiling some branfuck code is then done by:

echo "+[-->-[>>+>-----<<]<--<---]>-.>>>+.>>..+++[.>]<<<<.+++.------.<<-.>>>>+." > hello.b
bfc -o hello.o hello.b
ld -o hello hello.o

The assembly can be inspected by running:

bfc -gS -o hello.s hello.o

Help

bfc [-gShv] [-o file] file
  S        skips the assembler and only outputs the generated assembly.
  g        generates assembly with comments about the bf instructions.
  o file   the file to write the assembly/linkable object to.
  h        shows this.
  v        shows the version of the program.

Testing

A part of the challenge was also writing a testssuite in sh for testing the compiler and the generated binaries. These can be run with make test to output the following:

./check.sh out/bfc nocolor
rot13:  ok
t10:    ok
t11:    ok
t12:    ok
t1:     ok
t3:     ok
t4:     ok
t5:     ok
t6:     ok
t7:     ok
t8:     ok
t9:     ok
ran 14 tests with 79 scenarios.

Licensing

This project, and all code it contains, is licensed under the MIT License and can be read here.

bfc's People

Contributors

ollelogdahl avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.