#ifdef VHDL

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

#include <math.h>
#include "Behavioural/include/Vhdl.h"

namespace morpheo              {
namespace behavioural          {

#undef  FUNCTION
#define FUNCTION "Vhdl::std_logic"
  string std_logic (uint32_t size)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");

    string type;

    if (size == 1)
      type = "std_logic";
    else
      type = "std_logic_vector(" + toString(size-1) + " downto 0)";

    log_printf(FUNC,Behavioural,FUNCTION,"End");

    return type;
  };

#undef  FUNCTION
#define FUNCTION "Vhdl::std_logic_conv"
  string std_logic_conv (uint32_t size, string value)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");

    string conv;

    if (size == 1)
      conv = "'"+toString(value)+"'";
    else
      conv = "conv_std_logic_vector("+value+","+toString(size)+")";

    log_printf(FUNC,Behavioural,FUNCTION,"End");

    return conv;
  };

  string std_logic_conv (uint32_t size, uint32_t value)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
    cout << toString(value) << endl;
    string _return = std_logic_conv(size,toString(value));
    log_printf(FUNC,Behavioural,FUNCTION,"End");

    return _return;
  };

#undef  FUNCTION
#define FUNCTION "Vhdl::std_logic_range"
  string std_logic_range (uint32_t size, uint32_t max, uint32_t min)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
    string type;

    if (size < 2)
      type = "";
    else
      if (max == min)
	type = "("+toString(max)+")";
      else
	type = "("+toString(max)+" downto "+toString(min)+")";

    log_printf(FUNC,Behavioural,FUNCTION,"End");

    return type;
  };

  string std_logic_range (uint32_t max, uint32_t min)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
    string type;

    if (max == 0)
      type = "";
    else
      if (max == min)
	type = "("+toString(max)+")";
      else
	type = "("+toString(max)+" downto "+toString(min)+")";

    log_printf(FUNC,Behavioural,FUNCTION,"End");

    return type;
  };

  string std_logic_range (uint32_t size)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
    string _return = std_logic_range(size-1,0);
    log_printf(FUNC,Behavioural,FUNCTION,"End");

    return _return;
  }

#undef  FUNCTION
#define FUNCTION "Vhdl::std_logic_others"
  string std_logic_others (uint32_t size, uint32_t cst  )
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");

    string _return;

    if (size < 2)
      _return = "'"+toString(cst)+"'";
    else
      _return = "(others => '"+toString(cst)+"')";

    log_printf(FUNC,Behavioural,FUNCTION,"End");

    return _return;
  }



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

#endif
