pform_set_data_type(): Avoid signal look-up by name

The `pform_set_data_type()` function is used to set the data type as well
as attributes on a list of signals. Currently the signals are passed as a
list of signal names and then the function looks up the actual signals from
the names.

Refactor the code to directly pass a list of signals. This will allow 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-17 20:57:03 +02:00
parent 135c664adf
commit 254e9dc094
3 changed files with 36 additions and 28 deletions

22
parse.y
View File

@ -603,9 +603,12 @@ static void current_function_set_statement(const YYLTYPE&loc, std::vector<Statem
%type <statement> udp_initial udp_init_opt
%type <expr> udp_initial_expr_opt
%type <text> net_variable event_variable label_opt class_declaration_endlabel_opt
%type <wire> net_variable
%type <wires> net_variable_list
%type <text> event_variable label_opt class_declaration_endlabel_opt
%type <text> block_identifier_opt
%type <perm_strings> net_variable_list event_variable_list
%type <perm_strings> event_variable_list
%type <perm_strings> list_of_identifiers loop_variables
%type <port_list> list_of_port_identifiers list_of_variable_port_identifiers
@ -5833,23 +5836,20 @@ dimensions
net_variable
: IDENTIFIER dimensions_opt
{ perm_string name = lex_strings.make($1);
pform_makewire(@1, name, NetNet::IMPLICIT, IVL_VT_NO_TYPE, $2);
$$ = $1;
$$ = pform_makewire(@1, name, NetNet::IMPLICIT, IVL_VT_NO_TYPE, $2);
delete [] $1;
}
;
net_variable_list
: net_variable
{ std::list<perm_string>*tmp = new std::list<perm_string>;
tmp->push_back(lex_strings.make($1));
{ std::vector<PWire*> *tmp = new std::vector<PWire*>;
tmp->push_back($1);
$$ = tmp;
delete[]$1;
}
| net_variable_list ',' net_variable
{ std::list<perm_string>*tmp = $1;
tmp->push_back(lex_strings.make($3));
$$ = tmp;
delete[]$3;
{ $1->push_back($3);
$$ = $1;
}
;

View File

@ -2714,8 +2714,8 @@ static PWire* pform_get_or_make_wire(const vlltype&li, perm_string name,
* the variable/net. Other forms of pform_makewire ultimately call
* this one to create the wire and stash it.
*/
void pform_makewire(const vlltype&li, perm_string name, NetNet::Type type,
ivl_variable_type_t dt, std::list<pform_range_t> *indices)
PWire *pform_makewire(const vlltype&li, perm_string name, NetNet::Type type,
ivl_variable_type_t dt, std::list<pform_range_t> *indices)
{
PWire*cur = pform_get_or_make_wire(li, name, type, NetNet::NOT_A_PORT,
dt);
@ -2741,6 +2741,8 @@ void pform_makewire(const vlltype&li, perm_string name, NetNet::Type type,
if (indices && !indices->empty())
cur->set_unpacked_idx(*indices);
return cur;
}
void pform_makewire(const struct vlltype&li,
@ -2756,16 +2758,17 @@ void pform_makewire(const struct vlltype&li,
return;
}
list<perm_string>*names = new list<perm_string>;
std::vector<PWire*> *wires = new std::vector<PWire*>;
for (list<decl_assignment_t*>::iterator cur = assign_list->begin()
; cur != assign_list->end() ; ++ cur) {
decl_assignment_t* curp = *cur;
pform_makewire(li, curp->name, type, IVL_VT_NO_TYPE, &curp->index);
names->push_back(curp->name);
PWire *wire = pform_makewire(li, curp->name, type, IVL_VT_NO_TYPE,
&curp->index);
wires->push_back(wire);
}
pform_set_data_type(li, data_type, names, type, attr);
pform_set_data_type(li, data_type, wires, type, attr);
while (! assign_list->empty()) {
decl_assignment_t*first = assign_list->front();
@ -3350,7 +3353,9 @@ void pform_set_port_type(const struct vlltype&li,
* This function detects the derived class for the given type and
* dispatches the type to the proper subtype function.
*/
void pform_set_data_type(const struct vlltype&li, data_type_t*data_type, list<perm_string>*names, NetNet::Type net_type, list<named_pexpr_t>*attr)
void pform_set_data_type(const struct vlltype&li, data_type_t*data_type,
std::vector<PWire*> *wires, NetNet::Type net_type,
list<named_pexpr_t>*attr)
{
ivl_variable_type_t vt;
if (data_type == 0) {
@ -3380,16 +3385,15 @@ void pform_set_data_type(const struct vlltype&li, data_type_t*data_type, list<pe
vt = data_type->figure_packed_base_type();
}
for (list<perm_string>::iterator cur = names->begin()
; cur != names->end() ; ++ cur ) {
PWire*wire = pform_get_wire_in_scope(*cur);
for (std::vector<PWire*>::iterator it= wires->begin();
it != wires->end() ; ++it) {
PWire *wire = *it;
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);
bool rc = wire->set_wire_type(net_type);
ivl_assert(li, rc);
rc = wire->set_data_type(vt);
@ -3404,7 +3408,7 @@ void pform_set_data_type(const struct vlltype&li, data_type_t*data_type, list<pe
pform_bind_attributes(wire->attributes, attr, true);
}
delete names;
delete wires;
}
vector<PWire*>* pform_make_udp_input_ports(list<perm_string>*names)

14
pform.h
View File

@ -347,10 +347,10 @@ extern PForeach* pform_make_foreach(const struct vlltype&loc,
* The makewire functions announce to the pform code new wires. These
* go into a module that is currently opened.
*/
extern void pform_makewire(const struct vlltype&li, perm_string name,
NetNet::Type type,
ivl_variable_type_t dt,
std::list<pform_range_t> *indices);
extern PWire *pform_makewire(const struct vlltype&li, perm_string name,
NetNet::Type type,
ivl_variable_type_t dt,
std::list<pform_range_t> *indices);
/* This form handles assignment declarations. */
@ -380,7 +380,11 @@ extern void pform_set_port_type(const struct vlltype&li,
data_type_t*dt,
std::list<named_pexpr_t>*attr);
extern void pform_set_data_type(const struct vlltype&li, data_type_t*, std::list<perm_string>*names, NetNet::Type net_type, std::list<named_pexpr_t>*attr);
extern void pform_set_data_type(const struct vlltype&li,
data_type_t *data_type,
std::vector<PWire*> *wires,
NetNet::Type net_type,
std::list<named_pexpr_t>*attr);
extern void pform_set_string_type(const struct vlltype&li, const string_type_t*string_type, std::list<perm_string>*names, NetNet::Type net_type, std::list<named_pexpr_t>*attr);