Consolidate parameter and localparam declaration handling
The code for handling parameter and localparameter declarations is very similar. Consolidate this into a single helper function. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
30c169026e
commit
ac040dae42
6
parse.y
6
parse.y
|
|
@ -5681,7 +5681,8 @@ localparam_assign_list
|
|||
parameter_assign
|
||||
: IDENTIFIER '=' expression parameter_value_ranges_opt
|
||||
{ PExpr*tmp = $3;
|
||||
pform_set_parameter(@1, lex_strings.make($1), param_data_type, tmp, $4);
|
||||
pform_set_parameter(@1, lex_strings.make($1), false, param_data_type,
|
||||
tmp, $4);
|
||||
delete[]$1;
|
||||
}
|
||||
;
|
||||
|
|
@ -5689,7 +5690,8 @@ parameter_assign
|
|||
localparam_assign
|
||||
: IDENTIFIER '=' expression
|
||||
{ PExpr*tmp = $3;
|
||||
pform_set_localparam(@1, lex_strings.make($1), param_data_type, tmp);
|
||||
pform_set_parameter(@1, lex_strings.make($1), true, param_data_type,
|
||||
tmp, 0);
|
||||
delete[]$1;
|
||||
}
|
||||
;
|
||||
|
|
|
|||
37
pform.cc
37
pform.cc
|
|
@ -3223,15 +3223,16 @@ LexicalScope::range_t* pform_parameter_value_range(bool exclude_flag,
|
|||
}
|
||||
|
||||
void pform_set_parameter(const struct vlltype&loc,
|
||||
perm_string name, data_type_t*data_type, PExpr*expr,
|
||||
perm_string name, bool is_local, data_type_t*data_type, PExpr*expr,
|
||||
LexicalScope::range_t*value_range)
|
||||
{
|
||||
LexicalScope*scope = lexical_scope;
|
||||
if (is_compilation_unit(scope) && !gn_system_verilog()) {
|
||||
VLerror(loc, "error: parameter declarations must be contained within a module.");
|
||||
VLerror(loc, "error: %s declarations must be contained within a module.",
|
||||
is_local ? "localparam" : "parameter");
|
||||
return;
|
||||
}
|
||||
if (scope == pform_cur_generate) {
|
||||
if (scope == pform_cur_generate && !is_local) {
|
||||
VLerror("parameter declarations are not permitted in generate blocks");
|
||||
return;
|
||||
}
|
||||
|
|
@ -3241,36 +3242,20 @@ void pform_set_parameter(const struct vlltype&loc,
|
|||
FILE_NAME(parm, loc);
|
||||
|
||||
add_local_symbol(scope, name, parm);
|
||||
scope->parameters[name] = parm;
|
||||
|
||||
parm->expr = expr;
|
||||
parm->data_type = data_type;
|
||||
parm->range = value_range;
|
||||
|
||||
// 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);
|
||||
}
|
||||
if (is_local) {
|
||||
scope->localparams[name] = parm;
|
||||
} else {
|
||||
scope->parameters[name] = parm;
|
||||
|
||||
void pform_set_localparam(const struct vlltype&loc,
|
||||
perm_string name, data_type_t*data_type, PExpr*expr)
|
||||
{
|
||||
LexicalScope*scope = lexical_scope;
|
||||
if (is_compilation_unit(scope) && !gn_system_verilog()) {
|
||||
VLerror(loc, "error: localparam declarations must be contained within a module.");
|
||||
return;
|
||||
// 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);
|
||||
}
|
||||
|
||||
assert(expr);
|
||||
Module::param_expr_t*parm = new Module::param_expr_t();
|
||||
FILE_NAME(parm, loc);
|
||||
|
||||
add_local_symbol(scope, name, parm);
|
||||
scope->localparams[name] = parm;
|
||||
|
||||
parm->expr = expr;
|
||||
parm->data_type = data_type;
|
||||
parm->range = 0;
|
||||
}
|
||||
|
||||
void pform_set_specparam(const struct vlltype&loc, perm_string name,
|
||||
|
|
|
|||
5
pform.h
5
pform.h
|
|
@ -432,12 +432,9 @@ extern LexicalScope::range_t* pform_parameter_value_range(bool exclude_flag,
|
|||
|
||||
extern void pform_set_parameter(const struct vlltype&loc,
|
||||
perm_string name,
|
||||
bool is_local,
|
||||
data_type_t*data_type,
|
||||
PExpr*expr, LexicalScope::range_t*value_range);
|
||||
extern void pform_set_localparam(const struct vlltype&loc,
|
||||
perm_string name,
|
||||
data_type_t*data_type,
|
||||
PExpr*expr);
|
||||
extern void pform_set_specparam(const struct vlltype&loc,
|
||||
perm_string name,
|
||||
std::list<pform_range_t>*range,
|
||||
|
|
|
|||
Loading…
Reference in New Issue