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