Brainfuck

The compiler has a front-end for the brainfuck language. You can use bf_to_ir() to transform brainfuck code into IR-code:

>>> from ppci.lang.bf import bf_to_ir
>>> import io
>>> ir_module = bf_to_ir(io.StringIO('>>ignore.'), 'arm')
>>> ir_module.display()
module main;

external procedure bsp_putc(u8);

variable data (30000 bytes aligned at 4)

procedure main() {
  main_block0: {
    blob<4:4> ptr_alloc = alloc 4 bytes aligned at 4;
    ptr ptr_addr = &ptr_alloc;
    i32 one = 1;
    i8 val_inc = cast one;
    ptr ptr_incr = cast one;
    i32 zero = 0;
    ptr zero_ptr = cast zero;
    i8 zero_ptr_0 = cast zero;
    ptr array_max = 30000;
    store zero_ptr, ptr_addr;
    jmp main_block2;
  }

  main_block1: {
    exit;
  }

  main_block2: {
    ptr ptr_val = load ptr_addr;
    ptr cell_addr = data + ptr_val;
    store zero, cell_addr;
    ptr add = ptr_val + ptr_incr;
    store add, ptr_addr;
    cjmp add == array_max ? main_block1 : main_block2;
  }

}

Reference

This is the brain-fuck language front-end.

ppci.lang.bf.bf_to_ir(source, target)

Compile brainfuck source into ir code

class ppci.lang.bf.BrainFuckGenerator(arch)

Brainfuck is a language that is so simple, the entire front-end can be implemented in one pass.

generate(src, module_name='main', function_name='main')

Takes a brainfuck program and returns the IR-code module