Home | | Compiler Design | Procedure Calls

Chapter: Principles of Compiler Design : Intermediate Code Generation

Procedure Calls

The procedure is such an important and frequently used programming construct that it is imperative for a compiler to generate good code for procedure calls and returns.

PROCEDURE CALLS

 

The procedure is such an important and frequently used programming construct that it is imperative for a compiler to generate good code for procedure calls and returns. The run-time routines that handle procedure argument passing, calls and returns are part of the run-time support package.

 

Let us consider a grammar for a simple procedure call statement

 

 

(1)             S->call id(Elist)

(2)             Elist-> Elist , E

 

(3)             Elist-> E

 

Calling Sequences:

 

The translation for a call includes a calling sequence, a sequence of actions taken on entry to and exit from each procedure. The falling are the actions that take place in a calling sequence :

*  When a procedure call occurs, space must be allocated for the activation record of the called procedure.

 

*  The arguments of the called procedure must be evaluated and made available to the called procedure in a known place.

 

*  Environment pointers must be established to enable the called procedure to access data in enclosing blocks.

*  The state of the calling procedure must be saved so it can resume execution after the call.

 

*    Also saved in a known place is the return address, the location to which the called routine must transfer after it is finished.

*   Finally a jump to the beginning of the code for the called procedure must be generated. For example, consider the following syntax-directed translation

 

(1)   S-> call id ( Elist )

 

{ for each item p on queue do emit (‘ param’ p );

 

emit (‘call’ id.place) }

 

Here, the code for S is the code for Elist, which evaluates the arguments, followed by a param p statement for each argument, followed by a call statement.

 

(2) Elist-> Elist , E

{ append E.place to the end of queue }

(3) Elist-> E

 

{ initialize queue to contain only E.place }

 

Here, queue is emptied and then gets a single pointer to the symbol table location for the name that denotes the value of E.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Principles of Compiler Design : Intermediate Code Generation : Procedure Calls |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.