Header Ads Widget

Procedures call

Procedures call

Procedure is an important and frequently used programming construct for a compiler. It is used to generate good code for procedure calls and returns.

Calling sequence:

The translation for a call includes a sequence of actions taken on entry and exit from each procedure. Following actions take place in a calling sequence:

  • When a procedure call occurs then space is allocated for activation record.
  • Evaluate the argument of the called procedure.
  • Establish the environment pointers to enable the called procedure to access data in enclosing blocks.
  • Save the state of the calling procedure so that it can resume execution after the call.
  • Also save the return address. It is the address of the location to which the called routine must transfer after it is finished.
  • Finally generate a jump to the beginning of the code for the called procedure.

Let us consider a grammar for a simple procedure call statement

  1. S →    call id(Elist)  
  2.    Elist →   Elist, E  
  3.    Elist →  E  

A suitable transition scheme for procedure call would be:

Production RuleSemantic Action
S → call id(Elist)for each item p on QUEUE do
  GEN (param p)
    GEN (call id.PLACE)
Elist → Elist, Eappend E.PLACE to the end of QUEUE
Elist → Einitialize QUEUE to contain only
   E.PLACE

Queue is used to store the list of parameters in the procedure call.

Post a Comment

0 Comments