1999-06-17 07:34:42 +02:00
|
|
|
/*
|
2021-09-11 00:09:03 +02:00
|
|
|
* Copyright (c) 1999-2021 Stephen Williams (steve@icarus.com)
|
1999-06-17 07:34:42 +02:00
|
|
|
*
|
|
|
|
|
* 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.
|
1999-06-17 07:34:42 +02:00
|
|
|
*/
|
|
|
|
|
|
2001-07-25 05:10:48 +02:00
|
|
|
# include "config.h"
|
2022-03-13 09:50:52 +01:00
|
|
|
# include "ivl_assert.h"
|
1999-06-17 07:34:42 +02:00
|
|
|
# include "PWire.h"
|
2007-08-22 04:52:42 +02:00
|
|
|
# include "PExpr.h"
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cassert>
|
1999-06-17 07:34:42 +02:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
2008-02-25 04:40:54 +01:00
|
|
|
PWire::PWire(perm_string n,
|
2005-07-07 18:22:49 +02:00
|
|
|
NetNet::Type t,
|
|
|
|
|
NetNet::PortType pt,
|
2022-03-13 09:50:52 +01:00
|
|
|
ivl_variable_type_t dt,
|
|
|
|
|
PWSRType rt)
|
2008-02-25 04:40:54 +01:00
|
|
|
: name_(n), type_(t), port_type_(pt), data_type_(dt),
|
2022-03-12 21:10:19 +01:00
|
|
|
signed_(false),
|
2012-02-05 01:19:27 +01:00
|
|
|
port_set_(false), net_set_(false), is_scalar_(false),
|
2019-12-22 12:03:50 +01:00
|
|
|
error_cnt_(0), uarray_type_(0), set_data_type_(0),
|
2011-12-04 02:16:01 +01:00
|
|
|
discipline_(0)
|
1999-06-17 07:34:42 +02:00
|
|
|
{
|
2022-03-13 09:50:52 +01:00
|
|
|
switch (rt) {
|
|
|
|
|
case SR_PORT:
|
|
|
|
|
port_set_ = true;
|
|
|
|
|
break;
|
|
|
|
|
case SR_NET:
|
|
|
|
|
net_set_ = true;
|
|
|
|
|
break;
|
|
|
|
|
case SR_BOTH:
|
|
|
|
|
port_set_ = true;
|
|
|
|
|
net_set_ = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-06-17 07:34:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetNet::Type PWire::get_wire_type() const
|
|
|
|
|
{
|
|
|
|
|
return type_;
|
|
|
|
|
}
|
2002-01-26 06:28:28 +01:00
|
|
|
|
2008-02-25 04:40:54 +01:00
|
|
|
perm_string PWire::basename() const
|
2001-12-03 05:47:14 +01:00
|
|
|
{
|
2008-02-25 04:40:54 +01:00
|
|
|
return name_;
|
2001-12-03 05:47:14 +01:00
|
|
|
}
|
1999-06-17 07:34:42 +02:00
|
|
|
|
|
|
|
|
bool PWire::set_wire_type(NetNet::Type t)
|
|
|
|
|
{
|
|
|
|
|
assert(t != NetNet::IMPLICIT);
|
|
|
|
|
|
|
|
|
|
switch (type_) {
|
|
|
|
|
case NetNet::IMPLICIT:
|
|
|
|
|
type_ = t;
|
|
|
|
|
return true;
|
1999-09-10 07:02:09 +02:00
|
|
|
case NetNet::IMPLICIT_REG:
|
2011-01-27 04:33:49 +01:00
|
|
|
if (t == NetNet::REG) {
|
|
|
|
|
type_ = t;
|
|
|
|
|
return true;
|
2011-01-28 18:47:16 +01:00
|
|
|
}
|
2019-09-16 21:35:27 +02:00
|
|
|
if (t == NetNet::IMPLICIT_REG) return true;
|
1999-09-10 07:02:09 +02:00
|
|
|
return false;
|
1999-06-17 07:34:42 +02:00
|
|
|
case NetNet::REG:
|
|
|
|
|
if (t == NetNet::REG) return true;
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
if (type_ != t)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetNet::PortType PWire::get_port_type() const
|
|
|
|
|
{
|
|
|
|
|
return port_type_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PWire::set_port_type(NetNet::PortType pt)
|
|
|
|
|
{
|
|
|
|
|
assert(pt != NetNet::NOT_A_PORT);
|
|
|
|
|
assert(pt != NetNet::PIMPLICIT);
|
|
|
|
|
|
|
|
|
|
switch (port_type_) {
|
|
|
|
|
case NetNet::PIMPLICIT:
|
2022-03-11 22:15:05 +01:00
|
|
|
case NetNet::NOT_A_PORT:
|
1999-06-17 07:34:42 +02:00
|
|
|
port_type_ = pt;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (port_type_ != pt)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-07 18:22:49 +02:00
|
|
|
bool PWire::set_data_type(ivl_variable_type_t dt)
|
|
|
|
|
{
|
2008-01-05 04:21:26 +01:00
|
|
|
if (data_type_ != IVL_VT_NO_TYPE) {
|
2005-07-07 18:22:49 +02:00
|
|
|
if (data_type_ != dt)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
2008-01-05 04:21:26 +01:00
|
|
|
}
|
2005-07-07 18:22:49 +02:00
|
|
|
|
|
|
|
|
assert(data_type_ == IVL_VT_NO_TYPE);
|
|
|
|
|
data_type_ = dt;
|
2013-04-15 03:03:21 +02:00
|
|
|
|
2005-07-07 18:22:49 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-11 01:31:43 +01:00
|
|
|
void PWire::set_signed(bool flag)
|
|
|
|
|
{
|
2021-09-11 00:09:03 +02:00
|
|
|
// For a non-ANSI style port declaration where the data type is
|
|
|
|
|
// specified in a corresponding variable declaration, the signed
|
|
|
|
|
// attribute may be attached to either the port declaration or to
|
|
|
|
|
// the variable declaration (IEEE 1364-2005 section 12.3.3). The
|
|
|
|
|
// signal is signed if either the port or the variable is signed.
|
|
|
|
|
// Handle that here.
|
|
|
|
|
signed_ = signed_ || flag;
|
2000-12-11 01:31:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PWire::get_signed() const
|
|
|
|
|
{
|
|
|
|
|
return signed_;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-13 09:50:52 +01:00
|
|
|
void PWire::set_port(NetNet::PortType pt)
|
2007-08-22 04:52:42 +02:00
|
|
|
{
|
2022-03-13 09:50:52 +01:00
|
|
|
ivl_assert(*this, !port_set_);
|
|
|
|
|
port_set_ = true;
|
2007-08-22 04:52:42 +02:00
|
|
|
|
2022-03-13 09:50:52 +01:00
|
|
|
bool rc = set_port_type(pt);
|
|
|
|
|
ivl_assert(*this, rc);
|
|
|
|
|
}
|
2007-08-22 04:52:42 +02:00
|
|
|
|
2022-03-13 09:50:52 +01:00
|
|
|
void PWire::set_net(NetNet::Type t)
|
|
|
|
|
{
|
|
|
|
|
ivl_assert(*this, !net_set_);
|
|
|
|
|
net_set_ = true;
|
|
|
|
|
|
|
|
|
|
if (t != NetNet::IMPLICIT) {
|
|
|
|
|
bool rc = set_wire_type(t);
|
|
|
|
|
ivl_assert(*this, rc);
|
2012-02-05 01:19:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-10 23:29:28 +02:00
|
|
|
void PWire::set_range(const list<pform_range_t>&rlist, PWSRType type)
|
2012-02-05 01:19:27 +01:00
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case SR_PORT:
|
2022-03-13 09:50:52 +01:00
|
|
|
if (!port_.empty())
|
|
|
|
|
return;
|
|
|
|
|
port_ = rlist;
|
|
|
|
|
break;
|
2012-02-05 01:19:27 +01:00
|
|
|
case SR_NET:
|
2022-03-13 09:50:52 +01:00
|
|
|
if (!net_.empty())
|
|
|
|
|
return;
|
|
|
|
|
net_ = rlist;
|
|
|
|
|
break;
|
2012-02-05 01:19:27 +01:00
|
|
|
case SR_BOTH:
|
2022-03-13 09:50:52 +01:00
|
|
|
if (!port_.empty() || !net_.empty())
|
|
|
|
|
return;
|
|
|
|
|
port_ = rlist;
|
|
|
|
|
net_ = rlist;
|
|
|
|
|
break;
|
2007-08-22 04:52:42 +02:00
|
|
|
}
|
1999-06-17 07:34:42 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-26 00:58:29 +02:00
|
|
|
void PWire::set_unpacked_idx(const list<pform_range_t>&ranges)
|
1999-06-17 07:34:42 +02:00
|
|
|
{
|
2012-05-26 00:58:29 +02:00
|
|
|
if (! unpacked_.empty()) {
|
2008-02-25 04:40:54 +01:00
|
|
|
cerr << get_fileline() << ": error: Array ``" << name_
|
2007-11-08 04:48:47 +01:00
|
|
|
<< "'' has already been declared." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
} else {
|
2012-05-26 00:58:29 +02:00
|
|
|
unpacked_ = ranges;
|
2007-11-08 04:48:47 +01:00
|
|
|
}
|
1999-06-17 07:34:42 +02:00
|
|
|
}
|
|
|
|
|
|
2012-11-12 02:42:31 +01:00
|
|
|
void PWire::set_data_type(data_type_t*type)
|
2010-10-31 19:26:09 +01:00
|
|
|
{
|
2021-11-07 18:41:11 +01:00
|
|
|
assert(set_data_type_ == 0 || set_data_type_ == type);
|
2012-08-03 05:14:55 +02:00
|
|
|
set_data_type_ = type;
|
2011-12-04 02:16:01 +01:00
|
|
|
}
|
|
|
|
|
|
2008-11-02 17:10:41 +01:00
|
|
|
void PWire::set_discipline(ivl_discipline_t d)
|
2008-05-12 02:30:33 +02:00
|
|
|
{
|
|
|
|
|
assert(discipline_ == 0);
|
|
|
|
|
discipline_ = d;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-02 17:10:41 +01:00
|
|
|
ivl_discipline_t PWire::get_discipline(void) const
|
2008-05-12 02:30:33 +02:00
|
|
|
{
|
|
|
|
|
return discipline_;
|
|
|
|
|
}
|
2019-09-24 00:17:31 +02:00
|
|
|
|
|
|
|
|
PNamedItem::SymbolType PWire::symbol_type() const
|
|
|
|
|
{
|
|
|
|
|
switch (type_) {
|
|
|
|
|
case NetNet::IMPLICIT_REG:
|
|
|
|
|
case NetNet::REG:
|
|
|
|
|
return VAR;
|
|
|
|
|
default:
|
|
|
|
|
return NET;
|
|
|
|
|
}
|
|
|
|
|
}
|