#undef  FUNCTION
#define FUNCTION "Load_store_unit::"

#ifdef SYSTEMC
/*
 * $Id: Load_store_unit_deallocation.cpp 124 2009-06-17 12:11:25Z rosiere $
 *
 * [ Description ]
 * 
 */

#include "Behavioural/Core/Multi_Execute_loop/Execute_loop/Multi_Execute_unit/Execute_unit/Load_store_unit/include/Load_store_unit.h"
#include "Behavioural/include/Allocation.h"

namespace morpheo                    {
namespace behavioural {
namespace core {
namespace multi_execute_loop {
namespace execute_loop {
namespace multi_execute_unit {
namespace execute_unit {
namespace load_store_unit {


#undef  FUNCTION
#define FUNCTION "Load_store_unit::deallocation"
  void Load_store_unit::deallocation (void)
  {
    log_printf(FUNC,Load_store_unit,FUNCTION,"Begin");

    if (usage_is_set(_usage,USE_SYSTEMC))
      {
//#if defined(STATISTICS) or defined(VHDL_TESTBENCH)
    delete    in_CLOCK ;
//#endif
    delete    in_NRESET;

    DELETE1_SIGNAL( in_MEMORY_IN_VAL                  ,_param->_nb_inst_memory,1);
    DELETE1_SIGNAL(out_MEMORY_IN_ACK                  ,_param->_nb_inst_memory,1);
    DELETE1_SIGNAL( in_MEMORY_IN_CONTEXT_ID           ,_param->_nb_inst_memory,_param->_size_context_id           );
    DELETE1_SIGNAL( in_MEMORY_IN_FRONT_END_ID         ,_param->_nb_inst_memory,_param->_size_front_end_id         );
    DELETE1_SIGNAL( in_MEMORY_IN_OOO_ENGINE_ID        ,_param->_nb_inst_memory,_param->_size_ooo_engine_id        );
    DELETE1_SIGNAL( in_MEMORY_IN_PACKET_ID            ,_param->_nb_inst_memory,_param->_size_rob_ptr              );
    DELETE1_SIGNAL( in_MEMORY_IN_OPERATION            ,_param->_nb_inst_memory,_param->_size_operation            );
    DELETE1_SIGNAL( in_MEMORY_IN_TYPE                 ,_param->_nb_inst_memory,_param->_size_type                 );
    DELETE1_SIGNAL( in_MEMORY_IN_STORE_QUEUE_PTR_WRITE,_param->_nb_inst_memory,_param->_size_store_queue_ptr      );
    DELETE1_SIGNAL( in_MEMORY_IN_STORE_QUEUE_PTR_READ ,_param->_nb_inst_memory,_param->_size_store_queue_ptr      );
    DELETE1_SIGNAL( in_MEMORY_IN_STORE_QUEUE_EMPTY    ,_param->_nb_inst_memory,1);
    DELETE1_SIGNAL( in_MEMORY_IN_LOAD_QUEUE_PTR_WRITE ,_param->_nb_inst_memory,_param->_size_load_queue_ptr       );
    DELETE1_SIGNAL( in_MEMORY_IN_HAS_IMMEDIAT         ,_param->_nb_inst_memory,1                                  );
    DELETE1_SIGNAL( in_MEMORY_IN_IMMEDIAT             ,_param->_nb_inst_memory,_param->_size_general_data         );
    DELETE1_SIGNAL( in_MEMORY_IN_DATA_RA              ,_param->_nb_inst_memory,_param->_size_general_data         );
    DELETE1_SIGNAL( in_MEMORY_IN_DATA_RB              ,_param->_nb_inst_memory,_param->_size_general_data         );
    DELETE1_SIGNAL( in_MEMORY_IN_DATA_RC              ,_param->_nb_inst_memory,_param->_size_special_data         );
    DELETE1_SIGNAL( in_MEMORY_IN_WRITE_RD             ,_param->_nb_inst_memory,1                                  );
    DELETE1_SIGNAL( in_MEMORY_IN_NUM_REG_RD           ,_param->_nb_inst_memory,1                                  );
    DELETE1_SIGNAL( in_MEMORY_IN_WRITE_RE             ,_param->_nb_inst_memory,1                                  );
    DELETE1_SIGNAL( in_MEMORY_IN_NUM_REG_RE           ,_param->_nb_inst_memory,1                                  );

    DELETE1_SIGNAL(out_MEMORY_OUT_VAL          ,_param->_nb_inst_memory,1);
    DELETE1_SIGNAL( in_MEMORY_OUT_ACK          ,_param->_nb_inst_memory,1);
    DELETE1_SIGNAL(out_MEMORY_OUT_CONTEXT_ID   ,_param->_nb_inst_memory,_param->_size_context_id       );
    DELETE1_SIGNAL(out_MEMORY_OUT_FRONT_END_ID ,_param->_nb_inst_memory,_param->_size_front_end_id     );
    DELETE1_SIGNAL(out_MEMORY_OUT_OOO_ENGINE_ID,_param->_nb_inst_memory,_param->_size_ooo_engine_id    );
    DELETE1_SIGNAL(out_MEMORY_OUT_PACKET_ID    ,_param->_nb_inst_memory,_param->_size_rob_ptr          );
//  DELETE1_SIGNAL(out_MEMORY_OUT_OPERATION    ,_param->_nb_inst_memory,_param->_size_operation        );
//  DELETE1_SIGNAL(out_MEMORY_OUT_TYPE         ,_param->_nb_inst_memory,_param->_size_type             );
    DELETE1_SIGNAL(out_MEMORY_OUT_WRITE_RD     ,_param->_nb_inst_memory,1                              );
    DELETE1_SIGNAL(out_MEMORY_OUT_NUM_REG_RD   ,_param->_nb_inst_memory,_param->_size_general_register );
    DELETE1_SIGNAL(out_MEMORY_OUT_DATA_RD      ,_param->_nb_inst_memory,_param->_size_general_data     );
    DELETE1_SIGNAL(out_MEMORY_OUT_WRITE_RE     ,_param->_nb_inst_memory,1                              );
    DELETE1_SIGNAL(out_MEMORY_OUT_NUM_REG_RE   ,_param->_nb_inst_memory,_param->_size_general_register );
    DELETE1_SIGNAL(out_MEMORY_OUT_DATA_RE      ,_param->_nb_inst_memory,_param->_size_general_data     );
    DELETE1_SIGNAL(out_MEMORY_OUT_EXCEPTION    ,_param->_nb_inst_memory,_param->_size_exception        );
    DELETE1_SIGNAL(out_MEMORY_OUT_NO_SEQUENCE  ,_param->_nb_inst_memory,1                              );
    DELETE1_SIGNAL(out_MEMORY_OUT_ADDRESS      ,_param->_nb_inst_memory,_param->_size_general_data     );

    DELETE1_SIGNAL(out_DCACHE_REQ_VAL        ,_param->_nb_cache_port,1);
    DELETE1_SIGNAL( in_DCACHE_REQ_ACK        ,_param->_nb_cache_port,1);
    DELETE1_SIGNAL(out_DCACHE_REQ_CONTEXT_ID ,_param->_nb_cache_port,_param->_size_dcache_context_id  );
    DELETE1_SIGNAL(out_DCACHE_REQ_PACKET_ID  ,_param->_nb_cache_port,_param->_size_dcache_packet_id   );
    DELETE1_SIGNAL(out_DCACHE_REQ_ADDRESS    ,_param->_nb_cache_port,_param->_size_general_data);
    DELETE1_SIGNAL(out_DCACHE_REQ_TYPE       ,_param->_nb_cache_port,_param->_size_dcache_type );
    DELETE1_SIGNAL(out_DCACHE_REQ_WDATA      ,_param->_nb_cache_port,_param->_size_general_data);

    DELETE1_SIGNAL( in_DCACHE_RSP_VAL        ,_param->_nb_cache_port,1);
    DELETE1_SIGNAL(out_DCACHE_RSP_ACK        ,_param->_nb_cache_port,1);
    DELETE1_SIGNAL( in_DCACHE_RSP_CONTEXT_ID ,_param->_nb_cache_port,_param->_size_dcache_context_id  );
    DELETE1_SIGNAL( in_DCACHE_RSP_PACKET_ID  ,_param->_nb_cache_port,_param->_size_dcache_packet_id   );
    DELETE1_SIGNAL( in_DCACHE_RSP_RDATA      ,_param->_nb_cache_port,_param->_size_general_data);
    DELETE1_SIGNAL( in_DCACHE_RSP_ERROR      ,_param->_nb_cache_port,_param->_size_dcache_error);

    DELETE1_SIGNAL(out_BYPASS_MEMORY_VAL           ,_param->_nb_bypass_memory,1);
    DELETE1_SIGNAL(out_BYPASS_MEMORY_OOO_ENGINE_ID ,_param->_nb_bypass_memory,_param->_size_ooo_engine_id   );
    DELETE1_SIGNAL(out_BYPASS_MEMORY_NUM_REG       ,_param->_nb_bypass_memory,_param->_size_general_register);
    DELETE1_SIGNAL(out_BYPASS_MEMORY_DATA          ,_param->_nb_bypass_memory,_param->_size_general_data    );

    // ~~~~~[ Internal ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    delete    _speculative_access_queue_control ;
    
    DELETE1(_store_queue             ,_param->_size_store_queue);
    DELETE1(_load_queue              ,_param->_size_load_queue);
    DELETE1(_speculative_access_queue,_param->_size_speculative_access_queue);

    DELETE1(reg_STORE_QUEUE_NB_CHECK                  ,_param->_size_store_queue);

//  DELETE1(internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ,_param->_nb_cache_port);

//  DELETE1(internal_MEMORY_IN_ACK                    ,_param->_nb_inst_memory);
//  DELETE1(internal_MEMORY_OUT_VAL                   ,_param->_nb_inst_memory);
//  DELETE1(internal_MEMORY_OUT_SELECT_QUEUE          ,_param->_nb_inst_memory);
//  DELETE1(internal_MEMORY_OUT_PTR                   ,_param->_nb_inst_memory);
                                                     
//  DELETE1(internal_DCACHE_RSP_ACK                   ,_param->_nb_cache_port );
//  DELETE1(internal_DCACHE_REQ_VAL                   ,_param->_nb_cache_port );
//  DELETE1(internal_DCACHE_REQ_SELECT_QUEUE          ,_param->_nb_cache_port );
      }

    // ~~~~~[ Component ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    

    delete    _component;

#if defined(DEBUG) and defined(DEBUG_Load_store_unit) and (DEBUG_Load_store_unit == true)
    for (uint32_t i=0; i<_param->_nb_thread; ++i)
      if (_param->_num_thread_valid [i])
        {
          memory_log_file [i].close();
        }
#endif

    log_printf(FUNC,Load_store_unit,FUNCTION,"End");
  };

}; // end namespace load_store_unit
}; // end namespace execute_unit
}; // end namespace multi_execute_unit
}; // end namespace execute_loop
}; // end namespace multi_execute_loop
}; // end namespace core

}; // end namespace behavioural
}; // end namespace morpheo              
#endif
