2002-01-28 02:39:45 +01:00
|
|
|
/*
|
2011-02-10 06:03:08 +01:00
|
|
|
* Copyright (c) 2002-2011 Stephen Williams (steve@icarus.com)
|
2002-01-28 02:39:45 +01: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
|
|
|
|
|
*/
|
|
|
|
|
|
2002-01-29 23:36:31 +01:00
|
|
|
# include "config.h"
|
2002-01-28 02:39:45 +01:00
|
|
|
# include "netlist.h"
|
2010-11-08 00:02:42 +01:00
|
|
|
# include "netenum.h"
|
2003-03-01 07:25:30 +01:00
|
|
|
# include "compiler.h"
|
2008-03-08 03:51:50 +01:00
|
|
|
# include "netmisc.h"
|
2002-06-06 20:57:18 +02:00
|
|
|
# include <iostream>
|
2002-01-28 02:39:45 +01:00
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
/*
|
|
|
|
|
* the grand default data type is a logic vector.
|
|
|
|
|
*/
|
|
|
|
|
ivl_variable_type_t NetExpr::expr_type() const
|
2003-01-26 22:15:58 +01:00
|
|
|
{
|
2005-07-11 18:56:50 +02:00
|
|
|
return IVL_VT_LOGIC;
|
2003-01-26 22:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-03 04:16:42 +01:00
|
|
|
netenum_t*NetExpr::enumeration() const
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-06 03:25:13 +01:00
|
|
|
/*
|
2011-02-26 23:59:52 +01:00
|
|
|
* Create an add/sub node from the two operands.
|
2002-11-06 03:25:13 +01:00
|
|
|
*/
|
2011-02-26 23:59:52 +01:00
|
|
|
NetEBAdd::NetEBAdd(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
|
|
|
|
|
: NetEBinary(op__, l, r, wid, signed_flag)
|
2002-11-06 03:25:13 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEBAdd::~NetEBAdd()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
ivl_variable_type_t NetEBAdd::expr_type() const
|
2003-01-26 22:15:58 +01:00
|
|
|
{
|
2005-07-11 18:56:50 +02:00
|
|
|
if (left_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
2003-01-26 22:15:58 +01:00
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
if (right_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
2003-01-26 22:15:58 +01:00
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
return IVL_VT_LOGIC;
|
2003-01-26 22:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
2003-03-15 19:08:43 +01:00
|
|
|
/*
|
|
|
|
|
* Create a comparison operator with two sub-expressions.
|
|
|
|
|
*/
|
2008-10-13 18:51:05 +02:00
|
|
|
NetEBComp::NetEBComp(char op__, NetExpr*l, NetExpr*r)
|
2011-02-26 23:59:52 +01:00
|
|
|
: NetEBinary(op__, l, r, 1, false)
|
2003-03-15 19:08:43 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEBComp::~NetEBComp()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NetEBComp::has_width() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-14 04:53:13 +02:00
|
|
|
ivl_variable_type_t NetEBComp::expr_type() const
|
|
|
|
|
{
|
|
|
|
|
// Case compare always returns BOOL
|
|
|
|
|
if (op() == 'E' || op() == 'N')
|
|
|
|
|
return IVL_VT_BOOL;
|
|
|
|
|
|
|
|
|
|
if (left()->expr_type() == IVL_VT_LOGIC)
|
|
|
|
|
return IVL_VT_LOGIC;
|
|
|
|
|
|
|
|
|
|
if (right()->expr_type() == IVL_VT_LOGIC)
|
|
|
|
|
return IVL_VT_LOGIC;
|
|
|
|
|
|
|
|
|
|
return IVL_VT_BOOL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-26 23:59:52 +01:00
|
|
|
NetEBDiv::NetEBDiv(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
|
|
|
|
|
: NetEBinary(op__, l, r, wid, signed_flag)
|
2003-01-26 22:15:58 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEBDiv::~NetEBDiv()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
ivl_variable_type_t NetEBDiv::expr_type() const
|
2003-01-26 22:15:58 +01:00
|
|
|
{
|
2005-07-11 18:56:50 +02:00
|
|
|
if (left_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
2003-01-26 22:15:58 +01:00
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
if (right_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
2003-01-26 22:15:58 +01:00
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
return IVL_VT_LOGIC;
|
2003-01-26 22:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-26 23:59:52 +01:00
|
|
|
NetEBMinMax::NetEBMinMax(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
|
|
|
|
|
: NetEBinary(op__, l, r, wid, signed_flag)
|
2008-05-04 06:54:42 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEBMinMax::~NetEBMinMax()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ivl_variable_type_t NetEBMinMax::expr_type() const
|
|
|
|
|
{
|
|
|
|
|
if (left_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
|
|
|
|
if (right_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
|
|
|
|
|
|
|
|
|
return IVL_VT_LOGIC;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-26 23:59:52 +01:00
|
|
|
NetEBMult::NetEBMult(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
|
|
|
|
|
: NetEBinary(op__, l, r, wid, signed_flag)
|
2003-01-26 22:15:58 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEBMult::~NetEBMult()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
ivl_variable_type_t NetEBMult::expr_type() const
|
2003-01-26 22:15:58 +01:00
|
|
|
{
|
2005-07-11 18:56:50 +02:00
|
|
|
if (left_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
2003-01-26 22:15:58 +01:00
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
if (right_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
2003-01-26 22:15:58 +01:00
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
return IVL_VT_LOGIC;
|
2003-01-26 22:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-26 23:59:52 +01:00
|
|
|
NetEBPow::NetEBPow(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
|
|
|
|
|
: NetEBinary(op__, l, r, wid, signed_flag)
|
2006-07-31 05:50:17 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEBPow::~NetEBPow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ivl_variable_type_t NetEBPow::expr_type() const
|
|
|
|
|
{
|
|
|
|
|
if (right_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
|
|
|
|
if (left_->expr_type() == IVL_VT_REAL)
|
|
|
|
|
return IVL_VT_REAL;
|
|
|
|
|
|
|
|
|
|
return IVL_VT_LOGIC;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-26 23:59:52 +01:00
|
|
|
NetEBShift::NetEBShift(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
|
|
|
|
|
: NetEBinary(op__, l, r, wid, signed_flag)
|
2003-06-18 05:55:18 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEBShift::~NetEBShift()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NetEBShift::has_width() const
|
|
|
|
|
{
|
|
|
|
|
return left_->has_width();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-26 23:59:52 +01:00
|
|
|
NetEConcat::NetEConcat(unsigned cnt, unsigned r)
|
2002-05-05 23:11:49 +02:00
|
|
|
: parms_(cnt), repeat_(r)
|
|
|
|
|
{
|
|
|
|
|
expr_width(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEConcat::~NetEConcat()
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < parms_.count() ; idx += 1)
|
|
|
|
|
delete parms_[idx];
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-09 02:40:19 +01:00
|
|
|
bool NetEConcat::has_width() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-05 23:11:49 +02:00
|
|
|
void NetEConcat::set(unsigned idx, NetExpr*e)
|
|
|
|
|
{
|
|
|
|
|
assert(idx < parms_.count());
|
|
|
|
|
assert(parms_[idx] == 0);
|
|
|
|
|
parms_[idx] = e;
|
2011-02-26 23:59:52 +01:00
|
|
|
expr_width( expr_width() + repeat_ * e->expr_width() );
|
2002-05-05 23:11:49 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-03 04:16:42 +01:00
|
|
|
NetEConstEnum::NetEConstEnum(NetScope*s, perm_string n, netenum_t*eset, const verinum&v)
|
2010-11-04 04:11:19 +01:00
|
|
|
: NetEConst(v), scope_(s), enum_set_(eset), name_(n)
|
2010-10-31 19:26:09 +01:00
|
|
|
{
|
2010-11-07 18:58:00 +01:00
|
|
|
assert(has_width());
|
2010-10-31 19:26:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEConstEnum::~NetEConstEnum()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-03 04:16:42 +01:00
|
|
|
netenum_t*NetEConstEnum::enumeration() const
|
2010-10-31 19:26:09 +01:00
|
|
|
{
|
|
|
|
|
return enum_set_;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-26 22:15:58 +01:00
|
|
|
NetECReal::NetECReal(const verireal&val)
|
|
|
|
|
: value_(val)
|
|
|
|
|
{
|
2007-08-16 07:01:59 +02:00
|
|
|
expr_width(1);
|
2011-02-26 23:59:52 +01:00
|
|
|
cast_signed_base_(true);
|
2003-01-26 22:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetECReal::~NetECReal()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const verireal& NetECReal::value() const
|
|
|
|
|
{
|
|
|
|
|
return value_;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-06 18:50:23 +01:00
|
|
|
bool NetECReal::has_width() const
|
|
|
|
|
{
|
2011-02-26 23:59:52 +01:00
|
|
|
return true;
|
2003-01-26 22:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
ivl_variable_type_t NetECReal::expr_type() const
|
2003-01-26 22:15:58 +01:00
|
|
|
{
|
2005-07-11 18:56:50 +02:00
|
|
|
return IVL_VT_REAL;
|
2003-01-26 22:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
2004-02-20 07:22:56 +01:00
|
|
|
NetECRealParam::NetECRealParam(NetScope*s, perm_string n, const verireal&v)
|
2003-05-30 04:55:32 +02:00
|
|
|
: NetECReal(v), scope_(s), name_(n)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetECRealParam::~NetECRealParam()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-20 07:22:56 +01:00
|
|
|
perm_string NetECRealParam::name() const
|
2003-05-30 04:55:32 +02:00
|
|
|
{
|
|
|
|
|
return name_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetScope* NetECRealParam::scope() const
|
|
|
|
|
{
|
|
|
|
|
return scope_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-11-21 00:09:32 +01:00
|
|
|
NetENetenum::NetENetenum(netenum_t*s)
|
|
|
|
|
: netenum_(s)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetENetenum::~NetENetenum()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
netenum_t* NetENetenum::netenum() const
|
|
|
|
|
{
|
|
|
|
|
return netenum_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-23 18:15:36 +01:00
|
|
|
NetESelect::NetESelect(NetExpr*exp, NetExpr*base, unsigned wid,
|
|
|
|
|
ivl_select_type_t sel_type)
|
|
|
|
|
: expr_(exp), base_(base), sel_type_(sel_type)
|
2002-01-28 02:39:45 +01:00
|
|
|
{
|
|
|
|
|
expr_width(wid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetESelect::~NetESelect()
|
|
|
|
|
{
|
|
|
|
|
delete expr_;
|
|
|
|
|
delete base_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetExpr*NetESelect::sub_expr() const
|
|
|
|
|
{
|
|
|
|
|
return expr_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetExpr*NetESelect::select() const
|
|
|
|
|
{
|
|
|
|
|
return base_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-23 18:15:36 +01:00
|
|
|
ivl_select_type_t NetESelect::select_type() const
|
|
|
|
|
{
|
|
|
|
|
return sel_type_;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 02:39:45 +01:00
|
|
|
bool NetESelect::has_width() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
NetESFunc::NetESFunc(const char*n, ivl_variable_type_t t,
|
2003-03-15 05:46:28 +01:00
|
|
|
unsigned width, unsigned np)
|
2010-11-08 00:02:42 +01:00
|
|
|
: name_(0), type_(t), enum_type_(0), parms_(np)
|
2003-01-27 01:14:37 +01:00
|
|
|
{
|
2003-03-01 07:25:30 +01:00
|
|
|
name_ = lex_strings.add(n);
|
2003-01-27 01:14:37 +01:00
|
|
|
expr_width(width);
|
2010-11-08 00:02:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetESFunc::NetESFunc(const char*n, netenum_t*enum_type, unsigned np)
|
|
|
|
|
: name_(0), type_(enum_type->base_type()), enum_type_(enum_type), parms_(np)
|
|
|
|
|
{
|
|
|
|
|
name_ = lex_strings.add(n);
|
|
|
|
|
expr_width(enum_type->base_width());
|
2003-01-27 01:14:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetESFunc::~NetESFunc()
|
|
|
|
|
{
|
2010-11-08 00:02:42 +01:00
|
|
|
for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1)
|
2003-01-27 01:14:37 +01:00
|
|
|
if (parms_[idx]) delete parms_[idx];
|
|
|
|
|
|
2003-03-01 07:25:30 +01:00
|
|
|
/* name_ string ls lex_strings allocated. */
|
2003-01-27 01:14:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* NetESFunc::name() const
|
|
|
|
|
{
|
|
|
|
|
return name_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned NetESFunc::nparms() const
|
|
|
|
|
{
|
2010-11-08 00:02:42 +01:00
|
|
|
return parms_.size();
|
2003-01-27 01:14:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetESFunc::parm(unsigned idx, NetExpr*v)
|
|
|
|
|
{
|
2010-11-08 00:02:42 +01:00
|
|
|
assert(idx < parms_.size());
|
2003-01-27 01:14:37 +01:00
|
|
|
if (parms_[idx])
|
|
|
|
|
delete parms_[idx];
|
|
|
|
|
parms_[idx] = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetExpr* NetESFunc::parm(unsigned idx) const
|
|
|
|
|
{
|
2010-11-08 00:02:42 +01:00
|
|
|
assert(idx < parms_.size());
|
2003-01-27 01:14:37 +01:00
|
|
|
return parms_[idx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetExpr* NetESFunc::parm(unsigned idx)
|
|
|
|
|
{
|
2010-11-08 00:02:42 +01:00
|
|
|
assert(idx < parms_.size());
|
2003-01-27 01:14:37 +01:00
|
|
|
return parms_[idx];
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 18:56:50 +02:00
|
|
|
ivl_variable_type_t NetESFunc::expr_type() const
|
2003-01-27 01:14:37 +01:00
|
|
|
{
|
2003-03-15 05:46:28 +01:00
|
|
|
return type_;
|
2003-01-27 01:14:37 +01:00
|
|
|
}
|
2008-07-31 03:01:41 +02:00
|
|
|
|
2010-11-08 00:02:42 +01:00
|
|
|
netenum_t* NetESFunc::enumeration() const
|
|
|
|
|
{
|
|
|
|
|
return enum_type_;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-04 06:10:10 +01:00
|
|
|
NetEAccess::NetEAccess(NetBranch*br, ivl_nature_t nat)
|
2008-08-05 05:54:05 +02:00
|
|
|
: branch_(br), nature_(nat)
|
2008-07-31 03:01:41 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEAccess::~NetEAccess()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ivl_variable_type_t NetEAccess::expr_type() const
|
|
|
|
|
{
|
|
|
|
|
return IVL_VT_REAL;
|
|
|
|
|
}
|