From 484846ab3e9f28408298d603c26114db71af4887 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 6 Jan 2022 15:41:18 +0100 Subject: [PATCH] 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`. Signed-off-by: Lars-Peter Clausen --- design_dump.cc | 9 --------- elab_sig.cc | 2 +- expr_synth.cc | 2 +- netlist.cc | 18 ++++-------------- netlist.h | 2 +- netmisc.cc | 15 --------------- netmisc.h | 3 --- nettypes.h | 1 - netvector.h | 6 ------ 9 files changed, 7 insertions(+), 51 deletions(-) diff --git a/design_dump.cc b/design_dump.cc index 533abf6c4..c1e74325d 100644 --- a/design_dump.cc +++ b/design_dump.cc @@ -409,15 +409,6 @@ static inline ostream&operator<<(ostream&out, const netrange_t&that) return out; } -ostream&operator<<(ostream&out, const list&rlist) -{ - for (list::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() diff --git a/elab_sig.cc b/elab_sig.cc index fd5b92427..0c8ec6f39 100644 --- a/elab_sig.cc +++ b/elab_sig.cc @@ -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 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(type)) { diff --git a/expr_synth.cc b/expr_synth.cc index f8105e679..fe10f0c28 100644 --- a/expr_synth.cc +++ b/expr_synth.cc @@ -846,7 +846,7 @@ NetNet *NetEArrayPattern::synthesize(Design *des, NetScope *scope, NetExpr *root if (dim > type_dims.size()) return nullptr; - std::list 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; diff --git a/netlist.cc b/netlist.cc index e3c232d1e..c77f9ff1c 100644 --- a/netlist.cc +++ b/netlist.cc @@ -518,19 +518,9 @@ void NetNet::initialize_dir_() } } -static unsigned calculate_count(const list&unpacked) +static unsigned calculate_count(const netranges_t &unpacked) { - unsigned long sum = 1; - for (list::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&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_(); diff --git a/netlist.h b/netlist.h index d242363eb..aaadc089f 100644 --- a/netlist.h +++ b/netlist.h @@ -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&unpacked, + const netranges_t &unpacked, ivl_type_t type); explicit NetNet(NetScope*s, perm_string n, Type t, ivl_type_t type); diff --git a/netmisc.cc b/netmisc.cc index 99f28cb44..5f391fe04 100644 --- a/netmisc.cc +++ b/netmisc.cc @@ -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&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&indices, NetExpr*base, const NetNet*reg) { diff --git a/netmisc.h b/netmisc.h index 13dbcaee2..fcc483b75 100644 --- a/netmisc.h +++ b/netmisc.h @@ -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&dims, - unsigned long wid, bool is_up); /* * Calculate a canonicalizing expression for a bit select, when the diff --git a/nettypes.h b/nettypes.h index 6362b6de4..5726d8751 100644 --- a/nettypes.h +++ b/nettypes.h @@ -148,7 +148,6 @@ class netrange_t { long lsb_; }; -extern std::ostream&operator << (std::ostream&out, const std::list&rlist); extern std::ostream&operator << (std::ostream&out, const netranges_t&rlist); extern unsigned long netrange_width(const netranges_t &dims, diff --git a/netvector.h b/netvector.h index e2ea71152..11de49657 100644 --- a/netvector.h +++ b/netvector.h @@ -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&packed, - ivl_variable_type_t type); - // special case: there is a single packed dimension and we // know it in the form [:]. This step saves me // creating a netrange_t for this single item.