1999-06-17 07:34:42 +02:00
|
|
|
/*
|
2007-05-24 06:07:11 +02:00
|
|
|
* Copyright (c) 1999-2007 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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
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"
|
1999-06-17 07:34:42 +02:00
|
|
|
# include <assert.h>
|
|
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
PWire::PWire(const pform_name_t&n,
|
2005-07-07 18:22:49 +02:00
|
|
|
NetNet::Type t,
|
|
|
|
|
NetNet::PortType pt,
|
|
|
|
|
ivl_variable_type_t dt)
|
|
|
|
|
: hname_(n), type_(t), port_type_(pt), data_type_(dt),
|
2007-08-22 04:52:42 +02:00
|
|
|
signed_(false), isint_(false), port_set_(false), net_set_(false),
|
2007-08-22 18:16:34 +02:00
|
|
|
port_msb_(0), port_lsb_(0), net_msb_(0), net_lsb_(0), error_cnt_(0),
|
|
|
|
|
lidx_(0), ridx_(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
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
const pform_name_t& PWire::path() const
|
2001-12-03 05:47:14 +01:00
|
|
|
{
|
|
|
|
|
return hname_;
|
|
|
|
|
}
|
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:
|
|
|
|
|
if (t == NetNet::REG) { type_ = t; return true; }
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (data_type_ != IVL_VT_NO_TYPE)
|
|
|
|
|
if (data_type_ != dt)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
assert(data_type_ == IVL_VT_NO_TYPE);
|
|
|
|
|
data_type_ = dt;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
return isint_;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-24 19:13:25 +02:00
|
|
|
/*
|
|
|
|
|
* Since implicitly defined list of port declarations are no longer
|
|
|
|
|
* considered fully defined we no longer need this routine to force
|
|
|
|
|
* them to be fully defined.
|
|
|
|
|
*
|
2007-08-22 04:52:42 +02:00
|
|
|
void PWire::set_net_range()
|
1999-06-17 07:34:42 +02:00
|
|
|
{
|
2007-08-22 04:52:42 +02:00
|
|
|
net_msb_ = port_msb_;
|
|
|
|
|
net_lsb_ = port_lsb_;
|
|
|
|
|
net_set_ = true;
|
|
|
|
|
}
|
2007-08-24 19:13:25 +02:00
|
|
|
*/
|
2007-08-22 04:52:42 +02:00
|
|
|
|
|
|
|
|
void PWire::set_range(PExpr*m, PExpr*l, PWSRType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case SR_PORT:
|
|
|
|
|
if (port_set_) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: Port ``" << hname_
|
2007-08-22 04:52:42 +02:00
|
|
|
<< "'' has already been declared a port." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
} else {
|
|
|
|
|
port_msb_ = m;
|
|
|
|
|
port_lsb_ = l;
|
|
|
|
|
port_set_ = true;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case SR_NET:
|
|
|
|
|
if (net_set_) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: Net ``" << hname_
|
2007-08-22 04:52:42 +02:00
|
|
|
<< "'' has already been declared." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
} else {
|
|
|
|
|
net_msb_ = m;
|
|
|
|
|
net_lsb_ = l;
|
|
|
|
|
net_set_ = true;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case SR_BOTH:
|
|
|
|
|
if (port_set_ || net_set_) {
|
|
|
|
|
if (port_set_) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: Port ``" << hname_
|
2007-08-22 04:52:42 +02:00
|
|
|
<< "'' has already been declared a port." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
}
|
|
|
|
|
if (net_set_) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: Net ``" << hname_
|
2007-08-22 04:52:42 +02:00
|
|
|
<< "'' has already been declared." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
port_msb_ = m;
|
|
|
|
|
port_lsb_ = l;
|
|
|
|
|
port_set_ = true;
|
|
|
|
|
net_msb_ = m;
|
|
|
|
|
net_lsb_ = l;
|
|
|
|
|
net_set_ = true;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
1999-06-17 07:34:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PWire::set_memory_idx(PExpr*ldx, PExpr*rdx)
|
|
|
|
|
{
|
2007-11-08 04:48:47 +01:00
|
|
|
if (lidx_ != 0 || ridx_ != 0) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: Array ``" << hname_
|
2007-11-08 04:48:47 +01:00
|
|
|
<< "'' has already been declared." << endl;
|
|
|
|
|
error_cnt_ += 1;
|
|
|
|
|
} else {
|
|
|
|
|
lidx_ = ldx;
|
|
|
|
|
ridx_ = rdx;
|
|
|
|
|
}
|
1999-06-17 07:34:42 +02:00
|
|
|
}
|
|
|
|
|
|