/*
 * $Id$
 *
 * [ Description ]
 * 
 */

#include "Behavioural/Core/Multi_OOO_Engine/OOO_Engine/Rename_unit/Rename_select/include/Rename_select.h"

namespace morpheo                    {
namespace behavioural {
namespace core {
namespace multi_ooo_engine {
namespace ooo_engine {
namespace rename_unit {
namespace rename_select {


#undef  FUNCTION
#define FUNCTION "Rename_select::Rename_select"
  Rename_select::Rename_select 
  (
#ifdef SYSTEMC
   sc_module_name name,
#else
   string name,
#endif
#ifdef STATISTICS
   morpheo::behavioural::Parameters_Statistics * param_statistics,
#endif
   morpheo::behavioural::core::multi_ooo_engine::ooo_engine::rename_unit::rename_select::Parameters * param,
   morpheo::behavioural::Tusage_t usage
   ):
    _name              (name)
    ,_param            (param)
    ,_usage            (usage)
  {
    log_printf(FUNC,Rename_select,FUNCTION,"Begin");

    log_printf(INFO,Rename_select,FUNCTION,"Allocation");

    allocation (
#ifdef STATISTICS
		param_statistics
#endif
		);

#ifdef STATISTICS
    if (_usage & USE_STATISTICS)
      {	
	log_printf(INFO,Rename_select,FUNCTION,"Allocation of statistics");

	statistics_declaration(param_statistics);
      }
#endif

#ifdef VHDL
    if (_usage & USE_VHDL)
      {
	// generate the vhdl
	log_printf(INFO,Rename_select,FUNCTION,"Generate the vhdl");
	
	vhdl();
      }
#endif

#ifdef SYSTEMC
    if (_usage & USE_SYSTEMC)
      {
	log_printf(INFO,Rename_select,FUNCTION,"Method - transition");

	SC_METHOD (transition);
	dont_initialize ();
	sensitive << (*(in_CLOCK)).pos();
	
# ifdef SYSTEMCASS_SPECIFIC
	// List dependency information
# endif    

	log_printf(INFO,Rename_select,FUNCTION,"Method - genMealy");

	SC_METHOD (genMealy);
	dont_initialize ();
	sensitive << (*(in_CLOCK)).neg();
	for (uint32_t i=0; i<_param->_nb_front_end; i++)
	  for (uint32_t j=0; j<_param->_nb_inst_decod [i]; j++)
	    {
	      sensitive << (*(in_RENAME_IN_VAL           [i][j]))
			<< (*(in_RENAME_IN_TYPE          [i][j]))
			<< (*(in_RENAME_IN_OPERATION     [i][j]))
			<< (*(in_RENAME_IN_ADDRESS       [i][j]))
			<< (*(in_RENAME_IN_HAS_IMMEDIAT  [i][j]))
			<< (*(in_RENAME_IN_IMMEDIAT      [i][j]))
			<< (*(in_RENAME_IN_READ_RA       [i][j]))
			<< (*(in_RENAME_IN_NUM_REG_RA    [i][j]))
			<< (*(in_RENAME_IN_READ_RB       [i][j]))
			<< (*(in_RENAME_IN_NUM_REG_RB    [i][j]))
			<< (*(in_RENAME_IN_READ_RC       [i][j]))
			<< (*(in_RENAME_IN_NUM_REG_RC    [i][j]))
			<< (*(in_RENAME_IN_WRITE_RD      [i][j]))
			<< (*(in_RENAME_IN_NUM_REG_RD    [i][j]))
			<< (*(in_RENAME_IN_WRITE_RE      [i][j]))
			<< (*(in_RENAME_IN_NUM_REG_RE    [i][j]))
			<< (*(in_RENAME_IN_EXCEPTION_USE [i][j]));
	      if (_param->_have_port_front_end_id)
	      sensitive << (*(in_RENAME_IN_FRONT_END_ID  [i][j]));
	      if (_param->_have_port_context_id)
	      sensitive << (*(in_RENAME_IN_CONTEXT_ID    [i][j]));
	      if (_param->_have_port_depth)
	      sensitive << (*(in_RENAME_IN_DEPTH         [i][j]));
	    }
	for (uint32_t i=0; i<_param->_nb_inst_rename; i++)
	  sensitive << (*(in_RENAME_OUT_ACK          [i]));
	
# ifdef SYSTEMCASS_SPECIFIC
	// List dependency information
	
	for (uint32_t i=0; i<_param->_nb_front_end; i++)
	  for (uint32_t j=0; j<_param->_nb_inst_decod [i]; j++)
	    for (uint32_t x=0; x<_param->_nb_inst_rename; x++)
	      {
		(*(out_RENAME_IN_ACK            [i][j])) (*(in_RENAME_IN_VAL           [i][j]));
		(*(out_RENAME_IN_ACK            [i][j])) (*(in_RENAME_OUT_ACK          [x]   ));
	      }

	for (uint32_t x=0; x<_param->_nb_inst_rename; x++)
	  {
	    for (uint32_t i=0; i<_param->_nb_front_end; i++)
	      for (uint32_t j=0; j<_param->_nb_inst_decod [i]; j++)
		{
		  (*(out_RENAME_OUT_VAL           [x])) (*(in_RENAME_IN_VAL           [i][j]));

		  if (_param->_have_port_front_end_id)
		    {
		  (*(out_RENAME_OUT_FRONT_END_ID  [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_FRONT_END_ID  [x])) (*(in_RENAME_IN_FRONT_END_ID  [i][j]));
		    }
		  if (_param->_have_port_context_id)
		    {
		  (*(out_RENAME_OUT_CONTEXT_ID    [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_CONTEXT_ID    [x])) (*(in_RENAME_IN_CONTEXT_ID    [i][j]));
		    }
		  if (_param->_have_port_depth)
		    {
		  (*(out_RENAME_OUT_DEPTH         [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_DEPTH         [x])) (*(in_RENAME_IN_DEPTH         [i][j]));
		    }
		  (*(out_RENAME_OUT_TYPE          [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_TYPE          [x])) (*(in_RENAME_IN_TYPE          [i][j]));
		  (*(out_RENAME_OUT_OPERATION     [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_OPERATION     [x])) (*(in_RENAME_IN_OPERATION     [i][j]));
		  (*(out_RENAME_OUT_ADDRESS       [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_ADDRESS       [x])) (*(in_RENAME_IN_ADDRESS       [i][j]));
		  (*(out_RENAME_OUT_HAS_IMMEDIAT  [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_HAS_IMMEDIAT  [x])) (*(in_RENAME_IN_HAS_IMMEDIAT  [i][j]));
		  (*(out_RENAME_OUT_IMMEDIAT      [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_IMMEDIAT      [x])) (*(in_RENAME_IN_IMMEDIAT      [i][j]));
		  (*(out_RENAME_OUT_READ_RA       [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_READ_RA       [x])) (*(in_RENAME_IN_READ_RA       [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RA    [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RA    [x])) (*(in_RENAME_IN_NUM_REG_RA    [i][j]));
		  (*(out_RENAME_OUT_READ_RB       [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_READ_RB       [x])) (*(in_RENAME_IN_READ_RB       [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RB    [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RB    [x])) (*(in_RENAME_IN_NUM_REG_RB    [i][j]));
		  (*(out_RENAME_OUT_READ_RC       [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_READ_RC       [x])) (*(in_RENAME_IN_READ_RC       [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RC    [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RC    [x])) (*(in_RENAME_IN_NUM_REG_RC    [i][j]));
		  (*(out_RENAME_OUT_WRITE_RD      [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_WRITE_RD      [x])) (*(in_RENAME_IN_WRITE_RD      [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RD    [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RD    [x])) (*(in_RENAME_IN_NUM_REG_RD    [i][j]));
		  (*(out_RENAME_OUT_WRITE_RE      [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_WRITE_RE      [x])) (*(in_RENAME_IN_WRITE_RE      [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RE    [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_NUM_REG_RE    [x])) (*(in_RENAME_IN_NUM_REG_RE    [i][j]));
		  (*(out_RENAME_OUT_EXCEPTION_USE [x])) (*(in_RENAME_IN_VAL           [i][j]));
		  (*(out_RENAME_OUT_EXCEPTION_USE [x])) (*(in_RENAME_IN_EXCEPTION_USE [i][j]));
		}
	  }
# endif    
	
#endif
      }
    log_printf(FUNC,Rename_select,FUNCTION,"End");
  };
    
#undef  FUNCTION
#define FUNCTION "Rename_select::~Rename_select"
  Rename_select::~Rename_select (void)
  {
    log_printf(FUNC,Rename_select,FUNCTION,"Begin");

#ifdef STATISTICS
    if (_usage & USE_STATISTICS)
      {
	log_printf(INFO,Rename_select,FUNCTION,"Generate Statistics file");
	
	delete _stat;
      }
#endif

    log_printf(INFO,Rename_select,FUNCTION,"Deallocation");
    deallocation ();

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

}; // end namespace rename_select
}; // end namespace rename_unit
}; // end namespace ooo_engine
}; // end namespace multi_ooo_engine
}; // end namespace core

}; // end namespace behavioural
}; // end namespace morpheo              
