https://github.com/akkartik/mu/blob/master/apps/mu.subx
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 == data
237
238 Program:
239 0/imm32
240
241 Function-name:
242 0/imm32
243 Function-subx-name:
244 4/imm32
245 Function-inouts:
246 8/imm32
247 Function-outputs:
248 0xc/imm32
249 Function-body:
250 0x10/imm32
251 Function-next:
252 0x14/imm32
253 Function-size:
254 0x18/imm32/24
255
256 Primitive-name:
257 0/imm32
258 Primitive-inouts:
259 4/imm32
260 Primitive-outputs:
261 8/imm32
262 Primitive-subx-name:
263 0xc/imm32
264 Primitive-subx-rm32:
265 0x10/imm32
266 Primitive-subx-r32:
267 0x14/imm32
268 Primitive-subx-imm32:
269 0x18/imm32
270 Primitive-next:
271 0x1c/imm32
272 Primitive-size:
273 0x20/imm32/24
274
275 Stmt-tag:
276 0/imm32
277
278 Block-statements:
279 4/imm32
280
281 Stmt1-operation:
282 4/imm32
283 Stmt1-inouts:
284 8/imm32
285 Stmt1-outputs:
286 0xc/imm32
287
288 Vardef-name:
289 4/imm32
290 Vardef-type:
291 8/imm32
292
293 Regvardef-name:
294 4/imm32
295 Regvardef-type:
296 8/imm32
297 Regvardef-register:
298 0xc/imm32
299
300 Named-block-name:
301 4/imm32
302 Named-block-statements:
303 8/imm32
304
305 Stmt-operation:
306 0/imm32
307 Stmt-inouts:
308 4/imm32
309 Stmt-outputs:
310 8/imm32
311 Stmt-next:
312 0xc/imm32
313 Stmt-size:
314 0x10/imm32
315
316 Var-name:
317 0/imm32
318 Var-type:
319 4/imm32
320 Var-block:
321 8/imm32
322 Var-stack-offset:
323 0xc/imm32
324 Var-register:
325 0x10/imm32
326 Var-size:
327 0x14/imm32
328
329 Any-register:
330
331 1/imm32
332
333 2a/asterisk
334
335 == code
336
337 Entry:
338
339 89/<- %ebp 4/r32/esp
340 (new-segment Heap-size Heap)
341
342 {
343
344 81 7/subop/compare *ebp 1/imm32
345 7e/jump-if-lesser-or-equal break/disp8
346
347 (kernel-string-equal? *(ebp+8) "test")
348 3d/compare-eax-and 0/imm32
349 74/jump-if-equal break/disp8
350
351 (run-tests)
352
353 8b/-> *Num-test-failures 3/r32/ebx
354 eb/jump $mu-main:end/disp8
355 }
356
357 (convert-mu Stdin Stdout)
358 (flush Stdout)
359
360 bb/copy-to-ebx 0/imm32
361 $mu-main:end:
362 b8/copy-to-eax 1/imm32/exit
363 cd/syscall 0x80/imm8
364
365 convert-mu:
366
367 55/push-ebp
368 89/<- %ebp 4/r32/esp
369
370 (parse-mu *(ebp+8))
371 (check-mu-types)
372 (emit-subx *(ebp+0xc))
373 $convert-mu:end:
374
375 89/<- %esp 5/r32/ebp
376 5d/pop-to-ebp
377 c3/return
378
379 test-convert-empty-input:
380
381
382 55/push-ebp
383 89/<- %ebp 4/r32/esp
384
385 (clear-stream _test-input-stream)
386 (clear-stream _test-input-buffered-file->buffer)
387 (clear-stream _test-output-stream)
388 (clear-stream _test-output-buffered-file->buffer)
389
390 (convert-mu _test-input-buffered-file _test-output-buffered-file)
391 (flush _test-output-buffered-file)
392 (check-stream-equal _test-output-stream "" "F - test-convert-empty-input")
393
394 89/<- %esp 5/r32/ebp
395 5d/pop-to-ebp
396 c3/return
397
398 test-convert-function-skeleton:
399
400
401
402
403
404
405
406
407
408
409
410
411
412 55/push-ebp
413 89/<- %ebp 4/r32/esp
414
415 (clear-stream _test-input-stream)
416 (clear-stream _test-input-buffered-file->buffer)
417 (clear-stream _test-output-stream)
418 (clear-stream _test-output-buffered-file->buffer)
419
420 (write _test-input-stream "fn foo {\n")
421 (write _test-input-stream "}\n")
422
423 (convert-mu _test-input-buffered-file _test-output-buffered-file)
424 (flush _test-output-buffered-file)
425 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
431
432 (check-next-stream-line-equal _test-output-stream "foo:" "F - test-convert-function-skeleton/0")
433 (check-next-stream-line-equal _test-output-stream "# . prologue" "F - test-convert-function-skeleton/1")
434 (check-next-stream-line-equal _test-output-stream "55/push-ebp" "F - test-convert-function-skeleton/2")
435 (check-next-stream-line-equal _test-output-stream "89/<- %ebp 4/r32/esp" "F - test-convert-function-skeleton/3")
436 (check-next-stream-line-equal _test-output-stream "# . epilogue" "F - test-convert-function-skeleton/4")
437 (check-next-stream-line-equal _test-output-stream "89/<- %esp 5/r32/ebp" "F - test-convert-function-skeleton/5")
438 (check-next-stream-line-equal _test-output-stream "5d/pop-to-ebp" "F - test-convert-function-skeleton/6")
439 (check-next-stream-line-equal _test-output-stream "c3/return" "F - test-convert-function-skeleton/7")
440
441 89/<- %esp 5/r32/ebp
442 5d/pop-to-ebp
443 c3/return
444
445 test-convert-multiple-function-skeletons:
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469 55/push-ebp
470 89/<- %ebp 4/r32/esp
471
472 (clear-stream _test-input-stream)
473 (clear-stream _test-input-buffered-file->buffer)
474 (clear-stream _test-output-stream)
475 (clear-stream _test-output-buffered-file->buffer)
476
477 (write _test-input-stream "fn foo {\n")
478 (write _test-input-stream "}\n")
479 (write _test-input-stream "fn bar {\n")
480 (write _test-input-stream "}\n")
481
482 (convert-mu _test-input-buffered-file _test-output-buffered-file)
483 (flush _test-output-buffered-file)
484 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
490
491 (check-next-stream-line-equal _test-output-stream "foo:" "F - test-convert-multiple-function-skeletons/0")
492 (check-next-stream-line-equal _test-output-stream "# . prologue" "F - test-convert-multiple-function-skeletons/1")
493 (check-next-stream-line-equal _test-output-stream "55/push-ebp" "F - test-convert-multiple-function-skeletons/2")
494 (check-next-stream-line-equal _test-output-stream "89/<- %ebp 4/r32/esp" "F - test-convert-multiple-function-skeletons/3")
495 (check-next-stream-line-equal _test-output-stream "# . epilogue" "F - test-convert-multiple-function-skeletons/4")
496 (check-next-stream-line-equal _test-output-stream "89/<- %esp 5/r32/ebp" "F - test-convert-multiple-function-skeletons/5")
497 (check-next-stream-line-equal _test-output-stream "5d/pop-to-ebp" "F - test-convert-multiple-function-skeletons/6")
498 (check-next-stream-line-equal _test-output-stream "c3/return" "F - test-convert-multiple-function-skeletons/7")
499
500 (check-next-stream-line-equal _test-output-stream "bar:" "F - test-convert-multiple-function-skeletons/10")
501 (check-next-stream-line-equal _test-output-stream "# . prologue" "F - test-convert-multiple-function-skeletons/11")
502 (check-next-stream-line-equal _test-output-stream "55/push-ebp" "F - test-convert-multiple-function-skeletons/12")
503 (check-next-stream-line-equal _test-output-stream "89/<- %ebp 4/r32/esp" "F - test-convert-multiple-function-skeletons/13")
504 (check-next-stream-line-equal _test-output-stream "# . epilogue" "F - test-convert-multiple-function-skeletons/14")
505 (check-next-stream-line-equal _test-output-stream "89/<- %esp 5/r32/ebp" "F - test-convert-multiple-function-skeletons/15")
506 (check-next-stream-line-equal _test-output-stream "5d/pop-to-ebp" "F - test-convert-multiple-function-skeletons/16")
507 (check-next-stream-line-equal _test-output-stream "c3/return" "F - test-convert-multiple-function-skeletons/17")
508
509 89/<- %esp 5/r32/ebp
510 5d/pop-to-ebp
511 c3/return
512
513 test-convert-function-with-arg:
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532 55/push-ebp
533 89/<- %ebp 4/r32/esp
534
535 (clear-stream _test-input-stream)
536 (clear-stream _test-input-buffered-file->buffer)
537 (clear-stream _test-output-stream)
538 (clear-stream _test-output-buffered-file->buffer)
539
540 (write _test-input-stream "fn foo {\n")
541 (write _test-input-stream "}\n")
542
543 (convert-mu _test-input-buffered-file _test-output-buffered-file)
544 (flush _test-output-buffered-file)
545 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
551
552 (check-next-stream-line-equal _test-output-stream "foo:" "F - test-convert-function-skeleton/0")
553 (check-next-stream-line-equal _test-output-stream "# . prologue" "F - test-convert-function-skeleton/1")
554 (check-next-stream-line-equal _test-output-stream "55/push-ebp" "F - test-convert-function-skeleton/2")
555 (check-next-stream-line-equal _test-output-stream "89/<- %ebp 4/r32/esp" "F - test-convert-function-skeleton/3")
556 (check-next-stream-line-equal _test-output-stream "# . epilogue" "F - test-convert-function-skeleton/4")
557 (check-next-stream-line-equal _test-output-stream "89/<- %esp 5/r32/ebp" "F - test-convert-function-skeleton/5")
558 (check-next-stream-line-equal _test-output-stream "5d/pop-to-ebp" "F - test-convert-function-skeleton/6")
559 (check-next-stream-line-equal _test-output-stream "c3/return" "F - test-convert-function-skeleton/7")
560
561 89/<- %esp 5/r32/ebp
562 5d/pop-to-ebp
563 c3/return
564
565 parse-mu:
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589 55/push-ebp
590 89/<- %ebp 4/r32/esp
591
592 50/push-eax
593 51/push-ecx
594 52/push-edx
595 57/push-edi
596
597 81 5/subop/subtract %esp 0x200/imm32
598 68/push 0x200/imm32/length
599 68/push 0/imm32/read
600 68/push 0/imm32/write
601 89/<- %ecx 4/r32/esp
602
603 68/push 0/imm32/end
604 68/push 0/imm32/start
605 89/<- %edx 4/r32/esp
606
607 bf/copy-to-edi Program/imm32
608 {
609 $parse-mu:line-loop:
610 (clear-stream %ecx)
611 (read-line-buffered *(ebp+8) %ecx)
612
613 81 7/subop/compare *ecx 0/imm32
614 0f 84/jump-if-equal break/disp32
615 +-- 6 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
621 {
622 $parse-mu:word-loop:
623 (next-word-or-string %ecx %edx)
624
625 (slice-empty? %edx)
626 3d/compare-eax-and 0/imm32
627 0f 85/jump-if-not-equal break/disp32
628
629
630 8b/-> *edx 0/r32/eax
631 8a/copy-byte *eax 0/r32/AL
632 81 4/subop/and %eax 0xff/imm32
633
634 3d/compare-eax-and 0x23/imm32/hash
635 0f 84/jump-if-equal break/disp32
636
637 {
638 (slice-equal? %edx "fn")
639 3d/compare-eax-and 0/imm32
640 0f 84/jump-if-equal break/disp32
641
642 (allocate Heap *Function-size)
643 (populate-mu-function-header %ecx %eax)
644 (populate-mu-function-body *(ebp+8) %eax)
645
646 89/<- *edi 0/r32/eax
647
648 8d/address-> *(eax+0x14) 7/r32/edi
649 e9/jump $parse-mu:word-loop/disp32
650 }
651
652 e9/jump $parse-mu:abort/disp32
653 }
654 e9/jump loop/disp32
655 }
656 $parse-mu:end:
657
658 81 0/subop/add %esp 0x214/imm32
659
660 5f/pop-to-edi
661 5a/pop-to-edx
662 59/pop-to-ecx
663 58/pop-to-eax
664
665 89/<- %esp 5/r32/ebp
666 5d/pop-to-ebp
667 c3/return
668
669 $parse-mu:abort:
670
671 (write-buffered Stderr "unexpected top-level command: ")
672 (write-buffered Stderr %edx)
673 (write-buffered Stderr "\n")
674 (flush Stderr)
675
676 bb/copy-to-ebx 1/imm32
677 b8/copy-to-eax 1/imm32/exit
678 cd/syscall 0x80/imm8
679
680
681
682
683
684
685
686 populate-mu-function-header:
687
688 55/push-ebp
689 89/<- %ebp 4/r32/esp
690
691 50/push-eax
692 51/push-ecx
693 57/push-edi
694
695 8b/-> *(ebp+0xc) 7/r32/edi
696
697 68/push 0/imm32/end
698 68/push 0/imm32/start
699 89/<- %ecx 4/r32/esp
700
701 (next-word *(ebp+8) %ecx)
702 (slice-to-string Heap %ecx)
703 89/<- *edi 0/r32/eax
704
705 (next-word *(ebp+8) %ecx)
706 (slice-equal? %ecx "{")
707 3d/compare-eax-and 0/imm32
708 74/jump-if-equal $populate-mu-function-header:abort/disp8
709
710 {
711
712 (next-word *(ebp+8) %ecx)
713
714 (slice-empty? %ecx)
715 3d/compare-eax-and 0/imm32
716 75/jump-if-not-equal break/disp8
717
718
719 8b/-> *edx 0/r32/eax
720 8a/copy-byte *eax 0/r32/AL
721 81 4/subop/and %eax 0xff/imm32
722
723 3d/compare-eax-and 0x23/imm32/hash
724 74/jump-if-equal break/disp8
725
726 eb/jump $populate-mu-function-header:abort/disp8
727 }
728 $populate-mu-function-header:end:
729
730 81 0/subop/add %esp 8/imm32
731
732 5f/pop-to-edi
733 59/pop-to-ecx
734 58/pop-to-eax
735
736 89/<- %esp 5/r32/ebp
737 5d/pop-to-ebp
738 c3/return
739
740 $populate-mu-function-header:abort:
741
742 (write-buffered Stderr "function header not in form 'fn <name> {' -- '")
743 (rewind-stream *(ebp+8))
744 (write-stream 2 *(ebp+8))
745 (write-buffered Stderr "'\n")
746 (flush Stderr)
747
748 bb/copy-to-ebx 1/imm32
749 b8/copy-to-eax 1/imm32/exit
750 cd/syscall 0x80/imm8
751
752
753 populate-mu-function-body:
754
755 55/push-ebp
756 89/<- %ebp 4/r32/esp
757
758 50/push-eax
759 56/push-esi
760
761 8b/-> *(ebp+8) 6/r32/esi
762
763 (parse-mu-block %esi)
764
765 89/<- *(eax+0x10) 0/r32/eax
766 $populate-mu-function-body:end:
767
768 5e/pop-to-esi
769 58/pop-to-eax
770
771 89/<- %esp 5/r32/ebp
772 5d/pop-to-ebp
773 c3/return
774
775
776
777
778 parse-mu-block:
779
780 55/push-ebp
781 89/<- %ebp 4/r32/esp
782
783 50/push-eax
784 51/push-ecx
785 52/push-edx
786 53/push-ebx
787
788 81 5/subop/subtract %esp 0x200/imm32
789 68/push 0x200/imm32/length
790 68/push 0/imm32/read
791 68/push 0/imm32/write
792 89/<- %ecx 4/r32/esp
793
794 68/push 0/imm32/end
795 68/push 0/imm32/start
796 89/<- %edx 4/r32/esp
797
798 bb/copy-to-ebx 1/imm32
799 {
800 $parse-mu-block:line-loop:
801
802 81 7/subop/compare %ebx 0/imm32
803 0f 84/jump-if-equal break/disp32
804
805 (clear-stream %ecx)
806 (read-line-buffered *(ebp+8) %ecx)
807
808 81 7/subop/compare *ecx 0/imm32
809 0f 84/jump-if-equal break/disp32
810
811 (next-word %ecx %edx)
812
813 (slice-empty? %ecx)
814 3d/compare-eax-and 0/imm32
815 75/jump-if-not-equal loop/disp8
816
817
818 8b/-> *edx 0/r32/eax
819 8a/copy-byte *eax 0/r32/AL
820 81 4/subop/and %eax 0xff/imm32
821
822 3d/compare-eax-and 0x23/imm32/hash
823 74/jump-if-equal loop/disp8
824 {
825
826 {
827 (slice-equal? %ecx "{")
828 3d/compare-eax-and 0/imm32
829 74/jump-if-equal break/disp8
830 43/increment-ebx
831 eb/jump $curly-found:end/disp8
832 }
833
834 {
835 (slice-equal? %ecx "}")
836 3d/compare-eax-and 0/imm32
837 74/jump-if-equal break/disp8
838 4b/decrement-ebx
839 eb/jump $curly-found:end/disp8
840 }
841
842 eb/jump $parse-mu-block:end/disp8
843 }
844
845 $curly-found:end:
846
847 (next-word %ecx %edx)
848
849 (slice-empty? %ecx)
850 3d/compare-eax-and 0/imm32
851 0f 85/jump-if-not-equal loop/disp32
852
853
854 8b/-> *edx 0/r32/eax
855 8a/copy-byte *eax 0/r32/AL
856 81 4/subop/and %eax 0xff/imm32
857
858 3d/compare-eax-and 0x23/imm32/hash
859 0f 84/jump-if-equal loop/disp32
860
861 eb/jump $parse-mu-block:abort/disp8
862 }
863 $parse-mu-block:end:
864
865 81 0/subop/add %esp 0x214/imm32
866
867 5b/pop-to-ebx
868 5a/pop-to-edx
869 59/pop-to-ecx
870 58/pop-to-eax
871
872 89/<- %esp 5/r32/ebp
873 5d/pop-to-ebp
874 c3/return
875
876 $parse-mu-block:abort:
877
878 (write-buffered Stderr "'{' or '}' should be on its own line, but got '")
879 (rewind-stream %ecx)
880 (write-stream 2 %ecx)
881 (write-buffered Stderr "'\n")
882 (flush Stderr)
883
884 bb/copy-to-ebx 1/imm32
885 b8/copy-to-eax 1/imm32/exit
886 cd/syscall 0x80/imm8
887
888
889 check-mu-types:
890
891 55/push-ebp
892 89/<- %ebp 4/r32/esp
893
894 $check-types:end:
895
896 89/<- %esp 5/r32/ebp
897 5d/pop-to-ebp
898 c3/return
899
900 emit-subx:
901
902 55/push-ebp
903 89/<- %ebp 4/r32/esp
904
905 50/push-eax
906 51/push-ecx
907 57/push-edi
908
909 8b/-> *(ebp+8) 7/r32/edi
910
911 8b/-> *Program 1/r32/ecx
912 {
913
914 81 7/subop/compare %ecx 0/imm32
915 0f 84/jump-if-equal break/disp32
916 (emit-subx-function %edi %ecx)
917
918 8b/-> *(ecx+0x14) 1/r32/ecx
919 e9/jump loop/disp32
920 }
921 $emit-subx:end:
922
923 5f/pop-to-edi
924 59/pop-to-ecx
925 58/pop-to-eax
926
927 89/<- %esp 5/r32/ebp
928 5d/pop-to-ebp
929 c3/return
930
931
932
933
934
935
936
937 emit-subx-function:
938
939 55/push-ebp
940 89/<- %ebp 4/r32/esp
941
942 50/push-eax
943 51/push-ecx
944 57/push-edi
945
946 8b/-> *(ebp+8) 7/r32/edi
947
948 8b/-> *(ebp+0xc) 1/r32/ecx
949
950 (write-buffered %edi *ecx)
951 (write-buffered %edi ":\n")
952 (emit-subx-prologue %edi)
953 (emit-subx-block %edi *(ecx+0x10))
954 (emit-subx-epilogue %edi)
955 $emit-subx-function:end:
956
957 5f/pop-to-edi
958 59/pop-to-ecx
959 58/pop-to-eax
960
961 89/<- %esp 5/r32/ebp
962 5d/pop-to-ebp
963 c3/return
964
965 emit-subx-block:
966
967 55/push-ebp
968 89/<- %ebp 4/r32/esp
969
970 $emit-subx-block:end:
971
972 89/<- %esp 5/r32/ebp
973 5d/pop-to-ebp
974 c3/return
975
976 emit-subx-statement:
977
978 55/push-ebp
979 89/<- %ebp 4/r32/esp
980
981 50/push-eax
982 51/push-ecx
983
984 {
985 $emit-subx-statement:primitive:
986 (find-matching-primitive *(ebp+0x14) *(ebp+0xc))
987 3d/compare-eax-and 0/imm32
988 74/jump-if-equal break/disp8
989 (emit-subx-primitive *(ebp+8) *(ebp+0xc) *(ebp+0x10) %eax)
990 e9/jump $emit-subx-statement:end/disp32
991 }
992
993 {
994 $emit-subx-statement:call:
995 (find-matching-function *(ebp+0x18) *(ebp+0xc))
996 3d/compare-eax-and 0/imm32
997 74/jump-if-equal break/disp8
998 (emit-subx-call *(ebp+8) *(ebp+0xc) *(ebp+0x10) %eax)
999 e9/jump $emit-subx-statement:end/disp32
1000 }
1001
1002 e9/jump $emit-subx-statement:abort/disp32
1003 $emit-subx-statement:end:
1004
1005 59/pop-to-ecx
1006 58/pop-to-eax
1007
1008 89/<- %esp 5/r32/ebp
1009 5d/pop-to-ebp
1010 c3/return
1011
1012 $emit-subx-statement:abort:
1013
1014 (write-buffered Stderr "couldn't translate '")
1015
1016 (write-buffered Stderr "'\n")
1017 (flush Stderr)
1018
1019 bb/copy-to-ebx 1/imm32
1020 b8/copy-to-eax 1/imm32/exit
1021 cd/syscall 0x80/imm8
1022
1023
1024
1025 == data
1026 Primitives:
1027
1028 "increment"/imm32/name
1029 Single-int-var-on-stack/imm32/inouts
1030 0/imm32/no-outputs
1031 "ff 0/subop/increment"/imm32/subx-name
1032 1/imm32/rm32-is-first-inout
1033 0/imm32/no-r32
1034 0/imm32/no-imm32
1035 _Primitive-inc-reg/imm32/next
1036 _Primitive-inc-reg:
1037
1038 "increment"/imm32/name
1039 0/imm32/no-inouts
1040 Single-int-var-in-some-register/imm32/outputs
1041 "ff 0/subop/increment"/imm32/subx-name
1042 3/imm32/rm32-is-first-output
1043 0/imm32/no-r32
1044 0/imm32/no-imm32
1045 _Primitive-add-reg-to-reg/imm32/next
1046 _Primitive-add-reg-to-reg:
1047
1048 "add"/imm32/name
1049 Single-int-var-in-some-register/imm32/inouts
1050 Single-int-var-in-some-register/imm32/outputs
1051 "01"/imm32/subx-name
1052 3/imm32/rm32-is-first-output
1053 1/imm32/r32-is-first-inout
1054 0/imm32/no-imm32
1055 _Primitive-add-reg-to-mem/imm32/next
1056 _Primitive-add-reg-to-mem:
1057
1058 "add-to"/imm32/name
1059 Int-var-and-second-int-var-in-some-register/imm32/inouts
1060 0/imm32/outputs
1061 "01"/imm32/subx-name
1062 1/imm32/rm32-is-first-inout
1063 2/imm32/r32-is-second-inout
1064 0/imm32/no-imm32
1065 _Primitive-add-mem-to-reg/imm32/next
1066 _Primitive-add-mem-to-reg:
1067
1068 "add"/imm32/name
1069 Single-int-var-on-stack/imm32/inouts
1070 Single-int-var-in-some-register/imm32/outputs
1071 "03"/imm32/subx-name
1072 1/imm32/rm32-is-first-inout
1073 3/imm32/r32-is-first-output
1074 0/imm32/no-imm32
1075 _Primitive-add-lit-to-reg/imm32/next
1076 _Primitive-add-lit-to-reg:
1077
1078 "add"/imm32/name
1079 Single-lit-var/imm32/inouts
1080 Single-int-var-in-some-register/imm32/outputs
1081 "81 0/subop/add"/imm32/subx-name
1082 3/imm32/rm32-is-first-output
1083 0/imm32/no-r32
1084 1/imm32/imm32-is-first-inout
1085 _Primitive-add-lit-to-mem/imm32/next
1086 _Primitive-add-lit-to-mem:
1087
1088 "add-to"/imm32/name
1089 Int-var-and-literal/imm32/inouts
1090 0/imm32/outputs
1091 "81 0/subop/add"/imm32/subx-name
1092 1/imm32/rm32-is-first-inout
1093 0/imm32/no-r32
1094 2/imm32/imm32-is-first-inout
1095 0/imm32/next
1096
1097 Single-int-var-on-stack:
1098 Int-var-on-stack/imm32
1099 0/imm32/next
1100
1101 Int-var-on-stack:
1102 "arg1"/imm32/name
1103 1/imm32/type-int
1104 1/imm32/some-block-depth
1105 1/imm32/some-stack-offset
1106 0/imm32/no-register
1107
1108 Int-var-and-second-int-var-in-some-register:
1109 Int-var-on-stack/imm32
1110 Single-int-var-in-some-register/imm32/next
1111
1112 Int-var-and-literal:
1113 Int-var-on-stack/imm32
1114 Single-lit-var/imm32/next
1115
1116 Single-int-var-in-some-register:
1117 Int-var-in-some-register/imm32
1118 0/imm32/next
1119
1120 Int-var-in-some-register:
1121 "arg1"/imm32/name
1122 1/imm32/type-int
1123 1/imm32/some-block-depth
1124 0/imm32/no-stack-offset
1125 "*"/imm32/register
1126
1127 Single-lit-var:
1128 Lit-var/imm32
1129 0/imm32/next
1130
1131 Lit-var:
1132 "literal"/imm32/name
1133 0/imm32/type-literal
1134 1/imm32/some-block-depth
1135 0/imm32/no-stack-offset
1136 0/imm32/no-register
1137
1138 == code
1139 emit-subx-primitive:
1140
1141 55/push-ebp
1142 89/<- %ebp 4/r32/esp
1143
1144 50/push-eax
1145 51/push-ecx
1146
1147 8b/-> *(ebp+0x14) 1/r32/ecx
1148
1149 (write-buffered *(ebp+8) *(ecx+0xc))
1150
1151 (emit-subx-rm32 *(ebp+8) *(ecx+0x10) *(ebp+0xc))
1152
1153 (emit-subx-r32 *(ebp+8) *(ecx+0x14) *(ebp+0xc))
1154
1155 (emit-subx-imm32 *(ebp+8) *(ecx+0x18) *(ebp+0xc))
1156 $emit-subx-primitive:end:
1157
1158 59/pop-to-ecx
1159 58/pop-to-eax
1160
1161 89/<- %esp 5/r32/ebp
1162 5d/pop-to-ebp
1163 c3/return
1164
1165 emit-subx-rm32:
1166
1167 55/push-ebp
1168 89/<- %ebp 4/r32/esp
1169
1170 50/push-eax
1171
1172 81 7/subop/compare *(ebp+0xc) 0/imm32
1173 74/jump-if-equal $emit-subx-rm32:end/disp8
1174
1175 (get-stmt-operand-from-arg-location *(ebp+0x10) *(ebp+0xc))
1176 (emit-subx-var-as-rm32 *(ebp+8) %eax)
1177 $emit-subx-rm32:end:
1178
1179 58/pop-to-eax
1180
1181 89/<- %esp 5/r32/ebp
1182 5d/pop-to-ebp
1183 c3/return
1184
1185 get-stmt-operand-from-arg-location:
1186
1187 55/push-ebp
1188 89/<- %ebp 4/r32/esp
1189
1190 51/push-ecx
1191
1192 8b/-> *(ebp+0xc) 0/r32/eax
1193
1194 8b/-> *(ebp+8) 1/r32/ecx
1195
1196 {
1197 3d/compare-eax-and 1/imm32
1198 75/jump-if-not-equal break/disp8
1199 $get-stmt-operand-from-arg-location:1:
1200 8b/-> *(ecx+8) 0/r32/eax
1201 8b/-> *eax 0/r32/eax
1202 eb/jump $get-stmt-operand-from-arg-location:end/disp8
1203 }
1204
1205 {
1206 3d/compare-eax-and 2/imm32
1207 75/jump-if-not-equal break/disp8
1208 $get-stmt-operand-from-arg-location:2:
1209 8b/-> *(ecx+8) 0/r32/eax
1210 8b/-> *(eax+4) 0/r32/eax
1211 8b/-> *eax 0/r32/eax
1212 eb/jump $get-stmt-operand-from-arg-location:end/disp8
1213 }
1214
1215 {
1216 3d/compare-eax-and 3/imm32
1217 75/jump-if-not-equal break/disp8
1218 $get-stmt-operand-from-arg-location:3:
1219 8b/-> *(ecx+0xc) 0/r32/eax
1220 8b/-> *eax 0/r32/eax
1221 eb/jump $get-stmt-operand-from-arg-location:end/disp8
1222 }
1223
1224 e9/jump $get-stmt-operand-from-arg-location:abort/disp32
1225 $get-stmt-operand-from-arg-location:end:
1226
1227 59/pop-to-ecx
1228
1229 89/<- %esp 5/r32/ebp
1230 5d/pop-to-ebp
1231 c3/return
1232
1233 $get-stmt-operand-from-arg-location:abort:
1234
1235 (write-buffered Stderr "invalid arg-location ")
1236 (print-int32-buffered Stderr %eax)
1237 (write-buffered Stderr "\n")
1238 (flush Stderr)
1239
1240 bb/copy-to-ebx 1/imm32
1241 b8/copy-to-eax 1/imm32/exit
1242 cd/syscall 0x80/imm8
1243
1244
1245 emit-subx-r32:
1246
1247 55/push-ebp
1248 89/<- %ebp 4/r32/esp
1249
1250 50/push-eax
1251 51/push-ecx
1252
1253 81 7/subop/compare *(ebp+0xc) 0/imm32
1254 0f 84/jump-if-equal $emit-subx-r32:end/disp32
1255
1256 (get-stmt-operand-from-arg-location *(ebp+0x10) *(ebp+0xc))
1257 (maybe-get Registers *(eax+0x10) 8)
1258 (write-buffered *(ebp+8) Space)
1259 (print-int32-buffered *(ebp+8) *eax)
1260 (write-buffered *(ebp+8) "/r32")
1261 $emit-subx-r32:end:
1262
1263 59/pop-to-ecx
1264 58/pop-to-eax
1265
1266 89/<- %esp 5/r32/ebp
1267 5d/pop-to-ebp
1268 c3/return
1269
1270 emit-subx-imm32:
1271
1272 55/push-ebp
1273 89/<- %ebp 4/r32/esp
1274
1275 50/push-eax
1276 51/push-ecx
1277
1278 81 7/subop/compare *(ebp+0xc) 0/imm32
1279 74/jump-if-equal $emit-subx-imm32:end/disp8
1280
1281 (get-stmt-operand-from-arg-location *(ebp+0x10) *(ebp+0xc))
1282 (write-buffered *(ebp+8) Space)
1283 (write-buffered *(ebp+8) *eax)
1284 (write-buffered *(ebp+8) "/imm32")
1285 $emit-subx-imm32:end:
1286
1287 59/pop-to-ecx
1288 58/pop-to-eax
1289
1290 89/<- %esp 5/r32/ebp
1291 5d/pop-to-ebp
1292 c3/return
1293
1294 emit-subx-call:
1295
1296 55/push-ebp
1297 89/<- %ebp 4/r32/esp
1298
1299 50/push-eax
1300 51/push-ecx
1301
1302 (write-buffered *(ebp+8) "(")
1303
1304 8b/-> *(ebp+0x14) 1/r32/ecx
1305 (write-buffered *(ebp+8) *(ecx+4))
1306
1307
1308 8b/-> *(ebp+0xc) 1/r32/ecx
1309 8b/-> *(ecx+8) 1/r32/ecx
1310 {
1311
1312 81 7/subop/compare %ecx 0/imm32
1313 74/jump-if-equal break/disp8
1314
1315 (emit-subx-call-operand *(ebp+8) *ecx)
1316
1317 8b/-> *(ecx+4) 1/r32/ecx
1318 }
1319
1320 (write-buffered *(ebp+8) ")")
1321 $emit-subx-call:end:
1322
1323 59/pop-to-ecx
1324 58/pop-to-eax
1325
1326 89/<- %esp 5/r32/ebp
1327 5d/pop-to-ebp
1328 c3/return
1329
1330 emit-subx-call-operand:
1331
1332 55/push-ebp
1333 89/<- %ebp 4/r32/esp
1334
1335 50/push-eax
1336
1337 8b/-> *(ebp+0xc) 0/r32/eax
1338
1339 (emit-subx-var-as-rm32 *(ebp+8) %eax)
1340
1341 {
1342 81 7/subop/compare *(eax+4) 0/imm32
1343 75/jump-if-not-equal break/disp8
1344 $emit-subx-call-operand:literal:
1345 (write-buffered *(ebp+8) Space)
1346 (write-buffered *(ebp+8) *eax)
1347 }
1348 $emit-subx-call-operand:end:
1349
1350 58/pop-to-eax
1351
1352 89/<- %esp 5/r32/ebp
1353 5d/pop-to-ebp
1354 c3/return
1355
1356 emit-subx-var-as-rm32:
1357
1358 55/push-ebp
1359 89/<- %ebp 4/r32/esp
1360
1361 50/push-eax
1362
1363 8b/-> *(ebp+0xc) 0/r32/eax
1364
1365 {
1366 81 7/subop/compare *(eax+0x10) 0/imm32
1367 74/jump-if-equal break/disp8
1368 $emit-subx-var-as-rm32:register:
1369 (write-buffered *(ebp+8) " %")
1370 (write-buffered *(ebp+8) *(eax+0x10))
1371 }
1372
1373 {
1374 81 7/subop/compare *(eax+0xc) 0/imm32
1375 74/jump-if-equal break/disp8
1376 $emit-subx-var-as-rm32:stack:
1377 (write-buffered *(ebp+8) Space)
1378 (write-buffered *(ebp+8) "*(ebp+")
1379 8b/-> *(ebp+0xc) 0/r32/eax
1380 (print-int32-buffered *(ebp+8) *(eax+0xc))
1381 (write-buffered *(ebp+8) ")")
1382 }
1383 $emit-subx-var-as-rm32:end:
1384
1385 58/pop-to-eax
1386
1387 89/<- %esp 5/r32/ebp
1388 5d/pop-to-ebp
1389 c3/return
1390
1391 find-matching-function:
1392
1393 55/push-ebp
1394 89/<- %ebp 4/r32/esp
1395
1396 51/push-ecx
1397
1398 8b/-> *(ebp+8) 1/r32/ecx
1399 {
1400
1401 81 7/subop/compare %ecx 0/imm32
1402 74/jump-if-equal break/disp8
1403
1404 {
1405 (mu-stmt-matches-function? *(ebp+0xc) %ecx)
1406 3d/compare-eax-and 0/imm32
1407 74/jump-if-equal break/disp8
1408 89/<- %eax 1/r32/ecx
1409 eb/jump $find-matching-function:end/disp8
1410 }
1411
1412 8b/-> *(ecx+0x10) 1/r32/ecx
1413 eb/jump loop/disp8
1414 }
1415
1416 b8/copy-to-eax 0/imm32
1417 $find-matching-function:end:
1418
1419 59/pop-to-ecx
1420
1421 89/<- %esp 5/r32/ebp
1422 5d/pop-to-ebp
1423 c3/return
1424
1425 find-matching-primitive:
1426
1427 55/push-ebp
1428 89/<- %ebp 4/r32/esp
1429
1430 51/push-ecx
1431
1432 8b/-> *(ebp+8) 1/r32/ecx
1433 {
1434 $find-matching-primitive:loop:
1435
1436 81 7/subop/compare %ecx 0/imm32
1437 74/jump-if-equal break/disp8
1438
1439 {
1440 (mu-stmt-matches-primitive? *(ebp+0xc) %ecx)
1441 3d/compare-eax-and 0/imm32
1442 74/jump-if-equal break/disp8
1443 89/<- %eax 1/r32/ecx
1444 eb/jump $find-matching-function:end/disp8
1445 }
1446 $find-matching-primitive:next-primitive:
1447
1448 8b/-> *(ecx+0x1c) 1/r32/ecx
1449 eb/jump loop/disp8
1450 }
1451
1452 b8/copy-to-eax 0/imm32
1453 $find-matching-primitive:end:
1454
1455 59/pop-to-ecx
1456
1457 89/<- %esp 5/r32/ebp
1458 5d/pop-to-ebp
1459 c3/return
1460
1461 mu-stmt-matches-function?:
1462
1463 55/push-ebp
1464 89/<- %ebp 4/r32/esp
1465
1466 51/push-ecx
1467
1468 8b/-> *(ebp+8) 1/r32/ecx
1469 8b/-> *(ebp+0xc) 0/r32/eax
1470 (string-equal? *(ecx+4) *eax)
1471 $mu-stmt-matches-function?:end:
1472
1473 59/pop-to-ecx
1474
1475 89/<- %esp 5/r32/ebp
1476 5d/pop-to-ebp
1477 c3/return
1478
1479 mu-stmt-matches-primitive?:
1480
1481
1482
1483
1484
1485
1486 55/push-ebp
1487 89/<- %ebp 4/r32/esp
1488
1489 51/push-ecx
1490 52/push-edx
1491 53/push-ebx
1492 56/push-esi
1493 57/push-edi
1494
1495 8b/-> *(ebp+8) 1/r32/ecx
1496
1497 8b/-> *(ebp+0xc) 2/r32/edx
1498 {
1499 $mu-stmt-matches-primitive?:check-name:
1500
1501 (string-equal? *(ecx+4) *edx)
1502 3d/compare-eax-and 0/imm32
1503 75/jump-if-not-equal break/disp8
1504 b8/copy-to-eax 0/imm32
1505 e9/jump $mu-stmt-matches-primitive?:end/disp32
1506 }
1507 $mu-stmt-matches-primitive?:check-inouts:
1508
1509 8b/-> *(ecx+8) 6/r32/esi
1510 8b/-> *(edx+4) 7/r32/edi
1511 {
1512
1513 {
1514 81 7/subop/compare %esi 0/imm32
1515 75/jump-if-not-equal break/disp8
1516 {
1517 81 7/subop/compare %edi 0/imm32
1518 75/jump-if-not-equal break/disp8
1519
1520 b8/copy-to-eax 1/imm32
1521 e9/jump $mu-stmt-matches-primitive?:end/disp32
1522 }
1523
1524 b8/copy-to-eax 0/imm32
1525 e9/jump $mu-stmt-matches-primitive?:end/disp32
1526 }
1527
1528 {
1529 81 7/subop/compare %edi 0/imm32
1530 75/jump-if-not-equal break/disp8
1531 b8/copy-to-eax 0/imm32
1532 e9/jump $mu-stmt-matches-primitive?:end/disp32
1533 }
1534
1535 {
1536 (operand-matches-primitive? *esi *edi)
1537 3d/compare-eax-and 0/imm32
1538 75/jump-if-not-equal break/disp8
1539 b8/copy-to-eax 0/imm32
1540 e9/jump $mu-stmt-matches-primitive?:end/disp32
1541 }
1542
1543 8b/-> *(esi+4) 6/r32/esi
1544
1545 8b/-> *(edi+4) 7/r32/edi
1546 eb/jump loop/disp8
1547 }
1548 $mu-stmt-matches-primitive?:check-outputs:
1549
1550 8b/-> *(ecx+0xc) 6/r32/esi
1551 8b/-> *(edx+8) 7/r32/edi
1552 {
1553
1554 {
1555 81 7/subop/compare %esi 0/imm32
1556 75/jump-if-not-equal break/disp8
1557 {
1558 81 7/subop/compare %edi 0/imm32
1559 75/jump-if-not-equal break/disp8
1560
1561 b8/copy-to-eax 1/imm32
1562 e9/jump $mu-stmt-matches-primitive?:end/disp32
1563 }
1564
1565 b8/copy-to-eax 0/imm32
1566 e9/jump $mu-stmt-matches-primitive?:end/disp32
1567 }
1568
1569 {
1570 81 7/subop/compare %edi 0/imm32
1571 75/jump-if-not-equal break/disp8
1572 b8/copy-to-eax 0/imm32
1573 e9/jump $mu-stmt-matches-primitive?:end/disp32
1574 }
1575
1576 {
1577 (operand-matches-primitive? *esi *edi)
1578 3d/compare-eax-and 0/imm32
1579 75/jump-if-not-equal break/disp8
1580 b8/copy-to-eax 0/imm32
1581 e9/jump $mu-stmt-matches-primitive?:end/disp32
1582 }
1583
1584 8b/-> *(ecx+4) 1/r32/ecx
1585
1586 8b/-> *(edx+4) 2/r32/edx
1587 eb/jump loop/disp8
1588 }
1589 $mu-stmt-matches-primitive?:return-true:
1590 b8/copy-to-eax 1/imm32
1591 $mu-stmt-matches-primitive?:end:
1592
1593 5f/pop-to-edi
1594 5e/pop-to-esi
1595 5b/pop-to-ebx
1596 5a/pop-to-edx
1597 59/pop-to-ecx
1598
1599 89/<- %esp 5/r32/ebp
1600 5d/pop-to-ebp
1601 c3/return
1602
1603 operand-matches-primitive?:
1604
1605 55/push-ebp
1606 89/<- %ebp 4/r32/esp
1607
1608 56/push-esi
1609 57/push-edi
1610
1611 8b/-> *(ebp+8) 6/r32/esi
1612
1613 8b/-> *(ebp+0xc) 7/r32/edi
1614
1615 8b/-> *(esi+4) 0/r32/eax
1616 39/compare *(edi+4) 0/r32/eax
1617 b8/copy-to-eax 0/imm32/false
1618 75/jump-if-not-equal $operand-matches-primitive?:end/disp8
1619
1620 {
1621
1622 8b/-> *(esi+0x10) 0/r32/eax
1623 39/compare *(edi+0x10) 0/r32/eax
1624 74/jump-if-equal break/disp8
1625
1626 3d/compare-eax-and 0/imm32
1627 74/jump-if-equal $operand-matches-primitive?:end/disp8
1628 81 7/subop/compare *(edi+0x10) 0/imm32
1629 74/jump-if-equal $operand-matches-primitive?:end/disp8
1630
1631 (string-equal? *(edi+0x10) "*")
1632 3d/compare-eax-and 0/imm32
1633 b8/copy-to-eax 1/imm32/true
1634 75/jump-if-not-equal $operand-matches-primitive?:end/disp8
1635
1636 (string-equal? *(esi+0x10) *(edi+0x10))
1637 3d/compare-eax-and 0/imm32
1638 b8/copy-to-eax 0/imm32/false
1639 74/jump-if-equal $operand-matches-primitive?:end/disp8
1640 }
1641
1642 b8/copy-to-eax 1/imm32/true
1643 $operand-matches-primitive?:end:
1644
1645 5f/pop-to-edi
1646 5e/pop-to-esi
1647
1648 89/<- %esp 5/r32/ebp
1649 5d/pop-to-ebp
1650 c3/return
1651
1652 test-emit-subx-statement-primitive:
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671 55/push-ebp
1672 89/<- %ebp 4/r32/esp
1673
1674 (clear-stream _test-output-stream)
1675 (clear-stream _test-output-buffered-file->buffer)
1676
1677 68/push 0/imm32/no-register
1678 68/push -8/imm32/stack-offset
1679 68/push 1/imm32/block-depth
1680 68/push 1/imm32/type-int
1681 68/push "foo"/imm32
1682 89/<- %ecx 4/r32/esp
1683
1684 51/push-ecx/var-foo
1685 68/push 1/imm32/data-length
1686 68/push 1/imm32/top
1687 89/<- %edx 4/r32/esp
1688
1689 68/push 0/imm32/next
1690 51/push-ecx/var-foo
1691 89/<- %ebx 4/r32/esp
1692
1693 68/push 0/imm32/next
1694 68/push 0/imm32/outputs
1695 53/push-ebx/operands
1696 68/push "increment"/imm32/operation
1697 68/push 1/imm32
1698 89/<- %esi 4/r32/esp
1699
1700 68/push 0/imm32/next
1701 68/push 0/imm32/no-imm32
1702 68/push 0/imm32/no-r32
1703 68/push 1/imm32/rm32-is-first-inout
1704 68/push "ff 0/subop/increment"/imm32/subx-name
1705 68/push 0/imm32/outputs
1706 53/push-ebx/inouts
1707 68/push "increment"/imm32/name
1708 89/<- %ebx 4/r32/esp
1709
1710 (emit-subx-statement _test-output-buffered-file %esi %edx %ebx 0)
1711 (flush _test-output-buffered-file)
1712 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1718
1719 (check-next-stream-line-equal _test-output-stream "ff 0/subop/increment *(ebp+0xfffffff8)" "F - test-emit-subx-statement-primitive")
1720
1721 89/<- %esp 5/r32/ebp
1722 5d/pop-to-ebp
1723 c3/return
1724
1725 test-emit-subx-statement-primitive-register:
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744 55/push-ebp
1745 89/<- %ebp 4/r32/esp
1746
1747 (clear-stream _test-output-stream)
1748 (clear-stream _test-output-buffered-file->buffer)
1749
1750 68/push "eax"/imm32/register
1751 68/push 0/imm32/no-stack-offset
1752 68/push 1/imm32/block-depth
1753 68/push 1/imm32/type-int
1754 68/push "foo"/imm32
1755 89/<- %ecx 4/r32/esp
1756
1757 51/push-ecx/var-foo
1758 68/push 1/imm32/data-length
1759 68/push 1/imm32/top
1760 89/<- %edx 4/r32/esp
1761
1762 68/push 0/imm32/next
1763 51/push-ecx/var-foo
1764 89/<- %ebx 4/r32/esp
1765
1766 68/push 0/imm32/next
1767 53/push-ebx/outputs
1768 68/push 0/imm32/inouts
1769 68/push "increment"/imm32/operation
1770 68/push 1/imm32
1771 89/<- %esi 4/r32/esp
1772
1773 68/push Any-register/imm32
1774 68/push 0/imm32/no-stack-offset
1775 68/push 1/imm32/block-depth
1776 68/push 1/imm32/type-int
1777 68/push "dummy"/imm32
1778 89/<- %ebx 4/r32/esp
1779
1780 68/push 0/imm32/next
1781 53/push-ebx/formal-var
1782 89/<- %ebx 4/r32/esp
1783
1784 68/push 0/imm32/next
1785 68/push 0/imm32/no-imm32
1786 68/push 0/imm32/no-r32
1787 68/push 3/imm32/rm32-in-first-output
1788 68/push "ff 0/subop/increment"/imm32/subx-name
1789 53/push-ebx/outputs
1790 68/push 0/imm32/inouts
1791 68/push "increment"/imm32/name
1792 89/<- %ebx 4/r32/esp
1793
1794 (emit-subx-statement _test-output-buffered-file %esi %edx %ebx 0)
1795 (flush _test-output-buffered-file)
1796 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1802
1803 (check-next-stream-line-equal _test-output-stream "ff 0/subop/increment %eax" "F - test-emit-subx-statement-primitive-register")
1804
1805 89/<- %esp 5/r32/ebp
1806 5d/pop-to-ebp
1807 c3/return
1808
1809 test-emit-subx-statement-select-primitive:
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831 55/push-ebp
1832 89/<- %ebp 4/r32/esp
1833
1834 (clear-stream _test-output-stream)
1835 (clear-stream _test-output-buffered-file->buffer)
1836
1837 68/push "eax"/imm32/register
1838 68/push 0/imm32/no-stack-offset
1839 68/push 1/imm32/block-depth
1840 68/push 1/imm32/type-int
1841 68/push "foo"/imm32
1842 89/<- %ecx 4/r32/esp
1843
1844 51/push-ecx/var-foo
1845 68/push 1/imm32/data-length
1846 68/push 1/imm32/top
1847 89/<- %edx 4/r32/esp
1848
1849 68/push 0/imm32/next
1850 51/push-ecx/var-foo
1851 89/<- %edi 4/r32/esp
1852
1853 68/push 0/imm32/next
1854 57/push-edi/outputs
1855 68/push 0/imm32/inouts
1856 68/push "increment"/imm32/operation
1857 68/push 1/imm32
1858 89/<- %esi 4/r32/esp
1859
1860 68/push Any-register/imm32
1861 68/push 0/imm32/no-stack-offset
1862 68/push 1/imm32/block-depth
1863 68/push 1/imm32/type-int
1864 68/push "dummy"/imm32
1865 89/<- %ebx 4/r32/esp
1866
1867 68/push 0/imm32/next
1868 53/push-ebx/formal-var
1869 89/<- %ebx 4/r32/esp
1870
1871 68/push 0/imm32/next
1872 68/push 0/imm32/no-imm32
1873 68/push 0/imm32/no-r32
1874 68/push 3/imm32/rm32-in-first-output
1875 68/push "ff 0/subop/increment"/imm32/subx-name
1876 53/push-ebx/outputs/formal-outputs
1877 68/push 0/imm32/inouts
1878 68/push "increment"/imm32/name
1879 89/<- %ebx 4/r32/esp
1880
1881 53/push-ebx/next
1882 68/push 0/imm32/no-imm32
1883 68/push 0/imm32/no-r32
1884 68/push 1/imm32/rm32-is-first-inout
1885 68/push "ff 0/subop/increment"/imm32/subx-name
1886 68/push 0/imm32/outputs
1887 57/push-edi/inouts/real-outputs
1888 68/push "increment"/imm32/name
1889 89/<- %ebx 4/r32/esp
1890
1891 (emit-subx-statement _test-output-buffered-file %esi %edx %ebx 0)
1892 (flush _test-output-buffered-file)
1893 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1899
1900 (check-next-stream-line-equal _test-output-stream "ff 0/subop/increment %eax" "F - test-emit-subx-statement-select-primitive")
1901
1902 89/<- %esp 5/r32/ebp
1903 5d/pop-to-ebp
1904 c3/return
1905
1906 test-emit-subx-statement-select-primitive-2:
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928 55/push-ebp
1929 89/<- %ebp 4/r32/esp
1930
1931 (clear-stream _test-output-stream)
1932 (clear-stream _test-output-buffered-file->buffer)
1933
1934 68/push "eax"/imm32/register
1935 68/push 0/imm32/no-stack-offset
1936 68/push 1/imm32/block-depth
1937 68/push 1/imm32/type-int
1938 68/push "foo"/imm32
1939 89/<- %ecx 4/r32/esp
1940
1941 51/push-ecx/var-foo
1942 68/push 1/imm32/data-length
1943 68/push 1/imm32/top
1944 89/<- %edx 4/r32/esp
1945
1946 68/push 0/imm32/next
1947 51/push-ecx/var-foo
1948 89/<- %edi 4/r32/esp
1949
1950 68/push 0/imm32/next
1951 68/push 0/imm32/outputs
1952 57/push-edi/inouts
1953 68/push "increment"/imm32/operation
1954 68/push 1/imm32
1955 89/<- %esi 4/r32/esp
1956
1957 68/push Any-register/imm32
1958 68/push 0/imm32/no-stack-offset
1959 68/push 1/imm32/block-depth
1960 68/push 1/imm32/type-int
1961 68/push "dummy"/imm32
1962 89/<- %ebx 4/r32/esp
1963
1964 68/push 0/imm32/next
1965 53/push-ebx/formal-var
1966 89/<- %ebx 4/r32/esp
1967
1968 68/push 0/imm32/next
1969 68/push 0/imm32/no-imm32
1970 68/push 0/imm32/no-r32
1971 68/push 3/imm32/rm32-in-first-output
1972 68/push "ff 0/subop/increment"/imm32/subx-name
1973 53/push-ebx/outputs/formal-outputs
1974 68/push 0/imm32/inouts
1975 68/push "increment"/imm32/name
1976 89/<- %ebx 4/r32/esp
1977
1978 53/push-ebx/next
1979 68/push 0/imm32/no-imm32
1980 68/push 0/imm32/no-r32
1981 68/push 1/imm32/rm32-is-first-inout
1982 68/push "ff 0/subop/increment"/imm32/subx-name
1983 68/push 0/imm32/outputs
1984 57/push-edi/inouts/real-outputs
1985 68/push "increment"/imm32/name
1986 89/<- %ebx 4/r32/esp
1987
1988 (emit-subx-statement _test-output-buffered-file %esi %edx %ebx 0)
1989 (flush _test-output-buffered-file)
1990 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1996
1997 (check-next-stream-line-equal _test-output-stream "ff 0/subop/increment %eax" "F - test-emit-subx-statement-select-primitive-2")
1998
1999 89/<- %esp 5/r32/ebp
2000 5d/pop-to-ebp
2001 c3/return
2002
2003 test-increment-register:
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019 55/push-ebp
2020 89/<- %ebp 4/r32/esp
2021
2022 (clear-stream _test-output-stream)
2023 (clear-stream _test-output-buffered-file->buffer)
2024
2025 68/push "eax"/imm32/register
2026 68/push 0/imm32/no-stack-offset
2027 68/push 1/imm32/block-depth
2028 68/push 1/imm32/type-int
2029 68/push "foo"/imm32
2030 89/<- %ecx 4/r32/esp
2031
2032 51/push-ecx/var-foo
2033 68/push 1/imm32/data-length
2034 68/push 1/imm32/top
2035 89/<- %edx 4/r32/esp
2036
2037 68/push 0/imm32/next
2038 51/push-ecx/var-foo
2039 89/<- %edi 4/r32/esp
2040
2041 68/push 0/imm32/next
2042 57/push-edi/outputs
2043 68/push 0/imm32/inouts
2044 68/push "increment"/imm32/operation
2045 68/push 1/imm32
2046 89/<- %esi 4/r32/esp
2047
2048 (emit-subx-statement _test-output-buffered-file %esi %edx Primitives 0)
2049 (flush _test-output-buffered-file)
2050 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2056
2057 (check-next-stream-line-equal _test-output-stream "ff 0/subop/increment %eax" "F - test-increment-register")
2058
2059 89/<- %esp 5/r32/ebp
2060 5d/pop-to-ebp
2061 c3/return
2062
2063 test-increment-var:
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079 55/push-ebp
2080 89/<- %ebp 4/r32/esp
2081
2082 (clear-stream _test-output-stream)
2083 (clear-stream _test-output-buffered-file->buffer)
2084
2085 68/push "eax"/imm32/register
2086 68/push 0/imm32/no-stack-offset
2087 68/push 1/imm32/block-depth
2088 68/push 1/imm32/type-int
2089 68/push "foo"/imm32
2090 89/<- %ecx 4/r32/esp
2091
2092 51/push-ecx/var-foo
2093 68/push 1/imm32/data-length
2094 68/push 1/imm32/top
2095 89/<- %edx 4/r32/esp
2096
2097 68/push 0/imm32/next
2098 51/push-ecx/var-foo
2099 89/<- %edi 4/r32/esp
2100
2101 68/push 0/imm32/next
2102 68/push 0/imm32/outputs
2103 57/push-edi/inouts
2104 68/push "increment"/imm32/operation
2105 68/push 1/imm32
2106 89/<- %esi 4/r32/esp
2107
2108 (emit-subx-statement _test-output-buffered-file %esi %edx Primitives 0)
2109 (flush _test-output-buffered-file)
2110 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2116
2117 (check-next-stream-line-equal _test-output-stream "ff 0/subop/increment %eax" "F - test-increment-var")
2118
2119 89/<- %esp 5/r32/ebp
2120 5d/pop-to-ebp
2121 c3/return
2122
2123 test-add-reg-to-reg:
2124
2125
2126
2127
2128
2129 55/push-ebp
2130 89/<- %ebp 4/r32/esp
2131
2132 (clear-stream _test-output-stream)
2133 (clear-stream _test-output-buffered-file->buffer)
2134
2135 68/push "eax"/imm32/register
2136 68/push 0/imm32/no-stack-offset
2137 68/push 1/imm32/block-depth
2138 68/push 1/imm32/type-int
2139 68/push "var1"/imm32
2140 89/<- %ecx 4/r32/esp
2141
2142 68/push "ecx"/imm32/register
2143 68/push 0/imm32/no-stack-offset
2144 68/push 1/imm32/block-depth
2145 68/push 1/imm32/type-int
2146 68/push "var2"/imm32
2147 89/<- %edx 4/r32/esp
2148
2149 68/push 0/imm32/next
2150 52/push-edx/var-var2
2151 89/<- %esi 4/r32/esp
2152
2153 68/push 0/imm32/next
2154 51/push-ecx/var-var1
2155 89/<- %edi 4/r32/esp
2156
2157 68/push 0/imm32/next
2158 57/push-edi/outputs
2159 56/push-esi/inouts
2160 68/push "add"/imm32/operation
2161 68/push 1/imm32
2162 89/<- %esi 4/r32/esp
2163
2164 (emit-subx-statement _test-output-buffered-file %esi 0 Primitives 0)
2165 (flush _test-output-buffered-file)
2166 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2172
2173 (check-next-stream-line-equal _test-output-stream "01 %eax 0x00000001/r32" "F - test-add-reg-to-reg")
2174
2175 89/<- %esp 5/r32/ebp
2176 5d/pop-to-ebp
2177 c3/return
2178
2179 test-add-literal-to-reg:
2180
2181
2182
2183
2184
2185 55/push-ebp
2186 89/<- %ebp 4/r32/esp
2187
2188 (clear-stream _test-output-stream)
2189 (clear-stream _test-output-buffered-file->buffer)
2190
2191 68/push "eax"/imm32/register
2192 68/push 0/imm32/no-stack-offset
2193 68/push 1/imm32/block-depth
2194 68/push 1/imm32/type-int
2195 68/push "var1"/imm32
2196 89/<- %ecx 4/r32/esp
2197
2198 68/push 0/imm32/no-register
2199 68/push 0/imm32/no-stack-offset
2200 68/push 1/imm32/block-depth
2201 68/push 0/imm32/type-literal
2202 68/push "0x34"/imm32
2203 89/<- %edx 4/r32/esp
2204
2205 68/push 0/imm32/next
2206 52/push-edx/var-var2
2207 89/<- %esi 4/r32/esp
2208
2209 68/push 0/imm32/next
2210 51/push-ecx/var-var1
2211 89/<- %edi 4/r32/esp
2212
2213 68/push 0/imm32/next
2214 57/push-edi/outputs
2215 56/push-esi/inouts
2216 68/push "add"/imm32/operation
2217 68/push 1/imm32
2218 89/<- %esi 4/r32/esp
2219
2220 (emit-subx-statement _test-output-buffered-file %esi 0 Primitives 0)
2221 (flush _test-output-buffered-file)
2222 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2228
2229 (check-next-stream-line-equal _test-output-stream "81 0/subop/add %eax 0x34/imm32" "F - test-add-literal-to-reg")
2230
2231 89/<- %esp 5/r32/ebp
2232 5d/pop-to-ebp
2233 c3/return
2234
2235 test-add-literal-to-mem:
2236
2237
2238
2239
2240
2241 55/push-ebp
2242 89/<- %ebp 4/r32/esp
2243
2244 (clear-stream _test-output-stream)
2245 (clear-stream _test-output-buffered-file->buffer)
2246
2247 68/push 0/imm32/no-register
2248 68/push 8/imm32/stack-offset
2249 68/push 1/imm32/block-depth
2250 68/push 1/imm32/type-int
2251 68/push "var1"/imm32
2252 89/<- %ecx 4/r32/esp
2253
2254 68/push 0/imm32/no-register
2255 68/push 0/imm32/no-stack-offset
2256 68/push 1/imm32/block-depth
2257 68/push 0/imm32/type-literal
2258 68/push "0x34"/imm32
2259 89/<- %edx 4/r32/esp
2260
2261 68/push 0/imm32/next
2262 52/push-edx/var-var2
2263 89/<- %esi 4/r32/esp
2264
2265 56/push-esi/next
2266 51/push-ecx/var-var1
2267 89/<- %esi 4/r32/esp
2268
2269 68/push 0/imm32/next
2270 68/push 0/imm32/outputs
2271 56/push-esi/inouts
2272 68/push "add-to"/imm32/operation
2273 68/push 1/imm32
2274 89/<- %esi 4/r32/esp
2275
2276 (emit-subx-statement _test-output-buffered-file %esi 0 Primitives 0)
2277 (flush _test-output-buffered-file)
2278 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2284
2285 (check-next-stream-line-equal _test-output-stream "81 0/subop/add *(ebp+0x00000008) 0x34/imm32" "F - test-add-literal-to-mem")
2286
2287 89/<- %esp 5/r32/ebp
2288 5d/pop-to-ebp
2289 c3/return
2290
2291 test-emit-subx-statement-function-call:
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312 55/push-ebp
2313 89/<- %ebp 4/r32/esp
2314
2315 (clear-stream _test-output-stream)
2316 (clear-stream _test-output-buffered-file->buffer)
2317
2318 68/push 0/imm32/no-register
2319 68/push -8/imm32/stack-offset
2320 68/push 0/imm32/block-depth
2321 68/push 1/imm32/type-int
2322 68/push "foo"/imm32
2323 89/<- %ecx 4/r32/esp
2324
2325 51/push-ecx/var-foo
2326 68/push 1/imm32/data-length
2327 68/push 1/imm32/top
2328 89/<- %edx 4/r32/esp
2329
2330 68/push 0/imm32/next
2331 51/push-ecx/var-foo
2332 89/<- %esi 4/r32/esp
2333
2334 68/push 0/imm32/next
2335 68/push 0/imm32/outputs
2336 56/push-esi/inouts
2337 68/push "f"/imm32/operation
2338 68/push 1/imm32
2339 89/<- %esi 4/r32/esp
2340
2341 68/push 0/imm32/next
2342 68/push 0/imm32/body
2343 68/push 0/imm32/outputs
2344 51/push-ecx/inouts
2345 68/push "f2"/imm32/subx-name
2346 68/push "f"/imm32/name
2347 89/<- %ebx 4/r32/esp
2348
2349 (emit-subx-statement _test-output-buffered-file %esi %edx 0 %ebx)
2350 (flush _test-output-buffered-file)
2351 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2357
2358 (check-next-stream-line-equal _test-output-stream "(f2 *(ebp+0xfffffff8))" "F - test-emit-subx-statement-function-call")
2359
2360 89/<- %esp 5/r32/ebp
2361 5d/pop-to-ebp
2362 c3/return
2363
2364 test-emit-subx-statement-function-call-with-literal-arg:
2365
2366
2367
2368
2369
2370
2371 55/push-ebp
2372 89/<- %ebp 4/r32/esp
2373
2374 (clear-stream _test-output-stream)
2375 (clear-stream _test-output-buffered-file->buffer)
2376
2377 68/push 0/imm32/no-register
2378 68/push 0/imm32/no-stack-offset
2379 68/push 0/imm32/block-depth
2380 68/push 0/imm32/type-literal
2381 68/push "34"/imm32
2382 89/<- %ecx 4/r32/esp
2383
2384 51/push-ecx/var-foo
2385 68/push 1/imm32/data-length
2386 68/push 1/imm32/top
2387 89/<- %edx 4/r32/esp
2388
2389 68/push 0/imm32/next
2390 51/push-ecx/var-foo
2391 89/<- %esi 4/r32/esp
2392
2393 68/push 0/imm32/next
2394 68/push 0/imm32/outputs
2395 56/push-esi/inouts
2396 68/push "f"/imm32/operation
2397 68/push 1/imm32
2398 89/<- %esi 4/r32/esp
2399
2400 68/push 0/imm32/next
2401 68/push 0/imm32/body
2402 68/push 0/imm32/outputs
2403 51/push-ecx/inouts
2404 68/push "f2"/imm32/subx-name
2405 68/push "f"/imm32/name
2406 89/<- %ebx 4/r32/esp
2407
2408 (emit-subx-statement _test-output-buffered-file %esi %edx 0 %ebx)
2409 (flush _test-output-buffered-file)
2410 +-- 6 lines: #? # dump _test-output-stream ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2416
2417 (check-next-stream-line-equal _test-output-stream "(f2 34)" "F - test-emit-subx-statement-function-call-with-literal-arg")
2418
2419 89/<- %esp 5/r32/ebp
2420 5d/pop-to-ebp
2421 c3/return
2422
2423 emit-subx-prologue:
2424
2425 55/push-ebp
2426 89/<- %ebp 4/r32/esp
2427
2428 (write-buffered *(ebp+8) "# . prologue\n")
2429 (write-buffered *(ebp+8) "55/push-ebp\n")
2430 (write-buffered *(ebp+8) "89/<- %ebp 4/r32/esp\n")
2431 $emit-subx-prologue:end:
2432
2433 89/<- %esp 5/r32/ebp
2434 5d/pop-to-ebp
2435 c3/return
2436
2437 emit-subx-epilogue:
2438
2439 55/push-ebp
2440 89/<- %ebp 4/r32/esp
2441
2442 (write-buffered *(ebp+8) "# . epilogue\n")
2443 (write-buffered *(ebp+8) "89/<- %esp 5/r32/ebp\n")
2444 (write-buffered *(ebp+8) "5d/pop-to-ebp\n")
2445 (write-buffered *(ebp+8) "c3/return\n")
2446 $emit-subx-epilogue:end:
2447
2448 89/<- %esp 5/r32/ebp
2449 5d/pop-to-ebp
2450 c3/return