Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
brainfucker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
brainfucker
Commits
4ad2e109
Commit
4ad2e109
authored
Jan 08, 2015
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a small optimization example
parent
d1d5c13d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
1 deletion
+57
-1
README.md
README.md
+57
-1
No files found.
README.md
View file @
4ad2e109
...
@@ -7,6 +7,7 @@ purpose of practicing OCaml LLVM bindings and seeing how well LLVM optimizes
...
@@ -7,6 +7,7 @@ purpose of practicing OCaml LLVM bindings and seeing how well LLVM optimizes
arrays. Brainfuck commands are transformed to LLVM IR, which is generated in
arrays. Brainfuck commands are transformed to LLVM IR, which is generated in
such a way that it is easy to optimize for LLVM's
`opt`
utility.
such a way that it is easy to optimize for LLVM's
`opt`
utility.
Building and usage
Building and usage
==================
==================
...
@@ -15,7 +16,7 @@ Building the `bf` compiler (Debian dependencies):
...
@@ -15,7 +16,7 @@ Building the `bf` compiler (Debian dependencies):
$ sudo apt-get install ocaml llvm-3.4 libllvm-3.4-ocaml-dev
$ sudo apt-get install ocaml llvm-3.4 libllvm-3.4-ocaml-dev
$ make
$ make
Building a
b
rainfuck program (plain and optimized):
Building a
B
rainfuck program (plain and optimized):
$ make hello hello-opt # compile file "hello.b" to binaries
$ make hello hello-opt # compile file "hello.b" to binaries
$ ./hello
$ ./hello
...
@@ -35,3 +36,58 @@ Examining generated LLVM:
...
@@ -35,3 +36,58 @@ Examining generated LLVM:
...
...
$ echo ++++++++++++. | ./bf | opt -O3 -S
$ echo ++++++++++++. | ./bf | opt -O3 -S
...
...
Optimization example
--------------------
The
`text.py`
utility genrates single-cell Brainfuck code for a given text:
$ ./text.py Hello World!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
+++++++++++++++++++++++++++++.
+++++++.
.
+++.
-------------------------------------------------------------------------------.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++.
++++++++++++++++++++++++.
+++.
------.
--------.
-------------------------------------------------------------------.
-----------------------.
The LLVM optimization engine is able to completely optimize away array accesses
(in the absence of loops):
$ ./text.py Hello World! | ./bf | opt -O3 -S
; ModuleID = '<stdin>'
target datalayout = "e"
; Function Attrs: nounwind
declare i32 @putchar(i8) #0
declare void @exit(i32)
define void @_start() {
entry:
%0 = tail call i32 @putchar(i8 72)
%1 = tail call i32 @putchar(i8 101)
%2 = tail call i32 @putchar(i8 108)
%3 = tail call i32 @putchar(i8 108)
%4 = tail call i32 @putchar(i8 111)
%5 = tail call i32 @putchar(i8 32)
%6 = tail call i32 @putchar(i8 87)
%7 = tail call i32 @putchar(i8 111)
%8 = tail call i32 @putchar(i8 114)
%9 = tail call i32 @putchar(i8 108)
%10 = tail call i32 @putchar(i8 100)
%11 = tail call i32 @putchar(i8 33)
%12 = tail call i32 @putchar(i8 10)
tail call void @exit(i32 0)
ret void
}
attributes #0 = { nounwind }
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment