1 Star 0 Fork 0

theta405/iverilog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
net_expr.cc 11.43 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
/*
* Copyright (c) 2002-2020 Stephen Williams (steve@icarus.com)
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
# include "config.h"
# include "netlist.h"
# include "netenum.h"
# include "netclass.h"
# include "netdarray.h"
# include "netscalar.h"
# include "compiler.h"
# include "netmisc.h"
# include <iostream>
# include "ivl_assert.h"
using namespace std;
NetExpr::NetExpr(unsigned w)
: net_type_(0), width_(w), signed_flag_(false)
{
}
NetExpr::NetExpr(ivl_type_t t)
: net_type_(t), width_(0), signed_flag_(false)
{
}
NetExpr::~NetExpr()
{
}
ivl_type_t NetExpr::net_type() const
{
return net_type_;
}
void NetExpr::cast_signed(bool flag)
{
cast_signed_base_(flag);
}
bool NetExpr::has_width() const
{
return true;
}
/*
* the grand default data type is a logic vector.
*/
ivl_variable_type_t NetExpr::expr_type() const
{
if (net_type_)
return net_type_->base_type();
else
return IVL_VT_LOGIC;
}
const netenum_t*NetExpr::enumeration() const
{
return 0;
}
NetEArrayPattern::NetEArrayPattern(ivl_type_t lv_type, vector<NetExpr*>&items)
: NetExpr(lv_type), items_(items)
{
}
NetEArrayPattern::~NetEArrayPattern()
{
for (size_t idx = 0 ; idx < items_.size() ; idx += 1)
delete items_[idx];
}
/*
* Create an add/sub node from the two operands.
*/
NetEBAdd::NetEBAdd(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
: NetEBinary(op__, l, r, wid, signed_flag)
{
}
NetEBAdd::~NetEBAdd()
{
}
ivl_variable_type_t NetEBAdd::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;
}
/*
* Create a comparison operator with two sub-expressions.
*/
NetEBComp::NetEBComp(char op__, NetExpr*l, NetExpr*r)
: NetEBinary(op__, l, r, 1, false)
{
}
NetEBComp::~NetEBComp()
{
}
bool NetEBComp::has_width() const
{
return true;
}
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;
}
NetEBDiv::NetEBDiv(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
: NetEBinary(op__, l, r, wid, signed_flag)
{
}
NetEBDiv::~NetEBDiv()
{
}
ivl_variable_type_t NetEBDiv::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;
}
NetEBMinMax::NetEBMinMax(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
: NetEBinary(op__, l, r, wid, signed_flag)
{
}
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;
}
NetEBMult::NetEBMult(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
: NetEBinary(op__, l, r, wid, signed_flag)
{
}
NetEBMult::~NetEBMult()
{
}
ivl_variable_type_t NetEBMult::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;
}
NetEBPow::NetEBPow(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
: NetEBinary(op__, l, r, wid, signed_flag)
{
}
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;
}
NetEBShift::NetEBShift(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
: NetEBinary(op__, l, r, wid, signed_flag)
{
}
NetEBShift::~NetEBShift()
{
}
bool NetEBShift::has_width() const
{
return left_->has_width();
}
NetEConcat::NetEConcat(unsigned cnt, unsigned r, ivl_variable_type_t vt)
: parms_(cnt), repeat_(r), expr_type_(vt)
{
expr_width(0);
}
NetEConcat::~NetEConcat()
{
for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1)
delete parms_[idx];
}
ivl_variable_type_t NetEConcat::expr_type() const
{
return expr_type_;
}
bool NetEConcat::has_width() const
{
return true;
}
void NetEConcat::set(unsigned idx, NetExpr*e)
{
assert(idx < parms_.size());
assert(parms_[idx] == 0);
parms_[idx] = e;
expr_width( expr_width() + repeat_ * e->expr_width() );
}
NetEConstEnum::NetEConstEnum(perm_string n, const netenum_t*eset, const verinum&v)
: NetEConst(v), enum_set_(eset), name_(n)
{
assert(has_width());
}
NetEConstEnum::~NetEConstEnum()
{
}
const netenum_t*NetEConstEnum::enumeration() const
{
return enum_set_;
}
NetECReal::NetECReal(const verireal&val)
: value_(val)
{
expr_width(1);
cast_signed_base_(true);
}
NetECReal::~NetECReal()
{
}
const verireal& NetECReal::value() const
{
return value_;
}
bool NetECReal::has_width() const
{
return true;
}
ivl_variable_type_t NetECReal::expr_type() const
{
return IVL_VT_REAL;
}
NetECRealParam::NetECRealParam(const NetScope*s, perm_string n, const verireal&v)
: NetECReal(v), scope_(s), name_(n)
{
}
NetECRealParam::~NetECRealParam()
{
}
perm_string NetECRealParam::name() const
{
return name_;
}
const NetScope* NetECRealParam::scope() const
{
return scope_;
}
NetECString::NetECString(const std::string& val)
: NetEConst(verinum(val))
{
}
NetECString::~NetECString()
{
}
ivl_variable_type_t NetECString::expr_type() const
{
return IVL_VT_STRING;
}
NetELast::NetELast(NetNet*s)
: sig_(s)
{
}
NetELast::~NetELast()
{
}
ivl_variable_type_t NetELast::expr_type() const
{
return IVL_VT_BOOL;
}
NetENetenum::NetENetenum(const netenum_t*s)
: netenum_(s)
{
}
NetENetenum::~NetENetenum()
{
}
const netenum_t* NetENetenum::netenum() const
{
return netenum_;
}
NetENew::NetENew(ivl_type_t t)
: obj_type_(t), size_(0), init_val_(0)
{
}
NetENew::NetENew(ivl_type_t t, NetExpr*size, NetExpr*init_val)
: obj_type_(t), size_(size), init_val_(init_val)
{
}
NetENew::~NetENew()
{
}
ivl_variable_type_t NetENew::expr_type() const
{
return size_ ? IVL_VT_DARRAY : IVL_VT_CLASS;
}
NetENull::NetENull()
{
}
NetENull::~NetENull()
{
}
NetEProperty::NetEProperty(NetNet*net, perm_string pnam, NetExpr*idx)
: net_(net), index_(idx)
{
const netclass_t*use_type = dynamic_cast<const netclass_t*>(net->net_type());
assert(use_type);
pidx_ = use_type->property_idx_from_name(pnam);
ivl_type_t prop_type = use_type->get_prop_type(pidx_);
expr_width(prop_type->packed_width());
cast_signed(prop_type->get_signed());
}
NetEProperty::~NetEProperty()
{
}
ivl_variable_type_t NetEProperty::expr_type() const
{
const netclass_t*use_type = dynamic_cast<const netclass_t*>(net_->net_type());
assert(use_type);
ivl_type_t prop_type = use_type->get_prop_type(pidx_);
return prop_type->base_type();
}
NetESelect::NetESelect(NetExpr*exp, NetExpr*base, unsigned wid,
ivl_select_type_t sel_type)
: expr_(exp), base_(base), use_type_(0), sel_type_(sel_type)
{
expr_width(wid);
}
NetESelect::NetESelect(NetExpr*exp, NetExpr*base, unsigned wid,
ivl_type_t use_type)
: expr_(exp), base_(base), use_type_(use_type), sel_type_(IVL_SEL_OTHER)
{
expr_width(wid);
}
NetESelect::~NetESelect()
{
delete expr_;
delete base_;
}
const NetExpr*NetESelect::sub_expr() const
{
return expr_;
}
const NetExpr*NetESelect::select() const
{
return base_;
}
ivl_select_type_t NetESelect::select_type() const
{
return sel_type_;
}
ivl_variable_type_t NetESelect::expr_type() const
{
if (use_type_)
return use_type_->base_type();
ivl_variable_type_t type = expr_->expr_type();
// Special case: If the sub-expression is an IVL_VT_STRING,
// then this node is representing a character select. The
// width is the width of a byte, and the data type is BOOL.
if (type == IVL_VT_STRING && expr_width()==8)
return IVL_VT_BOOL;
return type;
}
const netenum_t* NetESelect::enumeration() const
{
return dynamic_cast<const netenum_t*> (use_type_);
}
bool NetESelect::has_width() const
{
return true;
}
NetESFunc::NetESFunc(const char*n, ivl_variable_type_t t,
unsigned width, unsigned np, bool is_overridden)
: name_(0), type_(t), enum_type_(0), parms_(np), is_overridden_(is_overridden)
{
name_ = lex_strings.add(n);
expr_width(width);
}
NetESFunc::NetESFunc(const char*n, ivl_type_t rtype, unsigned np)
: NetExpr(rtype), name_(0), type_(IVL_VT_NO_TYPE), enum_type_(0), parms_(np), is_overridden_(false)
{
name_ = lex_strings.add(n);
expr_width(rtype->packed_width());
// FIXME: For now, assume that all uses of this constructor
// are for the IVL_VT_DARRAY type. Eventually, the type_
// member will go away.
if (dynamic_cast<const netdarray_t*>(rtype))
type_ = IVL_VT_DARRAY;
else if (dynamic_cast<const netclass_t*>(rtype))
type_ = IVL_VT_CLASS;
else if (dynamic_cast<const netstring_t*>(rtype))
type_ = IVL_VT_STRING;
else
ivl_assert(*this, 0);
}
NetESFunc::NetESFunc(const char*n, const netenum_t*enum_type, unsigned np)
: name_(0), type_(enum_type->base_type()), enum_type_(enum_type), parms_(np), is_overridden_(false)
{
name_ = lex_strings.add(n);
expr_width(enum_type->packed_width());
}
NetESFunc::~NetESFunc()
{
for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1)
if (parms_[idx]) delete parms_[idx];
/* name_ string ls lex_strings allocated. */
}
const char* NetESFunc::name() const
{
return name_;
}
unsigned NetESFunc::nparms() const
{
return parms_.size();
}
void NetESFunc::parm(unsigned idx, NetExpr*v)
{
assert(idx < parms_.size());
if (parms_[idx])
delete parms_[idx];
parms_[idx] = v;
}
const NetExpr* NetESFunc::parm(unsigned idx) const
{
assert(idx < parms_.size());
return parms_[idx];
}
NetExpr* NetESFunc::parm(unsigned idx)
{
assert(idx < parms_.size());
return parms_[idx];
}
ivl_variable_type_t NetESFunc::expr_type() const
{
return type_;
}
const netenum_t* NetESFunc::enumeration() const
{
return enum_type_;
}
NetEShallowCopy::NetEShallowCopy(NetExpr*arg1, NetExpr*arg2)
: arg1_(arg1), arg2_(arg2)
{
}
NetEShallowCopy::~NetEShallowCopy()
{
}
ivl_variable_type_t NetEShallowCopy::expr_type() const
{
return arg1_->expr_type();
}
NetEAccess::NetEAccess(NetBranch*br, ivl_nature_t nat)
: branch_(br), nature_(nat)
{
}
NetEAccess::~NetEAccess()
{
}
ivl_variable_type_t NetEAccess::expr_type() const
{
return IVL_VT_REAL;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
VHDL
1
https://gitee.com/theta405/iverilog.git
git@gitee.com:theta405/iverilog.git
theta405
iverilog
iverilog
master

搜索帮助