03-09compilingProcedures

03-09compilingProcedures - Compiling procedures Topics:...

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 procedures Topics: – Quick overview of remaining project issues – 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 Remaining project issues Project 5: Add support for: – procedures and functions – arrays • No dynamic arrays for this project • Likewise no arrays or strings returned from functions • Strings and arrays always passed by reference – translation to 3-address code Project 6: Generate target code CSE 450: Compilers K. Stirewalt Subprogram definitions subprogDefn subprogSpec subprogBody subprogSpec procedure id formals? | function id formals? return type subprogBody is declarations? begin stmt* end id? ‘;’ CSE 450: Compilers K. Stirewalt Examples function Gen return Integer is begin return GenInt; end; procedure main is i: Integer; j : Integer := 30; begin i := Gen + Gen; i := i + j; Put(i); end; CSE 450: Compilers K. Stirewalt Issues: Translating subprograms 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. Need to perform these tasks in a single pass over the input CSE 450: Compilers K. Stirewalt Subprograms and symbol tables Subprograms define a new scope – Need a new symbol table environment – Formal parameters will be added to this new environment so that they will be visible when translating the statements (and variable initializers) in the subprogram Once subprogram is translated, this new environment may be deleted Subprogram information must be added to the environment in which it is defined
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 CSE 450: Compilers K. Stirewalt Consider the function… function factorial ( k : in Integer ) return Integer is begin if (k > 1) then return k * factorial(k-1); else return 1; end if; end; CSE 450: Compilers K. Stirewalt Consider the function… function factorial ( k : in Integer ) return Integer is begin if (k > 1) then return k * factorial (k-1); else return 1; end if; end;
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.

Page1 / 5

03-09compilingProcedures - Compiling procedures Topics:...

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