LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
translate::Level Class Reference

Stack frames for languages with non local variables. More...

#include <level.hh>

Collaboration diagram for translate::Level:

Public Member Functions

 Level (const misc::symbol &name, const Level *parent=nullptr, frame::bool_list_type formal_escapes=frame::bool_list_type())
 ~Level ()
tree::rExp sl () const
 A Tree expression computing this level's static link.
tree::rExp fp (const Level &use) const
 Return a Tree expression representing the frame pointer of this Level, but from the use level point of view (i.e., climbing the static links from use level to this Level).
std::ostream & dump (std::ostream &o) const
 Report on stream o.
const Accesslocal_alloc (bool escapes)
 Allocate a new local variable.
const Accessformal_alloc (bool escapes)
 Similar to local_alloc () for formal arguments.
Accessors.

Level of the enclosing function.

const Levelparent_get () const
frame::Frameframe_get ()
 Stack frame that we enhance with static link support.
const frame::Frameframe_get () const
 Stack frame that we enhance with static link support.
temp::Label label_get () const
 Label of this function (from the Frame).
const access_list_typeformals_get () const
 Accesses to the formals arguments.
int frame_size_get () const
 Size of the Frame.

Private Attributes

const Levelparent_
 Level of the enclosing function.
frame::Frameframe_
 Stack frame that we enhance with static link support.
access_list_type formals_
 Accesses to the formal arguments.
access_list_type locals_
 Accesses to the local (automatic) variables.

Detailed Description

Stack frames for languages with non local variables.

frame::Frame holds the information on the function stack frame. translate::Level adds information on the parents of the current Level (which is used to fetch escaping variables), and also the list of the Access'es to the formals of the functions.

A frame::Frame is a frame::Access factory, and translate::Level is a translate::Access factory.

Constructor & Destructor Documentation

translate::Level::Level ( const misc::symbol name,
const Level parent = nullptr,
frame::bool_list_type  formal_escapes = frame::bool_list_type() 
)

References formal_alloc().

translate::Level::~Level ( )
Destroy \a locals_ completely, but not \a formals_.

locals_ and formals_ are translate::Access binding some frame::Access. The frame::Frame keeps tracks of its formals, but not of its locals; hence it destroys by itself its locals and we must not do it here. As a result, we have to destroy the high level parts of both formals and locals, and the low level part (frame::Access) only for locals_.

References misc::deep_clear(), formals_, and locals_.

Member Function Documentation

std::ostream & translate::Level::dump ( std::ostream &  o) const

Report on stream o.

References misc::decindent(), formals_, frame_, misc::incendl(), label_get(), and parent_.

Referenced by translate::operator<<().

const Access * translate::Level::formal_alloc ( bool  escapes)

Similar to local_alloc () for formal arguments.

References frame::Frame::formal_alloc(), formals_, and frame_.

Referenced by Level().

const access_list_type & translate::Level::formals_get ( ) const
inline

Accesses to the formals arguments.

References formals_.

Referenced by sl(), and translate::Translator::visit_function_dec_body().

tree::rExp translate::Level::fp ( const Level use) const

Return a Tree expression representing the frame pointer of this Level, but from the use level point of view (i.e., climbing the static links from use level to this Level).

This is used in at least two places:

  1. when calling a function (which needs a static link), to pass the location of the frame of its parent.
  1. when accessing a frame resident variable, to produce an expression computing the location of the frame it belongs to. For instance this is `Temp fp' if the variable is in the function using it, but it is more complex when the function uses a variable from an enclosing function.

Referenced by translate::Access::exp().

frame::Frame & translate::Level::frame_get ( )
inline

Stack frame that we enhance with static link support.

References frame_.

Referenced by label_get(), sl(), and translate::Translator::visit_function_dec_body().

const frame::Frame & translate::Level::frame_get ( ) const
inline

Stack frame that we enhance with static link support.

References frame_.

int translate::Level::frame_size_get ( ) const

Size of the Frame.

References frame_, and frame::Frame::get_current_frame_size().

temp::Label translate::Level::label_get ( ) const

Label of this function (from the Frame).

References frame_get(), and frame::Frame::label_get().

Referenced by dump(), and translate::operator<<().

const Access * translate::Level::local_alloc ( bool  escapes)

Allocate a new local variable.

Parameters
escapesif true, make it frame resident.
Returns
an Access to allocated memory.

References frame_, frame::Frame::local_alloc(), and locals_.

Referenced by translate::Translator::operator()().

const Level * translate::Level::parent_get ( ) const
inline

References parent_.

tree::rExp translate::Level::sl ( ) const

A Tree expression computing this level's static link.

References formals_get(), and frame_get().

Member Data Documentation

access_list_type translate::Level::formals_
private

Accesses to the formal arguments.

Referenced by dump(), formal_alloc(), formals_get(), and ~Level().

frame::Frame* translate::Level::frame_
private

Stack frame that we enhance with static link support.

Referenced by dump(), formal_alloc(), frame_get(), frame_size_get(), and local_alloc().

access_list_type translate::Level::locals_
private

Accesses to the local (automatic) variables.

Referenced by local_alloc(), and ~Level().

const Level* translate::Level::parent_
private

Level of the enclosing function.

Referenced by dump(), and parent_get().


The documentation for this class was generated from the following files: