VAR i : INTEGER;
FUNCTION foo2(REF z : INTEGER) : INTEGER;
BEGIN
z := z * 2;
COUT << "z = " << z << NL;
RETURN 1;
END foo2;
FUNCTION foo(REF c : INTEGER) : INTEGER;
BEGIN
RETURN foo2(c);
END foo;
BEGIN
i := 5;
COUT << "i = " << foo(i) << NL;
RETURN 3;
END.
Compile: success.
/*
* Generated Fri Jun 08 15:48:09 PDT 2007
*/
.section ".rodata"
NL: .asciz "\n"
intFmt: .asciz "%d"
strFmt: .asciz "%s"
boolT: .asciz "TRUE"
boolF: .asciz "FALSE"
.section ".data"
.align 4
id0: .word 0 ! Setting up variable integer: id0 == i
.section ".text"
.align 4
.global foo2.I
foo2.I:
set foo2.I.SIZE, %g1
save %sp, %g1, %sp ! Setting up proc header
st %i0, [%fp-4] ! storing parameter away into memory ==================================================
.section ".text"
.align 4
ld [%fp-4], %l0 ! -------------------------------------------------- Dealing with the fact that this is a REF param
ld [%l0], %l0
st %l0, [%fp-8]
ld [%fp-4], %l0 ! -------------------------------------------------- Dealing with the fact that this is a REF param
ld [%l0], %l0
st %l0, [%fp-12]
set 2, %l0 ! store 2 into register
st %l0, [%fp-16] ! store 2 into memory
ld [%fp-12], %l0 ! setting first variable into register
ld [%fp-16], %l1 ! setting second variable into register
mov %l0, %o0 ! moving first multiplicand
mov %l1, %o1 ! moving second multiplicand
call .mul ! mulling
nop
st %o0, [%fp-20] ! storing
sub %fp, 4, %l0 ! doing final assignment of op into var that is PARAM
ld [%l0], %l0 ! doing final assignment of op into var that is PARAM
ld [%fp-20], %l1 ! loading what we want to save
st %l1, [%l0] ! storing it up
.section ".data"
id1: .asciz "z = " ! setting string
.section ".text"
set strFmt, %o0
set id1, %o1
call printf
nop ! printing string
ld [%fp-4], %l0 ! -------------------------------------------------- Dealing with the fact that this is a REF param
ld [%l0], %l0
st %l0, [%fp-24]
ld [%fp-24], %l0 ! setting first variable into register
set intFmt, %o0
mov %l0, %o1
call printf
nop ! printing integer
set NL, %o0
call printf
nop ! printing new line
set 1, %l0 ! store 1 into register
st %l0, [%fp-28] ! store 1 into memory
ld [%fp-28], %i0
ret
restore
foo2.I.SIZE = -(92 + 0 + 28) & -8 ! Finishing up proc
.section ".text"
.align 4
.global foo.I
foo.I:
set foo.I.SIZE, %g1
save %sp, %g1, %sp ! Setting up proc header
st %i0, [%fp-4] ! storing parameter away into memory ==================================================
.section ".text"
.align 4
ld [%fp-4], %l0 ! -------------------------------------------------- Dealing with the fact that this is a REF param
ld [%l0], %l0
st %l0, [%fp-8]
ld [%fp - 4], %o0 ! ref -> ref
call foo2.I ! calling function
nop
st %o0, [%fp-12] ! storing
ld [%fp-12], %i0
ret
restore
foo.I.SIZE = -(92 + 0 + 12) & -8 ! Finishing up proc
.section ".text"
.align 4
.global main
main:
set main.SIZE, %g1
save %sp, %g1, %sp ! Setting up MAIN header
set 5, %l0 ! store 5 into register
st %l0, [%fp-4] ! store 5 into memory
set id0, %l0 ! doing final assignment of op into var that is VAR
ld [%fp-4], %l1 ! loading what we want to save
st %l1, [%l0] ! storing it up
.section ".data"
id2: .asciz "i = " ! setting string
.section ".text"
set strFmt, %o0
set id2, %o1
call printf
nop ! printing string
set id0, %o0 ! var -> ref
call foo.I ! calling function
nop
st %o0, [%fp-8] ! storing
ld [%fp-8], %l0 ! setting first variable into register
set intFmt, %o0
mov %l0, %o1
call printf
nop ! printing integer
set NL, %o0
call printf
nop ! printing new line
set 3, %l0 ! store 3 into register
st %l0, [%fp-12] ! store 3 into memory
ld [%fp-12], %i0
ret
restore
main.SIZE = -(92 + 0 + 12) & -8 ! Setting up MAIN tail with local and temp offset