2011-07-20 04:19:27 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form 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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-07-20 04:19:27 +02:00
|
|
|
*/
|
|
|
|
|
|
2013-06-06 06:10:33 +02:00
|
|
|
# define __STDC_LIMIT_MACROS
|
2011-07-20 04:19:27 +02:00
|
|
|
# include "vtype.h"
|
2011-10-16 21:18:34 +02:00
|
|
|
# include "expression.h"
|
2011-07-20 04:19:27 +02:00
|
|
|
# include <typeinfo>
|
2013-06-06 06:10:33 +02:00
|
|
|
# include <stdint.h>
|
2011-07-20 04:19:27 +02:00
|
|
|
# include <cassert>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
void VType::write_to_stream(ostream&fd) const
|
|
|
|
|
{
|
|
|
|
|
fd << "/* UNKNOWN TYPE: " << typeid(*this).name() << " */";
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 00:15:45 +02:00
|
|
|
void VType::write_type_to_stream(ostream&fd) const
|
|
|
|
|
{
|
|
|
|
|
write_to_stream(fd);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-20 04:19:27 +02:00
|
|
|
void VTypeArray::write_to_stream(ostream&fd) const
|
|
|
|
|
{
|
2011-07-23 19:44:36 +02:00
|
|
|
// Special case: std_logic_vector
|
2011-07-24 20:06:22 +02:00
|
|
|
if (etype_ == primitive_STDLOGIC) {
|
2011-07-23 19:44:36 +02:00
|
|
|
fd << "std_logic_vector";
|
2012-03-18 20:49:19 +01:00
|
|
|
if (! ranges_.empty() && ! ranges_[0].is_box()) {
|
2011-07-23 19:44:36 +02:00
|
|
|
assert(ranges_.size() < 2);
|
2011-10-16 21:18:34 +02:00
|
|
|
fd << " (";
|
2012-03-18 19:21:23 +01:00
|
|
|
if (ranges_[0].msb())
|
|
|
|
|
ranges_[0].msb()->write_to_stream(fd);
|
|
|
|
|
else
|
|
|
|
|
fd << "<>";
|
2011-10-16 21:18:34 +02:00
|
|
|
fd << " downto ";
|
2012-03-18 19:21:23 +01:00
|
|
|
if (ranges_[0].lsb())
|
|
|
|
|
ranges_[0].lsb()->write_to_stream(fd);
|
|
|
|
|
else
|
|
|
|
|
fd << "<>";
|
2011-10-16 21:18:34 +02:00
|
|
|
fd << ") ";
|
2011-07-23 19:44:36 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-20 04:19:27 +02:00
|
|
|
fd << "array ";
|
2011-07-29 02:07:49 +02:00
|
|
|
if (! ranges_.empty()) {
|
2011-07-20 04:19:27 +02:00
|
|
|
assert(ranges_.size() < 2);
|
2012-03-18 19:21:23 +01:00
|
|
|
if (ranges_[0].is_box()) {
|
|
|
|
|
fd << "(INTEGER range <>) ";
|
|
|
|
|
} else {
|
|
|
|
|
assert(ranges_[0].msb() && ranges_[0].lsb());
|
|
|
|
|
fd << "(";
|
|
|
|
|
if (ranges_[0].msb())
|
|
|
|
|
ranges_[0].msb()->write_to_stream(fd);
|
|
|
|
|
else
|
|
|
|
|
fd << "<>";
|
|
|
|
|
fd << " downto ";
|
|
|
|
|
if (ranges_[0].lsb())
|
|
|
|
|
ranges_[0].lsb()->write_to_stream(fd);
|
|
|
|
|
else
|
|
|
|
|
fd << "<>";
|
|
|
|
|
fd << ") ";
|
|
|
|
|
}
|
2011-07-20 04:19:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fd << "of ";
|
|
|
|
|
etype_->write_to_stream(fd);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 00:15:45 +02:00
|
|
|
void VTypeDef::write_type_to_stream(ostream&fd) const
|
|
|
|
|
{
|
|
|
|
|
type_->write_to_stream(fd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VTypeDef::write_to_stream(ostream&fd) const
|
|
|
|
|
{
|
|
|
|
|
fd << name_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-20 04:19:27 +02:00
|
|
|
void VTypePrimitive::write_to_stream(ostream&fd) const
|
|
|
|
|
{
|
|
|
|
|
switch (type_) {
|
2011-07-25 01:16:01 +02:00
|
|
|
case BIT:
|
|
|
|
|
fd << "bit";
|
|
|
|
|
break;
|
2011-07-20 04:19:27 +02:00
|
|
|
case INTEGER:
|
|
|
|
|
fd << "integer";
|
|
|
|
|
break;
|
|
|
|
|
case STDLOGIC:
|
|
|
|
|
fd << "std_logic";
|
|
|
|
|
break;
|
2012-03-18 19:21:23 +01:00
|
|
|
case BOOLEAN:
|
|
|
|
|
fd << "boolean";
|
|
|
|
|
break;
|
2011-07-20 04:19:27 +02:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
fd << "/* PRIMITIVE: " << type_ << " */";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-18 19:21:23 +01:00
|
|
|
|
|
|
|
|
void VTypeRange::write_to_stream(ostream&fd) const
|
|
|
|
|
{
|
2013-06-06 06:10:33 +02:00
|
|
|
// Detect some special cases that can be written as ieee or
|
|
|
|
|
// standard types.
|
|
|
|
|
if (const VTypePrimitive*tmp = dynamic_cast<const VTypePrimitive*> (base_)) {
|
|
|
|
|
if (min_==0 && max_==INT64_MAX && tmp->type()==VTypePrimitive::INTEGER) {
|
|
|
|
|
fd << "natural";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 00:15:45 +02:00
|
|
|
base_->write_to_stream(fd);
|
|
|
|
|
fd << " range " << min_ << " to " << max_;
|
2012-03-18 19:21:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VTypeRecord::write_to_stream(ostream&fd) const
|
|
|
|
|
{
|
|
|
|
|
fd << "record ";
|
|
|
|
|
for (size_t idx = 0 ; idx < elements_.size() ; idx += 1) {
|
|
|
|
|
elements_[idx]->write_to_stream(fd);
|
|
|
|
|
fd << "; ";
|
|
|
|
|
}
|
2012-05-06 00:15:45 +02:00
|
|
|
fd << "end record";
|
2012-03-18 19:21:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VTypeRecord::element_t::write_to_stream(ostream&fd) const
|
|
|
|
|
{
|
2012-05-06 00:15:45 +02:00
|
|
|
fd << name_ << ": ";
|
2012-03-18 19:21:23 +01:00
|
|
|
type_->write_to_stream(fd);
|
|
|
|
|
}
|