Add support for param declarations with signed type but no range
The standard allows a parameter (or localparam) declaration of the form "parameter signed my_param = ...". The parser currently rejects this. A small adjustment is also required in the parameter evaluation code to correctly apply the type.
This commit is contained in:
parent
c96619527a
commit
2b67a6d465
|
|
@ -150,19 +150,6 @@ static void elaborate_parm_item_(perm_string name,
|
|||
return;
|
||||
}
|
||||
|
||||
if (signed_flag) {
|
||||
/* If explicitly signed, then say so. */
|
||||
val->cast_signed(true);
|
||||
} else if (cur.msb) {
|
||||
/* If there is a range, then the signedness comes
|
||||
from the type and not the expression. */
|
||||
val->cast_signed(signed_flag);
|
||||
} else {
|
||||
/* otherwise, let the expression describe
|
||||
itself. */
|
||||
signed_flag = val->has_sign();
|
||||
}
|
||||
|
||||
val = scope->set_parameter(name, val, cur.type, msb, lsb, signed_flag,
|
||||
range_list, cur);
|
||||
delete val;
|
||||
|
|
|
|||
|
|
@ -389,10 +389,10 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur)
|
|||
return;
|
||||
}
|
||||
|
||||
/* If the parameter has range information, then make
|
||||
sure the value is set right. Note that if the
|
||||
parameter doesn't have an explicit range, then it
|
||||
will get the signedness from the expression itself. */
|
||||
/* If the parameter has type or range information, then make
|
||||
sure the type is set right. Note that if the parameter
|
||||
doesn't have an explicit type or range, then it will get
|
||||
the signedness from the expression itself. */
|
||||
if (range_flag) {
|
||||
unsigned long wid = (msb >= lsb)? msb - lsb : lsb - msb;
|
||||
wid += 1;
|
||||
|
|
@ -420,6 +420,8 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur)
|
|||
val = new NetEConst(tmp);
|
||||
(*cur).second.expr = expr = val;
|
||||
}
|
||||
} else if ((*cur).second.signed_flag) {
|
||||
(*cur).second.expr->cast_signed(true);
|
||||
}
|
||||
|
||||
// If there are no value ranges to test the value against,
|
||||
|
|
|
|||
20
parse.y
20
parse.y
|
|
@ -2635,6 +2635,16 @@ parameter_assign_decl
|
|||
param_active_signed = false;
|
||||
param_active_type = IVL_VT_LOGIC;
|
||||
}
|
||||
| K_signed
|
||||
{ param_active_range = 0;
|
||||
param_active_signed = true;
|
||||
param_active_type = IVL_VT_LOGIC;
|
||||
}
|
||||
parameter_assign_list
|
||||
{ param_active_range = 0;
|
||||
param_active_signed = false;
|
||||
param_active_type = IVL_VT_LOGIC;
|
||||
}
|
||||
| K_signed range
|
||||
{ param_active_range = $2;
|
||||
param_active_signed = true;
|
||||
|
|
@ -2764,6 +2774,16 @@ localparam_assign_decl
|
|||
param_active_signed = false;
|
||||
param_active_type = IVL_VT_LOGIC;
|
||||
}
|
||||
| K_signed
|
||||
{ param_active_range = 0;
|
||||
param_active_signed = true;
|
||||
param_active_type = IVL_VT_LOGIC;
|
||||
}
|
||||
localparam_assign_list
|
||||
{ param_active_range = 0;
|
||||
param_active_signed = false;
|
||||
param_active_type = IVL_VT_LOGIC;
|
||||
}
|
||||
| K_signed range
|
||||
{ param_active_range = $2;
|
||||
param_active_signed = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue