-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgen.s
More file actions
2458 lines (2448 loc) · 73.8 KB
/
gen.s
File metadata and controls
2458 lines (2448 loc) · 73.8 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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;
; generated by baz
;
DEFAULT REL
section .bss
stk resd 131072
stk.end:
section .data
;[1:1] field hello = "hello world from baz\n"
hello: db 'hello world from baz', 10,''
hello.len equ $ - hello
;[2:1] field prompt1 = "enter name:\n"
prompt1: db 'enter name:', 10,''
prompt1.len equ $ - prompt1
;[3:1] field prompt2 = "that is not a name.\n"
prompt2: db 'that is not a name.', 10,''
prompt2.len equ $ - prompt2
;[4:1] field prompt3 = "hello "
prompt3: db 'hello '
prompt3.len equ $ - prompt3
;[5:1] field dot = "."
dot: db '.'
dot.len equ $ - dot
;[6:1] field nl = "\n"
nl: db '', 10,''
nl.len equ $ - nl
section .text
bits 64
global _start
_start:
mov rsp, stk.end
;
; program
;
;[8:1] # all functions are inlined
;[10:1] # arguments can be placed in specified register using `reg_...` syntax
;[18:1] # single statement blocks can ommit { ... }
;[39:1] # user types are defined using keyword `type`
;[41:1] # default type is `i64` and does not need to be specified
;[43:1] point : 16B fields:
;[43:1] name : offset : size : array? : array size
;[43:1] x : 0 : 8 : no :
;[43:1] y : 8 : 8 : no :
;[45:1] object : 20B fields:
;[45:1] name : offset : size : array? : array size
;[45:1] pos : 0 : 16 : no :
;[45:1] color : 16 : 4 : no :
;[47:1] world : 64B fields:
;[47:1] name : offset : size : array? : array size
;[47:1] locations : 0 : 64 : yes : 8
;[49:1] # function arguments are equivalent to mutable references
;[56:1] # default argument type is `i64`
;[63:1] # return target is specified as a variable, in this case `res`
;[73:1] # array arguments are declared with type and []
;[79:1] str : 128B fields:
;[79:1] name : offset : size : array? : array size
;[79:1] len : 0 : 1 : no :
;[79:1] data : 1 : 127 : yes : 127
main:
; [102:5] var arr : i32[4]
; [102:9] arr: i32[4] (16B @ [rsp - 16])
; [102:9] clear 4 * 4B = 16B
; [102:5] size <= 32B, use mov
mov qword [rsp - 16], 0
mov qword [rsp - 8], 0
; [103:5] # arrays are initialized to 0
; [105:5] var ix = 1
; [105:9] ix: i64 (8B @ [rsp - 24])
; [105:9] ix = 1
; [105:14] 1
mov qword [rsp - 24], 1
; [107:5] arr[ix] = 2
; [107:5] allocate scratch register -> r15
; [107:9] set array index
; [107:9] ix
mov r15, qword [rsp - 24]
; [107:9] bounds check
; [107:9] allocate scratch register -> r14
; [107:9] line number
mov r14, 107
test r15, r15
cmovs rbp, r14
js panic_bounds
cmp r15, 4
cmovge rbp, r14
jge panic_bounds
; [107:9] free scratch register 'r14'
; [107:15] 2
mov dword [rsp + r15 * 4 - 16], 2
; [107:5] free scratch register 'r15'
; [108:5] arr[ix + 1] = arr[ix]
; [108:5] allocate scratch register -> r15
; [108:9] set array index
; [108:9] ix
mov r15, qword [rsp - 24]
; [108:14] r15 + 1
add r15, 1
; [108:9] bounds check
; [108:9] allocate scratch register -> r14
; [108:9] line number
mov r14, 108
test r15, r15
cmovs rbp, r14
js panic_bounds
cmp r15, 4
cmovge rbp, r14
jge panic_bounds
; [108:9] free scratch register 'r14'
; [108:19] arr[ix]
; [108:19] allocate scratch register -> r14
; [108:23] set array index
; [108:23] ix
mov r14, qword [rsp - 24]
; [108:23] bounds check
; [108:23] allocate scratch register -> r13
; [108:23] line number
mov r13, 108
test r14, r14
cmovs rbp, r13
js panic_bounds
cmp r14, 4
cmovge rbp, r13
jge panic_bounds
; [108:23] free scratch register 'r13'
; [108:19] allocate scratch register -> r13
mov r13d, dword [rsp + r14 * 4 - 16]
mov dword [rsp + r15 * 4 - 16], r13d
; [108:19] free scratch register 'r13'
; [108:19] free scratch register 'r14'
; [108:5] free scratch register 'r15'
; [109:5] assert(arr[1] == 2)
; [109:12] allocate scratch register -> r15
; [109:12] ? arr[1] == 2
; [109:12] ? arr[1] == 2
cmp_109_12:
; [109:12] allocate scratch register -> r14
; [109:16] set array index
; [109:16] 1
mov r14, 1
; [109:16] bounds check
; [109:16] allocate scratch register -> r13
; [109:16] line number
mov r13, 109
test r14, r14
cmovs rbp, r13
js panic_bounds
cmp r14, 4
cmovge rbp, r13
jge panic_bounds
; [109:16] free scratch register 'r13'
cmp dword [rsp + r14 * 4 - 16], 2
; [109:12] free scratch register 'r14'
sete r15b
bool_end_109_12:
; [20:6] assert(expr : bool)
assert_109_5:
; [109:5] alias expr -> r15b (lea: )
if_20_29_109_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_109_5:
cmp r15b, 0
jne if_20_26_109_5_end
if_20_29_109_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_109_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_109_5_end:
if_20_26_109_5_end:
; [109:5] free scratch register 'r15'
assert_109_5_end:
; [110:5] assert(arr[2] == 2)
; [110:12] allocate scratch register -> r15
; [110:12] ? arr[2] == 2
; [110:12] ? arr[2] == 2
cmp_110_12:
; [110:12] allocate scratch register -> r14
; [110:16] set array index
; [110:16] 2
mov r14, 2
; [110:16] bounds check
; [110:16] allocate scratch register -> r13
; [110:16] line number
mov r13, 110
test r14, r14
cmovs rbp, r13
js panic_bounds
cmp r14, 4
cmovge rbp, r13
jge panic_bounds
; [110:16] free scratch register 'r13'
cmp dword [rsp + r14 * 4 - 16], 2
; [110:12] free scratch register 'r14'
sete r15b
bool_end_110_12:
; [20:6] assert(expr : bool)
assert_110_5:
; [110:5] alias expr -> r15b (lea: )
if_20_29_110_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_110_5:
cmp r15b, 0
jne if_20_26_110_5_end
if_20_29_110_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_110_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_110_5_end:
if_20_26_110_5_end:
; [110:5] free scratch register 'r15'
assert_110_5_end:
; [112:5] array_copy(arr[2], arr, 2)
; [112:5] allocate named register 'rsi'
; [112:5] allocate named register 'rdi'
; [112:5] allocate named register 'rcx'
; [112:29] 2
; [112:29] 2
mov rcx, 2
; [112:16] arr[2]
; [112:16] allocate scratch register -> r15
; [112:20] set array index
; [112:20] 2
mov r15, 2
; [112:20] bounds check
; [112:20] allocate scratch register -> r14
; [112:20] line number
mov r14, 112
test r15, r15
cmovs rbp, r14
js panic_bounds
; [112:20] allocate scratch register -> r13
mov r13, rcx
add r13, r15
cmp r13, 4
; [112:20] free scratch register 'r13'
cmovg rbp, r14
jg panic_bounds
; [112:20] free scratch register 'r14'
lea rsi, [rsp + r15 * 4 - 16]
; [112:5] free scratch register 'r15'
; [112:24] arr
; [112:24] bounds check
; [112:24] allocate scratch register -> r15
; [112:24] line number
mov r15, 112
test rcx, rcx
cmovs rbp, r15
js panic_bounds
cmp rcx, 4
cmovg rbp, r15
jg panic_bounds
; [112:24] free scratch register 'r15'
lea rdi, [rsp - 16]
shl rcx, 2
rep movsb
; [112:5] free named register 'rcx'
; [112:5] free named register 'rdi'
; [112:5] free named register 'rsi'
; [113:5] # copy from, to, number of elements
; [114:5] assert(arr[0] == 2)
; [114:12] allocate scratch register -> r15
; [114:12] ? arr[0] == 2
; [114:12] ? arr[0] == 2
cmp_114_12:
; [114:12] allocate scratch register -> r14
; [114:16] set array index
; [114:16] 0
mov r14, 0
; [114:16] bounds check
; [114:16] allocate scratch register -> r13
; [114:16] line number
mov r13, 114
test r14, r14
cmovs rbp, r13
js panic_bounds
cmp r14, 4
cmovge rbp, r13
jge panic_bounds
; [114:16] free scratch register 'r13'
cmp dword [rsp + r14 * 4 - 16], 2
; [114:12] free scratch register 'r14'
sete r15b
bool_end_114_12:
; [20:6] assert(expr : bool)
assert_114_5:
; [114:5] alias expr -> r15b (lea: )
if_20_29_114_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_114_5:
cmp r15b, 0
jne if_20_26_114_5_end
if_20_29_114_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_114_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_114_5_end:
if_20_26_114_5_end:
; [114:5] free scratch register 'r15'
assert_114_5_end:
; [116:5] var arr1 : i32[8]
; [116:9] arr1: i32[8] (32B @ [rsp - 56])
; [116:9] clear 8 * 4B = 32B
; [116:5] size <= 32B, use mov
mov qword [rsp - 56], 0
mov qword [rsp - 48], 0
mov qword [rsp - 40], 0
mov qword [rsp - 32], 0
; [117:5] array_copy(arr, arr1, 4)
; [117:5] allocate named register 'rsi'
; [117:5] allocate named register 'rdi'
; [117:5] allocate named register 'rcx'
; [117:27] 4
; [117:27] 4
mov rcx, 4
; [117:16] arr
; [117:16] bounds check
; [117:16] allocate scratch register -> r15
; [117:16] line number
mov r15, 117
test rcx, rcx
cmovs rbp, r15
js panic_bounds
cmp rcx, 4
cmovg rbp, r15
jg panic_bounds
; [117:16] free scratch register 'r15'
lea rsi, [rsp - 16]
; [117:21] arr1
; [117:21] bounds check
; [117:21] allocate scratch register -> r15
; [117:21] line number
mov r15, 117
test rcx, rcx
cmovs rbp, r15
js panic_bounds
cmp rcx, 8
cmovg rbp, r15
jg panic_bounds
; [117:21] free scratch register 'r15'
lea rdi, [rsp - 56]
shl rcx, 2
rep movsb
; [117:5] free named register 'rcx'
; [117:5] free named register 'rdi'
; [117:5] free named register 'rsi'
; [118:5] assert(arrays_equal(arr, arr1, 4))
; [118:12] allocate scratch register -> r15
; [118:12] ? arrays_equal(arr, arr1, 4)
; [118:12] ? arrays_equal(arr, arr1, 4)
cmp_118_12:
; [118:12] allocate scratch register -> r14
; [118:12] r14 = arrays_equal(arr, arr1, 4)
; [118:12] = expression
; [118:12] arrays_equal(arr, arr1, 4)
; [118:12] allocate named register 'rsi'
; [118:12] allocate named register 'rdi'
; [118:12] allocate named register 'rcx'
; [118:36] 4
; [118:36] 4
mov rcx, 4
; [118:25] arr
; [118:25] bounds check
; [118:25] allocate scratch register -> r13
; [118:25] line number
mov r13, 118
test rcx, rcx
cmovs rbp, r13
js panic_bounds
cmp rcx, 4
cmovg rbp, r13
jg panic_bounds
; [118:25] free scratch register 'r13'
lea rsi, [rsp - 16]
; [118:30] arr1
; [118:30] bounds check
; [118:30] allocate scratch register -> r13
; [118:30] line number
mov r13, 118
test rcx, rcx
cmovs rbp, r13
js panic_bounds
cmp rcx, 8
cmovg rbp, r13
jg panic_bounds
; [118:30] free scratch register 'r13'
lea rdi, [rsp - 56]
shl rcx, 2
repe cmpsb
; [118:12] free named register 'rcx'
; [118:12] free named register 'rdi'
; [118:12] free named register 'rsi'
sete r14b
cmp r14, 0
; [118:12] free scratch register 'r14'
setne r15b
bool_end_118_12:
; [20:6] assert(expr : bool)
assert_118_5:
; [118:5] alias expr -> r15b (lea: )
if_20_29_118_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_118_5:
cmp r15b, 0
jne if_20_26_118_5_end
if_20_29_118_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_118_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_118_5_end:
if_20_26_118_5_end:
; [118:5] free scratch register 'r15'
assert_118_5_end:
; [119:5] # note: `arrays_equal` is built-in function
; [121:5] arr1[2] = -1
; [121:5] allocate scratch register -> r15
; [121:10] set array index
; [121:10] 2
mov r15, 2
; [121:10] bounds check
; [121:10] allocate scratch register -> r14
; [121:10] line number
mov r14, 121
test r15, r15
cmovs rbp, r14
js panic_bounds
cmp r15, 8
cmovge rbp, r14
jge panic_bounds
; [121:10] free scratch register 'r14'
; [121:16] -1
mov dword [rsp + r15 * 4 - 56], -1
; [121:5] free scratch register 'r15'
; [122:5] assert(not arrays_equal(arr, arr1, 4))
; [122:12] allocate scratch register -> r15
; [122:12] ? not arrays_equal(arr, arr1, 4)
; [122:12] ? not arrays_equal(arr, arr1, 4)
cmp_122_12:
; [122:16] allocate scratch register -> r14
; [122:16] r14 = arrays_equal(arr, arr1, 4)
; [122:16] = expression
; [122:16] arrays_equal(arr, arr1, 4)
; [122:16] allocate named register 'rsi'
; [122:16] allocate named register 'rdi'
; [122:16] allocate named register 'rcx'
; [122:40] 4
; [122:40] 4
mov rcx, 4
; [122:29] arr
; [122:29] bounds check
; [122:29] allocate scratch register -> r13
; [122:29] line number
mov r13, 122
test rcx, rcx
cmovs rbp, r13
js panic_bounds
cmp rcx, 4
cmovg rbp, r13
jg panic_bounds
; [122:29] free scratch register 'r13'
lea rsi, [rsp - 16]
; [122:34] arr1
; [122:34] bounds check
; [122:34] allocate scratch register -> r13
; [122:34] line number
mov r13, 122
test rcx, rcx
cmovs rbp, r13
js panic_bounds
cmp rcx, 8
cmovg rbp, r13
jg panic_bounds
; [122:34] free scratch register 'r13'
lea rdi, [rsp - 56]
shl rcx, 2
repe cmpsb
; [122:16] free named register 'rcx'
; [122:16] free named register 'rdi'
; [122:16] free named register 'rsi'
sete r14b
cmp r14, 0
; [122:12] free scratch register 'r14'
sete r15b
bool_end_122_12:
; [20:6] assert(expr : bool)
assert_122_5:
; [122:5] alias expr -> r15b (lea: )
if_20_29_122_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_122_5:
cmp r15b, 0
jne if_20_26_122_5_end
if_20_29_122_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_122_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_122_5_end:
if_20_26_122_5_end:
; [122:5] free scratch register 'r15'
assert_122_5_end:
; [124:5] ix = 3
; [124:10] 3
mov qword [rsp - 24], 3
; [125:5] arr[ix] = ~inv(arr[ix - 1])
; [125:5] allocate scratch register -> r15
; [125:9] set array index
; [125:9] ix
mov r15, qword [rsp - 24]
; [125:9] bounds check
; [125:9] allocate scratch register -> r14
; [125:9] line number
mov r14, 125
test r15, r15
cmovs rbp, r14
js panic_bounds
cmp r15, 4
cmovge rbp, r14
jge panic_bounds
; [125:9] free scratch register 'r14'
; [125:16] arr = ~inv(arr[ix - 1])
; [125:16] = expression
; [125:16] ~inv(arr[ix - 1])
; [125:20] allocate scratch register -> r14
; [125:24] set array index
; [125:24] ix
mov r14, qword [rsp - 24]
; [125:29] r14 - 1
sub r14, 1
; [125:24] bounds check
; [125:24] allocate scratch register -> r13
; [125:24] line number
mov r13, 125
test r14, r14
cmovs rbp, r13
js panic_bounds
cmp r14, 4
cmovge rbp, r13
jge panic_bounds
; [125:24] free scratch register 'r13'
; [65:6] inv(i : i32) : i32 res
inv_125_16:
; [125:16] alias res -> dword [rsp + r15 * 4 - 16] (lea: )
; [125:16] alias i -> arr (lea: rsp + r14 * 4 - 16)
; [66:5] res = ~i
; [66:12] ~i
; [66:12] allocate scratch register -> r13
mov r13d, dword [rsp + r14 * 4 - 16]
mov dword [rsp + r15 * 4 - 16], r13d
; [66:12] free scratch register 'r13'
not dword [rsp + r15 * 4 - 16]
; [125:16] free scratch register 'r14'
inv_125_16_end:
not dword [rsp + r15 * 4 - 16]
; [125:5] free scratch register 'r15'
; [126:5] assert(arr[ix] == 2)
; [126:12] allocate scratch register -> r15
; [126:12] ? arr[ix] == 2
; [126:12] ? arr[ix] == 2
cmp_126_12:
; [126:12] allocate scratch register -> r14
; [126:16] set array index
; [126:16] ix
mov r14, qword [rsp - 24]
; [126:16] bounds check
; [126:16] allocate scratch register -> r13
; [126:16] line number
mov r13, 126
test r14, r14
cmovs rbp, r13
js panic_bounds
cmp r14, 4
cmovge rbp, r13
jge panic_bounds
; [126:16] free scratch register 'r13'
cmp dword [rsp + r14 * 4 - 16], 2
; [126:12] free scratch register 'r14'
sete r15b
bool_end_126_12:
; [20:6] assert(expr : bool)
assert_126_5:
; [126:5] alias expr -> r15b (lea: )
if_20_29_126_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_126_5:
cmp r15b, 0
jne if_20_26_126_5_end
if_20_29_126_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_126_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_126_5_end:
if_20_26_126_5_end:
; [126:5] free scratch register 'r15'
assert_126_5_end:
; [128:5] faz(arr)
; [75:6] faz(arg : i32[])
faz_128_5:
; [128:5] alias arg -> arr (lea: )
; [76:5] arg[1] = 0xfe
; [76:5] allocate scratch register -> r15
; [76:9] set array index
; [76:9] 1
mov r15, 1
; [76:9] bounds check
; [76:9] allocate scratch register -> r14
; [76:9] line number
mov r14, 76
test r15, r15
cmovs rbp, r14
js panic_bounds
cmp r15, 4
cmovge rbp, r14
jge panic_bounds
; [76:9] free scratch register 'r14'
; [76:14] 0xfe
mov dword [rsp + r15 * 4 - 16], 254
; [76:5] free scratch register 'r15'
faz_128_5_end:
; [129:5] assert(arr[1] == 0xfe)
; [129:12] allocate scratch register -> r15
; [129:12] ? arr[1] == 0xfe
; [129:12] ? arr[1] == 0xfe
cmp_129_12:
; [129:12] allocate scratch register -> r14
; [129:16] set array index
; [129:16] 1
mov r14, 1
; [129:16] bounds check
; [129:16] allocate scratch register -> r13
; [129:16] line number
mov r13, 129
test r14, r14
cmovs rbp, r13
js panic_bounds
cmp r14, 4
cmovge rbp, r13
jge panic_bounds
; [129:16] free scratch register 'r13'
cmp dword [rsp + r14 * 4 - 16], 254
; [129:12] free scratch register 'r14'
sete r15b
bool_end_129_12:
; [20:6] assert(expr : bool)
assert_129_5:
; [129:5] alias expr -> r15b (lea: )
if_20_29_129_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_129_5:
cmp r15b, 0
jne if_20_26_129_5_end
if_20_29_129_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_129_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_129_5_end:
if_20_26_129_5_end:
; [129:5] free scratch register 'r15'
assert_129_5_end:
; [131:5] var p : point = {0, 0}
; [131:9] p: point (16B @ [rsp - 72])
; [131:9] p = {0, 0}
; [131:21] copy field 'x'
mov qword [rsp - 72], 0
; [131:21] copy field 'y'
mov qword [rsp - 64], 0
; [132:5] foo(p)
; [51:6] foo(pt : point)
foo_132_5:
; [132:5] alias pt -> p (lea: )
; [52:5] pt.x = 0b10
; [52:12] 0b10
mov qword [rsp - 72], 2
; [52:20] # binary value 2
; [53:5] pt.y = 0xb
; [53:12] 0xb
mov qword [rsp - 64], 11
; [53:20] # hex value 11
foo_132_5_end:
; [133:5] assert(p.x == 2)
; [133:12] allocate scratch register -> r15
; [133:12] ? p.x == 2
; [133:12] ? p.x == 2
cmp_133_12:
cmp qword [rsp - 72], 2
sete r15b
bool_end_133_12:
; [20:6] assert(expr : bool)
assert_133_5:
; [133:5] alias expr -> r15b (lea: )
if_20_29_133_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_133_5:
cmp r15b, 0
jne if_20_26_133_5_end
if_20_29_133_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_133_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_133_5_end:
if_20_26_133_5_end:
; [133:5] free scratch register 'r15'
assert_133_5_end:
; [134:5] assert(p.y == 0xb)
; [134:12] allocate scratch register -> r15
; [134:12] ? p.y == 0xb
; [134:12] ? p.y == 0xb
cmp_134_12:
cmp qword [rsp - 64], 11
sete r15b
bool_end_134_12:
; [20:6] assert(expr : bool)
assert_134_5:
; [134:5] alias expr -> r15b (lea: )
if_20_29_134_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_134_5:
cmp r15b, 0
jne if_20_26_134_5_end
if_20_29_134_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_134_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_134_5_end:
if_20_26_134_5_end:
; [134:5] free scratch register 'r15'
assert_134_5_end:
; [136:5] var q : point = p
; [136:9] q: point (16B @ [rsp - 88])
; [136:9] q = p
; [136:21] allocate named register 'rsi'
; [136:21] allocate named register 'rdi'
; [136:21] allocate named register 'rcx'
lea rsi, [rsp - 72]
lea rdi, [rsp - 88]
mov rcx, 2
rep movsq
; [136:21] free named register 'rcx'
; [136:21] free named register 'rdi'
; [136:21] free named register 'rsi'
; [137:5] assert(equal(p, q))
; [137:12] allocate scratch register -> r15
; [137:12] ? equal(p, q)
; [137:12] ? equal(p, q)
cmp_137_12:
; [137:12] allocate scratch register -> r14
; [137:12] r14 = equal(p, q)
; [137:12] = expression
; [137:12] equal(p, q)
; [137:12] allocate named register 'rsi'
; [137:12] allocate named register 'rdi'
; [137:12] allocate named register 'rcx'
; [137:18] p
lea rsi, [rsp - 72]
; [137:21] q
lea rdi, [rsp - 88]
mov rcx, 2
repe cmpsq
; [137:12] free named register 'rcx'
; [137:12] free named register 'rdi'
; [137:12] free named register 'rsi'
sete r14b
cmp r14, 0
; [137:12] free scratch register 'r14'
setne r15b
bool_end_137_12:
; [20:6] assert(expr : bool)
assert_137_5:
; [137:5] alias expr -> r15b (lea: )
if_20_29_137_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_137_5:
cmp r15b, 0
jne if_20_26_137_5_end
if_20_29_137_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_137_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_137_5_end:
if_20_26_137_5_end:
; [137:5] free scratch register 'r15'
assert_137_5_end:
; [138:5] # note: `equal` is built-in function to compare user types for equality
; [139:5] # or same size arrays
; [141:5] q.x = 3
; [141:11] 3
mov qword [rsp - 88], 3
; [142:5] assert(not equal(p, q))
; [142:12] allocate scratch register -> r15
; [142:12] ? not equal(p, q)
; [142:12] ? not equal(p, q)
cmp_142_12:
; [142:16] allocate scratch register -> r14
; [142:16] r14 = equal(p, q)
; [142:16] = expression
; [142:16] equal(p, q)
; [142:16] allocate named register 'rsi'
; [142:16] allocate named register 'rdi'
; [142:16] allocate named register 'rcx'
; [142:22] p
lea rsi, [rsp - 72]
; [142:25] q
lea rdi, [rsp - 88]
mov rcx, 2
repe cmpsq
; [142:16] free named register 'rcx'
; [142:16] free named register 'rdi'
; [142:16] free named register 'rsi'
sete r14b
cmp r14, 0
; [142:12] free scratch register 'r14'
sete r15b
bool_end_142_12:
; [20:6] assert(expr : bool)
assert_142_5:
; [142:5] alias expr -> r15b (lea: )
if_20_29_142_5:
; [20:29] ? not expr
; [20:29] ? not expr
cmp_20_29_142_5:
cmp r15b, 0
jne if_20_26_142_5_end
if_20_29_142_5_code:
; [20:38] exit(1)
; [20:43] allocate named register 'rdi'
mov rdi, 1
; [12:6] exit(v : reg_rdi)
exit_20_38_142_5:
; [20:38] alias v -> rdi (lea: )
; [13:5] mov(rax, 60)
; [13:14] 60
mov rax, 60
; [13:19] # exit system call
; [14:5] mov(rdi, v)
; [14:14] v
; [14:19] # return code
; [15:5] syscall()
syscall
; [20:38] free named register 'rdi'
exit_20_38_142_5_end:
if_20_26_142_5_end:
; [142:5] free scratch register 'r15'
assert_142_5_end:
; [144:5] var i = 0
; [144:9] i: i64 (8B @ [rsp - 96])
; [144:9] i = 0
; [144:13] 0
mov qword [rsp - 96], 0
; [145:5] bar(i)
; [58:6] bar(arg)
bar_145_5:
; [145:5] alias arg -> i (lea: )
if_59_8_145_5:
; [59:8] ? arg == 0
; [59:8] ? arg == 0