annotate lab4/test/nasty.p @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
mike@0 1 (* Order of evaluation and unnesting of procedure calls *)
mike@0 2
mike@0 3 var x, y, z: integer;
mike@0 4
mike@0 5 proc nasty(x: integer): integer;
mike@0 6 begin
mike@0 7 y := 1;
mike@0 8 return 2 * x;
mike@0 9 end;
mike@0 10
mike@0 11 begin
mike@0 12 x := 3; y := 5;
mike@0 13 z := y + nasty(x);
mike@0 14 print_num(z); newline()
mike@0 15 end.
mike@0 16
mike@0 17 (* Gives 7 without optimisation owing to lifting of procedure call;
mike@0 18 with full CSE, gives 11 because the two occurrences of y can share. *)
mike@0 19
mike@0 20 (*<<
mike@0 21 11
mike@0 22 >>*)
mike@0 23
mike@0 24 (*[[
mike@0 25 @ picoPascal compiler output
mike@0 26 .include "fixup.s"
mike@0 27 .global pmain
mike@0 28
mike@0 29 @ proc nasty(x: integer): integer;
mike@0 30 .text
mike@0 31 _nasty:
mike@0 32 mov ip, sp
mike@0 33 stmfd sp!, {r0-r1}
mike@0 34 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 35 mov fp, sp
mike@0 36 @ y := 1;
mike@0 37 mov r0, #1
mike@0 38 set r1, _y
mike@0 39 str r0, [r1]
mike@0 40 @ return 2 * x;
mike@0 41 ldr r0, [fp, #40]
mike@0 42 lsl r0, r0, #1
mike@0 43 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 44 .ltorg
mike@0 45
mike@0 46 pmain:
mike@0 47 mov ip, sp
mike@0 48 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 49 mov fp, sp
mike@0 50 @ x := 3; y := 5;
mike@0 51 mov r4, #3
mike@0 52 set r0, _x
mike@0 53 str r4, [r0]
mike@0 54 mov r5, #5
mike@0 55 set r0, _y
mike@0 56 str r5, [r0]
mike@0 57 @ z := y + nasty(x);
mike@0 58 mov r0, r4
mike@0 59 bl _nasty
mike@0 60 add r4, r5, r0
mike@0 61 set r0, _z
mike@0 62 str r4, [r0]
mike@0 63 @ print_num(z); newline()
mike@0 64 mov r0, r4
mike@0 65 bl print_num
mike@0 66 bl newline
mike@0 67 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 68 .ltorg
mike@0 69
mike@0 70 .comm _x, 4, 4
mike@0 71 .comm _y, 4, 4
mike@0 72 .comm _z, 4, 4
mike@0 73 @ End
mike@0 74 ]]*)
mike@0 75