-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin.s
More file actions
534 lines (529 loc) · 11.4 KB
/
builtin.s
File metadata and controls
534 lines (529 loc) · 11.4 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
.text
.file "builtin.cpp"
.globl string__add # -- Begin function string__add
.p2align 2
.type string__add,@function
string__add: # @string__add
.cfi_startproc
# %bb.0:
addi sp, sp, -32
.cfi_def_cfa_offset 32
sw ra, 28(sp)
sw s0, 24(sp)
sw s1, 20(sp)
.cfi_offset ra, -4
.cfi_offset s0, -8
.cfi_offset s1, -12
sw a0, 16(sp)
sw a1, 8(sp)
call strlen
lw a2, 8(sp)
mv s0, a0
mv s1, a1
mv a0, a2
call strlen
add a1, s1, a1
add a2, s0, a0
sltu a0, a2, s0
add a1, a1, a0
addi a0, a2, 4
sltu a2, a0, a2
add a1, a1, a2
call malloc
lw a1, 16(sp)
sw a0, 0(sp)
call strcpy
lw a0, 0(sp)
lw a1, 8(sp)
call strcat
lw a0, 0(sp)
lw s1, 20(sp)
lw s0, 24(sp)
lw ra, 28(sp)
addi sp, sp, 32
ret
.Lfunc_end1:
.size string__add, .Lfunc_end1-string__add
.cfi_endproc
# -- End function
.globl string__eq # -- Begin function string__eq
.p2align 2
.type string__eq,@function
string__eq: # @string__eq
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
sw a0, 8(sp)
sw a1, 0(sp)
call strcmp
seqz a0, a0
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end2:
.size string__eq, .Lfunc_end2-string__eq
.cfi_endproc
# -- End function
.globl string__neq # -- Begin function string__neq
.p2align 2
.type string__neq,@function
string__neq: # @string__neq
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
sw a0, 8(sp)
sw a1, 0(sp)
call strcmp
snez a0, a0
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end3:
.size string__neq, .Lfunc_end3-string__neq
.cfi_endproc
# -- End function
.globl string__l # -- Begin function string__l
.p2align 2
.type string__l,@function
string__l: # @string__l
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
sw a0, 8(sp)
sw a1, 0(sp)
call strcmp
srli a0, a0, 31
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end4:
.size string__l, .Lfunc_end4-string__l
.cfi_endproc
# -- End function
.globl string__leq # -- Begin function string__leq
.p2align 2
.type string__leq,@function
string__leq: # @string__leq
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
sw a0, 8(sp)
sw a1, 0(sp)
call strcmp
slti a0, a0, 1
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end5:
.size string__leq, .Lfunc_end5-string__leq
.cfi_endproc
# -- End function
.globl string__g # -- Begin function string__g
.p2align 2
.type string__g,@function
string__g: # @string__g
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
sw a0, 8(sp)
sw a1, 0(sp)
call strcmp
sgtz a0, a0
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end6:
.size string__g, .Lfunc_end6-string__g
.cfi_endproc
# -- End function
.globl string__geq # -- Begin function string__geq
.p2align 2
.type string__geq,@function
string__geq: # @string__geq
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
sw a0, 8(sp)
sw a1, 0(sp)
call strcmp
not a0, a0
srli a0, a0, 31
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end7:
.size string__geq, .Lfunc_end7-string__geq
.cfi_endproc
# -- End function
.globl print # -- Begin function print
.p2align 2
.type print,@function
print: # @print
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
mv a1, a0
sw a0, 8(sp)
lui a0, %hi(.L.str)
addi a0, a0, %lo(.L.str)
call printf
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end8:
.size print, .Lfunc_end8-print
.cfi_endproc
# -- End function
.globl println # -- Begin function println
.p2align 2
.type println,@function
println: # @println
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
mv a1, a0
sw a0, 8(sp)
lui a0, %hi(.L.str.1)
addi a0, a0, %lo(.L.str.1)
call printf
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end9:
.size println, .Lfunc_end9-println
.cfi_endproc
# -- End function
.globl printInt # -- Begin function printInt
.p2align 2
.type printInt,@function
printInt: # @printInt
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
mv a1, a0
sw a0, 8(sp)
lui a0, %hi(.L.str.2)
addi a0, a0, %lo(.L.str.2)
call printf
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end10:
.size printInt, .Lfunc_end10-printInt
.cfi_endproc
# -- End function
.globl printlnInt # -- Begin function printlnInt
.p2align 2
.type printlnInt,@function
printlnInt: # @printlnInt
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
mv a1, a0
sw a0, 8(sp)
lui a0, %hi(.L.str.3)
addi a0, a0, %lo(.L.str.3)
call printf
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end11:
.size printlnInt, .Lfunc_end11-printlnInt
.cfi_endproc
# -- End function
.globl getString # -- Begin function getString
.p2align 2
.type getString,@function
getString: # @getString
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
addi a0, zero, 1024
mv a1, zero
call malloc
mv a1, a0
sw a0, 8(sp)
lui a0, %hi(.L.str)
addi a0, a0, %lo(.L.str)
call __isoc99_scanf
lw a0, 8(sp)
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end12:
.size getString, .Lfunc_end12-getString
.cfi_endproc
# -- End function
.globl getInt # -- Begin function getInt
.p2align 2
.type getInt,@function
getInt: # @getInt
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
lui a0, %hi(.L.str.2)
addi a0, a0, %lo(.L.str.2)
addi a1, sp, 8
call __isoc99_scanf
lw a0, 8(sp)
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end13:
.size getInt, .Lfunc_end13-getInt
.cfi_endproc
# -- End function
.globl toString # -- Begin function toString
.p2align 2
.type toString,@function
toString: # @toString
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
sw a0, 8(sp)
addi a0, zero, 20
mv a1, zero
call malloc
lw a2, 8(sp)
sw a0, 0(sp)
lui a1, %hi(.L.str.2)
addi a1, a1, %lo(.L.str.2)
call sprintf
lw a0, 0(sp)
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end14:
.size toString, .Lfunc_end14-toString
.cfi_endproc
# -- End function
.globl string__length # -- Begin function string__length
.p2align 2
.type string__length,@function
string__length: # @string__length
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
sw a0, 8(sp)
call strlen
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end15:
.size string__length, .Lfunc_end15-string__length
.cfi_endproc
# -- End function
.globl string__substring # -- Begin function string__substring
.p2align 2
.type string__substring,@function
string__substring: # @string__substring
.cfi_startproc
# %bb.0:
addi sp, sp, -32
.cfi_def_cfa_offset 32
sw ra, 28(sp)
.cfi_offset ra, -4
sw a0, 24(sp)
sw a1, 20(sp)
sw a2, 16(sp)
sub a0, a1, a0
addi a0, a0, 1
srai a1, a0, 31
call malloc
lw a1, 16(sp)
lw a2, 24(sp)
lw a3, 20(sp)
sw a0, 8(sp)
add a1, a1, a2
sub a2, a3, a2
call memcpy
lw a0, 20(sp)
lw a1, 24(sp)
lw a2, 8(sp)
sub a0, a0, a1
slli a0, a0, 2
add a0, a2, a0
sw zero, 0(a0)
lw a0, 8(sp)
lw ra, 28(sp)
addi sp, sp, 32
ret
.Lfunc_end16:
.size string__substring, .Lfunc_end16-string__substring
.cfi_endproc
# -- End function
.globl string__parseInt # -- Begin function string__parseInt
.p2align 2
.type string__parseInt,@function
string__parseInt: # @string__parseInt
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw ra, 12(sp)
.cfi_offset ra, -4
sw a0, 8(sp)
lui a1, %hi(.L.str.2)
addi a1, a1, %lo(.L.str.2)
addi a2, sp, 4
call __isoc99_sscanf
lw a0, 4(sp)
lw ra, 12(sp)
addi sp, sp, 16
ret
.Lfunc_end17:
.size string__parseInt, .Lfunc_end17-string__parseInt
.cfi_endproc
# -- End function
.globl string__ord # -- Begin function string__ord
.p2align 2
.type string__ord,@function
string__ord: # @string__ord
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw a0, 12(sp)
sw a1, 8(sp)
add a0, a1, a0
lb a0, 0(a0)
addi sp, sp, 16
ret
.Lfunc_end18:
.size string__ord, .Lfunc_end18-string__ord
.cfi_endproc
# -- End function
.globl array__size # -- Begin function array__size
.p2align 2
.type array__size,@function
array__size: # @array__size
.cfi_startproc
# %bb.0:
addi sp, sp, -16
.cfi_def_cfa_offset 16
sw a0, 8(sp)
lw a0, -4(a0)
addi sp, sp, 16
ret
.Lfunc_end19:
.size array__size, .Lfunc_end19-array__size
.cfi_endproc
# -- End function
.globl ir_new_array # -- Begin function ir_new_array
.p2align 2
.type ir_new_array,@function
ir_new_array: # @ir_new_array
.cfi_startproc
# %bb.0:
addi sp, sp, -32
.cfi_def_cfa_offset 32
sw ra, 28(sp)
.cfi_offset ra, -4
sw a0, 24(sp)
sw a1, 20(sp)
add a0, a0, a1
lw a0, 0(a0)
sw a0, 16(sp)
slli a0, a0, 2
addi a0, a0, 4
srai a1, a0, 31
call malloc
lw a1, 16(sp)
sw a0, 12(sp)
sw a1, 0(a0)
lw a1, 24(sp)
addi a0, a0, 4
sw a0, 12(sp)
lw a0, 20(sp)
lw a1, 0(a1)
addi a0, a0, 4
slli a1, a1, 2
blt a1, a0, .LBB1_4
# %bb.1:
lw a0, 16(sp)
slli a0, a0, 2
.LBB1_2: # =>This Inner Loop Header: Depth=1
addi a0, a0, -4
sw a0, 8(sp)
bltz a0, .LBB1_4
# %bb.3: # in Loop: Header=BB1_2 Depth=1
lw a1, 20(sp)
lw a0, 24(sp)
addi a1, a1, 4
call ir_new_array
lw a1, 12(sp)
lw a2, 8(sp)
add a1, a1, a2
sw a0, 0(a1)
lw a0, 8(sp)
j .LBB1_2
.LBB1_4:
lw a0, 12(sp)
lw ra, 28(sp)
addi sp, sp, 32
ret
.Lfunc_end21:
.size ir_new_array, .Lfunc_end21-ir_new_array
.cfi_endproc
# -- End function
.type .L.str,@object # @.str
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "%s"
.size .L.str, 3
.type .L.str.1,@object # @.str.1
.L.str.1:
.asciz "%s\n"
.size .L.str.1, 4
.type .L.str.2,@object # @.str.2
.L.str.2:
.asciz "%d"
.size .L.str.2, 3
.type .L.str.3,@object # @.str.3
.L.str.3:
.asciz "%d\n"
.size .L.str.3, 4
.ident "clang version 10.0.0-4ubuntu1 "
.section ".note.GNU-stack","",@progbits