2000-09-02 22:54:20 +02:00
|
|
|
/*
|
2011-06-23 19:36:26 +02:00
|
|
|
* Copyright (c) 2000-2011 Stephen Williams (steve@icarus.com)
|
2000-09-02 22:54:20 +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.
|
2000-09-02 22:54:20 +02:00
|
|
|
*/
|
|
|
|
|
|
2001-07-25 05:10:48 +02:00
|
|
|
# include "config.h"
|
|
|
|
|
|
2000-09-02 22:54:20 +02:00
|
|
|
# include "netlist.h"
|
2012-11-22 20:08:13 +01:00
|
|
|
# include "netclass.h"
|
2012-07-21 17:59:29 +02:00
|
|
|
# include "netdarray.h"
|
2013-11-17 01:27:05 +01:00
|
|
|
# include "netenum.h"
|
2012-11-25 19:13:05 +01:00
|
|
|
# include "ivl_assert.h"
|
2000-09-02 22:54:20 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NetAssign
|
|
|
|
|
*/
|
|
|
|
|
|
2000-09-20 04:53:14 +02:00
|
|
|
unsigned count_lval_width(const NetAssign_*idx)
|
|
|
|
|
{
|
|
|
|
|
unsigned wid = 0;
|
|
|
|
|
while (idx) {
|
|
|
|
|
wid += idx->lwidth();
|
|
|
|
|
idx = idx->more;
|
|
|
|
|
}
|
|
|
|
|
return wid;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-17 01:27:05 +01:00
|
|
|
NetAssign_::NetAssign_(NetAssign_*n)
|
|
|
|
|
: nest_(n), sig_(0), word_(0), base_(0), sel_type_(IVL_SEL_OTHER)
|
|
|
|
|
{
|
|
|
|
|
more = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-26 01:50:02 +02:00
|
|
|
NetAssign_::NetAssign_(NetNet*s)
|
2013-11-17 01:27:05 +01:00
|
|
|
: nest_(0), sig_(s), word_(0), base_(0), sel_type_(IVL_SEL_OTHER)
|
2000-09-02 22:54:20 +02:00
|
|
|
{
|
2004-12-11 03:31:25 +01:00
|
|
|
lwid_ = sig_->vector_width();
|
2002-05-26 03:39:02 +02:00
|
|
|
sig_->incr_lref();
|
2000-09-10 04:18:16 +02:00
|
|
|
more = 0;
|
2010-07-24 00:58:00 +02:00
|
|
|
turn_sig_to_wire_on_release_ = false;
|
2000-09-02 22:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetAssign_::~NetAssign_()
|
|
|
|
|
{
|
2002-07-02 05:02:57 +02:00
|
|
|
if (sig_) {
|
|
|
|
|
sig_->decr_lref();
|
2004-08-28 17:08:31 +02:00
|
|
|
if (turn_sig_to_wire_on_release_ && sig_->peek_lref() == 0)
|
2002-07-02 05:02:57 +02:00
|
|
|
sig_->type(NetNet::WIRE);
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-10 04:18:16 +02:00
|
|
|
assert( more == 0 );
|
2010-04-14 06:29:15 +02:00
|
|
|
delete word_;
|
2000-09-02 22:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-17 01:27:05 +01:00
|
|
|
string NetAssign_::get_fileline() const
|
|
|
|
|
{
|
|
|
|
|
if (sig_) return sig_->get_fileline();
|
|
|
|
|
else return nest_->get_fileline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetScope*NetAssign_::scope() const
|
|
|
|
|
{
|
|
|
|
|
if (sig_) return sig_->scope();
|
|
|
|
|
else return nest_->scope();
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-16 06:44:14 +01:00
|
|
|
void NetAssign_::set_word(NetExpr*r)
|
2000-09-02 22:54:20 +02:00
|
|
|
{
|
2007-01-16 06:44:14 +01:00
|
|
|
assert(word_ == 0);
|
|
|
|
|
word_ = r;
|
2000-09-02 22:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
2007-01-16 06:44:14 +01:00
|
|
|
NetExpr* NetAssign_::word()
|
2002-06-09 01:42:46 +02:00
|
|
|
{
|
2007-01-16 06:44:14 +01:00
|
|
|
return word_;
|
2002-06-09 01:42:46 +02:00
|
|
|
}
|
|
|
|
|
|
2007-01-16 06:44:14 +01:00
|
|
|
const NetExpr* NetAssign_::word() const
|
2000-09-02 22:54:20 +02:00
|
|
|
{
|
2007-01-16 06:44:14 +01:00
|
|
|
return word_;
|
2000-09-02 22:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
2006-02-02 03:43:57 +01:00
|
|
|
const NetExpr* NetAssign_::get_base() const
|
|
|
|
|
{
|
|
|
|
|
return base_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-23 18:15:36 +01:00
|
|
|
ivl_select_type_t NetAssign_::select_type() const
|
|
|
|
|
{
|
|
|
|
|
return sel_type_;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-07 02:06:53 +02:00
|
|
|
unsigned NetAssign_::lwidth() const
|
|
|
|
|
{
|
2013-11-17 01:27:05 +01:00
|
|
|
// This gets me the type of the l-value expression, down to
|
|
|
|
|
// the type of the member. If this returns nil, then resort to
|
|
|
|
|
// the lwid_ value.
|
|
|
|
|
ivl_type_t ntype = net_type();
|
|
|
|
|
if (ntype == 0)
|
|
|
|
|
return lwid_;
|
|
|
|
|
|
|
|
|
|
// If the type is a darray, and there is a word index, then we
|
|
|
|
|
// actually want the width of the elements.
|
|
|
|
|
if (const netdarray_t*darray = dynamic_cast<const netdarray_t*> (ntype)) {
|
2012-07-21 17:59:29 +02:00
|
|
|
if (word_ == 0)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
2012-09-30 19:34:09 +02:00
|
|
|
return darray->element_width();
|
2012-07-21 17:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-17 01:27:05 +01:00
|
|
|
return ntype->packed_width();
|
2001-08-26 01:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
2008-09-23 06:09:06 +02:00
|
|
|
ivl_variable_type_t NetAssign_::expr_type() const
|
|
|
|
|
{
|
2013-11-17 01:27:05 +01:00
|
|
|
ivl_type_t ntype = net_type();
|
|
|
|
|
if (const netdarray_t*darray = dynamic_cast<const netdarray_t*>(ntype)) {
|
2012-07-21 17:59:29 +02:00
|
|
|
if (word_ == 0)
|
|
|
|
|
return IVL_VT_DARRAY;
|
|
|
|
|
else
|
2012-09-23 18:28:49 +02:00
|
|
|
return darray->element_base_type();
|
2012-07-21 17:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
2014-03-02 01:49:15 +01:00
|
|
|
if (sig_ && sig_->data_type()==IVL_VT_STRING && base_!=0)
|
2014-02-01 04:01:28 +01:00
|
|
|
return IVL_VT_BOOL;
|
|
|
|
|
|
2013-11-17 01:27:05 +01:00
|
|
|
if (ntype) return ntype->base_type();
|
|
|
|
|
|
|
|
|
|
ivl_assert(*this, sig_);
|
2008-09-23 06:09:06 +02:00
|
|
|
return sig_->data_type();
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-22 20:08:13 +01:00
|
|
|
const ivl_type_s* NetAssign_::net_type() const
|
|
|
|
|
{
|
2013-11-17 01:27:05 +01:00
|
|
|
if (nest_) {
|
|
|
|
|
const ivl_type_s*ntype = nest_->net_type();
|
|
|
|
|
if (member_.nil())
|
|
|
|
|
return ntype;
|
|
|
|
|
|
|
|
|
|
if (const netclass_t*class_type = dynamic_cast<const netclass_t*>(ntype)) {
|
|
|
|
|
int pidx = class_type->property_idx_from_name(member_);
|
|
|
|
|
ivl_assert(*this, pidx >= 0);
|
|
|
|
|
ivl_type_t tmp = class_type->get_prop_type(pidx);
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (const netdarray_t*darray = dynamic_cast<const netdarray_t*> (ntype)) {
|
|
|
|
|
if (word_ == 0)
|
|
|
|
|
return ntype;
|
|
|
|
|
else
|
|
|
|
|
return darray->element_type();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-25 19:13:05 +01:00
|
|
|
if (const netclass_t*class_type = sig_->class_type()) {
|
|
|
|
|
if (member_.nil())
|
|
|
|
|
return sig_->net_type();
|
|
|
|
|
|
2013-06-26 15:16:24 +02:00
|
|
|
int pidx = class_type->property_idx_from_name(member_);
|
|
|
|
|
ivl_assert(*sig_, pidx >= 0);
|
|
|
|
|
ivl_type_t tmp = class_type->get_prop_type(pidx);
|
2012-11-25 19:13:05 +01:00
|
|
|
return tmp;
|
|
|
|
|
}
|
2012-11-22 20:08:13 +01:00
|
|
|
|
2013-11-17 01:27:05 +01:00
|
|
|
if (const netdarray_t*darray = dynamic_cast<const netdarray_t*> (sig_->net_type())) {
|
2012-11-22 20:08:13 +01:00
|
|
|
if (word_ == 0)
|
|
|
|
|
return sig_->net_type();
|
2013-11-17 01:27:05 +01:00
|
|
|
else
|
|
|
|
|
return darray->element_type();
|
2012-11-22 20:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 03:03:21 +02:00
|
|
|
const netenum_t*NetAssign_::enumeration() const
|
2010-11-03 04:16:42 +01:00
|
|
|
{
|
2013-04-15 03:03:21 +02:00
|
|
|
const netenum_t*tmp = 0;
|
2013-11-17 01:27:05 +01:00
|
|
|
ivl_type_t ntype = net_type();
|
|
|
|
|
if (ntype == 0) {
|
2010-11-03 04:16:42 +01:00
|
|
|
|
2013-11-17 01:27:05 +01:00
|
|
|
ivl_assert(*this, sig_);
|
|
|
|
|
|
|
|
|
|
// If the base signal is not an enumeration, return nil.
|
|
|
|
|
if ( (tmp = sig_->enumeration()) == 0 )
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
tmp = dynamic_cast<const netenum_t*>(ntype);
|
|
|
|
|
if (tmp == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-11-03 04:16:42 +01:00
|
|
|
|
|
|
|
|
// Part select of an enumeration is not an enumeration.
|
|
|
|
|
if (base_ != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
// Concatenation of enumerations is not an enumeration.
|
|
|
|
|
if (more != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-18 18:11:54 +01:00
|
|
|
perm_string NetAssign_::name() const
|
2001-08-26 01:50:02 +02:00
|
|
|
{
|
|
|
|
|
if (sig_) {
|
|
|
|
|
return sig_->name();
|
|
|
|
|
} else {
|
2004-02-18 18:11:54 +01:00
|
|
|
return perm_string::literal("");
|
2001-08-26 01:50:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetNet* NetAssign_::sig() const
|
|
|
|
|
{
|
2013-11-23 04:54:42 +01:00
|
|
|
assert(sig_? nest_==0 : nest_!=0);
|
2001-08-26 01:50:02 +02:00
|
|
|
return sig_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-23 18:15:36 +01:00
|
|
|
void NetAssign_::set_part(NetExpr*base, unsigned wid,
|
|
|
|
|
ivl_select_type_t sel_type)
|
2001-08-26 01:50:02 +02:00
|
|
|
{
|
2006-02-02 03:43:57 +01:00
|
|
|
base_ = base;
|
|
|
|
|
lwid_ = wid;
|
2011-02-23 18:15:36 +01:00
|
|
|
sel_type_ = sel_type;
|
2000-09-07 02:06:53 +02:00
|
|
|
}
|
|
|
|
|
|
2012-11-25 19:13:05 +01:00
|
|
|
void NetAssign_::set_property(const perm_string&mname)
|
|
|
|
|
{
|
2013-11-17 01:27:05 +01:00
|
|
|
//ivl_assert(*sig_, sig_->class_type());
|
2012-11-25 19:13:05 +01:00
|
|
|
member_ = mname;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-28 17:08:31 +02:00
|
|
|
/*
|
|
|
|
|
*/
|
|
|
|
|
void NetAssign_::turn_sig_to_wire_on_release()
|
|
|
|
|
{
|
|
|
|
|
turn_sig_to_wire_on_release_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-02 22:54:20 +02:00
|
|
|
NetAssignBase::NetAssignBase(NetAssign_*lv, NetExpr*rv)
|
2002-04-22 00:31:02 +02:00
|
|
|
: lval_(lv), rval_(rv), delay_(0)
|
2000-09-02 22:54:20 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetAssignBase::~NetAssignBase()
|
|
|
|
|
{
|
2010-04-14 06:29:15 +02:00
|
|
|
delete rval_;
|
2000-09-10 04:18:16 +02:00
|
|
|
while (lval_) {
|
|
|
|
|
NetAssign_*tmp = lval_;
|
|
|
|
|
lval_ = tmp->more;
|
|
|
|
|
tmp->more = 0;
|
|
|
|
|
delete tmp;
|
|
|
|
|
}
|
2000-09-02 22:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetExpr* NetAssignBase::rval()
|
|
|
|
|
{
|
|
|
|
|
return rval_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetExpr* NetAssignBase::rval() const
|
|
|
|
|
{
|
|
|
|
|
return rval_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetAssignBase::set_rval(NetExpr*r)
|
|
|
|
|
{
|
2010-04-14 06:29:15 +02:00
|
|
|
delete rval_;
|
2000-09-02 22:54:20 +02:00
|
|
|
rval_ = r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetAssign_* NetAssignBase::l_val(unsigned idx)
|
|
|
|
|
{
|
2000-09-10 04:18:16 +02:00
|
|
|
NetAssign_*cur = lval_;
|
|
|
|
|
while (idx > 0) {
|
|
|
|
|
if (cur == 0)
|
|
|
|
|
return cur;
|
|
|
|
|
|
|
|
|
|
cur = cur->more;
|
|
|
|
|
idx -= 1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-02 22:54:20 +02:00
|
|
|
assert(idx == 0);
|
2000-09-10 04:18:16 +02:00
|
|
|
return cur;
|
2000-09-02 22:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetAssign_* NetAssignBase::l_val(unsigned idx) const
|
|
|
|
|
{
|
2000-09-10 04:18:16 +02:00
|
|
|
const NetAssign_*cur = lval_;
|
|
|
|
|
while (idx > 0) {
|
|
|
|
|
if (cur == 0)
|
|
|
|
|
return cur;
|
|
|
|
|
|
|
|
|
|
cur = cur->more;
|
|
|
|
|
idx -= 1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-02 22:54:20 +02:00
|
|
|
assert(idx == 0);
|
2000-09-10 04:18:16 +02:00
|
|
|
return cur;
|
2000-09-02 22:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
2000-10-18 22:04:39 +02:00
|
|
|
unsigned NetAssignBase::l_val_count() const
|
|
|
|
|
{
|
|
|
|
|
const NetAssign_*cur = lval_;
|
|
|
|
|
unsigned cnt = 0;
|
|
|
|
|
while (cur) {
|
|
|
|
|
cnt += 1;
|
|
|
|
|
cur = cur->more;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-07 02:06:53 +02:00
|
|
|
unsigned NetAssignBase::lwidth() const
|
|
|
|
|
{
|
2000-09-10 04:18:16 +02:00
|
|
|
unsigned sum = 0;
|
|
|
|
|
for (NetAssign_*cur = lval_ ; cur ; cur = cur->more)
|
|
|
|
|
sum += cur->lwidth();
|
|
|
|
|
return sum;
|
2000-09-07 02:06:53 +02:00
|
|
|
}
|
|
|
|
|
|
2002-04-22 00:31:02 +02:00
|
|
|
void NetAssignBase::set_delay(NetExpr*expr)
|
2000-09-02 22:54:20 +02:00
|
|
|
{
|
2002-04-22 00:31:02 +02:00
|
|
|
delay_ = expr;
|
2000-09-02 22:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
2002-04-22 00:31:02 +02:00
|
|
|
const NetExpr* NetAssignBase::get_delay() const
|
2000-09-02 22:54:20 +02:00
|
|
|
{
|
2002-04-22 00:31:02 +02:00
|
|
|
return delay_;
|
2000-09-02 22:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
2002-04-22 00:31:02 +02:00
|
|
|
NetAssign::NetAssign(NetAssign_*lv, NetExpr*rv)
|
2011-11-28 01:46:02 +01:00
|
|
|
: NetAssignBase(lv, rv), op_(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetAssign::NetAssign(NetAssign_*lv, char op, NetExpr*rv)
|
|
|
|
|
: NetAssignBase(lv, rv), op_(op)
|
2000-09-02 22:54:20 +02:00
|
|
|
{
|
2001-08-26 01:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
2002-04-22 00:31:02 +02:00
|
|
|
NetAssign::~NetAssign()
|
2001-08-26 01:50:02 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-11 04:37:11 +02:00
|
|
|
NetAssignNB::NetAssignNB(NetAssign_*lv, NetExpr*rv, NetEvWait*ev, NetExpr*cnt)
|
2002-04-22 00:31:02 +02:00
|
|
|
: NetAssignBase(lv, rv)
|
2001-08-26 01:50:02 +02:00
|
|
|
{
|
2008-09-11 04:37:11 +02:00
|
|
|
event_ = ev;
|
|
|
|
|
count_ = cnt;
|
2001-08-26 01:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
2002-04-22 00:31:02 +02:00
|
|
|
NetAssignNB::~NetAssignNB()
|
2001-08-26 01:50:02 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-11 04:37:11 +02:00
|
|
|
unsigned NetAssignNB::nevents() const
|
|
|
|
|
{
|
|
|
|
|
if (event_) return event_->nevents();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetEvent*NetAssignNB::event(unsigned idx) const
|
|
|
|
|
{
|
|
|
|
|
if (event_) return event_->event(idx);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetExpr*NetAssignNB::get_count() const
|
|
|
|
|
{
|
|
|
|
|
return count_;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
NetCAssign::NetCAssign(NetAssign_*lv, NetExpr*rv)
|
|
|
|
|
: NetAssignBase(lv, rv)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetCAssign::~NetCAssign()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetDeassign::NetDeassign(NetAssign_*l)
|
|
|
|
|
: NetAssignBase(l, 0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetDeassign::~NetDeassign()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetForce::NetForce(NetAssign_*lv, NetExpr*rv)
|
|
|
|
|
: NetAssignBase(lv, rv)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetForce::~NetForce()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetRelease::NetRelease(NetAssign_*l)
|
|
|
|
|
: NetAssignBase(l, 0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetRelease::~NetRelease()
|
|
|
|
|
{
|
|
|
|
|
}
|