PScope: Keep parameter and localparams in the same list

During parsing parameters and localparams are kept in a separate list only
to be collected into the same list during elaboration.

Store them in the same list during parsing as well, this allows to remove
some duplicated code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-02-09 22:30:12 +01:00
parent bc0fc4ab89
commit 1207e908b1
6 changed files with 23 additions and 75 deletions

View File

@ -415,8 +415,6 @@ void PEIdent::declare_implicit_nets(LexicalScope*scope, NetNet::Type type)
while (ss) {
if (ss->wires.find(name) != ss->wires.end())
return;
if (ss->localparams.find(name) != ss->localparams.end())
return;
if (ss->parameters.find(name) != ss->parameters.end())
return;
if (ss->genvars.find(name) != ss->genvars.end())

View File

@ -100,18 +100,20 @@ class LexicalScope {
is elaborated. During parsing, I put the parameters into
this map. */
struct param_expr_t : public PNamedItem {
inline param_expr_t() : data_type(0), expr(0), range(0) { }
inline param_expr_t() : data_type(0), expr(0), range(0),
local_flag(false) { }
// Type information.
data_type_t*data_type;
// Value expression
PExpr*expr;
// If there are range constraints, list them here
range_t*range;
// Whether it is a local parameter
bool local_flag;
SymbolType symbol_type() const;
};
std::map<perm_string,param_expr_t*>parameters;
std::map<perm_string,param_expr_t*>localparams;
// Defined types in the scope.
std::map<perm_string,data_type_t*>typedefs;
@ -155,8 +157,6 @@ class LexicalScope {
void dump_parameters_(std::ostream&out, unsigned indent) const;
void dump_localparams_(std::ostream&out, unsigned indent) const;
void dump_enumerations_(std::ostream&out, unsigned indent) const;
void dump_events_(std::ostream&out, unsigned indent) const;

View File

@ -68,7 +68,7 @@ typedef map<perm_string,LexicalScope::param_expr_t*>::const_iterator mparm_it_t;
static void collect_parm_item(Design*des, NetScope*scope, perm_string name,
const LexicalScope::param_expr_t&cur,
bool is_annotatable, bool local_flag)
bool is_annotatable)
{
if (debug_scopes) {
cerr << cur.get_fileline() << ": " << __func__ << ": "
@ -125,7 +125,8 @@ static void collect_parm_item(Design*des, NetScope*scope, perm_string name,
// not yet known, don't try to guess here, put the type guess off. Also
// don't try to elaborate it here, because there may be references to
// other parameters still being located during scope elaboration.
scope->set_parameter(name, is_annotatable, cur.expr, cur.data_type, local_flag, range_list, cur);
scope->set_parameter(name, is_annotatable, cur.expr, cur.data_type,
cur.local_flag, range_list, cur);
}
@ -140,22 +141,7 @@ static void collect_scope_parameters(Design*des, NetScope*scope,
for (mparm_it_t cur = parameters.begin()
; cur != parameters.end() ; ++ cur ) {
collect_parm_item(des, scope, cur->first, *(cur->second), false, false);
}
}
static void collect_scope_localparams(Design*des, NetScope*scope,
const map<perm_string,LexicalScope::param_expr_t*>&localparams)
{
if (debug_scopes) {
cerr << scope->get_fileline() << ": " << __func__ << ": "
<< "collect localparams for " << scope_path(scope) << "." << endl;
}
for (mparm_it_t cur = localparams.begin()
; cur != localparams.end() ; ++ cur ) {
collect_parm_item(des, scope, cur->first, *(cur->second), false, true);
collect_parm_item(des, scope, cur->first, *(cur->second), false);
}
}
@ -170,7 +156,7 @@ static void collect_scope_specparams(Design*des, NetScope*scope,
for (mparm_it_t cur = specparams.begin()
; cur != specparams.end() ; ++ cur ) {
collect_parm_item(des, scope, cur->first, *(cur->second), true, false);
collect_parm_item(des, scope, cur->first, *(cur->second), true);
}
}
@ -765,7 +751,6 @@ bool PPackage::elaborate_scope(Design*des, NetScope*scope)
scope->add_typedefs(&typedefs);
collect_scope_parameters(des, scope, parameters);
collect_scope_localparams(des, scope, localparams);
if (debug_scopes) {
cerr << get_fileline() << ": PPackage::elaborate_scope: "
@ -805,8 +790,6 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,
collect_scope_parameters(des, scope, parameters);
collect_scope_localparams(des, scope, localparams);
collect_scope_specparams(des, scope, specparams);
// Run parameter replacements that were collected from the
@ -1278,11 +1261,11 @@ void PGenerate::elaborate_subscope_(Design*des, NetScope*scope)
scope->add_genvar((*cur).first, (*cur).second);
}
// Scan the localparams in this scope, and store the information
// Scan the parameters in this scope, and store the information
// needed to evaluate the parameter expressions. The expressions
// will be evaluated later, once all parameter overrides for this
// module have been done.
collect_scope_localparams(des, scope, localparams);
collect_scope_parameters(des, scope, parameters);
// Run through the defparams for this scope and save the result
// in a table for later final override.
@ -1621,8 +1604,6 @@ void PFunction::elaborate_scope(Design*des, NetScope*scope) const
collect_scope_parameters(des, scope, parameters);
collect_scope_localparams(des, scope, localparams);
// Scan through all the named events in this scope.
elaborate_scope_events_(des, scope, events);
@ -1641,8 +1622,6 @@ void PTask::elaborate_scope(Design*des, NetScope*scope) const
collect_scope_parameters(des, scope, parameters);
collect_scope_localparams(des, scope, localparams);
// Scan through all the named events in this scope.
elaborate_scope_events_(des, scope, events);
@ -1691,8 +1670,6 @@ void PBlock::elaborate_scope(Design*des, NetScope*scope) const
collect_scope_parameters(des, my_scope, parameters);
collect_scope_localparams(des, my_scope, localparams);
// Scan through all the named events in this scope.
elaborate_scope_events_(des, my_scope, events);
}

View File

@ -6958,7 +6958,6 @@ static void check_timescales()
// We don't need a timescale if the compilation unit
// contains no items outside a design element.
if (pp->parameters.empty() &&
pp->localparams.empty() &&
pp->wires.empty() &&
pp->tasks.empty() &&
pp->funcs.empty() &&
@ -7018,7 +7017,6 @@ static void check_timescales()
continue;
if (pp->parameters.empty() &&
pp->localparams.empty() &&
pp->wires.empty() &&
pp->tasks.empty() &&
pp->funcs.empty() &&

View File

@ -3246,16 +3246,14 @@ void pform_set_parameter(const struct vlltype&loc,
parm->expr = expr;
parm->data_type = data_type;
parm->range = value_range;
parm->local_flag = is_local;
if (is_local) {
scope->localparams[name] = parm;
} else {
scope->parameters[name] = parm;
scope->parameters[name] = parm;
// Only a Module keeps the position of the parameter.
if ((dynamic_cast<Module*>(scope)) && (scope == pform_cur_module.front()))
pform_cur_module.front()->param_names.push_back(name);
}
// Only a module keeps the position of the parameter.
if (!is_local &&
(dynamic_cast<Module*>(scope)) && (scope == pform_cur_module.front()))
pform_cur_module.front()->param_names.push_back(name);
}
void pform_set_specparam(const struct vlltype&loc, perm_string name,

View File

@ -863,8 +863,6 @@ void PBlock::dump(ostream&out, unsigned ind) const
if (pscope_name() != 0) {
dump_parameters_(out, ind+2);
dump_localparams_(out, ind+2);
dump_events_(out, ind+2);
dump_wires_(out, ind+2);
@ -1133,8 +1131,6 @@ void PFunction::dump(ostream&out, unsigned ind) const
dump_parameters_(out, ind+2);
dump_localparams_(out, ind+2);
dump_events_(out, ind+2);
dump_wires_(out, ind+2);
@ -1207,8 +1203,6 @@ void PTask::dump(ostream&out, unsigned ind) const
dump_parameters_(out, ind+2);
dump_localparams_(out, ind+2);
dump_events_(out, ind+2);
dump_wires_(out, ind+2);
@ -1412,7 +1406,7 @@ void PGenerate::dump(ostream&out, unsigned indent) const
out << endl;
dump_localparams_(out, indent+2);
dump_parameters_(out, indent+2);
typedef list<PGenerate::named_expr_t>::const_iterator parm_hiter_t;
for (parm_hiter_t cur = defparms.begin()
@ -1482,7 +1476,11 @@ void LexicalScope::dump_parameters_(ostream&out, unsigned indent) const
typedef map<perm_string,param_expr_t*>::const_iterator parm_iter_t;
for (parm_iter_t cur = parameters.begin()
; cur != parameters.end() ; ++ cur ) {
out << setw(indent) << "" << "parameter ";
out << setw(indent) << "";
if (cur->second->local_flag)
out << "localparam ";
else
out << "parameter ";
if (cur->second->data_type)
cur->second->data_type->debug_dump(out);
else
@ -1524,24 +1522,6 @@ void LexicalScope::dump_parameters_(ostream&out, unsigned indent) const
}
}
void LexicalScope::dump_localparams_(ostream&out, unsigned indent) const
{
typedef map<perm_string,param_expr_t*>::const_iterator parm_iter_t;
for (parm_iter_t cur = localparams.begin()
; cur != localparams.end() ; ++ cur ) {
out << setw(indent) << "" << "localparam ";
if (cur->second->data_type) {
cur->second->data_type->debug_dump(out);
out << " ";
}
out << (*cur).first << " = ";
if ((*cur).second->expr)
out << *(*cur).second->expr << ";" << endl;
else
out << "/* ERROR */;" << endl;
}
}
void LexicalScope::dump_enumerations_(ostream&out, unsigned indent) const
{
for (vector<enum_type_t*>::const_iterator cur = enum_sets.begin()
@ -1695,8 +1675,6 @@ void Module::dump(ostream&out) const
dump_parameters_(out, 4);
dump_localparams_(out, 4);
dump_specparams_(out, 4);
dump_enumerations_(out, 4);
@ -1847,7 +1825,6 @@ void pform_dump(std::ostream&out, const PPackage*pac)
void PPackage::pform_dump(std::ostream&out) const
{
out << "package " << pscope_name() << endl;
dump_localparams_(out, 4);
dump_parameters_(out, 4);
dump_typedefs_(out, 4);
dump_enumerations_(out, 4);