NetNet: Pass unpacked dimensions as `std::vector` instead of `std::list`

Most places in the code use a std::vector for array dimensions.
The only exception is the constructor of NetNet, which uses
a `std::list` to pass the unpacked dimensions. But to store the
unpacked dimensions it also uses a `std::vector`.

There does not seem to be a good reason why the constructor
has to take a `std::list`, so switch it also to `std::vector`.

This allows to simplify the code and remove some special handling
for `std::list<netrange_t>`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-01-06 15:41:18 +01:00
parent 763907b0e5
commit 484846ab3e
9 changed files with 7 additions and 51 deletions

View File

@ -409,15 +409,6 @@ static inline ostream&operator<<(ostream&out, const netrange_t&that)
return out;
}
ostream&operator<<(ostream&out, const list<netrange_t>&rlist)
{
for (list<netrange_t>::const_iterator cur = rlist.begin()
; cur != rlist.end() ; ++cur) {
out << *cur;
}
return out;
}
ostream&operator<<(ostream&out, const netranges_t&rlist)
{
for (netranges_t::const_iterator cur = rlist.begin()

View File

@ -1175,7 +1175,7 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
// unpacked_dimensions are empty this will just return the base type.
type = elaborate_array_type(des, scope, *this, type, unpacked_);
list<netrange_t> unpacked_dimensions;
netranges_t unpacked_dimensions;
// If this is an unpacked array extract the base type and unpacked
// dimensions as these are separate properties of the NetNet.
while (const netuarray_t *atype = dynamic_cast<const netuarray_t*>(type)) {

View File

@ -846,7 +846,7 @@ NetNet *NetEArrayPattern::synthesize(Design *des, NetScope *scope, NetExpr *root
if (dim > type_dims.size())
return nullptr;
std::list<netrange_t> dims(type_dims.end() - dim, type_dims.end());
netranges_t dims(type_dims.end() - dim, type_dims.end());
if (dims.front().width() != items_.size())
return nullptr;

View File

@ -518,19 +518,9 @@ void NetNet::initialize_dir_()
}
}
static unsigned calculate_count(const list<netrange_t>&unpacked)
static unsigned calculate_count(const netranges_t &unpacked)
{
unsigned long sum = 1;
for (list<netrange_t>::const_iterator cur = unpacked.begin()
; cur != unpacked.end() ; ++cur) {
// Special case: If there are any undefined dimensions,
// then give up on trying to create pins for the net.
if (! cur->defined())
return 0;
sum *= cur->width();
}
unsigned long sum = netrange_width(unpacked);
if (sum >= UINT_MAX)
return 0;
@ -564,11 +554,11 @@ void NetNet::calculate_slice_widths_from_packed_dims_(void)
}
NetNet::NetNet(NetScope*s, perm_string n, Type t,
const list<netrange_t>&unpacked, ivl_type_t use_net_type)
const netranges_t&unpacked, ivl_type_t use_net_type)
: NetObj(s, n, calculate_count(unpacked)),
type_(t), port_type_(NOT_A_PORT),
local_flag_(false), net_type_(use_net_type),
discipline_(0), unpacked_dims_(unpacked.begin(), unpacked.end()),
discipline_(0), unpacked_dims_(unpacked),
eref_count_(0), lref_count_(0)
{
calculate_slice_widths_from_packed_dims_();

View File

@ -677,7 +677,7 @@ class NetNet : public NetObj, public PortType {
// This form is the more generic form of the constructor. For
// now, the unpacked type is not buried into an ivl_type_s object.
explicit NetNet(NetScope*s, perm_string n, Type t,
const std::list<netrange_t>&unpacked,
const netranges_t &unpacked,
ivl_type_t type);
explicit NetNet(NetScope*s, perm_string n, Type t, ivl_type_t type);

View File

@ -397,21 +397,6 @@ NetExpr *normalize_variable_base(NetExpr *base, long msb, long lsb,
return base;
}
/*
* This method is how indices should work except that the base should
* be a vector of expressions that matches the size of the dims list,
* so that we can generate an expression based on the entire packed
* vector. For now, we assert that there is only one set of dimensions.
*/
NetExpr *normalize_variable_base(NetExpr *base,
const list<netrange_t>&dims,
unsigned long wid, bool is_up)
{
ivl_assert(*base, dims.size() == 1);
const netrange_t&rng = dims.back();
return normalize_variable_base(base, rng.get_msb(), rng.get_lsb(), wid, is_up);
}
NetExpr *normalize_variable_bit_base(const list<long>&indices, NetExpr*base,
const NetNet*reg)
{

View File

@ -220,9 +220,6 @@ extern bool calculate_part(const LineInfo*li, Design*des, NetScope*scope,
extern NetExpr*normalize_variable_base(NetExpr *base, long msb, long lsb,
unsigned long wid, bool is_up,
long slice_off =0);
extern NetExpr*normalize_variable_base(NetExpr *base,
const std::list<netrange_t>&dims,
unsigned long wid, bool is_up);
/*
* Calculate a canonicalizing expression for a bit select, when the

View File

@ -148,7 +148,6 @@ class netrange_t {
long lsb_;
};
extern std::ostream&operator << (std::ostream&out, const std::list<netrange_t>&rlist);
extern std::ostream&operator << (std::ostream&out, const netranges_t&rlist);
extern unsigned long netrange_width(const netranges_t &dims,

View File

@ -28,12 +28,6 @@ class netvector_t : public ivl_type_s {
public:
explicit netvector_t(const netranges_t&packed, ivl_variable_type_t type);
// This is a variant of the vector form. Some code processes
// the list of packed ranges as a list, but we will store them
// as a vector in this constructor.
explicit netvector_t(const std::list<netrange_t>&packed,
ivl_variable_type_t type);
// special case: there is a single packed dimension and we
// know it in the form [<msb>:<lsb>]. This step saves me
// creating a netrange_t for this single item.