/*
 * $Id: main.cpp 111 2009-02-27 18:37:40Z rosiere $
 *
 * [ Description ]
 * 
 */

#include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/SelfTest/include/test.h"

#define NB_PARAMS 7

void usage (int argc, char * argv[])
{
  err (_("<Usage> %s name_instance list_params.\n"),argv[0]);
  err (_("list_params is :\n"));
  err (_(" * nb_context                           (uint32_t)\n"));
  err (_(" * size_upt_queue          [nb_context] (uint32_t)\n"));
  err (_(" * size_ufpt_queue         [nb_context] (uint32_t)\n"));
  err (_(" * size_address                         (uint32_t)\n"));
  err (_(" * nb_inst_predict                      (uint32_t)\n"));
  err (_(" * nb_inst_decod                        (uint32_t)\n"));
  err (_(" * nb_inst_branch_complete              (uint32_t)\n"));
  err (_(" * nb_inst_update                       (uint32_t)\n"));
  err (_(" * size_history                         (uint32_t)\n"));
  err (_(" * size_ras_index          [nb_context] (uint32_t)\n"));

  exit (1);
}

#ifndef SYSTEMC
int main    (int argc, char * argv[])
#else
int sc_main (int argc, char * argv[])
#endif
{
  if (argc <= static_cast<int>(2+NB_PARAMS))
    usage (argc, argv);

  uint32_t x = 1;

  string name = argv[x++];

  uint32_t   _nb_context              = fromString<uint32_t>(argv[x++]);

  if (argc != static_cast<int>(2+NB_PARAMS+3*_nb_context))
    usage (argc, argv);

  uint32_t * _size_upt_queue              = new uint32_t [_nb_context];
  for (uint32_t i=0; i<_nb_context; i++)
    _size_upt_queue  [i] = fromString<uint32_t>(argv[x++]);
  uint32_t * _size_ufpt_queue             = new uint32_t [_nb_context];
  for (uint32_t i=0; i<_nb_context; i++)
    _size_ufpt_queue [i] = fromString<uint32_t>(argv[x++]);
  uint32_t   _size_address            = fromString<uint32_t>(argv[x++]);
  uint32_t   _nb_inst_predict         = fromString<uint32_t>(argv[x++]);
  uint32_t   _nb_inst_decod           = fromString<uint32_t>(argv[x++]);
  uint32_t   _nb_inst_branch_complete = fromString<uint32_t>(argv[x++]);
  uint32_t   _nb_inst_update          = fromString<uint32_t>(argv[x++]);
  uint32_t   _size_history            = fromString<uint32_t>(argv[x++]);
  uint32_t * _size_ras_index          = new uint32_t [_nb_context];
  for (uint32_t i=0; i<_nb_context; i++)
    _size_ras_index [i] = fromString<uint32_t>(argv[x++]);

  uint32_t     _nb_thread                           = _nb_context;
  uint32_t *   _translate_num_context_to_num_thread = new uint32_t    [_nb_context];
  for (uint32_t i=0; i<_nb_context; i++)
    _translate_num_context_to_num_thread [i] = i;

  int _return = EXIT_SUCCESS;
  try 
    {
      morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::Parameters * param = new morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::Parameters
	(_nb_context             ,
	 _size_upt_queue         ,
	 _size_ufpt_queue        ,
	 _size_address           ,
	 _nb_inst_predict        ,
	 _nb_inst_decod          ,
	 _nb_inst_branch_complete,
	 _nb_inst_update         ,
	 _size_history           ,
	 _size_ras_index         ,
         _nb_thread                          ,
         _translate_num_context_to_num_thread,
         true //is_toplevel
         );
      
      msg(_("%s"),param->print(1).c_str());
      
      test (name,param);
    }
  catch (morpheo::ErrorMorpheo & error)
    {
      msg (_("<%s> :\n%s"),name.c_str(), error.what ());
      _return = EXIT_FAILURE;
    }
  catch (...)
    {
      err (_("<%s> : This test must generate a error.\n"),name.c_str());
      _return = EXIT_FAILURE;
    }


  delete [] _size_ras_index;
  delete [] _size_ufpt_queue;
  delete [] _size_upt_queue;
  delete [] _translate_num_context_to_num_thread;

  return (_return);
}
