2008-06-08 14:27:48 +02:00
|
|
|
/*
|
|
|
|
|
* VHDL variable and signal types.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2008 Nick Gasson (nick@nickg.me.uk)
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "vhdl_type.hh"
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vhdl_type *vhdl_type::std_logic()
|
|
|
|
|
{
|
|
|
|
|
return new vhdl_type(VHDL_TYPE_STD_LOGIC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vhdl_type *vhdl_type::string()
|
|
|
|
|
{
|
|
|
|
|
return new vhdl_type(VHDL_TYPE_STRING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vhdl_type *vhdl_type::line()
|
|
|
|
|
{
|
|
|
|
|
return new vhdl_type(VHDL_TYPE_LINE);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-12 11:36:38 +02:00
|
|
|
vhdl_type *vhdl_type::boolean()
|
|
|
|
|
{
|
|
|
|
|
return new vhdl_type(VHDL_TYPE_BOOLEAN);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-09 13:46:55 +02:00
|
|
|
vhdl_type *vhdl_type::integer()
|
|
|
|
|
{
|
|
|
|
|
return new vhdl_type(VHDL_TYPE_INTEGER);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-14 18:09:31 +02:00
|
|
|
vhdl_type *vhdl_type::nunsigned(int width)
|
|
|
|
|
{
|
|
|
|
|
return new vhdl_type(VHDL_TYPE_UNSIGNED, width-1, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vhdl_type *vhdl_type::nsigned(int width)
|
|
|
|
|
{
|
|
|
|
|
return new vhdl_type(VHDL_TYPE_SIGNED, width-1, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-19 13:16:19 +02:00
|
|
|
vhdl_type *vhdl_type::time()
|
|
|
|
|
{
|
|
|
|
|
return new vhdl_type(VHDL_TYPE_TIME);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-14 19:03:25 +02:00
|
|
|
/*
|
|
|
|
|
* This is just the name of the type, without any parameters.
|
|
|
|
|
*/
|
2008-06-08 14:27:48 +02:00
|
|
|
std::string vhdl_type::get_string() const
|
|
|
|
|
{
|
|
|
|
|
switch (name_) {
|
|
|
|
|
case VHDL_TYPE_STD_LOGIC:
|
|
|
|
|
return std::string("std_logic");
|
|
|
|
|
case VHDL_TYPE_STD_LOGIC_VECTOR:
|
2008-06-14 19:03:25 +02:00
|
|
|
return std::string("std_logic_vector");
|
2008-06-08 14:27:48 +02:00
|
|
|
case VHDL_TYPE_STRING:
|
|
|
|
|
return std::string("String");
|
|
|
|
|
case VHDL_TYPE_LINE:
|
|
|
|
|
return std::string("Line");
|
|
|
|
|
case VHDL_TYPE_FILE:
|
|
|
|
|
return std::string("File");
|
2008-06-09 13:46:55 +02:00
|
|
|
case VHDL_TYPE_INTEGER:
|
|
|
|
|
return std::string("Integer");
|
2008-06-12 12:36:21 +02:00
|
|
|
case VHDL_TYPE_BOOLEAN:
|
|
|
|
|
return std::string("Boolean");
|
2008-06-14 19:03:25 +02:00
|
|
|
case VHDL_TYPE_SIGNED:
|
|
|
|
|
return std::string("signed");
|
|
|
|
|
case VHDL_TYPE_UNSIGNED:
|
|
|
|
|
return std::string("unsigned");
|
2008-06-08 14:27:48 +02:00
|
|
|
default:
|
|
|
|
|
return std::string("BadType");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-14 19:03:25 +02:00
|
|
|
/*
|
|
|
|
|
* The is the qualified name of the type.
|
|
|
|
|
*/
|
|
|
|
|
std::string vhdl_type::get_decl_string() const
|
|
|
|
|
{
|
|
|
|
|
switch (name_) {
|
|
|
|
|
case VHDL_TYPE_STD_LOGIC_VECTOR:
|
|
|
|
|
case VHDL_TYPE_UNSIGNED:
|
|
|
|
|
case VHDL_TYPE_SIGNED:
|
|
|
|
|
{
|
|
|
|
|
std::ostringstream ss;
|
|
|
|
|
ss << get_string() << "(" << msb_;
|
|
|
|
|
ss << " downto " << lsb_ << ")";
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return get_string();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-01 11:37:22 +02:00
|
|
|
void vhdl_type::emit(std::ostream &of, int level) const
|
2008-06-08 14:27:48 +02:00
|
|
|
{
|
2008-06-14 19:03:25 +02:00
|
|
|
of << get_decl_string();
|
2008-06-08 14:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vhdl_type *vhdl_type::std_logic_vector(int msb, int lsb)
|
|
|
|
|
{
|
|
|
|
|
return new vhdl_type(VHDL_TYPE_STD_LOGIC_VECTOR, msb, lsb);
|
|
|
|
|
}
|
2008-07-07 22:45:27 +02:00
|
|
|
|
|
|
|
|
vhdl_type *vhdl_type::type_for(int width, bool issigned)
|
|
|
|
|
{
|
|
|
|
|
if (width == 0)
|
|
|
|
|
return vhdl_type::std_logic();
|
|
|
|
|
else if (issigned)
|
|
|
|
|
return vhdl_type::nsigned(width);
|
|
|
|
|
else
|
|
|
|
|
return vhdl_type::nunsigned(width);
|
|
|
|
|
}
|