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
|
parameter_assign
|
||||||
: IDENTIFIER '=' expression parameter_value_ranges_opt
|
: IDENTIFIER '=' expression parameter_value_ranges_opt
|
||||||
{ PExpr*tmp = $3;
|
{ 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;
|
delete[]$1;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
@ -5689,7 +5690,8 @@ parameter_assign
|
||||||
localparam_assign
|
localparam_assign
|
||||||
: IDENTIFIER '=' expression
|
: IDENTIFIER '=' expression
|
||||||
{ PExpr*tmp = $3;
|
{ 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;
|
delete[]$1;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
|
||||||
33
pform.cc
33
pform.cc
|
|
@ -3223,15 +3223,16 @@ LexicalScope::range_t* pform_parameter_value_range(bool exclude_flag,
|
||||||
}
|
}
|
||||||
|
|
||||||
void pform_set_parameter(const struct vlltype&loc,
|
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::range_t*value_range)
|
||||||
{
|
{
|
||||||
LexicalScope*scope = lexical_scope;
|
LexicalScope*scope = lexical_scope;
|
||||||
if (is_compilation_unit(scope) && !gn_system_verilog()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (scope == pform_cur_generate) {
|
if (scope == pform_cur_generate && !is_local) {
|
||||||
VLerror("parameter declarations are not permitted in generate blocks");
|
VLerror("parameter declarations are not permitted in generate blocks");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -3241,36 +3242,20 @@ void pform_set_parameter(const struct vlltype&loc,
|
||||||
FILE_NAME(parm, loc);
|
FILE_NAME(parm, loc);
|
||||||
|
|
||||||
add_local_symbol(scope, name, parm);
|
add_local_symbol(scope, name, parm);
|
||||||
scope->parameters[name] = parm;
|
|
||||||
|
|
||||||
parm->expr = expr;
|
parm->expr = expr;
|
||||||
parm->data_type = data_type;
|
parm->data_type = data_type;
|
||||||
parm->range = value_range;
|
parm->range = value_range;
|
||||||
|
|
||||||
|
if (is_local) {
|
||||||
|
scope->localparams[name] = parm;
|
||||||
|
} else {
|
||||||
|
scope->parameters[name] = parm;
|
||||||
|
|
||||||
// Only a Module keeps the position of the parameter.
|
// Only a Module keeps the position of the parameter.
|
||||||
if ((dynamic_cast<Module*>(scope)) && (scope == pform_cur_module.front()))
|
if ((dynamic_cast<Module*>(scope)) && (scope == pform_cur_module.front()))
|
||||||
pform_cur_module.front()->param_names.push_back(name);
|
pform_cur_module.front()->param_names.push_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
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,
|
extern void pform_set_parameter(const struct vlltype&loc,
|
||||||
perm_string name,
|
perm_string name,
|
||||||
|
bool is_local,
|
||||||
data_type_t*data_type,
|
data_type_t*data_type,
|
||||||
PExpr*expr, LexicalScope::range_t*value_range);
|
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,
|
extern void pform_set_specparam(const struct vlltype&loc,
|
||||||
perm_string name,
|
perm_string name,
|
||||||
std::list<pform_range_t>*range,
|
std::list<pform_range_t>*range,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue