/*
 * $Id: main.cpp 83 2008-05-09 18:00:21Z rosiere $
 *
 * [ Description ]
 * 
 */

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

#define NB_PARAMS 5

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 (_(" * nb_decod_unit                                 (uint32_t)\n"));
  err (_(" * nb_ooo_engine                                 (uint32_t)\n"));
  err (_(" * nb_inst_branch_complete                       (uint32_t)\n"));
  err (_(" * size_depth                    [nb_context]	   (uint32_t)\n"));
  err (_(" * size_address                                  (uint32_t)\n"));
  err (_(" * size_inst_decod               [nb_decod_unit] (uint32_t)\n"));
  err (_(" * size_inst_commit              [nb_ooo_engine] (uint32_t)\n"));
  err (_(" * link_context_to_decod_unit    [nb_context]	   (uint32_t)\n"));
  err (_(" * link_decod_unit_to_ooo_engine [nb_decod_unit] (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++];
//const uint32_t size_data = atoi(argv[x++]);
//const uint32_t nb_port   = atoi(argv[x++]);

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

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

  uint32_t * _size_depth                    = new uint32_t [_nb_context];
  for (uint32_t i=0; i<_nb_context; i++)
    _size_depth [i] = fromString<uint32_t>(argv[x++]);

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

  uint32_t * _size_inst_decod               = new uint32_t [_nb_decod_unit];
  for (uint32_t i=0; i<_nb_decod_unit; i++)
    _size_inst_decod [i] = fromString<uint32_t>(argv[x++]);
  uint32_t * _size_inst_commit              = new uint32_t [_nb_ooo_engine];
  for (uint32_t i=0; i<_nb_ooo_engine; i++)
    _size_inst_commit [i] = fromString<uint32_t>(argv[x++]);
  uint32_t * _link_context_to_decod_unit    = new uint32_t [_nb_context];
  for (uint32_t i=0; i<_nb_context; i++)
    _link_context_to_decod_unit [i] = fromString<uint32_t>(argv[x++]);
  uint32_t * _link_decod_unit_to_ooo_engine = new uint32_t [_nb_decod_unit];
  for (uint32_t i=0; i<_nb_decod_unit; i++)
    _link_decod_unit_to_ooo_engine [i] = fromString<uint32_t>(argv[x++]);

  int _return = EXIT_SUCCESS;
  try 
    {
      morpheo::behavioural::core::multi_front_end::front_end::context_state::Parameters * param = new morpheo::behavioural::core::multi_front_end::front_end::context_state::Parameters
	(_nb_context                   ,
	 _nb_decod_unit                ,
	 _nb_ooo_engine                ,
	 _nb_inst_branch_complete      ,
	 _size_depth                   ,
	 _size_address                 ,
	 _size_inst_decod              ,
	 _size_inst_commit             ,
	 _link_context_to_decod_unit   ,
	 _link_decod_unit_to_ooo_engine
	 );
      
      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;
    }

  delete [] _size_depth;                   
  delete [] _size_inst_decod;              
  delete [] _size_inst_commit;             
  delete [] _link_context_to_decod_unit;   
  delete [] _link_decod_unit_to_ooo_engine;

  try 
    {
      if (_return == EXIT_SUCCESS)
	TEST_OK("Context_State : no error");
      else
	TEST_KO("Context_State : a lot of error");
    }
  catch (morpheo::ErrorMorpheo & error)
    {
      msg (_("<%s> :\n%s\n"),name.c_str(), error.what ());
      _return = EXIT_FAILURE;
    }

  return (_return);
}
