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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-04-18 11:01:54 +02:00
parent e815d37c25
commit 135c664adf
1 changed files with 17 additions and 34 deletions

View File

@ -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<pform_range_t>*range,
bool signed_flag,
PWSRType rt,
std::list<named_pexpr_t>*attr)
PWSRType rt = SR_NET,
std::list<named_pexpr_t>*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<perm_string>*names,
list<pform_range_t>*range,
bool signed_flag,
std::list<named_pexpr_t>*attr)
{
for (list<perm_string>::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<pform_port_t>::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, list<pe
if (uarray_type)
data_type = uarray_type->base_type;
if (vector_type_t*vec_type = dynamic_cast<vector_type_t*> (data_type)) {
pform_set_net_range(names, vec_type->pdims.get(),
vec_type->signed_flag, 0);
vector_type_t*vec_type = dynamic_cast<vector_type_t*> (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, list<pe
; cur != names->end() ; ++ 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);