| CSC448: Code Generation: Run-Time Storage Location I [69/133] | ![]() ![]() ![]() |
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:
12(%ebp),
16(%ebp), 20(%ebp).
this: 8(%ebp).
-4(%ebp),
-8(%ebp), -12(%ebp).
mystdout.
Recall that:
4(%ebp).
0(%ebp).
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).