lecture11

lecture11 - Status We have covered the front-end phases...

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

View Full Document Right Arrow Icon
1 Profs. Aiken CS 143 Lecture 11 1 Run-time Environments Lecture 11 Profs. Aiken CS 143 Lecture 11 2 Status • We have covered the front-end phases – Lexical analysis – Parsing – Semantic analysis • Next are the back-end phases – Optimization – Code generation • We’ll do code generation first . . . Profs. Aiken CS 143 Lecture 11 3 Run-time environments • 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 Profs. Aiken CS 143 Lecture 11 4 Outline • Management of run-time resources • Correspondence between – static (compile-time) and – dynamic (run-time) structures • Storage organization Profs. Aiken CS 143 Lecture 11 5 Run-time Resources • Execution of a program is initially under the control of the 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”) Profs. Aiken CS 143 Lecture 11 6 Memory Layout Low Address High Address Memory Code Other Space
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 Profs. Aiken CS 143 Lecture 11 7 Notes • By tradition, pictures of machine organization have: – Low address at the top – High address at the bottom – Lines delimiting areas for different kinds of data • These pictures are simplifications – E.g., not all memory need be contiguous Profs. Aiken CS 143 Lecture 11 8 What is Other Space? • Holds all data for the program • Other Space = Data Space • Compiler is responsible for: – Generating code – Orchestrating use of the data area Profs. Aiken CS 143 Lecture 11 9 Code Generation Goals • Two goals: – Correctness – Speed • Most complications in code generation come from trying to be fast as well as correct Profs. Aiken CS 143 Lecture 11 10 Assumptions about Execution 1. Execution is sequential; control moves from one point in a program to another in a well- defined order 2. When a procedure is called, control eventually returns to the point immediately after the call Do these assumptions always hold? Profs. Aiken CS 143 Lecture 11 11 Activations • 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 P calls Profs. Aiken CS 143 Lecture 11 12 Lifetimes of Variables • 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
Background image of page 2
3 Profs. Aiken CS 143 Lecture 11 13 Activation Trees • Assumption (2) requires that when P calls Q , then Q returns before P does • Lifetimes of procedure activations are properly nested • Activation lifetimes can be depicted as a tree Profs. Aiken CS 143 Lecture 11 14 Example Class Main { g() : Int { 1 }; f(): Int { g() }; main(): Int {{ g(); f(); }}; } Main f g g
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/12/2010 for the course CS 143 at Stanford.

Page1 / 9

lecture11 - Status We have covered the front-end phases...

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

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