From 135c664adf51edaa7d40c3e6df0ea2e8cfeb3374 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 18 Apr 2022 11:01:54 +0200 Subject: [PATCH] pform_set_net_range(): Avoid signal look-up by name The `pform_set_net_range()` function currently looks up a signal by name. But in all places where it is called the reference to the signal is already available. Refactor the code to pass the signal itself, rather than the signal name, to `pform_set_net_range()`. This allows to skip the look-up by name. Signed-off-by: Lars-Peter Clausen --- pform.cc | 51 +++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/pform.cc b/pform.cc index a1136ab4f..b1af4d61b 100644 --- a/pform.cc +++ b/pform.cc @@ -2151,42 +2151,22 @@ void pform_make_udp(const struct vlltype&loc, perm_string name, * only called by the parser within the scope of the net declaration, * and the name that I receive only has the tail component. */ -static void pform_set_net_range(perm_string name, +static void pform_set_net_range(PWire *wire, const list*range, bool signed_flag, - PWSRType rt, - std::list*attr) + PWSRType rt = SR_NET, + std::list*attr = 0) { - PWire*cur = pform_get_wire_in_scope(name); - if (cur == 0) { - VLerror("error: name is not a valid net."); - return; - } - if (range == 0) { /* This is the special case that we really mean a scalar. Set a fake range. */ - cur->set_range_scalar(rt); - + wire->set_range_scalar(rt); } else { - cur->set_range(*range, rt); - } - cur->set_signed(signed_flag); - - pform_bind_attributes(cur->attributes, attr, true); -} - -static void pform_set_net_range(list*names, - list*range, - bool signed_flag, - std::list*attr) -{ - for (list::iterator cur = names->begin() - ; cur != names->end() ; ++ cur ) { - perm_string txt = *cur; - pform_set_net_range(txt, range, signed_flag, SR_NET, attr); + wire->set_range(*range, rt); } + wire->set_signed(signed_flag); + pform_bind_attributes(wire->attributes, attr, true); } /* @@ -3288,8 +3268,8 @@ extern void pform_module_specify_path(PSpecPath*obj) } -static void pform_set_port_type(const struct vlltype&li, - perm_string name, NetNet::PortType pt) +static PWire *pform_set_port_type(const struct vlltype&li, + perm_string name, NetNet::PortType pt) { PWire*cur = pform_get_wire_in_scope(name); if (cur == 0) { @@ -3313,6 +3293,7 @@ static void pform_set_port_type(const struct vlltype&li, break; } + return cur; } void pform_set_port_type(const struct vlltype&li, @@ -3337,8 +3318,8 @@ void pform_set_port_type(const struct vlltype&li, for (list::iterator cur = ports->begin() ; cur != ports->end() ; ++ cur ) { - pform_set_port_type(li, cur->name, pt); - pform_set_net_range(cur->name, range, signed_flag, SR_PORT, attr); + PWire *wire = pform_set_port_type(li, cur->name, pt); + pform_set_net_range(wire, range, signed_flag, SR_PORT, attr); if (cur->udims) { cerr << li << ": warning: " << "Array dimensions in incomplete port declarations " @@ -3381,9 +3362,8 @@ void pform_set_data_type(const struct vlltype&li, data_type_t*data_type, listbase_type; - if (vector_type_t*vec_type = dynamic_cast (data_type)) { - pform_set_net_range(names, vec_type->pdims.get(), - vec_type->signed_flag, 0); + vector_type_t*vec_type = dynamic_cast (data_type); + if (vec_type) { vt = vec_type->base_type; } @@ -3404,6 +3384,9 @@ void pform_set_data_type(const struct vlltype&li, data_type_t*data_type, listend() ; ++ cur ) { PWire*wire = pform_get_wire_in_scope(*cur); + if (vec_type) + pform_set_net_range(wire, vec_type->pdims.get(), vec_type->signed_flag); + // If these fail there is a bug somewhere else. pform_set_data_type() // is only ever called on a fresh wire that already exists. ivl_assert(li, wire);