1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
See parser/variable.cc and symtab/find.cc for the way variables are handled.
============================================================================
The stack grows from high SP values to low SP values. When a function
is called its arguments are pushed in reversed order, followed by the
function's return address. Then the current BP is pushed and BP is set to
point to that location.
Local variables take up 1 index position per variable. Arguments are reached
as 'bp + index', where index value 2 refers to the function's 1st argument;
Local variables are reached as 'bp - index' where index is negative (-1, -2,
...) and refers to the '-index'th local variable number.
Here's the stack frame organization:
high stack offsets
|
| arg#N BP + N+1 0xc0[N+1 (width 2)]
| ...
| arg#2 BP + 3 0xc003
| arg#1 BP + 2 0xc002 = 0xc002 + param. offset
| RA (ret. addr.) 0xc001
BP--> | old BP 0xc000
| local#1 BP - 1 0xc000 - 1 (0xbfff)
| local#2 BP - 2 0xc000 - 2
| ...
| local#N BP - N 0xc000 - N
|
SP--> low stack offsets
The Frame class stores the types of the local variables in a vector:
its 1st element defines the type of the 1st local variable: access it
as element [-index - 1]
The values of variables in the symbol table are the above indices:
* global variables have values 0..x,
* parameters have values 0xc000 + 2 + parameter offset,
* local variables have values 0xc000 - 1 - local variable offset
Symtab::find() returns 0xc000 if the specified variable name does not exist.
|