CSC448: Code Generation: Run-Time Storage Location I [69/133] Previous pageContentsNext page

Corin did not show

In the type-checking phase we maintained a structure that maps a variable to its type.

In the code generation phase we maintain a structure that maps a variable to its run-time location.

A Frame is created for every block (bodies of non-native methods and the entry block). It is initialized with the block and the method signature (or null for the entry block).

With this information, the Frame can return an assembly language expression for the run-time location of a variable (the getLocation method). There are four cases:

Recall that:

A diagram:

Location Value
20(%ebp) argument 3
16(%ebp) argument 2
12(%ebp) argument 1
8(%ebp) this
4(%ebp) return address
0(%ebp) old ebp
-4(%ebp) local variable 1
-8(%ebp) local variable 2
-12(%ebp) local variable 3

Global variables are stored in a fixed location that can be referenced via an assembly language symbol (with the same name as the global variable).

Previous pageContentsNext page