#ifdef VHDL

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

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

namespace morpheo              {
namespace behavioural          {

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

    std::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"
  std::string std_logic_conv (uint32_t size, std::string value)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");

    std::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;
  };

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

    return _return;
  };

#undef  FUNCTION
#define FUNCTION "Vhdl::std_logic_range"
  std::string std_logic_range (uint32_t size, uint32_t max, uint32_t min)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
    std::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;
  };

  std::string std_logic_range (uint32_t max, uint32_t min)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
    std::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;
  };

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

    return _return;
  }

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

    std::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
