mem_alloc_manager.cc

Go to the documentation of this file.
00001 /*!
00002         \file
00003         \brief Memory allocator.
00004         \author jaz
00005 */
00006 
00007 #include <lestes/lang/cplus/sem/ss_declaration.g.hh>
00008 #include <lestes/lang/cplus/sem/ss_type.g.hh>
00009 #include <lestes/md/types/tm_data_type_base.g.hh>
00010 #include <lestes/md/mem/memory_allocators.g.hh>
00011 #include <lestes/md/literals/literal_info_base.g.hh>
00012 #include <lestes/md/types/ss_type2tm_type.g.hh>
00013 #include <lestes/backend_v2/intercode/pi_mem_factory.g.hh>
00014 #include <lestes/backend_v2/intercode/pi.g.hh>
00015 #include "mem_alloc_manager.g.hh"
00016 
00017 package(lestes);
00018 package(md);
00019 package(mem);
00020 
00021 using namespace ::lestes::backend_v2::intercode;
00022 using namespace ::lestes::md::types;
00023 using namespace ::lestes::md::literals;
00024 using namespace ::lestes::md::mem;
00025 using namespace ::lestes::lang::cplus::sem;
00026 
00027 /*!
00028         Returns instance.
00029 */
00030 ptr<mem_alloc_manager> mem_alloc_manager::instance() {
00031         if ( !singleton_instance_get() ) {
00032                 singleton_instance_set(mem_alloc_manager::create());
00033         }
00034         return singleton_instance_get();
00035 }
00036 
00037 /*!
00038         \brief Allocates space for variable on the local stack.
00039         
00040         \param function The function where the new variable is allocated.
00041         \param decl Declaration of the variable.
00042         \return pi_mem_factory object representing memory space for variable.
00043 */
00044 ptr<pi_mem_factory> mem_alloc_manager::allocate_local_var(ptr<ss_function_declaration> function, ptr<ss_object_declaration > decl){
00045         return local_variable_allocator::instance(function)->allocate(decl);
00046 }
00047 
00048 /*!
00049         \brief Allocates space for temporal variable on the local stack.
00050         
00051         \param function The function where the new variable is allocated.
00052         \param type Data type of the variable.
00053         \return pi_mem_factory object representing memory space for variable.
00054 */
00055 ptr<pi_mem_factory> mem_alloc_manager::allocate_local_tmp(ptr<ss_function_declaration> function, ptr<ss_type > type){
00056         return local_variable_allocator::instance(function)->allocate_tmp(type->accept_ss_type2tm_type_gen_base(ss_type2tm_type::instance()));
00057 }
00058 
00059 
00060 /*!
00061         \brief Allocates space for temporal variable on the local stack.
00062         
00063         \param function The function where the new variable is allocated.
00064         \param type Data type of the variable.
00065         \return pi_mem_factory object representing memory space for variable.
00066 */
00067 ptr<pi_mem_factory> mem_alloc_manager::allocate_local_tmp(ptr<ss_function_declaration> function, ptr<tm_data_type_base> type){
00068         return local_variable_allocator::instance(function)->allocate_tmp(type);
00069 }
00070 
00071 /*!
00072         \brief Deallocates previously allocated space.
00073         
00074         Deallocates previously (by one of the mem_alloc_manager's functions) allocated memory space. Time of
00075         dealocation is bound by given sequencepoints.   
00076         \param mem The memory to be dealocated.
00077         \param psp The first boundary sequencepoint.
00078         \param nsp The second boundary sequencepoint.
00079 */
00080 void mem_alloc_manager::deallocate(ptr<pi_mem_factory> mem, ptr<pi_sp> psp, ptr<pi_sp> nsp){
00081         if ( mem->allocator_get() )
00082                 mem->allocator_get()->deallocate(mem, psp, nsp);
00083 }
00084 
00085 /*!
00086         \brief Allocates space for variable in global data storage.
00087         
00088         \param decl Declaration of the variable.
00089         \return pi_mem_factory object representing memory space for variable.
00090 */
00091 ptr<pi_mem_factory> mem_alloc_manager::allocate_global_var(ptr<ss_object_declaration> decl){
00092         return global_variable_allocator::instance()->allocate(decl);
00093 }
00094 
00095 /*!
00096         \brief Initialises given global memory with literal.
00097         
00098         \param mem The memory.
00099         \param value The literal.
00100 */
00101 void mem_alloc_manager::init_global_var(ptr<pi_mem_factory> mem, ptr<literal_info_base> value) {
00102         return global_variable_allocator::instance()->init_variable(mem, value);
00103 }
00104 
00105 
00106 end_package(mem);
00107 end_package(md);
00108 end_package(lestes);
00109 

Generated on Mon Feb 12 18:22:40 2007 for lestes by doxygen 1.5.1-20070107