From d4765e33542690b6019cebe9efb4de20d1e23f13 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 8 Oct 2022 13:08:59 +0200 Subject: [PATCH] Don't implement `packed_width()` for dynamic array types The `netdarray_t` type implements the `packed_width()` method by returning the packed width of the element type. It is the only non-packed type that implements the method. This triggers an assert in the vlog95 backend for tasks with dynamic array typed parameters. And while the vlog95 backend does not support dynamic array types it should not result in a crash, just an error message. The only place that relies on the behavior that the packed width of the element type is returned is in the vvp backend where variable declarations are generated. Update that code to query the packed width of the element type instead and then remove the `packed_width()` implementation for the `netdarray_t` type. This fixes the assert in the vlog95 backend. But it is also nicer from an architectural perspective as this brings the type in line with the other types in terms of behavior. Signed-off-by: Lars-Peter Clausen --- netdarray.h | 3 --- tgt-vvp/vvp_scope.c | 10 ++++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/netdarray.h b/netdarray.h index 890995ad1..326f07d4c 100644 --- a/netdarray.h +++ b/netdarray.h @@ -36,9 +36,6 @@ class netdarray_t : public netarray_t { // A dynamic array may have a type that is signed. inline bool get_signed() const { return element_type()->get_signed(); } - // Use the packed width to pass the element width - long packed_width() const { return element_type()->packed_width(); } - // This is the base_type() of the element of the array. We // need this in some cases in order to get the base type of // the element, and not the IVL_VT_DARRAY of the array itself. diff --git a/tgt-vvp/vvp_scope.c b/tgt-vvp/vvp_scope.c index 140a2020e..58b94c9be 100644 --- a/tgt-vvp/vvp_scope.c +++ b/tgt-vvp/vvp_scope.c @@ -540,15 +540,21 @@ static void draw_reg_in_scope(ivl_signal_t sig) swapped ? first: last, swapped ? last : first, msb, lsb); } else if (ivl_signal_data_type(sig) == IVL_VT_DARRAY) { + ivl_type_t var_type = ivl_signal_net_type(sig); + ivl_type_t element_type = ivl_type_element(var_type); + fprintf(vvp_out, "v%p_0 .var/darray \"%s\", %u;%s\n", sig, vvp_mangle_name(ivl_signal_basename(sig)), - ivl_signal_width(sig), + ivl_type_packed_width(element_type), ivl_signal_local(sig)? " Local signal" : ""); } else if (ivl_signal_data_type(sig) == IVL_VT_QUEUE) { + ivl_type_t var_type = ivl_signal_net_type(sig); + ivl_type_t element_type = ivl_type_element(var_type); + fprintf(vvp_out, "v%p_0 .var/queue \"%s\", %u;%s\n", sig, vvp_mangle_name(ivl_signal_basename(sig)), - ivl_signal_width(sig), + ivl_type_packed_width(element_type), ivl_signal_local(sig)? " Local signal" : ""); } else if (ivl_signal_data_type(sig) == IVL_VT_STRING) {