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

#include "Behavioural/Generic/RegisterFile/include/RegisterFile.h"

namespace morpheo                    {
namespace behavioural                {
namespace generic                    {
namespace registerfile               {

#ifdef SYSTEMC
  RegisterFile::RegisterFile (sc_module_name name,
#else
  RegisterFile::RegisterFile (string name        ,
#endif
#ifdef STATISTICS
			      morpheo::behavioural::Parameters_Statistics             param_statistics,
#endif
			      morpheo::behavioural::generic::registerfile::Parameters param ):
			      _name   (name)
			      ,_param (param)
  {
#ifdef STATISTICS
    _stat = new Statistics (static_cast<string>(_name),
			    param_statistics          ,
			    param);
#endif

#ifdef VHDL_TESTBENCH
    _vhdl_testbench = new Vhdl_Testbench (_name);
    vhdl_testbench_port           (*_vhdl_testbench);
    _vhdl_testbench->set_clock    ("in_CLOCK",true);
#endif

#ifdef VHDL
    // generate the vhdl
    vhdl();
#endif

#ifdef SYSTEMC
    allocation ();

    SC_METHOD (transition);
    dont_initialize ();
    sensitive_pos << *(in_CLOCK);
    
    SC_METHOD (genMealy_read);
    dont_initialize ();
    sensitive_neg << *(in_CLOCK);
    for (uint32_t i=0; i<_param._nb_port_read; i++)
      sensitive << *(in_READ_VAL     [i])
		<< *(in_READ_ADDRESS [i]);

#ifdef SYSTEMCASS_SPECIFIC
    // List dependency information
    for (uint32_t i=0; i<_param._nb_port_read; i++)
      {
	(*(out_READ_DATA [i])) (*( in_READ_VAL     [i]));
	(*(out_READ_DATA [i])) (*( in_READ_ADDRESS [i]));
      }
#endif    

    for (uint32_t i=0; i<_param._nb_port_read ; i++)
      PORT_WRITE(out_READ_ACK  [i], 1);
    for (uint32_t i=0; i<_param._nb_port_write; i++)
      PORT_WRITE(out_WRITE_ACK [i], 1);
#endif
  };
  
  RegisterFile::~RegisterFile (void)
  {
#ifdef SYSTEMC
    deallocation ();
#endif

#ifdef VHDL_TESTBENCH
    // generate the test bench
    _vhdl_testbench->generate_file();
    delete _vhdl_testbench;
#endif

#ifdef STATISTICS
    _stat->generate_file(statistics(0));
    delete _stat;
#endif
  };

}; // end namespace registerfile 
}; // end namespace generic
}; // end namespace behavioural          
}; // end namespace morpheo              
