Move net vector properties to netvector_t object.

This commit is contained in:
Stephen Williams 2012-09-15 17:16:05 -07:00
parent 997274b98f
commit 494dc876a5
15 changed files with 100 additions and 87 deletions

View File

@ -141,9 +141,21 @@ ostream& operator << (ostream&o, ivl_switch_type_t val)
return o;
}
ostream& netvector_t::debug_dump(std::ostream&o) const
ostream& nettype_base_t::debug_dump(ostream&o) const
{
o << type_ << packed_dims_;
o << typeid(*this).name();
return o;
}
ostream& netdarray_t::debug_dump(ostream&o) const
{
o << "dynamic array of " << *elem_type_;
return o;
}
ostream& netvector_t::debug_dump(ostream&o) const
{
o << type_ << (signed_? " signed" : " unsigned") << packed_dims_;
return o;
}
@ -242,8 +254,6 @@ void NetNet::dump_net(ostream&o, unsigned ind) const
o << " pin_count=" << pin_count();
if (local_flag_)
o << " (local)";
if (signed_)
o << " signed";
switch (port_type_) {
case NetNet::NOT_A_PORT:
break;
@ -267,18 +277,7 @@ void NetNet::dump_net(ostream&o, unsigned ind) const
if (ivl_discipline_t dis = get_discipline())
o << " discipline=" << dis->name();
if (netvector_t*varray = dynamic_cast<netvector_t*>(net_type_))
o << " vector " << varray->packed_dims()
<< " of " << *varray;
if (netdarray_t*darray = darray_type())
o << " dynamic array of " << darray->data_type();
if (! packed_dims_.empty())
o << " packed dims: " << packed_dims_;
if (net_type_)
o << " net_type_=" << typeid(*net_type_).name();
if (net_type_) o << " " << *net_type_;
o << " (eref=" << peek_eref() << ", lref=" << peek_lref() << ")";
if (scope())

View File

@ -525,47 +525,47 @@ void PFunction::elaborate_sig(Design*des, NetScope*scope) const
list<netrange_t> packed;
packed.push_back(netrange_t(mnum, lnum));
ret_vec = new netvector_t(packed, IVL_VT_LOGIC);
ret_vec->set_signed(return_type_.type == PTF_REG_S);
ret_vec->set_scalar(false);
ret_sig = new NetNet(scope, fname, NetNet::REG, ret_vec);
ret_sig->set_scalar(false);
} else {
ret_vec = new netvector_t(IVL_VT_LOGIC);
ret_vec->set_signed(return_type_.type == PTF_REG_S);
ret_vec->set_scalar(true);
ret_sig = new NetNet(scope, fname, NetNet::REG, ret_vec);
ret_sig->set_scalar(true);
}
ret_sig->set_line(*this);
ret_sig->set_signed(return_type_.type == PTF_REG_S);
ret_sig->port_type(NetNet::POUTPUT);
break;
case PTF_INTEGER:
ret_vec = new netvector_t(IVL_VT_LOGIC, integer_width-1,0);
ret_vec->set_signed(true);
ret_vec->set_isint(true);
ret_vec->set_scalar(false);
ret_sig = new NetNet(scope, fname, NetNet::REG, ret_vec);
ret_sig->set_line(*this);
ret_sig->set_signed(true);
ret_sig->set_isint(true);
ret_sig->set_scalar(false);
ret_sig->port_type(NetNet::POUTPUT);
break;
case PTF_TIME:
ret_vec = new netvector_t(IVL_VT_LOGIC, 64-1,0);
ret_vec->set_isint(false);
ret_vec->set_scalar(false);
ret_sig = new NetNet(scope, fname, NetNet::REG, ret_vec);
ret_sig->set_line(*this);
ret_sig->set_signed(false);
ret_sig->set_isint(false);
ret_sig->set_scalar(false);
ret_sig->port_type(NetNet::POUTPUT);
break;
case PTF_REAL:
case PTF_REALTIME:
ret_vec = new netvector_t(IVL_VT_REAL);
ret_vec->set_signed(true);
ret_vec->set_isint(false);
ret_vec->set_scalar(true);
ret_sig = new NetNet(scope, fname, NetNet::REG, ret_vec);
ret_sig->set_line(*this);
ret_sig->set_signed(true);
ret_sig->set_isint(false);
ret_sig->set_scalar(true);
ret_sig->port_type(NetNet::POUTPUT);
break;
@ -602,11 +602,11 @@ void PFunction::elaborate_sig(Design*des, NetScope*scope) const
use_wid = mnum - lnum + 1;
}
ret_vec = new netvector_t(IVL_VT_BOOL, use_wid-1, 0);
ret_vec->set_isint(true);
ret_vec->set_scalar(false);
ret_vec->set_signed(return_type_.type == PTF_ATOM2_S? true : false);
ret_sig = new NetNet(scope, fname, NetNet::REG, ret_vec);
ret_sig->set_line(*this);
ret_sig->set_signed(return_type_.type == PTF_ATOM2_S? true : false);
ret_sig->set_isint(true);
ret_sig->set_scalar(false);
ret_sig->port_type(NetNet::POUTPUT);
break;
@ -1288,6 +1288,10 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
}
netvector_t*vec = new netvector_t(packed_dimensions, use_data_type);
vec->set_signed(get_signed());
vec->set_isint(get_isint());
if (is_implicit_scalar) vec->set_scalar(true);
else vec->set_scalar(get_scalar());
packed_dimensions.clear();
sig = new NetNet(scope, name_, wtype, packed_dimensions, unpacked_dimensions, vec);
@ -1296,10 +1300,6 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
if (wtype == NetNet::WIRE) sig->devirtualize_pins();
sig->set_line(*this);
sig->port_type(port_type_);
sig->set_signed(get_signed());
sig->set_isint(get_isint());
if (is_implicit_scalar) sig->set_scalar(true);
else sig->set_scalar(get_scalar());
if (ivl_discipline_t dis = get_discipline()) {
sig->set_discipline(dis);

View File

@ -115,7 +115,6 @@ void PGAssign::elaborate(Design*des, NetScope*scope) const
cerr << get_fileline() << ": debug: PGAssign: elaborated r-value"
<< " width="<< rval->vector_width()
<< ", type="<< rval->data_type()
<< ", signed="<< rval->get_signed()
<< ", expr=" << *rval_expr << endl;
}

View File

@ -120,10 +120,10 @@ NetNet* NetEBAdd::synthesize(Design*des, NetScope*scope, NetExpr*root)
perm_string path = lsig->scope()->local_symbol();
netvector_t*osig_vec = new netvector_t(expr_type(), width-1, 0);
osig_vec->set_signed(has_sign());
NetNet*osig = new NetNet(lsig->scope(), path, NetNet::IMPLICIT, osig_vec);
osig->set_line(*this);
osig->local_flag(true);
osig->set_signed(has_sign());
perm_string oname = osig->scope()->local_symbol();
NetAddSub *adder = new NetAddSub(lsig->scope(), oname, width);
@ -392,10 +392,10 @@ NetNet* NetEBPow::synthesize(Design*des, NetScope*scope, NetExpr*root)
connect(powr->pin_DataB(), rsig->pin(0));
netvector_t*osig_vec = new netvector_t(expr_type(), width-1, 0);
osig_vec->set_signed(has_sign());
NetNet*osig = new NetNet(scope, scope->local_symbol(),
NetNet::IMPLICIT, osig_vec);
osig->set_line(*this);
osig->set_signed(has_sign());
osig->local_flag(true);
connect(powr->pin_Result(), osig->pin(0));
@ -429,10 +429,10 @@ NetNet* NetEBMult::synthesize(Design*des, NetScope*scope, NetExpr*root)
connect(mult->pin_DataB(), rsig->pin(0));
netvector_t*osig_vec = new netvector_t(expr_type(), width-1, 0);
osig_vec->set_signed(has_sign());
NetNet*osig = new NetNet(scope, scope->local_symbol(),
NetNet::IMPLICIT, osig_vec);
osig->set_line(*this);
osig->set_signed(has_sign());
osig->local_flag(true);
connect(mult->pin_Result(), osig->pin(0));
@ -454,10 +454,10 @@ NetNet* NetEBDiv::synthesize(Design*des, NetScope*scope, NetExpr*root)
else width = expr_width();
netvector_t*osig_vec = new netvector_t(lsig->data_type(), width-1, 0);
osig_vec->set_signed(has_sign());
NetNet*osig = new NetNet(scope, scope->local_symbol(),
NetNet::IMPLICIT, osig_vec);
osig->set_line(*this);
osig->set_signed(has_sign());
osig->local_flag(true);
switch (op()) {
@ -788,10 +788,10 @@ NetNet* NetEConst::synthesize(Design*des, NetScope*scope, NetExpr*)
}
netvector_t*osig_vec = new netvector_t(expr_type(), width-1, 0);
osig_vec->set_signed(has_sign());
NetNet*osig = new NetNet(scope, path, NetNet::IMPLICIT, osig_vec);
osig->set_line(*this);
osig->local_flag(true);
osig->set_signed(has_sign());
NetConst*con = new NetConst(scope, scope->local_symbol(), value());
con->set_line(*this);
@ -809,10 +809,10 @@ NetNet* NetECReal::synthesize(Design*des, NetScope*scope, NetExpr*)
perm_string path = scope->local_symbol();
netvector_t*osig_vec = new netvector_t(IVL_VT_REAL);
osig_vec->set_signed(has_sign());
NetNet*osig = new NetNet(scope, path, NetNet::WIRE, osig_vec);
osig->set_line(*this);
osig->local_flag(true);
osig->set_signed(has_sign());
NetLiteral*con = new NetLiteral(scope, scope->local_symbol(), value_);
con->set_line(*this);
@ -1140,6 +1140,7 @@ NetNet* NetESelect::synthesize(Design *des, NetScope*scope, NetExpr*root)
// of the expression.
netvector_t*net_vec = new netvector_t(expr_type(), expr_width()-1, 0);
net_vec->set_signed(has_sign());
NetNet*net = new NetNet(scope, scope->local_symbol(),
NetNet::IMPLICIT, net_vec);
net->set_line(*this);
@ -1153,7 +1154,6 @@ NetNet* NetESelect::synthesize(Design *des, NetScope*scope, NetExpr*root)
connect(pad->pin(1), sub->pin(0));
connect(pad->pin(0), net->pin(0));
net->set_signed(true);
} else {
@ -1361,11 +1361,11 @@ NetNet* NetESFunc::synthesize(Design*des, NetScope*scope, NetExpr*root)
des->add_node(net);
netvector_t*osig_vec = new netvector_t(def->type, def->wid-1, 0);
osig_vec->set_signed(def->type==IVL_VT_REAL? true : false);
NetNet*osig = new NetNet(scope, scope->local_symbol(),
NetNet::WIRE, osig_vec);
osig->set_line(*this);
osig->local_flag(true);
osig->set_signed(def->type==IVL_VT_REAL? true : false);
connect(net->pin(0), osig->pin(0));

View File

@ -35,6 +35,8 @@ class netdarray_t : public nettype_base_t {
inline ivl_variable_type_t data_type() const { return elem_type_->base_type(); }
inline unsigned long vector_width(void) const { return elem_type_->packed_width(); }
std::ostream& debug_dump(std::ostream&) const;
private:
netvector_t*elem_type_;
};

View File

@ -32,6 +32,11 @@ netenum_t::~netenum_t()
{
}
bool netenum_t::get_signed() const
{
return signed_flag_;
}
long netenum_t::packed_width() const
{
if (msb_ >= lsb_)

View File

@ -38,7 +38,7 @@ class netenum_t : public LineInfo, public nettype_base_t {
ivl_variable_type_t base_type() const;
long packed_width() const;
bool has_sign() const;
bool get_signed() const;
// The size() is the number of enumeration literals.
size_t size() const;
@ -75,6 +75,4 @@ inline ivl_variable_type_t netenum_t::base_type() const
inline size_t netenum_t::size() const { return names_.size(); }
inline bool netenum_t::has_sign() const { return signed_flag_; }
#endif

View File

@ -467,7 +467,7 @@ PortType::Enum PortType::merged( Enum lhs, Enum rhs )
NetNet::NetNet(NetScope*s, perm_string n, Type t, unsigned npins)
: NetObj(s, n, 1),
type_(t), port_type_(NOT_A_PORT),
signed_(false), isint_(false), is_scalar_(false), local_flag_(false),
local_flag_(false),
net_type_(0), discipline_(0),
eref_count_(0), lref_count_(0),
port_index_(-1)
@ -569,8 +569,7 @@ NetNet::NetNet(NetScope*s, perm_string n, Type t,
nettype_base_t*net_type)
: NetObj(s, n, calculate_count(unpacked)),
type_(t), port_type_(NOT_A_PORT),
signed_(false), isint_(false),
is_scalar_(false), local_flag_(false), net_type_(net_type),
local_flag_(false), net_type_(net_type),
discipline_(0), unpacked_dims_(unpacked.size()),
eref_count_(0), lref_count_(0)
{
@ -630,8 +629,7 @@ NetNet::NetNet(NetScope*s, perm_string n, Type t,
NetNet::NetNet(NetScope*s, perm_string n, Type t, netstruct_t*ty)
: NetObj(s, n, 1),
type_(t), port_type_(NOT_A_PORT),
signed_(false), isint_(false),
is_scalar_(false), local_flag_(false), net_type_(ty),
local_flag_(false), net_type_(ty),
discipline_(0),
eref_count_(0), lref_count_(0)
{
@ -662,8 +660,7 @@ NetNet::NetNet(NetScope*s, perm_string n, Type t, netstruct_t*ty)
NetNet::NetNet(NetScope*s, perm_string n, Type t, netdarray_t*ty)
: NetObj(s, n, 1),
type_(t), port_type_(NOT_A_PORT),
signed_(false), isint_(false),
is_scalar_(false), local_flag_(false), net_type_(ty),
local_flag_(false), net_type_(ty),
discipline_(0),
eref_count_(0), lref_count_(0)
{
@ -692,8 +689,7 @@ NetNet::NetNet(NetScope*s, perm_string n, Type t, netdarray_t*ty)
NetNet::NetNet(NetScope*s, perm_string n, Type t, netvector_t*ty)
: NetObj(s, n, 1),
type_(t), port_type_(NOT_A_PORT),
signed_(false), isint_(false),
is_scalar_(false), local_flag_(false), net_type_(ty),
local_flag_(false), net_type_(ty),
discipline_(0),
eref_count_(0), lref_count_(0)
{
@ -816,32 +812,26 @@ ivl_variable_type_t NetNet::data_type() const
bool NetNet::get_signed() const
{
return signed_;
}
void NetNet::set_signed(bool flag)
{
signed_ = flag;
if (net_type_==0)
return false;
else
return net_type_->get_signed();
}
bool NetNet::get_isint() const
{
return isint_;
}
void NetNet::set_isint(bool flag)
{
isint_ = flag;
if (netvector_t*vec = dynamic_cast<netvector_t*> (net_type_))
return vec->get_isint();
else
return false;
}
bool NetNet::get_scalar() const
{
return is_scalar_;
}
void NetNet::set_scalar(bool flag)
{
is_scalar_ = flag;
if (netvector_t*vec = dynamic_cast<netvector_t*> (net_type_))
return vec->get_scalar();
else
return false;
}
netenum_t*NetNet::enumeration(void) const

View File

@ -634,15 +634,12 @@ class NetNet : public NetObj, public PortType {
/* If a NetNet is signed, then its value is to be treated as
signed. Otherwise, it is unsigned. */
bool get_signed() const;
void set_signed(bool);
/* Used to maintain original type of net since integers are
implemented as 'reg signed [31:0]' in Icarus */
bool get_isint() const;
void set_isint(bool);
bool get_scalar() const;
void set_scalar(bool);
netenum_t*enumeration(void) const;
netstruct_t*struct_type(void) const;
@ -731,9 +728,6 @@ class NetNet : public NetObj, public PortType {
private:
Type type_ : 5;
PortType port_type_ : 3;
bool signed_ : 1;
bool isint_ : 1; // original type of integer
bool is_scalar_ : 1;
bool local_flag_: 1;
nettype_base_t*net_type_;
ivl_discipline_t discipline_;

View File

@ -36,6 +36,11 @@ ivl_variable_type_t nettype_base_t::base_type() const
return IVL_VT_NO_TYPE;
}
bool nettype_base_t::get_signed() const
{
return false;
}
unsigned long netrange_width(const list<netrange_t>&packed)
{
unsigned wid = 1;

View File

@ -22,6 +22,7 @@
# include "ivl_target.h"
# include <list>
# include <climits>
# include <ostream>
# include <cassert>
/*
@ -35,8 +36,16 @@ class nettype_base_t {
// Some types have a base variable type.
virtual ivl_variable_type_t base_type() const;
virtual bool get_signed() const;
virtual std::ostream& debug_dump(std::ostream&) const;
};
inline static std::ostream& operator << (std::ostream&out, const nettype_base_t&obj)
{
return obj.debug_dump(out);
}
class netrange_t {
public:

View File

@ -20,13 +20,13 @@
# include "netvector.h"
netvector_t::netvector_t(ivl_variable_type_t type, long msb, long lsb)
: type_(type)
: type_(type), signed_(false)
{
packed_dims_.push_back(netrange_t(msb,lsb));
}
netvector_t::netvector_t(ivl_variable_type_t type)
: type_(type)
: type_(type), signed_(false)
{
}

View File

@ -22,7 +22,6 @@
# include "nettypes.h"
# include "ivl_target.h"
# include <vector>
# include <ostream>
class netvector_t : public nettype_base_t {
@ -40,6 +39,17 @@ class netvector_t : public nettype_base_t {
~netvector_t();
// Vectors can be interpreted as signed or unsigned when
// handled as vectors.
inline void set_signed(bool flag) { signed_ = flag; }
inline bool get_signed(void) const { return signed_; }
inline void set_isint(bool flag) { isint_ = flag; }
inline bool get_isint(void) const { return isint_; }
inline void set_scalar(bool flag) { is_scalar_ = flag; }
inline bool get_scalar(void) const { return is_scalar_; }
ivl_variable_type_t base_type() const;
const std::list<netrange_t>&packed_dims() const;
@ -50,12 +60,14 @@ class netvector_t : public nettype_base_t {
private:
std::list<netrange_t> packed_dims_;
ivl_variable_type_t type_;
bool signed_ : 1;
bool isint_ : 1; // original type of integer
bool is_scalar_ : 1;
};
inline netvector_t::netvector_t(const std::list<netrange_t>&packed,
ivl_variable_type_t type)
: packed_dims_(packed), type_(type)
: packed_dims_(packed), type_(type), signed_(false)
{
}

View File

@ -112,10 +112,10 @@ NetNet*pad_to_width_signed(Design*des, NetNet*net, unsigned wid,
des->add_node(se);
netvector_t*tmp_vec = new netvector_t(net->data_type(), wid-1, 0);
tmp_vec->set_signed(true);
NetNet*tmp = new NetNet(scope, scope->local_symbol(), NetNet::WIRE, tmp_vec);
tmp->set_line(info);
tmp->local_flag(true);
tmp->set_signed(true);
connect(tmp->pin(0), se->pin(0));
connect(se->pin(1), net->pin(0));

View File

@ -265,7 +265,7 @@ extern "C" unsigned ivl_enum_width(ivl_enumtype_t net)
extern "C" int ivl_enum_signed(ivl_enumtype_t net)
{
assert(net);
return net->has_sign();
return net->get_signed();
}
extern "C" const char*ivl_enum_file(ivl_enumtype_t net)