### comparison lab4/test/nasty.p @ 0:bfdcc3820b32

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