1999-06-17 07:34:42 +02:00
|
|
|
/*
|
2019-09-24 00:17:31 +02:00
|
|
|
* Copyright (c) 1999-2019 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"
|
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
|
|
|
|
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,
|
|
|
|
|
ivl_variable_type_t dt)
|
2008-02-25 04:40:54 +01:00
|
|
|
: name_(n), type_(t), port_type_(pt), data_type_(dt),
|
2008-01-04 20:46:25 +01:00
|
|
|
signed_(false), isint_(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
|
|
|
{
|
2002-06-21 06:59:35 +02:00
|
|
|
if (t == NetNet::INTEGER) {
|
|
|
|
|
type_ = NetNet::REG;
|
|
|
|
|
signed_ = true;
|
|
|
|
|
isint_ = true;
|
|
|
|
|
}
|
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
|
|
|
}
|
2011-01-27 04:33:49 +01:00
|
|
|
if (t == NetNet::INTEGER) {
|
|
|
|
|
type_ = NetNet::REG;
|
|
|
|
|
isint_ = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
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:
|
2002-06-21 06:59:35 +02:00
|
|
|
if (t == NetNet::INTEGER) {
|
|
|
|
|
isint_ = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
1999-06-17 07:34:42 +02:00
|
|
|
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:
|
|
|
|
|
port_type_ = pt;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case NetNet::NOT_A_PORT:
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-04 05:13:56 +01:00
|
|
|
ivl_variable_type_t PWire::get_data_type() const
|
|
|
|
|
{
|
|
|
|
|
return data_type_;
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-11 01:31:43 +01:00
|
|
|
void PWire::set_signed(bool flag)
|
|
|
|
|
{
|
|
|
|
|
signed_ = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PWire::get_signed() const
|
|
|
|
|
{
|
|
|
|
|
return signed_;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-21 06:59:35 +02:00
|
|
|
bool PWire::get_isint() const
|
|
|
|
|
{
|
2013-04-15 03:03:21 +02:00
|
|
|
if (isint_)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (vector_type_t*tmp = dynamic_cast<vector_type_t*>(set_data_type_)) {
|
|
|
|
|
return tmp->integer_flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2002-06-21 06:59:35 +02:00
|
|
|
}
|
|
|
|
|
|
2009-04-15 01:08:27 +02:00
|
|
|
bool PWire::get_scalar() const
|
|
|
|
|
{
|
|
|
|
|
return is_scalar_;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-05 01:19:27 +01:00
|
|
|
void PWire::set_range_scalar(PWSRType type)
|
2007-08-22 04:52:42 +02:00
|
|
|
{
|
2012-02-05 01:19:27 +01:00
|
|
|
is_scalar_ = true;
|
2007-08-22 04:52:42 +02:00
|
|
|
switch (type) {
|
|
|
|
|
case SR_PORT:
|
|
|
|
|
if (port_set_) {
|
2008-02-25 04:40:54 +01:00
|
|
|
cerr << get_fileline() << ": error: Port ``" << name_
|
2007-08-22 04:52:42 +02:00
|
|
|
<< "'' has already been declared a port." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
} else {
|
|
|
|
|
port_set_ = true;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case SR_NET:
|
|
|
|
|
if (net_set_) {
|
2008-02-25 04:40:54 +01:00
|
|
|
cerr << get_fileline() << ": error: Net ``" << name_
|
2007-08-22 04:52:42 +02:00
|
|
|
<< "'' has already been declared." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
} else {
|
|
|
|
|
net_set_ = true;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case SR_BOTH:
|
|
|
|
|
if (port_set_ || net_set_) {
|
|
|
|
|
if (port_set_) {
|
2008-02-25 04:40:54 +01:00
|
|
|
cerr << get_fileline() << ": error: Port ``" << name_
|
2007-08-22 04:52:42 +02:00
|
|
|
<< "'' has already been declared a port." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
}
|
|
|
|
|
if (net_set_) {
|
2008-02-25 04:40:54 +01:00
|
|
|
cerr << get_fileline() << ": error: Net ``" << name_
|
2007-08-22 04:52:42 +02:00
|
|
|
<< "'' has already been declared." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
port_set_ = true;
|
|
|
|
|
net_set_ = true;
|
2012-02-05 01:19:27 +01:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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:
|
|
|
|
|
if (port_set_) {
|
|
|
|
|
cerr << get_fileline() << ": error: Port ``" << name_
|
|
|
|
|
<< "'' has already been declared a port." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
} else {
|
|
|
|
|
port_ = rlist;
|
|
|
|
|
port_set_ = true;
|
|
|
|
|
is_scalar_ = false;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case SR_NET:
|
|
|
|
|
if (net_set_) {
|
|
|
|
|
cerr << get_fileline() << ": error: Net ``" << name_
|
|
|
|
|
<< "'' has already been declared." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
} else {
|
|
|
|
|
net_ = rlist;
|
|
|
|
|
net_set_ = true;
|
|
|
|
|
is_scalar_ = false;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case SR_BOTH:
|
|
|
|
|
if (port_set_ || net_set_) {
|
|
|
|
|
if (port_set_) {
|
|
|
|
|
cerr << get_fileline() << ": error: Port ``" << name_
|
|
|
|
|
<< "'' has already been declared a port." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
}
|
|
|
|
|
if (net_set_) {
|
|
|
|
|
cerr << get_fileline() << ": error: Net ``" << name_
|
|
|
|
|
<< "'' has already been declared." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
port_ = rlist;
|
|
|
|
|
port_set_ = true;
|
|
|
|
|
net_ = rlist;
|
|
|
|
|
net_set_ = true;
|
|
|
|
|
is_scalar_ = false;
|
2007-08-22 04:52:42 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
|
|
|
{
|
2012-08-03 05:14:55 +02:00
|
|
|
assert(set_data_type_ == 0);
|
|
|
|
|
set_data_type_ = type;
|
2013-04-15 03:03:21 +02:00
|
|
|
|
|
|
|
|
if (vector_type_t*tmp = dynamic_cast<vector_type_t*>(type)) {
|
|
|
|
|
if (tmp->integer_flag)
|
|
|
|
|
isint_ = true;
|
|
|
|
|
}
|
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::INTEGER:
|
|
|
|
|
case NetNet::REG:
|
|
|
|
|
return VAR;
|
|
|
|
|
default:
|
|
|
|
|
return NET;
|
|
|
|
|
}
|
|
|
|
|
}
|