Files
iverilog/PWire.cc
T

211 lines
4.6 KiB
C++
Raw Normal View History

1999-06-17 05:34:42 +00:00
/*
* Copyright (c) 1999-2024 Stephen Williams ([email protected])
1999-06-17 05:34:42 +00: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-28 18:41:23 -07:00
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1999-06-17 05:34:42 +00:00
*/
# include "config.h"
2022-03-13 09:50:52 +01:00
# include "ivl_assert.h"
1999-06-17 05:34:42 +00:00
# include "PWire.h"
# include "PExpr.h"
1999-06-17 05:34:42 +00:00
using namespace std;
2008-02-24 19:40:54 -08:00
PWire::PWire(perm_string n,
unsigned lp,
2005-07-07 16:22:49 +00:00
NetNet::Type t,
NetNet::PortType pt,
2022-03-13 09:50:52 +01:00
PWSRType rt)
2026-07-26 12:56:45 -07:00
: name_(n), type_(t), port_type_(pt), signed_(false),
port_set_(false), net_set_(false), is_scalar_(false),
error_cnt_(0), discipline_(0)
1999-06-17 05:34:42 +00:00
{
2026-07-26 12:56:45 -07:00
lexical_pos(lp);
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 05:34:42 +00:00
}
NetNet::Type PWire::get_wire_type() const
{
return type_;
}
2002-01-26 05:28:28 +00:00
2008-02-24 19:40:54 -08:00
perm_string PWire::basename() const
{
2008-02-24 19:40:54 -08:00
return name_;
}
1999-06-17 05:34:42 +00:00
bool PWire::set_wire_type(NetNet::Type t)
{
ivl_assert(*this, t != NetNet::IMPLICIT);
1999-06-17 05:34:42 +00:00
switch (type_) {
case NetNet::IMPLICIT:
type_ = t;
return true;
1999-09-10 05:02:09 +00:00
case NetNet::IMPLICIT_REG:
if (t == NetNet::REG) {
type_ = t;
return true;
}
if (t == NetNet::IMPLICIT_REG) return true;
1999-09-10 05:02:09 +00:00
return false;
1999-06-17 05:34:42 +00: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)
{
ivl_assert(*this, pt != NetNet::NOT_A_PORT);
ivl_assert(*this, pt != NetNet::PIMPLICIT);
1999-06-17 05:34:42 +00:00
switch (port_type_) {
case NetNet::PIMPLICIT:
case NetNet::NOT_A_PORT:
1999-06-17 05:34:42 +00:00
port_type_ = pt;
return true;
default:
if (port_type_ != pt)
return false;
else
return true;
}
}
2000-12-11 00:31:43 +00:00
void PWire::set_signed(bool flag)
{
// 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 00:31:43 +00:00
}
bool PWire::get_signed() const
{
return signed_;
}
2022-03-13 09:50:52 +01:00
void PWire::set_port(NetNet::PortType pt)
{
2022-03-13 09:50:52 +01:00
ivl_assert(*this, !port_set_);
port_set_ = true;
2022-03-13 09:50:52 +01:00
bool rc = set_port_type(pt);
ivl_assert(*this, rc);
}
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-04-10 14:29:28 -07:00
void PWire::set_range(const list<pform_range_t>&rlist, PWSRType type)
{
switch (type) {
case SR_PORT:
2022-03-13 09:50:52 +01:00
if (!port_.empty())
return;
port_ = rlist;
break;
case SR_NET:
2022-03-13 09:50:52 +01:00
if (!net_.empty())
return;
net_ = rlist;
break;
case SR_BOTH:
2022-03-13 09:50:52 +01:00
if (!port_.empty() || !net_.empty())
return;
port_ = rlist;
net_ = rlist;
break;
}
1999-06-17 05:34:42 +00:00
}
2012-05-25 15:58:29 -07:00
void PWire::set_unpacked_idx(const list<pform_range_t>&ranges)
1999-06-17 05:34:42 +00:00
{
2012-05-25 15:58:29 -07:00
if (! unpacked_.empty()) {
2008-02-24 19:40:54 -08:00
cerr << get_fileline() << ": error: Array ``" << name_
<< "'' has already been declared." << endl;
error_cnt_ += 1;
} else {
2012-05-25 15:58:29 -07:00
unpacked_ = ranges;
}
1999-06-17 05:34:42 +00:00
}
2012-11-11 17:42:31 -08:00
void PWire::set_data_type(data_type_t*type)
2010-10-31 11:26:09 -07:00
{
if (set_data_type_.get() == type)
return;
ivl_assert(*this, !set_data_type_.get());
set_data_type_.reset(type);
2011-12-03 17:16:01 -08:00
}
void PWire::set_discipline(ivl_discipline_t d)
2008-05-11 17:30:33 -07:00
{
ivl_assert(*this, discipline_ == 0);
2008-05-11 17:30:33 -07:00
discipline_ = d;
}
ivl_discipline_t PWire::get_discipline(void) const
2008-05-11 17:30:33 -07:00
{
return discipline_;
}
PNamedItem::SymbolType PWire::symbol_type() const
{
switch (type_) {
case NetNet::IMPLICIT_REG:
case NetNet::REG:
return VAR;
default:
return NET;
}
}