Add helper function to get parameter line info

The NetScope class has a method called find_parameter() that looks up the
parameter and returns a iterator to it. This is only ever used to get the
line information of the parameter.

Refactor the function so that it only returns the line info. This will
allow to call this function on a const NetScope object.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-02-19 12:28:05 +01:00
parent cc0a8c8dd2
commit 892622bf64
3 changed files with 9 additions and 13 deletions

View File

@ -5091,8 +5091,7 @@ NetExpr* PEIdent::elaborate_expr_param_bit_(Design*des, NetScope*scope,
/* Create a parameter reference for the variable select. */
NetEConstParam*ptmp = new NetEConstParam(found_in, name, par_ex->value());
NetScope::param_ref_t pref = found_in->find_parameter(name);
ptmp->set_line((*pref).second);
ptmp->set_line(found_in->get_parameter_line_info(name));
NetExpr*tmp = new NetESelect(ptmp, sel, 1);
tmp->set_line(*this);
@ -5298,8 +5297,7 @@ NetExpr* PEIdent::elaborate_expr_param_idx_up_(Design*des, NetScope*scope,
/* Create a parameter reference for the variable select. */
NetEConstParam*ptmp = new NetEConstParam(found_in, name, par_ex->value());
NetScope::param_ref_t pref = found_in->find_parameter(name);
ptmp->set_line((*pref).second);
ptmp->set_line(found_in->get_parameter_line_info(name));
NetExpr*tmp = new NetESelect(ptmp, base, wid, IVL_SEL_IDX_UP);
tmp->set_line(*this);
@ -5380,8 +5378,7 @@ NetExpr* PEIdent::elaborate_expr_param_idx_do_(Design*des, NetScope*scope,
/* Create a parameter reference for the variable select. */
NetEConstParam*ptmp = new NetEConstParam(found_in, name, par_ex->value());
NetScope::param_ref_t pref = found_in->find_parameter(name);
ptmp->set_line((*pref).second);
ptmp->set_line(found_in->get_parameter_line_info(name));
NetExpr*tmp = new NetESelect(ptmp, base, wid, IVL_SEL_IDX_DOWN);
tmp->set_line(*this);
@ -5500,8 +5497,7 @@ NetExpr* PEIdent::elaborate_expr_param_(Design*des,
/* The numeric parameter value needs to have the file and line
* information for the actual parameter not the expression. */
assert(tmp);
NetScope::param_ref_t pref = found_in->find_parameter(name);
tmp->set_line((*pref).second);
tmp->set_line(found_in->get_parameter_line_info(name));
}
return tmp;

View File

@ -460,18 +460,18 @@ const NetExpr* NetScope::get_parameter(Design*des, perm_string key,
return tmp;
}
NetScope::param_ref_t NetScope::find_parameter(perm_string key)
LineInfo NetScope::get_parameter_line_info(perm_string key) const
{
map<perm_string,param_expr_t>::iterator idx;
map<perm_string,param_expr_t>::const_iterator idx;
idx = parameters.find(key);
if (idx != parameters.end()) return idx;
if (idx != parameters.end()) return idx->second;
// To get here the parameter must already exist, so we should
// never get here.
assert(0);
// But return something to avoid a compiler warning.
return idx;
return LineInfo();
}
void NetScope::print_type(ostream&stream) const

View File

@ -1239,7 +1239,7 @@ class NetScope : public Definitions, public Attrib {
typedef std::map<perm_string,param_expr_t>::iterator param_ref_t;
param_ref_t find_parameter(perm_string name);
LineInfo get_parameter_line_info(perm_string name) const;
/* Module instance arrays are collected here for access during
the multiple elaboration passes. */