bf-llvm

所属分类:collect
开发工具:C++
文件大小:0KB
下载次数:0
上传日期:2023-10-01 10:21:03
上 传 者sh-1993
说明:  LLVM brainf*ck编译器
(A LLVM brainf*ck compiler)

文件列表:
.clang-format (1953, 2024-01-06)
.clang-tidy (4643, 2024-01-06)
CMakeLists.txt (539, 2024-01-06)
LICENSE (1071, 2024-01-06)
examples/ (0, 2024-01-06)
examples/helloworld.bf (165, 2024-01-06)
examples/mandelbrot.bf (11669, 2024-01-06)
src/ (0, 2024-01-06)
src/AST.h (1035, 2024-01-06)
src/AstPrinter.cpp (1133, 2024-01-06)
src/Compiler.cpp (5621, 2024-01-06)
src/Interpreter.cpp (907, 2024-01-06)
src/Parser.cpp (4403, 2024-01-06)
src/Scanner.cpp (1899, 2024-01-06)
src/Token.h (734, 2024-01-06)
src/main.cpp (2270, 2024-01-06)

# An optimizing LLVM Brainf*ck compiler An optimizing [brainf*ck](http://brainfuck.org/brainfuck.html) compiler using LLVM. Some optimizations are applied before code generation: * Zero-ing loops (`[+]` / `[-]`) are represented as a single instruction * Consecutive move and add instructions are merged into single instructions with an amount parameter Then LLVM optimizations are applied on the generated LLVM IR. As an example of these powerful optimizations, brainf*ck HelloWorld will be optimized to simple `putchar` calls: ```llvm // Input >++++++++[<+++++++++>-]<.>++++[<+++++++>-]<+.+++++++..+++. >>++++++[<+++++++>-]<++.------------.>++++++[<+++++++++>-] <+.<.+++.------.--------.>>>++++[<++++++++>-]<+. // Optimized IR output define i32 @main() local_unnamed_addr #0 { entry: %0 = tail call i32 @putchar(i32 72) %1 = tail call i32 @putchar(i32 101) %2 = tail call i32 @putchar(i32 108) %3 = tail call i32 @putchar(i32 108) %4 = tail call i32 @putchar(i32 111) %5 = tail call i32 @putchar(i32 44) %6 = tail call i32 @putchar(i32 32) %7 = tail call i32 @putchar(i32 87) %8 = tail call i32 @putchar(i32 111) %9 = tail call i32 @putchar(i32 114) %10 = tail call i32 @putchar(i32 108) %11 = tail call i32 @putchar(i32 100) %12 = tail call i32 @putchar(i32 33) ret i32 0 } ``` ## Building and Executing ```shell $ cmake -G Ninja -B build $ ninja -C build $ build/bf examples/helloworld.bf -o build/helloworld.ll $ lli build/helloworld.ll ``` ## Other targets This project is a port of [bf](https://github.com/mrjameshamilton) which is a brainf*ck compiler with backends for: * JVM * Smali * Dex * C * LLVM IR * ARM assembly * WASM * JavaScript * Lox # Useful brainf*ck resources * [Brainf*ck language reference](http://brainfuck.org/brainfuck.html) * [Sample programs by Daniel B Cristofani](http://brainfuck.org/) * [Optimizing brainf*ck programs](http://calmerthanyouare.org/2015/01/07/optimizing-brainfuck.html) * [Brainf*ck Wikipedia article](https://en.wikipedia.org/wiki/Brainfuck)

近期下载者

相关文件


收藏者