Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brainfucker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
brainfucker
Commits
497e5399
Commit
497e5399
authored
10 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Code cleanup
parent
efc19d80
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bf.ml
+9
-24
9 additions, 24 deletions
bf.ml
with
9 additions
and
24 deletions
bf.ml
+
9
−
24
View file @
497e5399
...
...
@@ -27,22 +27,6 @@ let read_program ic =
in
next
[]
[]
let
rec
string_of_program
program
=
let
string_of_command
=
function
|
Incptr
->
">"
|
Decptr
->
"<"
|
Incdata
->
"+"
|
Decdata
->
"-"
|
Output
->
"."
|
Input
->
","
|
Loop
p
->
"["
^
string_of_program
p
^
"]"
in
let
rec
cat
buf
=
function
|
[]
->
buf
|
cmd
::
tl
->
cat
(
buf
^
string_of_command
cmd
)
tl
in
cat
""
program
let
compile
memsize
program
=
let
ctx
=
global_context
()
in
let
m
=
create_module
ctx
"brainfucker"
in
...
...
@@ -67,21 +51,22 @@ let compile memsize program =
bb_cur
:=
bb
in
let
i
n
=
const_int
i32_ty
n
in
let
i8
n
=
const_int
byte_ty
n
in
let
i
w
n
=
const_int
(
integer_type
ctx
w
)
n
in
let
i8
=
i
8
in
let
i32
=
i
32
in
let
mem
=
build_alloca
(
array_type
byte_ty
memsize
)
"mem"
b
in
let
idx
=
build_alloca
i32_ty
"idx"
b
in
let
gep
()
=
build_in_bounds_gep
mem
[
|
i
0
;
build_load
idx
""
b
|
]
""
b
in
let
load
ptr
=
build_load
ptr
""
b
in
let
store
ptr
value
=
ignore
(
build_store
value
ptr
b
)
in
let
gep
()
=
build_in_bounds_gep
mem
[
|
i32
0
;
load
idx
|
]
""
b
in
let
rec
compile_command
=
function
|
Incptr
->
build_add
(
load
idx
)
(
i
1
)
""
b
|>
store
idx
build_add
(
load
idx
)
(
i
32
1
)
""
b
|>
store
idx
|
Decptr
->
build_sub
(
load
idx
)
(
i
1
)
""
b
|>
store
idx
build_sub
(
load
idx
)
(
i
32
1
)
""
b
|>
store
idx
|
Incdata
->
build_add
(
load
(
gep
()
))
(
i8
1
)
""
b
|>
store
(
gep
()
)
|
Decdata
->
...
...
@@ -115,14 +100,14 @@ let compile memsize program =
declare_function
"llvm.memset.p0i8.i32"
(
function_type
void_ty
arg_types
)
m
in
let
ptr
=
build_bitcast
mem
byteptr_ty
""
b
in
build_call
memset
[
|
ptr
;
i8
0
;
i
memsize
;
i
0
;
const_int
bool_ty
0
|
]
""
b
|>
ignore
;
build_call
memset
[
|
ptr
;
i8
0
;
i
32
memsize
;
i
32
0
;
i
1
0
|
]
""
b
|>
ignore
;
(* set pivot to index 0 and compile program commands *)
store
idx
(
i
0
);
store
idx
(
i
32
0
);
List
.
iter
compile_command
program
;
(* exit gracefully *)
build_call
cexit
[
|
i
0
|
]
""
b
|>
ignore
;
build_call
cexit
[
|
i
32
0
|
]
""
b
|>
ignore
;
build_ret_void
b
|>
ignore
;
m
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment