From c4feb899570b7eae7dd1b863b8ad4752409d6ff8 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 7 Feb 2022 11:39:36 +0100 Subject: [PATCH] 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 --- elab_expr.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index a6cb6b447..0a5e31536 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -1727,9 +1727,25 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope, uint64_t use_width = 0; if (PETypename*type_expr = dynamic_cast(expr)) { - ivl_type_t tmp_type = type_expr->get_type()->elaborate_type(des, scope); - ivl_assert(*this, tmp_type); - use_width = tmp_type->packed_width(); + ivl_type_t data_type = type_expr->get_type()->elaborate_type(des, scope); + ivl_assert(*this, data_type); + use_width = 1; + while (const netuarray_t *utype = + dynamic_cast(data_type)) { + const vector &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) { cerr << get_fileline() << ": PECallFunction::elaborate_sfunc_: " << " Packed width of type argument is " << use_width << endl;