03-10subprogramParams

03-10subprogramParams - Compiling subprograms Part 2 Formal...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSE 450: Compilers K. Stirewalt Compiling subprograms Part 2: Formal parameters Topics: – Compiling procedure definitions in SpartanAda – Parameter passing modes Material drawn largely from: Fischer and LeBlanc Crafting a Compiler , first edition Benjamin Cummings Publishing, 1988 CSE 450: Compilers K. Stirewalt Recall: Translating subprograms Issues: 1. Generate code for subprogram 2. Generate and record summary information needed to translate calls to the subprogram type information parameter mode information start address 3. Perform these tasks in a single pass CSE 450: Compilers K. Stirewalt Translating subprogram defns Key idea: Create a summary record for the subprogram, filling its attributes incrementally, as different syntactic components of the subprogram definition are processed Summary record must contain info about activation record size, formal parameters (if any), type, etc Design of summary record often interleaved with design of symbol table entry for subprogram CSE 450: Compilers K. Stirewalt Subprogram definitions subprogSpec procedure id { StartSubprogram } formals? | function id { StartSubprogram } formals? return type { ReturnType } subprogBody is { StartSubprogramBody } declarations? begin stmt* end id ‘;’ { EndSubprogramBody } CSE 450: Compilers K. Stirewalt Struct SubprogramRec struct SubprogramRec { unsigned activationRecSize; unsigned startLabel; unsigned endLabel; vector<FormalParam*> formals; Type* returnType; Symbol* idEntry; Env* localDecls; } CSE 450: Compilers K. Stirewalt Formal parameters Issues: 1. Addresses (relative offsets) for each formal parameter need to be computed 2. Parameters have parameter passing modes that affect how parameters are accessed in the subprogram and how code must be generated to call the subprogram 3. The relative offset computation relies on the amount of space needed to represent the formal parameter, which is a function both of its declared type and its mode
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 CSE 450: Compilers K. Stirewalt Recall Size/layout of the activation record for a subprogram is determined as that subprogram is translated Storage for formal params and return value Storage for fixed-width data Storage for local variables and temporaries Generic activation record schema CSE 450: Compilers K. Stirewalt Example function foo ( i : in Integer, a : in array 1. .20 of Integer ) return Integer; Storage for formal params (i and a) and return value Storage for fixed-width data Storage for local variables and temporaries Activation record schema for function foo CSE 450: Compilers K. Stirewalt Example function foo ( i : in Integer, a : in array 1. .20 of Integer ) return Integer; Storage for formal params (i and a) and return value Storage for fixed-width data Storage for local variables and temporaries Activation record schema for function foo Question: How many bytes of storage must be allocated for formal params (i and a) and the return value? CSE 450: Compilers
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

03-10subprogramParams - Compiling subprograms Part 2 Formal...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online