All Projects → itchyny → llvm-brainfuck

itchyny / llvm-brainfuck

Licence: MIT License
Brainfuck compiler based on LLVM API

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to llvm-brainfuck

asmbf
The only true brainfuck-targetting assembler.
Stars: ✭ 81 (+200%)
Mutual labels:  brainfuck, brainfuck-compiler, brainfuck-interpreter
BF-it
A C-like language to Brainfuck compiler, written in Python
Stars: ✭ 101 (+274.07%)
Mutual labels:  brainfuck, brainfuck-compiler, brainfuck-interpreter
LLAST
A high level LLVM IR AST provider for GraphEngine JIT.
Stars: ✭ 21 (-22.22%)
Mutual labels:  llvm, llvm-ir
llvm-semantics
Formal semantics of LLVM IR in K
Stars: ✭ 42 (+55.56%)
Mutual labels:  llvm, llvm-ir
brainfuck
Brainfuck interpreter companion to the brain programming language
Stars: ✭ 32 (+18.52%)
Mutual labels:  brainfuck, brainfuck-interpreter
bfboot
A full brainfuck to bootable OS image compiler.
Stars: ✭ 35 (+29.63%)
Mutual labels:  brainfuck, brainfuck-compiler
Mcsema
Framework for lifting x86, amd64, aarch64, sparc32, and sparc64 program binaries to LLVM bitcode
Stars: ✭ 2,198 (+8040.74%)
Mutual labels:  llvm, llvm-ir
doc
Design documents related to the decompilation pipeline.
Stars: ✭ 23 (-14.81%)
Mutual labels:  llvm, llvm-ir
bl
Simple imperative programming language created for fun.
Stars: ✭ 57 (+111.11%)
Mutual labels:  llvm, llvm-ir
BrainfuckIDE
A Brainfuck IDE/debugger designed to be intuitive, featureful and visually appealing
Stars: ✭ 77 (+185.19%)
Mutual labels:  brainfuck, brainfuck-interpreter
LLVM-Metadata-Visualizer
LLVM Metadata Visualizer
Stars: ✭ 20 (-25.93%)
Mutual labels:  llvm, llvm-ir
llvm-hs-typed
Type Safe LLVM IR ( Experimental )
Stars: ✭ 47 (+74.07%)
Mutual labels:  llvm, llvm-ir
FasterBrainfuckProgramming
This project is to make brainfuck language programming easier, faster and more powerful .. everything is made out of functions making it very easy to port to other languages
Stars: ✭ 19 (-29.63%)
Mutual labels:  brainfuck, brainfuck-compiler
BrainF.Net
A .NET brainfuck code parsing and execution library
Stars: ✭ 23 (-14.81%)
Mutual labels:  brainfuck, brainfuck-compiler
esoo
Like the Programming Languages Zoo but with esoteric languages.
Stars: ✭ 18 (-33.33%)
Mutual labels:  brainfuck, brainfuck-interpreter
bfloader
🧠 Brainfuck IDE and interpreter in 512 bytes. (boot sector)
Stars: ✭ 41 (+51.85%)
Mutual labels:  brainfuck, brainfuck-interpreter
vbf
A brainfuck interpreter/compiler written in V.
Stars: ✭ 17 (-37.04%)
Mutual labels:  brainfuck, brainfuck-interpreter
ojisan f-ck
おじさん風文章を解釈して動く Brainfuck interpreter
Stars: ✭ 20 (-25.93%)
Mutual labels:  brainfuck, brainfuck-interpreter
TinyCompiler
c compiler based on flex(lex), bison(yacc) and LLVM, supports LLVM IR and obj code generation. 基于flex,bison以及LLVM,使用c++11实现的类C语法编译器, 支持生成中间代码及可执行文件.
Stars: ✭ 162 (+500%)
Mutual labels:  llvm, llvm-ir
Brainfuck
A flexible Brainfuck / Brainloller / Braincopter interpreter in Swift 3.1.
Stars: ✭ 13 (-51.85%)
Mutual labels:  brainfuck, brainfuck-interpreter

llvm-brainf**k

Brainf**k compiler based on LLVM API

This is the first step of my journey around LLVM compiler infrastructure.

In order to get familiar with LLVM IR instructions, I firstly employ clang to see how it compiles a simple C program to LLVM IR. For example,

int main() {
  char c;
  int i;
  long l;
  c = 'a';
  i = 72;
  l = 123456789012345;
}

this simple C program is compiled to the following LLVM IR instructions.

define i32 @main() {
  %1 = alloca i8, align 1
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  store i8 97, i8* %1, align 1
  store i32 72, i32* %2, align 4
  store i64 123456789012345, i64* %3, align 8
  ret i32 0
}

Try clang -S -emit-llvm -O0 test.c to see this, ignore attributes or some comments. Now you learn define, alloca, store and ret instructions in one minute. It's very easy isn't it?

The clang compiler shows us what LLVM IR instruction corresponds to C codes. This is the very first step for learning LLVM compiler infrastructure in my opinion.

The next step is generating LLVM IR instructions from programs. Are you going to try C++ API? Are you trying to start the Kaleidoscope tutorial? Please wait they are still difficult and complicated for beginners. Yeah, if you can learn forward, go ahead. But too difficult for me.

Brainf**k is like Hello world for learners of compiler and interpreter. I like this language. It has simple syntax that we can write its interpreter in an hour, but famous enough that complicated codes are found online (like mandelbrot.b written by Erik Bosman). We can pick up such Brainf**k codes to check whether our interpreter works correctly or not. Writing codes for 8 instructions then a mandelbrot art is generated on terminal, it's like a miracle!

I firstly wrote bf2llvm.c. Of course, I used clang -S -emit-llvm to see which instructions to output for each Brainf**k instructions. As you can see, it directly outputs LLVM IR instructions. It has no dependency on LLVM library and easy to what instructions will be generated by the code. But it's difficult to maintain temporary variable index, it can go into wrong codes easily and it requires the lli command to run the output.

Secondly I wrote bf2llvm.cpp. I explored the document generated by doxygen to see which functions to generate the IR instructions I need. It's very fun to use the LLVM C++ API! I need not take care for the index of temporary variables, precise type annotations for many instructions. The getOrInsertFunction function works like a charm that I don't care for declarations outside the main function. Object file generation is still difficult for me but I learned a lot from the chapter 8 of the Kaleidoscope tutorial.

In my experience of writing the two Brainf**k compilers, now I think I got familiar with LLVM IR instructions than before. After all, clang -S -emit-llvm is a great teacher for me, rather than complicated doxygen document and the Kaleidoscope tutorial. But now I'm going to try the Kaleidoscope tutorial (again; I gave up a few months ago).

Thank you LLVM infrastructure and it's contributors, you are great! I'm still a beginner of compiler techniques but I know you gave me a way to generate executables for my own language. I'm excited to learn LLVM infrastructure, want to contribute language compilers based on LLVM and create my own language in the future!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].