-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyb_example.tm
More file actions
1762 lines (1762 loc) · 52.8 KB
/
Copy pathpyb_example.tm
File metadata and controls
1762 lines (1762 loc) · 52.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
* File: pyb_example.tm
* Standard prelude:
0: LDC 6,65535(0) load mp adress
1: ST 0,0(0) clear location 0
2: LDC 5,4095(0) load gp adress from location 1
3: ST 0,1(0) clear location 1
4: LDC 4,2000(0) load gp adress from location 1
5: LDC 2,60000(0) load first fp from location 2
6: LDC 3,60000(0) load first sp from location 2
7: ST 0,2(0) clear location 2
* End of standard prelude.
* function entry:
* malloc
8: LDA 3,-1(3) stack expand for function variable
9: LDC 0,12(0) get function adress
10: ST 0,0(5) set function adress
11: GO 0,0,0 go to label
12: MOV 1,2,0 store the caller fp temporarily
13: MOV 2,3,0 exchang the stack(context)
14: PUSH 1,0(3) push the caller fp
15: PUSH 0,0(3) push the return adress
* -> Id
16: LD 0,1(2) load id value
17: PUSH 0,0(6) store exp
* <- Id
18: POP 0,0(6) get malloc parameters
19: MALLOC 0,0(0) system call for malloc
20: MOV 3,2,0 restore the caller sp
21: LD 2,0(2) resotre the caller fp
22: RETURN 0,-1,3 return to adress : reg[fp]+1
* function end:
23: LABEL 0,0,0 generate label
* function entry:
* free
24: LDA 3,-1(3) stack expand for function variable
25: LDC 0,28(0) get function adress
26: ST 0,-1(5) set function adress
27: GO 1,0,0 go to label
28: MOV 1,2,0 store the caller fp temporarily
29: MOV 2,3,0 exchang the stack(context)
30: PUSH 1,0(3) push the caller fp
31: PUSH 0,0(3) push the return adress
* -> Id
32: LD 0,1(2) load id value
33: PUSH 0,0(6) store exp
* <- Id
34: POP 0,0(6) get free parameters
35: FREE 0,0(0) system call for free
36: MOV 3,2,0 restore the caller sp
37: LD 2,0(2) resotre the caller fp
38: RETURN 0,-1,3 return to adress : reg[fp]+1
* function end:
39: LABEL 1,0,0 generate label
* call main function
* File: pyb_example.tm
* Standard prelude:
40: LDC 6,65535(0) load mp adress
41: ST 0,0(0) clear location 0
42: LDC 5,4095(0) load gp adress from location 1
43: ST 0,1(0) clear location 1
44: LDC 4,2000(0) load gp adress from location 1
45: LDC 2,60000(0) load first fp from location 2
46: LDC 3,60000(0) load first sp from location 2
47: ST 0,2(0) clear location 2
* End of standard prelude.
48: LDA 3,-1(3) stack expand
* -> Const
49: LDC 0,0(0) load integer const
50: PUSH 0,0(6) store exp
* <- Const
51: LDA 1,-2(5) move the adress of ID
52: POP 0,0(6) copy bytes
53: ST 0,0(1) copy bytes
54: LDA 3,-1(3) stack expand
55: LDA 3,-1(3) stack expand
56: LDA 3,-1(3) stack expand
57: LDA 3,-1(3) stack expand
58: LDA 3,-1(3) stack expand
59: LDA 3,-1(3) stack expand
* function entry:
* dup
60: LDA 3,-1(3) stack expand for function variable
61: GO 2,0,0 go to label
62: MOV 1,2,0 store the caller fp temporarily
63: MOV 2,3,0 exchang the stack(context)
64: PUSH 1,0(3) push the caller fp
65: PUSH 0,0(3) push the return adress
66: MOV 3,2,0 restore the caller sp
67: LD 2,0(2) resotre the caller fp
68: RETURN 0,-1,3 return to adress : reg[fp]+1
* function end:
69: LABEL 2,0,0 generate label
* function entry:
* freeList
70: LDA 3,-1(3) stack expand for function variable
71: GO 3,0,0 go to label
72: MOV 1,2,0 store the caller fp temporarily
73: MOV 2,3,0 exchang the stack(context)
74: PUSH 1,0(3) push the caller fp
75: PUSH 0,0(3) push the return adress
76: MOV 3,2,0 restore the caller sp
77: LD 2,0(2) resotre the caller fp
78: RETURN 0,-1,3 return to adress : reg[fp]+1
* function end:
79: LABEL 3,0,0 generate label
* function entry:
* match
80: LDA 3,-1(3) stack expand for function variable
81: GO 4,0,0 go to label
82: MOV 1,2,0 store the caller fp temporarily
83: MOV 2,3,0 exchang the stack(context)
84: PUSH 1,0(3) push the caller fp
85: PUSH 0,0(3) push the return adress
86: MOV 3,2,0 restore the caller sp
87: LD 2,0(2) resotre the caller fp
88: RETURN 0,-1,3 return to adress : reg[fp]+1
* function end:
89: LABEL 4,0,0 generate label
* function entry:
* self__removeList
90: LDA 3,-1(3) stack expand for function variable
91: GO 5,0,0 go to label
92: MOV 1,2,0 store the caller fp temporarily
93: MOV 2,3,0 exchang the stack(context)
94: PUSH 1,0(3) push the caller fp
95: PUSH 0,0(3) push the return adress
* -> if
* -> Op
* -> Id
96: LD 0,1(2) load id value
97: PUSH 0,0(6) store exp
* <- Id
98: POP 1,0,6 load adress of lhs struct
99: LDC 0,2,0 load offset of member
100: ADD 0,0,1 compute the real adress if pointK
101: PUSH 0,0(6)
102: POP 0,0(6) load adress from mp
103: LD 1,0(0) copy bytes
104: PUSH 1,0(6) push a.x value into tmp
* -> Const
105: LDC 0,0(0) load integer const
106: PUSH 0,0(6) store exp
* <- Const
107: POP 1,0(6) pop right
108: POP 0,0(6) pop left
109: SUB 0,0,1 op <
110: JLE 0,2(7) br if true
111: LDC 0,0(0) false case
112: LDA 7,1(7) unconditional jmp
113: LDC 0,1(0) true case
114: PUSH 0,0(6)
* <- Op
115: POP 0,0(6) pop from the mp
116: JNE 0,1,7 true case:, execute if part
117: GO 6,0,0 go to label
118: MOV 3,2,0 restore the caller sp
119: LD 2,0(2) resotre the caller fp
120: RETURN 0,-1,3 return to the caller
121: GO 7,0,0 go to label
122: LABEL 6,0,0 generate label
* if: jump to else
123: LABEL 7,0,0 generate label
* <- if
* ->Single Op
* -> Id
124: LD 0,1(2) load id value
125: PUSH 0,0(6) store exp
* <- Id
126: POP 1,0,6 load adress of lhs struct
127: LDC 0,2,0 load offset of member
128: ADD 0,0,1 compute the real adress if pointK
129: PUSH 0,0(6)
130: POP 0,0(6) load adress from mp
131: LD 1,0(0) copy bytes
132: PUSH 1,0(6) push a.x value into tmp
133: POP 0,0(6) pop right
* -> Op
* -> Id
134: LD 0,1(2) load id value
135: PUSH 0,0(6) store exp
* <- Id
136: POP 1,0,6 load adress of lhs struct
137: LDC 0,2,0 load offset of member
138: ADD 0,0,1 compute the real adress if pointK
139: PUSH 0,0(6)
140: POP 0,0(6) load adress from mp
141: LD 1,0(0) copy bytes
142: PUSH 1,0(6) push a.x value into tmp
* -> Const
143: LDC 0,1(0) load integer const
144: PUSH 0,0(6) store exp
* <- Const
145: POP 1,0(6) pop right
146: POP 0,0(6) pop left
147: SUB 0,0,1 op -
148: PUSH 0,0(6) op: load left
* <- Op
* -> Id
149: LD 0,1(2) load id value
150: PUSH 0,0(6) store exp
* <- Id
151: POP 1,0,6 load adress of lhs struct
152: LDC 0,2,0 load offset of member
153: ADD 0,0,1 compute the real adress if pointK
154: PUSH 0,0(6)
155: POP 1,0(6) move the adress of referenced
156: POP 0,0(6) copy bytes
157: ST 0,0(1) copy bytes
* <-Single Op
158: LDA 3,-1(3) stack expand
* -> Id
159: LD 0,1(2) load id value
160: PUSH 0,0(6) store exp
* <- Id
161: POP 1,0,6 load adress of lhs struct
162: LDC 0,0,0 load offset of member
163: ADD 0,0,1 compute the real adress if pointK
164: PUSH 0,0(6)
165: POP 0,0(6) load adress from mp
166: LD 1,0(0) copy bytes
167: PUSH 1,0(6) push a.x value into tmp
168: POP 1,0,6 load adress of lhs struct
169: LDC 0,1,0 load offset of member
170: ADD 0,0,1 compute the real adress if pointK
171: PUSH 0,0(6)
172: POP 0,0(6) load adress from mp
173: LD 1,0(0) copy bytes
174: PUSH 1,0(6) push a.x value into tmp
175: LDA 1,-2(2) move the adress of ID
176: POP 0,0(6) copy bytes
177: ST 0,0(1) copy bytes
* -> repeat
* while stmt:
178: LABEL 8,0,0 generate label
* -> Op
* -> Op
* -> Id
179: LD 0,-2(2) load id value
180: PUSH 0,0(6) store exp
* <- Id
* -> Id
181: LD 0,-2(5) load id value
182: PUSH 0,0(6) store exp
* <- Id
183: POP 1,0(6) pop right
184: POP 0,0(6) pop left
185: SUB 0,0,1 op ==, convertd_type
186: JNE 0,2(7) br if true
187: LDC 0,0(0) false case
188: LDA 7,1(7) unconditional jmp
189: LDC 0,1(0) true case
190: PUSH 0,0(6)
* <- Op
* -> Op
* push function parameters
* -> Id
191: LD 0,2(2) load id value
192: PUSH 0,0(6) store exp
* <- Id
193: POP 0,0(6) copy bytes
194: PUSH 0,0(3) PUSH bytes
* push function parameters
* -> Id
195: LD 0,-2(2) load id value
196: PUSH 0,0(6) store exp
* <- Id
197: POP 1,0,6 load adress of lhs struct
198: LDC 0,2,0 load offset of member
199: ADD 0,0,1 compute the real adress if pointK
200: PUSH 0,0(6)
201: POP 0,0(6) load adress from mp
202: LD 1,0(0) copy bytes
203: PUSH 1,0(6) push a.x value into tmp
204: POP 0,0(6) copy bytes
205: PUSH 0,0(3) PUSH bytes
* call function:
* match
* -> Id
206: LD 0,1(2) load id value
207: PUSH 0,0(6) store exp
* <- Id
208: POP 1,0,6 load adress of lhs struct
209: LDC 0,5,0 load offset of member
210: ADD 0,0,1 compute the real adress if pointK
211: PUSH 0,0(6)
212: POP 0,0(6) load adress from mp
213: LD 1,0(0) copy bytes
214: PUSH 1,0(6) push a.x value into tmp
215: LDC 0,217(0) store the return adress
216: POP 7,0(6) ujp to the function body
217: LDA 3,2(3) pop parameters
* -> Const
218: LDC 0,0(0) load integer const
219: PUSH 0,0(6) store exp
* <- Const
220: POP 1,0(6) pop right
221: POP 0,0(6) pop left
222: SUB 0,0,1 op ==, convertd_type
223: JNE 0,2(7) br if true
224: LDC 0,0(0) false case
225: LDA 7,1(7) unconditional jmp
226: LDC 0,1(0) true case
227: PUSH 0,0(6)
* <- Op
228: POP 1,0(6) pop right
229: POP 0,0(6) pop left
230: JEQ 0,3(7) br if false
231: JEQ 1,2(7) br if false
232: LDC 0,1(0) true case
233: LDA 7,1(7) unconditional jmp
234: LDC 0,0(0) false case
235: PUSH 0,0(6)
* <- Op
236: POP 0,0(6) pop from the mp
237: JNE 0,1,7 true case:, skip the break, execute the block code
238: GO 9,0,0 go to label
* -> assign
* -> Id
239: LD 0,-2(2) load id value
240: PUSH 0,0(6) store exp
* <- Id
241: POP 1,0,6 load adress of lhs struct
242: LDC 0,1,0 load offset of member
243: ADD 0,0,1 compute the real adress if pointK
244: PUSH 0,0(6)
245: POP 0,0(6) load adress from mp
246: LD 1,0(0) copy bytes
247: PUSH 1,0(6) push a.x value into tmp
248: LDA 1,-2(2) move the adress of ID
249: POP 0,0(6) copy bytes
250: ST 0,0(1) copy bytes
* <- assign
251: GO 8,0,0 go to label
252: LABEL 9,0,0 generate label
* <- repeat
* -> if
* -> Op
* -> Id
253: LD 0,-2(2) load id value
254: PUSH 0,0(6) store exp
* <- Id
* -> Id
255: LD 0,-2(5) load id value
256: PUSH 0,0(6) store exp
* <- Id
257: POP 1,0(6) pop right
258: POP 0,0(6) pop left
259: SUB 0,0,1 op ==, convertd_type
260: JEQ 0,2(7) br if true
261: LDC 0,0(0) false case
262: LDA 7,1(7) unconditional jmp
263: LDC 0,1(0) true case
264: PUSH 0,0(6)
* <- Op
265: POP 0,0(6) pop from the mp
266: JNE 0,1,7 true case:, execute if part
267: GO 10,0,0 go to label
268: MOV 3,2,0 restore the caller sp
269: LD 2,0(2) resotre the caller fp
270: RETURN 0,-1,3 return to the caller
271: GO 11,0,0 go to label
272: LABEL 10,0,0 generate label
* if: jump to else
273: LABEL 11,0,0 generate label
* <- if
274: LDA 3,-1(3) stack expand
* -> Id
275: LD 0,-2(2) load id value
276: PUSH 0,0(6) store exp
* <- Id
277: POP 1,0,6 load adress of lhs struct
278: LDC 0,0,0 load offset of member
279: ADD 0,0,1 compute the real adress if pointK
280: PUSH 0,0(6)
281: POP 0,0(6) load adress from mp
282: LD 1,0(0) copy bytes
283: PUSH 1,0(6) push a.x value into tmp
284: LDA 1,-3(2) move the adress of ID
285: POP 0,0(6) copy bytes
286: ST 0,0(1) copy bytes
287: LDA 3,-1(3) stack expand
* -> Id
288: LD 0,-2(2) load id value
289: PUSH 0,0(6) store exp
* <- Id
290: POP 1,0,6 load adress of lhs struct
291: LDC 0,1,0 load offset of member
292: ADD 0,0,1 compute the real adress if pointK
293: PUSH 0,0(6)
294: POP 0,0(6) load adress from mp
295: LD 1,0(0) copy bytes
296: PUSH 1,0(6) push a.x value into tmp
297: LDA 1,-4(2) move the adress of ID
298: POP 0,0(6) copy bytes
299: ST 0,0(1) copy bytes
* -> assign
* -> Id
300: LD 0,-4(2) load id value
301: PUSH 0,0(6) store exp
* <- Id
* -> Id
302: LD 0,-3(2) load id value
303: PUSH 0,0(6) store exp
* <- Id
304: POP 1,0,6 load adress of lhs struct
305: LDC 0,1,0 load offset of member
306: ADD 0,0,1 compute the real adress if pointK
307: PUSH 0,0(6)
308: POP 1,0(6) move the adress of referenced
309: POP 0,0(6) copy bytes
310: ST 0,0(1) copy bytes
* <- assign
* -> if
* -> Op
* -> Id
311: LD 0,-4(2) load id value
312: PUSH 0,0(6) store exp
* <- Id
* -> Id
313: LD 0,-2(5) load id value
314: PUSH 0,0(6) store exp
* <- Id
315: POP 1,0(6) pop right
316: POP 0,0(6) pop left
317: SUB 0,0,1 op ==, convertd_type
318: JNE 0,2(7) br if true
319: LDC 0,0(0) false case
320: LDA 7,1(7) unconditional jmp
321: LDC 0,1(0) true case
322: PUSH 0,0(6)
* <- Op
323: POP 0,0(6) pop from the mp
324: JNE 0,1,7 true case:, execute if part
325: GO 12,0,0 go to label
* -> assign
* -> Id
326: LD 0,-3(2) load id value
327: PUSH 0,0(6) store exp
* <- Id
* -> Id
328: LD 0,-4(2) load id value
329: PUSH 0,0(6) store exp
* <- Id
330: POP 1,0,6 load adress of lhs struct
331: LDC 0,0,0 load offset of member
332: ADD 0,0,1 compute the real adress if pointK
333: PUSH 0,0(6)
334: POP 1,0(6) move the adress of referenced
335: POP 0,0(6) copy bytes
336: ST 0,0(1) copy bytes
* <- assign
337: GO 13,0,0 go to label
338: LABEL 12,0,0 generate label
* if: jump to else
339: LABEL 13,0,0 generate label
* <- if
* -> if
* -> Op
* -> Id
340: LD 0,-2(2) load id value
341: PUSH 0,0(6) store exp
* <- Id
* -> Id
342: LD 0,1(2) load id value
343: PUSH 0,0(6) store exp
* <- Id
344: POP 1,0,6 load adress of lhs struct
345: LDC 0,1,0 load offset of member
346: ADD 0,0,1 compute the real adress if pointK
347: PUSH 0,0(6)
348: POP 0,0(6) load adress from mp
349: LD 1,0(0) copy bytes
350: PUSH 1,0(6) push a.x value into tmp
351: POP 1,0(6) pop right
352: POP 0,0(6) pop left
353: SUB 0,0,1 op ==, convertd_type
354: JEQ 0,2(7) br if true
355: LDC 0,0(0) false case
356: LDA 7,1(7) unconditional jmp
357: LDC 0,1(0) true case
358: PUSH 0,0(6)
* <- Op
359: POP 0,0(6) pop from the mp
360: JNE 0,1,7 true case:, execute if part
361: GO 14,0,0 go to label
* -> assign
* -> Id
362: LD 0,-3(2) load id value
363: PUSH 0,0(6) store exp
* <- Id
* -> Id
364: LD 0,1(2) load id value
365: PUSH 0,0(6) store exp
* <- Id
366: POP 1,0,6 load adress of lhs struct
367: LDC 0,1,0 load offset of member
368: ADD 0,0,1 compute the real adress if pointK
369: PUSH 0,0(6)
370: POP 1,0(6) move the adress of referenced
371: POP 0,0(6) copy bytes
372: ST 0,0(1) copy bytes
* <- assign
373: GO 15,0,0 go to label
374: LABEL 14,0,0 generate label
* if: jump to else
375: LABEL 15,0,0 generate label
* <- if
* push function parameters
* -> Id
376: LD 0,-2(2) load id value
377: PUSH 0,0(6) store exp
* <- Id
378: POP 0,0(6) copy bytes
379: PUSH 0,0(3) PUSH bytes
* call function:
* free
* -> Id
380: LD 0,-1(5) load id value
381: PUSH 0,0(6) store exp
* <- Id
382: LDC 0,384(0) store the return adress
383: POP 7,0(6) ujp to the function body
384: LDA 3,1(3) pop parameters
385: MOV 3,2,0 restore the caller sp
386: LD 2,0(2) resotre the caller fp
387: RETURN 0,-1,3 return to adress : reg[fp]+1
* function end:
388: LABEL 5,0,0 generate label
* function entry:
* createListNode
389: LDA 3,-1(3) stack expand for function variable
390: LDC 0,393(0) get function adress
391: ST 0,-3(5) set function adress
392: GO 16,0,0 go to label
393: MOV 1,2,0 store the caller fp temporarily
394: MOV 2,3,0 exchang the stack(context)
395: PUSH 1,0(3) push the caller fp
396: PUSH 0,0(3) push the return adress
397: LDA 3,-1(3) stack expand
* push function parameters
* ->Single Op
398: LDC 0,3,0 load size of exp
399: PUSH 0,0(6)
* <-Single Op
400: POP 0,0(6) copy bytes
401: PUSH 0,0(3) PUSH bytes
* call function:
* malloc
* -> Id
402: LD 0,0(5) load id value
403: PUSH 0,0(6) store exp
* <- Id
404: LDC 0,406(0) store the return adress
405: POP 7,0(6) ujp to the function body
406: LDA 3,1(3) pop parameters
407: LDA 1,-2(2) move the adress of ID
408: POP 0,0(6) copy bytes
409: ST 0,0(1) copy bytes
* -> assign
* -> Id
410: LD 0,-2(5) load id value
411: PUSH 0,0(6) store exp
* <- Id
* -> Id
412: LD 0,-2(2) load id value
413: PUSH 0,0(6) store exp
* <- Id
414: POP 1,0,6 load adress of lhs struct
415: LDC 0,0,0 load offset of member
416: ADD 0,0,1 compute the real adress if pointK
417: PUSH 0,0(6)
418: POP 1,0(6) move the adress of referenced
419: POP 0,0(6) copy bytes
420: ST 0,0(1) copy bytes
* <- assign
* -> assign
* -> Id
421: LD 0,-2(5) load id value
422: PUSH 0,0(6) store exp
* <- Id
* -> Id
423: LD 0,-2(2) load id value
424: PUSH 0,0(6) store exp
* <- Id
425: POP 1,0,6 load adress of lhs struct
426: LDC 0,1,0 load offset of member
427: ADD 0,0,1 compute the real adress if pointK
428: PUSH 0,0(6)
429: POP 1,0(6) move the adress of referenced
430: POP 0,0(6) copy bytes
431: ST 0,0(1) copy bytes
* <- assign
* -> assign
* -> Id
432: LD 0,-2(5) load id value
433: PUSH 0,0(6) store exp
* <- Id
* -> Id
434: LD 0,-2(2) load id value
435: PUSH 0,0(6) store exp
* <- Id
436: POP 1,0,6 load adress of lhs struct
437: LDC 0,2,0 load offset of member
438: ADD 0,0,1 compute the real adress if pointK
439: PUSH 0,0(6)
440: POP 1,0(6) move the adress of referenced
441: POP 0,0(6) copy bytes
442: ST 0,0(1) copy bytes
* <- assign
* -> Id
443: LD 0,-2(2) load id value
444: PUSH 0,0(6) store exp
* <- Id
445: MOV 3,2,0 restore the caller sp
446: LD 2,0(2) resotre the caller fp
447: RETURN 0,-1,3 return to the caller
448: MOV 3,2,0 restore the caller sp
449: LD 2,0(2) resotre the caller fp
450: RETURN 0,-1,3 return to adress : reg[fp]+1
* function end:
451: LABEL 16,0,0 generate label
* function entry:
* createList
452: LDA 3,-1(3) stack expand for function variable
453: LDC 0,456(0) get function adress
454: ST 0,-4(5) set function adress
455: GO 17,0,0 go to label
456: MOV 1,2,0 store the caller fp temporarily
457: MOV 2,3,0 exchang the stack(context)
458: PUSH 1,0(3) push the caller fp
459: PUSH 0,0(3) push the return adress
460: LDA 3,-7(3) stack expand
461: LDC 1,62(0) get function adress from struct
462: ST 1,4(3) Init Struct Instance
463: LDC 1,72(0) get function adress from struct
464: ST 1,5(3) Init Struct Instance
465: LDC 1,82(0) get function adress from struct
466: ST 1,6(3) Init Struct Instance
467: LDC 1,92(0) get function adress from struct
468: ST 1,7(3) Init Struct Instance
469: LDA 3,-1(3) stack expand
* -> Const
470: LDC 0,0(0) load integer const
471: PUSH 0,0(6) store exp
* <- Const
472: LDA 1,-9(2) move the adress of ID
473: POP 0,0(6) copy bytes
474: ST 0,0(1) copy bytes
* -> assign
* call function:
* createListNode
* -> Id
475: LD 0,-3(5) load id value
476: PUSH 0,0(6) store exp
* <- Id
477: LDC 0,479(0) store the return adress
478: POP 7,0(6) ujp to the function body
479: LDA 3,0(3) pop parameters
* -> Id
480: LDA 0,-8(2) load id adress
481: PUSH 0,0(6) push array adress to mp
* <- Id
482: POP 1,0,6 load adress of lhs struct
483: LDC 0,0,0 load offset of member
484: ADD 0,0,1 compute the real adress if pointK
485: PUSH 0,0(6)
486: POP 1,0(6) move the adress of referenced
487: POP 0,0(6) copy bytes
488: ST 0,0(1) copy bytes
* <- assign
* -> assign
* -> Id
489: LDA 0,-8(2) load id adress
490: PUSH 0,0(6) push array adress to mp
* <- Id
491: POP 1,0,6 load adress of lhs struct
492: LDC 0,0,0 load offset of member
493: ADD 0,0,1 compute the real adress if pointK
494: PUSH 0,0(6)
495: POP 0,0(6) load adress from mp
496: LD 1,0(0) copy bytes
497: PUSH 1,0(6) push a.x value into tmp
* -> Id
498: LDA 0,-8(2) load id adress
499: PUSH 0,0(6) push array adress to mp
* <- Id
500: POP 1,0,6 load adress of lhs struct
501: LDC 0,1,0 load offset of member
502: ADD 0,0,1 compute the real adress if pointK
503: PUSH 0,0(6)
504: POP 1,0(6) move the adress of referenced
505: POP 0,0(6) copy bytes
506: ST 0,0(1) copy bytes
* <- assign
* -> assign
* -> Const
507: LDC 0,0(0) load integer const
508: PUSH 0,0(6) store exp
* <- Const
* -> Id
509: LDA 0,-8(2) load id adress
510: PUSH 0,0(6) push array adress to mp
* <- Id
511: POP 1,0,6 load adress of lhs struct
512: LDC 0,2,0 load offset of member
513: ADD 0,0,1 compute the real adress if pointK
514: PUSH 0,0(6)
515: POP 1,0(6) move the adress of referenced
516: POP 0,0(6) copy bytes
517: ST 0,0(1) copy bytes
* <- assign
* -> Id
518: LD 0,-8(2) load id value
519: PUSH 0,0(6) store exp
520: LD 0,-7(2) load id value
521: PUSH 0,0(6) store exp
522: LD 0,-6(2) load id value
523: PUSH 0,0(6) store exp
524: LD 0,-5(2) load id value
525: PUSH 0,0(6) store exp
526: LD 0,-4(2) load id value
527: PUSH 0,0(6) store exp
528: LD 0,-3(2) load id value
529: PUSH 0,0(6) store exp
530: LD 0,-2(2) load id value
531: PUSH 0,0(6) store exp
* <- Id
532: MOV 3,2,0 restore the caller sp
533: LD 2,0(2) resotre the caller fp
534: RETURN 0,-1,3 return to the caller
535: MOV 3,2,0 restore the caller sp
536: LD 2,0(2) resotre the caller fp
537: RETURN 0,-1,3 return to adress : reg[fp]+1
* function end:
538: LABEL 17,0,0 generate label
* function entry:
* insertSortedList
539: LDA 3,-1(3) stack expand for function variable
540: LDC 0,543(0) get function adress
541: ST 0,-5(5) set function adress
542: GO 18,0,0 go to label
543: MOV 1,2,0 store the caller fp temporarily
544: MOV 2,3,0 exchang the stack(context)
545: PUSH 1,0(3) push the caller fp
546: PUSH 0,0(3) push the return adress
* -> if
* -> Op
* -> Id
547: LD 0,2(2) load id value
548: PUSH 0,0(6) store exp
* <- Id
* -> Id
549: LD 0,-2(5) load id value
550: PUSH 0,0(6) store exp
* <- Id
551: POP 1,0(6) pop right
552: POP 0,0(6) pop left
553: SUB 0,0,1 op ==, convertd_type
554: JEQ 0,2(7) br if true
555: LDC 0,0(0) false case
556: LDA 7,1(7) unconditional jmp
557: LDC 0,1(0) true case
558: PUSH 0,0(6)
* <- Op
559: POP 0,0(6) pop from the mp
560: JNE 0,1,7 true case:, execute if part
561: GO 19,0,0 go to label
562: MOV 3,2,0 restore the caller sp
563: LD 2,0(2) resotre the caller fp
564: RETURN 0,-1,3 return to the caller
565: GO 20,0,0 go to label
566: LABEL 19,0,0 generate label
* if: jump to else
567: LABEL 20,0,0 generate label
* <- if
568: LDA 3,-1(3) stack expand
* -> Const
569: LDC 0,10(0) load integer const
570: PUSH 0,0(6) store exp
* <- Const
571: LDA 1,-2(2) move the adress of ID
572: POP 0,0(6) copy bytes
573: ST 0,0(1) copy bytes
* -> assign
* -> Op
* -> Id
574: LD 0,1(2) load id value
575: PUSH 0,0(6) store exp
* <- Id
576: POP 1,0,6 load adress of lhs struct
577: LDC 0,2,0 load offset of member
578: ADD 0,0,1 compute the real adress if pointK
579: PUSH 0,0(6)
580: POP 0,0(6) load adress from mp
581: LD 1,0(0) copy bytes
582: PUSH 1,0(6) push a.x value into tmp
* -> Const
583: LDC 0,1(0) load integer const
584: PUSH 0,0(6) store exp
* <- Const
585: POP 1,0(6) pop right
586: POP 0,0(6) pop left
587: ADD 0,0,1 op +
588: PUSH 0,0(6) op: load left
* <- Op
* -> Id
589: LD 0,1(2) load id value
590: PUSH 0,0(6) store exp
* <- Id
591: POP 1,0,6 load adress of lhs struct
592: LDC 0,2,0 load offset of member
593: ADD 0,0,1 compute the real adress if pointK
594: PUSH 0,0(6)
595: POP 1,0(6) move the adress of referenced
596: POP 0,0(6) copy bytes
597: ST 0,0(1) copy bytes
* <- assign
598: LDA 3,-1(3) stack expand
* -> Id
599: LD 0,1(2) load id value
600: PUSH 0,0(6) store exp
* <- Id
601: POP 1,0,6 load adress of lhs struct
602: LDC 0,0,0 load offset of member
603: ADD 0,0,1 compute the real adress if pointK
604: PUSH 0,0(6)
605: POP 0,0(6) load adress from mp
606: LD 1,0(0) copy bytes
607: PUSH 1,0(6) push a.x value into tmp
608: LDA 1,-3(2) move the adress of ID
609: POP 0,0(6) copy bytes
610: ST 0,0(1) copy bytes
* -> repeat
* while stmt:
611: LABEL 21,0,0 generate label
* -> Op
* -> Id
612: LD 0,-3(2) load id value
613: PUSH 0,0(6) store exp
* <- Id
614: POP 1,0,6 load adress of lhs struct
615: LDC 0,1,0 load offset of member
616: ADD 0,0,1 compute the real adress if pointK
617: PUSH 0,0(6)
618: POP 0,0(6) load adress from mp
619: LD 1,0(0) copy bytes
620: PUSH 1,0(6) push a.x value into tmp
* -> Id
621: LD 0,-2(5) load id value
622: PUSH 0,0(6) store exp
* <- Id
623: POP 1,0(6) pop right
624: POP 0,0(6) pop left
625: SUB 0,0,1 op ==, convertd_type
626: JNE 0,2(7) br if true
627: LDC 0,0(0) false case
628: LDA 7,1(7) unconditional jmp
629: LDC 0,1(0) true case
630: PUSH 0,0(6)
* <- Op
631: POP 0,0(6) pop from the mp
632: JNE 0,1,7 true case:, skip the break, execute the block code
633: GO 22,0,0 go to label
* -> if
* -> Op
* push function parameters
* -> Id
634: LD 0,2(2) load id value
635: PUSH 0,0(6) store exp
* <- Id
636: POP 1,0,6 load adress of lhs struct
637: LDC 0,2,0 load offset of member
638: ADD 0,0,1 compute the real adress if pointK
639: PUSH 0,0(6)
640: POP 0,0(6) load adress from mp
641: LD 1,0(0) copy bytes
642: PUSH 1,0(6) push a.x value into tmp
643: POP 0,0(6) copy bytes
644: PUSH 0,0(3) PUSH bytes
* push function parameters
* -> Id
645: LD 0,-3(2) load id value
646: PUSH 0,0(6) store exp
* <- Id
647: POP 1,0,6 load adress of lhs struct
648: LDC 0,1,0 load offset of member
649: ADD 0,0,1 compute the real adress if pointK
650: PUSH 0,0(6)
651: POP 0,0(6) load adress from mp
652: LD 1,0(0) copy bytes
653: PUSH 1,0(6) push a.x value into tmp
654: POP 1,0,6 load adress of lhs struct
655: LDC 0,2,0 load offset of member
656: ADD 0,0,1 compute the real adress if pointK
657: PUSH 0,0(6)
658: POP 0,0(6) load adress from mp
659: LD 1,0(0) copy bytes
660: PUSH 1,0(6) push a.x value into tmp
661: POP 0,0(6) copy bytes
662: PUSH 0,0(3) PUSH bytes
* call function:
* match
* -> Id
663: LD 0,1(2) load id value
664: PUSH 0,0(6) store exp
* <- Id
665: POP 1,0,6 load adress of lhs struct
666: LDC 0,5,0 load offset of member
667: ADD 0,0,1 compute the real adress if pointK
668: PUSH 0,0(6)
669: POP 0,0(6) load adress from mp
670: LD 1,0(0) copy bytes
671: PUSH 1,0(6) push a.x value into tmp
672: LDC 0,674(0) store the return adress
673: POP 7,0(6) ujp to the function body
674: LDA 3,2(3) pop parameters
* -> Const
675: LDC 0,0(0) load integer const
676: PUSH 0,0(6) store exp
* <- Const
677: POP 1,0(6) pop right
678: POP 0,0(6) pop left
679: SUB 0,0,1 op <
680: JGE 0,2(7) br if true
681: LDC 0,0(0) false case
682: LDA 7,1(7) unconditional jmp
683: LDC 0,1(0) true case
684: PUSH 0,0(6)
* <- Op
685: POP 0,0(6) pop from the mp
686: JNE 0,1,7 true case:, execute if part
687: GO 23,0,0 go to label
688: GO 22,0,0 go to label
689: GO 24,0,0 go to label
690: LABEL 23,0,0 generate label
* if: jump to else
691: LABEL 24,0,0 generate label
* <- if
* -> assign
* -> Id
692: LD 0,-3(2) load id value
693: PUSH 0,0(6) store exp
* <- Id
694: POP 1,0,6 load adress of lhs struct
695: LDC 0,1,0 load offset of member
696: ADD 0,0,1 compute the real adress if pointK
697: PUSH 0,0(6)
698: POP 0,0(6) load adress from mp
699: LD 1,0(0) copy bytes
700: PUSH 1,0(6) push a.x value into tmp
701: LDA 1,-3(2) move the adress of ID
702: POP 0,0(6) copy bytes
703: ST 0,0(1) copy bytes
* -> Id
704: LD 0,-3(2) load id value
705: PUSH 0,0(6) store exp
* <- Id
* <- assign
706: GO 21,0,0 go to label
707: LABEL 22,0,0 generate label
* <- repeat
708: LDA 3,-1(3) stack expand
* -> Id
709: LD 0,-3(2) load id value
710: PUSH 0,0(6) store exp
* <- Id
711: POP 1,0,6 load adress of lhs struct
712: LDC 0,1,0 load offset of member
713: ADD 0,0,1 compute the real adress if pointK
714: PUSH 0,0(6)
715: POP 0,0(6) load adress from mp
716: LD 1,0(0) copy bytes
717: PUSH 1,0(6) push a.x value into tmp
718: LDA 1,-4(2) move the adress of ID
719: POP 0,0(6) copy bytes
720: ST 0,0(1) copy bytes
* -> assign
* -> Id
721: LD 0,2(2) load id value
722: PUSH 0,0(6) store exp
* <- Id
* -> Id
723: LD 0,-3(2) load id value
724: PUSH 0,0(6) store exp
* <- Id
725: POP 1,0,6 load adress of lhs struct
726: LDC 0,1,0 load offset of member
727: ADD 0,0,1 compute the real adress if pointK
728: PUSH 0,0(6)
729: POP 1,0(6) move the adress of referenced
730: POP 0,0(6) copy bytes
731: ST 0,0(1) copy bytes
* <- assign
* -> assign
* -> Id
732: LD 0,-4(2) load id value
733: PUSH 0,0(6) store exp
* <- Id
* -> Id
734: LD 0,2(2) load id value