LRDE Tiger Compiler
1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
|
Stack frame (or activation record) of a function. More...
#include <frame.hh>
Public Member Functions | |
Frame (const temp::Label &label) | |
Frame (const temp::Label &label, const bool_list_type &escapes) | |
Allocate a new frame. | |
Frame (const Frame &src) | |
Copy constructor. | |
~Frame () | |
Destroy this frame, and registered arguments (Frame::formals_). | |
Frame & | operator= (const Frame &src) |
Accessors. | |
temp::Label | label_get () const |
const access_list_type & | formals_get () const |
int | get_current_frame_size () const |
Allocation. | |
temp::Label | label_ |
Label of this frame: basically the name of the function. | |
access_list_type | formals_ |
Arguments of this function. | |
access_list_type | locals_ |
size_t | offset_ = 0 |
Current local variable offset (i.e. size) in the stack frame. | |
size_t | arg_offset_ = 0 |
Current argument offset. | |
const In_Frame * | frame_alloc () |
Allocate space for a frame resident local. | |
const Access * | local_alloc (bool escapes) |
Allocate space for a local. | |
const Access * | formal_alloc (bool escapes) |
Allocate space for a new formal. | |
void | formal_alloc (const bool_list_type &escapes) |
Allocate space for several possibly escaping formals. | |
void | arg_add (size_t n) |
Allocate at least n arguments dedicated word (s) in frame. | |
const Access * | alloc (bool escapes) |
Stack frame (or activation record) of a function.
The module frame is in charge of the low level frames''.
Higher level frames'' are translate::Level. A Level is basically a Frame that knows the Frame of its parent.
To allocate a new local variable, call frame::Frame::local_alloc () which returns a frame::Access. That makes Frame a Factory of Access.
The top level, which is the equivalent of ``main'' in C, of course, also needs a frame.
In its suggestion of implementation, Andrew Appel stores in the class Frame the names of the frame pointer register, and of the return value register. This introduces weird dependencies upon Frame in various places, or worse yet: it causes Frame to depend upon some value of target::Cpu. It turns out it is not necessary: we can use the names `fp' and `rv' directly, and have them translated to their real name much later. One problem remains that the sources are scattered with temp::TempFactory::create () invocation to create these registers. This should be factored out.
frame::Frame::Frame | ( | const temp::Label & | label | ) |
Referenced by operator=().
frame::Frame::Frame | ( | const temp::Label & | label, |
const bool_list_type & | escapes | ||
) |
Allocate a new frame.
label | the name of the function |
escapes | a list of one Boolean per formal, stating whether it escapes. |
References formal_alloc().
frame::Frame::Frame | ( | const Frame & | src | ) |
Copy constructor.
References frame::Access::clone(), formals_, and locals_.
frame::Frame::~Frame | ( | ) |
Destroy this frame, and registered arguments (Frame::formals_).
References misc::deep_clear(), formals_, and locals_.
|
protected |
References frame_alloc().
Referenced by formal_alloc(), and local_alloc().
void frame::Frame::arg_add | ( | size_t | n | ) |
Allocate at least n arguments dedicated word (s) in frame.
Used in code generation, when function's arguments need to be stored in frame.
References arg_offset_, and frame::word_size.
const Access * frame::Frame::formal_alloc | ( | bool | escapes | ) |
Allocate space for a new formal.
If it escapes, then store it in the frame.
References alloc(), and formals_.
Referenced by formal_alloc(), translate::Level::formal_alloc(), and Frame().
void frame::Frame::formal_alloc | ( | const bool_list_type & | escapes | ) |
Allocate space for several possibly escaping formals.
References formal_alloc().
const access_list_type & frame::Frame::formals_get | ( | ) | const |
References formals_.
const In_Frame * frame::Frame::frame_alloc | ( | ) |
Allocate space for a frame resident local.
References offset_, and frame::word_size.
Referenced by alloc().
int frame::Frame::get_current_frame_size | ( | ) | const |
References arg_offset_, and offset_.
Referenced by translate::Level::frame_size_get().
temp::Label frame::Frame::label_get | ( | ) | const |
References label_.
Referenced by translate::Level::label_get(), and frame::operator<<().
const Access * frame::Frame::local_alloc | ( | bool | escapes | ) |
Allocate space for a local.
If it escapes, then store it in the frame.
References alloc(), and locals_.
Referenced by translate::Level::local_alloc().
|
protected |
Current argument offset.
Referenced by arg_add(), and get_current_frame_size().
|
protected |
Arguments of this function.
The module `frame' depends upon the target, i.e., the architecture for which we are going to compile. Because the call conventions depend upon the target, the module frame needs to know what are the formals of a function. This is why they are stored here. For other reasons, translate::Level also needs to store the formals of a function, giving a taste of duplication.
Referenced by formal_alloc(), formals_get(), Frame(), and ~Frame().
|
protected |
Label of this frame: basically the name of the function.
Referenced by label_get().
|
protected |
Referenced by Frame(), local_alloc(), and ~Frame().
|
protected |
Current local variable offset (i.e. size) in the stack frame.
Referenced by frame_alloc(), and get_current_frame_size().