Handle unpacked array types for $bits()

For unpacked statically sized array types $bits() is supposed to return the
total size of the array. Accumulated the number of unpacked dimensions and
multiply it by the packed with of the base type to get the right result.

Signed-off-by: Lars-Peter Clausen <[email protected]>
This commit is contained in:
Lars-Peter Clausen
2022-02-13 15:03:49 +01:00
parent c76db2867c
commit c4feb89957
+19 -3
View File
@@ -1727,9 +1727,25 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope,
uint64_t use_width = 0; uint64_t use_width = 0;
if (PETypename*type_expr = dynamic_cast<PETypename*>(expr)) { if (PETypename*type_expr = dynamic_cast<PETypename*>(expr)) {
ivl_type_t tmp_type = type_expr->get_type()->elaborate_type(des, scope); ivl_type_t data_type = type_expr->get_type()->elaborate_type(des, scope);
ivl_assert(*this, tmp_type); ivl_assert(*this, data_type);
use_width = tmp_type->packed_width(); use_width = 1;
while (const netuarray_t *utype =
dynamic_cast<const netuarray_t*>(data_type)) {
const vector<netrange_t> &dims = utype->static_dimensions();
for (size_t i = 0; i < dims.size(); i++)
use_width *= dims[i].width();
data_type = utype->element_type();
}
if (!data_type->packed()) {
use_width = 0;
cerr << get_fileline() << ": error: "
<< "Invalid data type for $bits()."
<< endl;
des->errors++;
} else {
use_width *= data_type->packed_width();
}
if (debug_elaborate) { if (debug_elaborate) {
cerr << get_fileline() << ": PECallFunction::elaborate_sfunc_: " cerr << get_fileline() << ": PECallFunction::elaborate_sfunc_: "
<< " Packed width of type argument is " << use_width << endl; << " Packed width of type argument is " << use_width << endl;