Skip to content

caozhanhao/llvm-brainfuck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

llvm-brainfuck

A LLVM pass that lowers LLVM IR to Brainfuck.

Work in progress -- not all instructions and types are supported yet.

Quick Start

mkdir build && cd build
cmake .. && make
clang -O1 -S -fpass-plugin=./lib/libLLVMBrainfuck.so -o /dev/null ../tests/c/helloworld.c > helloworld.bf
./interpreter/BFInterp helloworld.bf
 
# For opt, use `-load-pass-plugin` 
# opt -load-pass-plugin ./lib/libLLVMBrainfuck.so -disable-output xxx.ll

Progress

  • Basic support for arithmetic, memory and function calls.
  • Currently, all types are treated as i8 and conversion are simply ignored.
  • ⚡ Fun Fact: Now it can compile a Brainfuck interpreter to Brainfuck. (See: tests/c/bf-interp.c)

Supported Instructions

Terminator Instructions

  • ret
  • br
  • switch
  • indirectbr
  • invoke
  • callbr
  • resume
  • catchswitch
  • catchret
  • cleanupret
  • unreachable

Unary Operations

  • fneg

Binary Operations

  • add
  • fadd
  • sub
  • fsub
  • mul
  • fmul
  • udiv
  • sdiv
  • fdiv
  • urem
  • srem
  • frem

Bitwise Binary Operations

  • shl
  • lshr
  • ashr
  • and
  • or
  • xor

Vector Operations

  • extractelement
  • insertelement
  • shufflevector

Aggregate Operations

  • extractvalue
  • insertvalue

Memory Access and Addressing Operations

  • alloca
  • load
  • store
  • fence
  • cmpxchg
  • atomicrmw
  • getelementptr

Conversion Operations

  • trunc ... to
  • zext ... to
  • sext ... to
  • fptrunc ... to
  • fpext ... to
  • fptoui ... to
  • fptosi ... to
  • uitofp ... to
  • sitofp ... to
  • ptrtoint ... to
  • inttoptr ... to
  • bitcast ... to
  • addrspacecast ... to

Other Operations

  • icmp
  • fcmp
  • phi (demote to memory)
  • select
  • freeze
  • call
  • va_arg
  • landingpad
  • catchpad
  • cleanuppad

Supported Types

  • i8
  • ...

License

This project is licensed under the MIT License.
See LICENSE for details.

About

A LLVM pass that lowers LLVM IR to Brainfuck.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages