

































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Peisert; Class: Compilers; Subject: Engineering Computer Science; University: University of California - Davis; Term: Spring 2009;
Typology: Study notes
1 / 41
This page cannot be seen from the preview
Don't miss anything!


































Lecture 19 Dr. Sean Peisert – ECS 142 – Spring 2009 1
< 2 weeks to go on project 3
Read Sec. 7.1 through 7.4 by next Monday, May 18 2
In Cool, we don’t allow function overloading. C++ & Java do.
How would we allow the equivalent of
myfunction(int c) and myfunction(char *p, int d)?
Keep a parameter list and check for duplicate parameter lists
myFunc(a : int) : Bool {false};
myFunc(b : bool, c : string) : Bool {false}; // OK
myFunc(d : int) // Error 4
We have:
Red : Int ← 0;
What would we have to do for:
Red : Const Int ← 0; 5
We have covered the front-end phases:
Lexical Analysis
Syntax Analysis (Parsing)
Semantic Analysis
Now are the back end phases
Code Generation (we’ll do this first)
Optimization 7
Before discussing code generation, we need to understand what we are trying to generate
There are a number of standard techniques for structuring executable code that are widely used. 8
Execution of a program is initially under the control of an operating system.
When a program is invoked:
The OS allocates space for the program
The code is loaded into part of the space
The OS jumps to the entry point (i.e., “main”) 10
11 Code Other Space Low Address High Address Memory
Holds all data for the program
other space = data space
Compiler is responsible for:
Generating code
Orchestrating use of the data area 13
Code Generation Goals
Most complications in code generation come from trying to be fast as well as correct. 14 An invocation of procedure P is an activation of P.
The lifetime of an activation of P is:
All the steps to execute P
Including all the steps in procedures that P calls 16
The lifetime of a variable x is the portion of execution in which x is defined.
Note that:
Lifetime is a dynamic (run-time) concept
Scope is a static concept 17
Class Main { g() : Int { 1 }; f() : Int { g() }; main() : Int { { g(); f(); } }; } 19 main g g f
Class Main { g() : Int { 1 }; f() : Int { g() }; main() : Int { { g(); f(); } }; } What is the activation tree for this example? 20