Various code generation skeletons

Here are some skeletons for code sequences to be generated in connection with procedure calls.

Note: They are meant as a help, and do not take all subtle cases into account!
They may even contain errors! (Some have been corrected)

Comment:: The space needed for parameters is known from the symbol table for ordinary proc/func calls. But for proc/func's passed as parameters this information is not known until they have all been loaded.

Call of a "normal" procedure/function (not passed as parameter)
       gen(sub, %sp, place.param_space, %sp); %%% Increment stack pointer
       < load of parameters >
       newtemp(temp);
       base(place, breg, temp);   %%% Find environment for proc/func.
       gen(call, place.entryaddr, 0);
       gen(st, breg, [%sp-4]);    %%% Set-up of access link, Delay slot!!
       releasetemp(temp);
       < fetch result of function >
       gen(add, %sp, place.param_space, %sp); %%% Decrement stack pointer
Transfer of proc/func as parameter
       newtemp(temp);
       base(place, breg, temp);           %%% Find access link for proc/func.
       gen(st, breg, [%sp + param_addr]); %%% Save it as first word
       gen(sethi, %HI(place.entryaddr), temp);
       gen(or, %LO(place.entryaddr), temp);    %%% Save entry address
       gen(st, temp, [%sp + param_addr + 4]);  %%% as second word
       releasetemp(temp);
       param_addr = param_addr + 8;
Call of a proc/func passed as parameter
       newsymb(space_for_param)  %%% returns a unique identifier 
       gen(sub, %sp, space_for_param, %sp); %%% Increment stack pointer
       < load of parameters >    %%% Here we dont know the space
                                 %%% needed before all parameters have 
                                 %%% been loaded, so we use a symbolic
				 %%% constant, defined after all
				 %%% parameters have been loaded. Its value
				 %%% is found during loads and then
				 %%% assigned to the symbol.
       gen(space_for_param = space_count):
       newtemp(temp1);
       newtemp(temp2);
       rval(param.proc_entryaddress,temp1)   %%% Get entry address and
       rval(param.proc_accesslink,temp2)     %%% access link from
                                             %%% parameter locations
                                             %%% somewhere in environment
       gen(jmpl, temp1, %O7);      %%% Jump and save return address
       gen(st, temp2, [%sp-4]);    %%% Set-up access link, Delay slot!!
       releasetemp(temp1);
       releasetemp(temp2);
       < fetch result of function >
       gen(add, %sp, space_for_param, %sp); %%% Decrement stack pointer


Peter Kornerup <kornerup@imada.sdu.dk>

Last modified:Wed May 6 11:50:16 1998