#ifndef morpheo_behavioural_core_multi_front_end_front_end_context_state_Context_State_h
#define morpheo_behavioural_core_multi_front_end_front_end_context_state_Context_State_h

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

#ifdef SYSTEMC
#include "systemc.h"
#endif


#include "Behavioural/Core/Multi_Front_end/Front_end/Context_State/include/Parameters.h"
#include "Behavioural/Core/Multi_Front_end/Front_end/Context_State/include/Types.h"
#ifdef STATISTICS
#include "Behavioural/include/Stat.h"
#endif
#include "Behavioural/include/Component.h"
#ifdef VHDL
#include "Behavioural/include/Vhdl.h"
#endif
#include "Behavioural/include/Usage.h"

#include "Common/include/ToString.h"
#include "Common/include/Debug.h"

#include <iostream>

namespace morpheo {
namespace behavioural {

namespace core {
namespace multi_front_end {
namespace front_end {
namespace context_state {


  class Context_State 
#if SYSTEMC
    : public sc_module
#endif
  {
    // -----[ fields ]----------------------------------------------------
    // Parameters
  protected : const std::string  _name;
  protected : const Parameters * _param;
  private   : const Tusage_t     _usage;

#ifdef STATISTICS
  public    : Stat                           * _stat;
#endif

  public    : Component                      * _component;
  private   : Interfaces                     * _interfaces;

#ifdef SYSTEMC
    // ~~~~~[ Interface ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // ~~~~~[ Interface : "" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public    : SC_CLOCK                      *  in_CLOCK        ;
  public    : SC_IN (Tcontrol_t)            *  in_NRESET       ;

    // ~~~~~[ Interface : "decod_event" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public    : SC_IN (Tcontrol_t         )  **  in_DECOD_EVENT_VAL                    ;//[nb_decod_unit]
  public    : SC_OUT(Tcontrol_t         )  ** out_DECOD_EVENT_ACK                    ;//[nb_decod_unit]
  public    : SC_IN (Tcontext_t         )  **  in_DECOD_EVENT_CONTEXT_ID             ;//[nb_decod_unit]
  public    : SC_IN (Tdepth_t           )  **  in_DECOD_EVENT_DEPTH                  ;//[nb_decod_unit]
  public    : SC_IN (Tevent_type_t      )  **  in_DECOD_EVENT_TYPE                   ;//[nb_decod_unit]
  public    : SC_IN (Tcontrol_t         )  **  in_DECOD_EVENT_IS_DELAY_SLOT          ;//[nb_decod_unit]
  public    : SC_IN (Taddress_t         )  **  in_DECOD_EVENT_ADDRESS                ;//[nb_decod_unit]
  public    : SC_IN (Taddress_t         )  **  in_DECOD_EVENT_ADDRESS_EPCR           ;//[nb_decod_unit]

    // ~~~~~[ Interface : "commit_event" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public    : SC_IN (Tcontrol_t         )  **  in_COMMIT_EVENT_VAL                   ;//[nb_ooo_engine]
  public    : SC_OUT(Tcontrol_t         )  ** out_COMMIT_EVENT_ACK                   ;//[nb_ooo_engine]
  public    : SC_IN (Tcontext_t         )  **  in_COMMIT_EVENT_CONTEXT_ID            ;//[nb_ooo_engine]
  public    : SC_IN (Tdepth_t           )  **  in_COMMIT_EVENT_DEPTH                 ;//[nb_ooo_engine]
  public    : SC_IN (Tevent_type_t      )  **  in_COMMIT_EVENT_TYPE                  ;//[nb_ooo_engine]
  public    : SC_IN (Tcontrol_t         )  **  in_COMMIT_EVENT_IS_DELAY_SLOT         ;//[nb_ooo_engine]
  public    : SC_IN (Taddress_t         )  **  in_COMMIT_EVENT_ADDRESS               ;//[nb_ooo_engine]
  public    : SC_IN (Taddress_t         )  **  in_COMMIT_EVENT_ADDRESS_EPCR          ;//[nb_ooo_engine]
  public    : SC_IN (Tcontrol_t         )  **  in_COMMIT_EVENT_ADDRESS_EEAR_VAL      ;//[nb_ooo_engine]
  public    : SC_IN (Taddress_t         )  **  in_COMMIT_EVENT_ADDRESS_EEAR          ;//[nb_ooo_engine]

    // ~~~~~[ Interface : "branch_complete" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public    : SC_IN (Tcontrol_t         )  **  in_BRANCH_COMPLETE_VAL                ;//[nb_inst_branch_complete]
  public    : SC_OUT(Tcontrol_t         )  ** out_BRANCH_COMPLETE_ACK                ;//[nb_inst_branch_complete]
  public    : SC_IN (Tcontext_t         )  **  in_BRANCH_COMPLETE_CONTEXT_ID         ;//[nb_inst_branch_complete]
  public    : SC_IN (Tdepth_t           )  **  in_BRANCH_COMPLETE_DEPTH              ;//[nb_inst_branch_complete]
  public    : SC_IN (Tcontrol_t         )  **  in_BRANCH_COMPLETE_MISS_PREDICTION    ;//[nb_inst_branch_complete]
  public    : SC_IN (Tcontrol_t         )  **  in_BRANCH_COMPLETE_TAKE               ;//[nb_inst_branch_complete]
  public    : SC_IN (Taddress_t         )  **  in_BRANCH_COMPLETE_ADDRESS_SRC        ;//[nb_inst_branch_complete]
  public    : SC_IN (Taddress_t         )  **  in_BRANCH_COMPLETE_ADDRESS_DEST       ;//[nb_inst_branch_complete]

    // ~~~~~[ Interface : "nb_inst" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public    : SC_IN (Tcounter_t         )  **  in_NB_INST_DECOD_ALL                  ;//[nb_decod_unit]
  public    : SC_IN (Tcounter_t         )  **  in_NB_INST_COMMIT_ALL                 ;//[nb_ooo_engine]
  public    : SC_IN (Tcounter_t         )  **  in_NB_INST_COMMIT_MEM                 ;//[nb_ooo_engine]

    // ~~~~~[ Interface "event" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public    : SC_OUT(Tcontrol_t         )  ** out_EVENT_VAL                          ;//[nb_context]
  public    : SC_IN (Tcontrol_t         )  **  in_EVENT_ACK                          ;//[nb_context]
  public    : SC_OUT(Taddress_t         )  ** out_EVENT_ADDRESS                      ;//[nb_context]
  public    : SC_OUT(Taddress_t         )  ** out_EVENT_ADDRESS_NEXT                 ;//[nb_context] 
  public    : SC_OUT(Tcontrol_t         )  ** out_EVENT_ADDRESS_NEXT_VAL             ;//[nb_context]
  public    : SC_OUT(Tcontrol_t         )  ** out_EVENT_IS_DS_TAKE                   ;//[nb_context]

    // ~~~~~[ Interface "spr" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public    : SC_OUT(Tcontrol_t         )  ** out_SPR_VAL                            ;//[nb_context]
  public    : SC_IN (Tcontrol_t         )  **  in_SPR_ACK                            ;//[nb_context]
  public    : SC_OUT(Taddress_t         )  ** out_SPR_EPCR                           ;//[nb_context]
  public    : SC_OUT(Taddress_t         )  ** out_SPR_EEAR                           ;//[nb_context]
  public    : SC_OUT(Tcontrol_t         )  ** out_SPR_EEAR_WEN                       ;//[nb_context]
  public    : SC_OUT(Tcontrol_t         )  ** out_SPR_SR_DSX                         ;//[nb_context]
  public    : SC_OUT(Tcontrol_t         )  ** out_SPR_SR_TO_ESR                      ;//[nb_context]

    // ~~~~~[ Interface : "context" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public    : SC_OUT(Tcontrol_t         )  ** out_CONTEXT_DECOD_ENABLE               ;//[nb_context]

    // ~~~~~[ Interface : "depth" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public    : SC_IN (Tdepth_t           )  **  in_DEPTH_TAIL                         ;//[nb_context]
                                                                                     
    // ~~~~~[ Component ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    

    // ~~~~~[ Register ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
  private   : context_state_t               * reg_STATE                              ;//[nb_context]
  private   : Taddress_t                    * reg_EVENT_ADDRESS                      ;//[nb_context]
  private   : Taddress_t                    * reg_EVENT_ADDRESS_EPCR                 ;//[nb_context] 
  private   : Tcontrol_t                    * reg_EVENT_ADDRESS_EPCR_VAL             ;//[nb_context]
  private   : Taddress_t                    * reg_EVENT_ADDRESS_EEAR                 ;//[nb_context] 
  private   : Tcontrol_t                    * reg_EVENT_ADDRESS_EEAR_VAL             ;//[nb_context]
  private   : Tcontrol_t                    * reg_EVENT_IS_DELAY_SLOT                ;//[nb_context]
  private   : Tcontrol_t                    * reg_EVENT_IS_DS_TAKE                   ;//[nb_context]
  private   : Tdepth_t                      * reg_EVENT_DEPTH                        ;//[nb_context]

    // ~~~~~[ Internal ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  private   : Tcontrol_t                    * internal_DECOD_EVENT_ACK               ;//[nb_decod_unit]
  private   : Tcontrol_t                    * internal_COMMIT_EVENT_ACK              ;//[nb_ooo_engine]
  private   : Tcontrol_t                    * internal_BRANCH_COMPLETE_ACK           ;//[nb_inst_branch_complete]
  private   : Tcontrol_t                    * internal_EVENT_VAL                     ;//[nb_context]
  private   : Tcontrol_t                    * internal_SPR_VAL                       ;//[nb_context]
#endif

    // -----[ Methods ]---------------------------------------------------

#ifdef SYSTEMC
    SC_HAS_PROCESS (Context_State);
#endif
  public  :          Context_State              
  (
#ifdef SYSTEMC
   sc_module_name                                name,
#else					       
   std::string                                   name,
#endif					       
#ifdef STATISTICS
   morpheo::behavioural::Parameters_Statistics * param_statistics,
#endif
   Parameters                                  * param,
   morpheo::behavioural::Tusage_t                usage
   );
  public  :          ~Context_State             (void);
					       
  private : void        allocation                (
#ifdef STATISTICS
						   morpheo::behavioural::Parameters_Statistics * param_statistics
#else
						   void
#endif
						   );
  private : void        deallocation              (void);
					       
#ifdef SYSTEMC				       
  public  : void        transition                (void);
  public  : void        genMoore                  (void);
#endif					       

#if VHDL				       
  public  : void        vhdl                      (void);
  private : void        vhdl_declaration          (Vhdl * & vhdl);
  private : void        vhdl_body                 (Vhdl * & vhdl);
#endif					       

#ifdef STATISTICS
  public  : void        statistics_allocation     (morpheo::behavioural::Parameters_Statistics * param_statistics);
  public  : void        statistics_deallocation   (void);
#endif
#if defined(STATISTICS) or defined(VHDL_TESTBENCH)
  private : void        end_cycle                 (void);
#endif
  };

}; // end namespace context_state
}; // end namespace front_end
}; // end namespace multi_front_end
}; // end namespace core

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

#endif
