03-08procCalls - Storage organization Run-time environments...

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 Run-time environments Topics: – Allocating space for variables – Implementing procedure call/return – Activation record design Readings: Sections 7.1 – 7.2 in Dragon Book CSE 450: Compilers K. Stirewalt Storage organization From perspective of compiler writer, a program runs in its own logical address space where each program value has a location Mgmt of this logical address space shared between compiler, operating system, and target machine – E.g., OS maps logical addresses to physical addresses, which might be spread out in memory – E.g., target architecture provides primitive instructions that manipulate run-time stack Compiler responsible for partitioning the logical address space into chunks that are used to store contents of program variables, code, etc CSE 450: Compilers K. Stirewalt Run-time org. of object program Logical address space partitioned into blocks – Code and static data located low in memory – Stack located in high memory and grows “down” – Heap located in low memory and grows “up” Code Static data Heap Stack Free memory CSE 450: Compilers K. Stirewalt Storage and layout From the type of a name, we can determine the amount of space needed for it at run time At compile time, we can use these amounts to assign each name a relative address – the type and relative address are stored with a name in the symbol table Data of varying length handled by reserving a fixed amount of storage for a pointer to data – E.g., string variables and arrays with dynamically determined bounds CSE 450: Compilers K. Stirewalt Static vs. dynamic allocation A storage -a location decision is: static if it can be made by the compiler looking only at the text of the program dynamic if it can be decided only when the program is running For dynamic allocation, compilers can use: Stack storage : for names local to a procedure Heap storage : for data that must outlive a call to a procedure CSE 450: Compilers K. Stirewalt Stack allocation of space Each time a procedure… – is called: space for its local variables pushed onto a stack – returns: space for local variables popped off of the stack Allows: – Space to be shared by calls whose duration does not overlap in time – Relative addresses of non-local variables is always the same regardless of sequence of calls
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 Example program (quicksort) int a[11]; void r() { /* reads 9 integers into a[1]. .a[9] */ int i; } int p(int m, int n) { /* partitions a[m]. .a[n] */ int i; } void q( int m, int n ) { int i; if (n > m) { i = p(m,n); q(m, i-1); q(i+1, n); } } int main(void) { r(); a[0]=-9999; a[10]=9999; q(1,9); } CSE 450: Compilers K. Stirewalt Activation trees An activation is the representation of a call to the procedure, including the values of any parameters Activations nest in time Activation trees used to visualize the activation nesting/sequencing in a run of a program – Nodes denote activations – Edges connect callers to callees – Sequencing in time is a pre-order traversal of the tree CSE 450: Compilers K. Stirewalt
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.

This note was uploaded on 07/25/2008 for the course CSE 450 taught by Professor Stirewalt during the Spring '08 term at Michigan State University.

Page1 / 10

03-08procCalls - Storage organization Run-time environments...

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