1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
target triple = "x86_64-pc-linux-gnu"
declare i64 @printf(i8*, ...)
@printf_d = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@printf_c = private unnamed_addr constant [3 x i8] c"%c\00", align 1
@printf_cycle = private unnamed_addr constant [16 x i8] c"cycle in spine\0a\00", align 1
@heap = global [10000 x i64] zeroinitializer, align 16
@astack = global [10000 x i64*] zeroinitializer, align 16
attributes #0 = { alwaysinline }
define private i64** @_push_local_astack(i64** %asp.0, i64** %aspstart, i64** %globasp.0) #0 {
entry:
br label %loop
loop:
%asp = phi i64** [%asp.0, %entry], [%asp.1, %loop.0]
%globasp = phi i64** [%globasp.0, %entry], [%globasp.1, %loop.0]
%t.0 = icmp eq i64** %asp, %aspstart
br i1 %t.0, label %done, label %loop.0
done:
ret i64** %globasp
loop.0:
%globasp.1 = getelementptr i64*, i64** %globasp, i64 1
%n = load i64*, i64** %asp
store i64* %n, i64** %globasp.1
%asp.1 = getelementptr i64*, i64** %asp, i64 -1
br label %loop
}
define private i64* @addI(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
%t.1 = load i64, i64* %bsp.1
%t.2 = add i64 %t.0, %t.1
store i64 %t.2, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @eqI_b(i64 %i, i64 %n, i64* %bsp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 %n
%bsp.2 = getelementptr i64, i64* %bsp.0, i64 -1
%t.0 = load i64, i64* %bsp.1
%t.1 = icmp eq i64 %t.0, %i
%t.2 = zext i1 %t.1 to i64
store i64 %t.2, i64* %bsp.2
ret i64* %bsp.2
}
define private i64** @fillI_b(i64 %b_offset, i64 %a_offset, i64* %bsp.0, i64** %asp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 %b_offset
%t.0 = load i64, i64* %bsp.1
%asp.1 = getelementptr i64*, i64** %asp.0, i64 %a_offset
%n.0 = load i64*, i64** %asp.1
%INT.0 = ptrtoint {i64, i64, i64*, i64, i8, i8, i8}* @INT to i64
%INT.1 = add i64 %INT.0, 2
store i64 %INT.1, i64* %n.0
%n.1 = getelementptr i64, i64* %n.0, i64 1
store i64 %t.0, i64* %n.1
ret i64** %asp.0
}
define private i64** @jsr_eval(i64 %n, i64** %asp.0, i64** %aspstart, i64** %globasp.0) #0 {
; TODO in case %n != 0 do we need to push it to the top of the stack?
%asp.1 = getelementptr i64*, i64** %asp.0, i64 %n
%n.0 = load i64*, i64** %asp.1
%d.0 = load i64, i64* %n.0
%t.0 = and i64 %d.0, 2
%t.1 = icmp eq i64 %t.0, 0
br i1 %t.1, label %eval, label %done
done:
ret i64** %asp.0
eval:
%globasp.1 = call i64** @_push_local_astack(i64** %asp.0, i64** %aspstart, i64** %globasp.0)
%nentry.0 = inttoptr i64 %d.0 to i64*(i64*, i64**)*
%n.1 = call i64* %nentry.0(i64* %n.0, i64** %globasp.1)
store i64* %n.1, i64** %asp.1
ret i64** %asp.0
}
define private i64* @ltI(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
%t.1 = load i64, i64* %bsp.1
%t.2 = icmp slt i64 %t.0, %t.1
%t.3 = zext i1 %t.2 to i64
store i64 %t.3, i64* %bsp.1
ret i64* %bsp.1
}
define private i64** @pop_a1(i64** %asp.0) #0 {
store i64* undef, i64** %asp.0
%asp.1 = getelementptr i64*, i64** %asp.0, i64 -1
ret i64** %asp.1
}
define private i64* @pop_b1(i64* %bsp.0) #0 {
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
ret i64* %bsp.1
}
define private i64* @print_int(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @printf_d, i64 0, i64 0), i64 %t.0)
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
ret i64* %bsp.1
}
define private i64* @push_b(i64 %n, i64* %bsp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 %n
%t.0 = load i64, i64* %bsp.1
%bsp.2 = getelementptr i64, i64* %bsp.0, i64 -1
store i64 %t.0, i64* %bsp.2
ret i64* %bsp.2
}
define private i64** @push_node(i64* %label, i64 %arity, i64** %asp.0) #0 {
entry:
%n.0 = load i64*, i64** %asp.0
%label.0 = ptrtoint i64* %label to i64
store i64 %label.0, i64* %n.0
br label %loop
loop:
%asp.1 = phi i64** [%asp.0, %entry], [%asp.2, %loop.0]
%arity.0 = phi i64 [%arity, %entry], [%arity.1, %loop.0]
%t.0 = icmp eq i64 %arity.0, 0
br i1 %t.0, label %done, label %loop.0
done:
ret i64** %asp.1
loop.0:
%n.1 = getelementptr i64, i64* %n.0, i64 %arity
%n.2 = load i64, i64* %n.1
%n.3 = inttoptr i64 %n.2 to i64*
%asp.2 = getelementptr i64*, i64** %asp.1, i64 1
store i64* %n.3, i64** %asp.2
%arity.1 = sub i64 %arity.0, 1
br label %loop
}
define private i64* @pushI(i64 %i, i64* %bsp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 -1
store i64 %i, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @pushI_a(i64 %n, i64* %bsp.0, i64** %asp.0) #0 {
%asp.1 = getelementptr i64*, i64** %asp.0, i64 %n
%n.0 = load i64*, i64** %asp.1
%n.1 = getelementptr i64, i64* %n.0, i64 1
%t.0 = load i64, i64* %n.1
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 -1
store i64 %t.0, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @subI(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
%t.1 = load i64, i64* %bsp.1
%t.2 = sub i64 %t.0, %t.1
store i64 %t.2, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @update_b(i64 %n1, i64 %n2, i64* %bsp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 %n1
%t.0 = load i64, i64* %bsp.1
%bsp.2 = getelementptr i64, i64* %bsp.0, i64 %n2
store i64 %t.0, i64* %bsp.2
ret i64* %bsp.0
}
define private i64* @updatepop_b01(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
store i64 %t.0, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @peek_a(i64** %asp) #0 {
%t = load i64*, i64** %asp
ret i64* %t
}
define private i64 @peek_b(i64* %bsp) #0 {
%t = load i64, i64* %bsp
ret i64 %t
}
@INT = constant {i64, i64, i64*, i64, i8, i8, i8}
{i64 0, i64 0, i64* inttoptr (i64 0 to i64*), i64 3, i8 73, i8 78, i8 84}
define i64* @_cycle_in_spine(i64** %globasp) prefix {i8*, i64} {i8* inttoptr (i64 0 to i8*), i64 0} {
call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @printf_cycle, i64 0, i64 0))
unreachable
}
|