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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-10-08 13:08:59 +02:00
parent f831d7d76f
commit d4765e3354
2 changed files with 8 additions and 5 deletions

View File

@ -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.

View File

@ -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) {