Provide type for array signals

Types for array signals are currently handled as a special case. The type
that is associated with the signal is not the array type itself but rather
the element type.

There is a fair amount of existing code that depends on this behavior so it
is not trivial to change this.

But there are certain constructs such as assignment patterns or array
concatenation where the array type itself is required.

Add a new `NetNet::array_type()` method that will return the array type if
the signal is an array. This will allow to query the array type when
needed.

`NetAssign_::net_type()` is updated to use this new method to return the
array type if the assigned signal is an array.

Long term the special handling of arrays for signals should be removed.
This will for example allow to unify the handling of arrays for signals,
class properties and struct members.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-02-04 21:18:13 -08:00
parent bc3cb04a41
commit 4defb9f51e
3 changed files with 16 additions and 4 deletions

View File

@ -149,11 +149,10 @@ ivl_type_t NetAssign_::net_type() const
} else {
ivl_assert(*this, sig_);
// We don't have types for array signals yet.
if (sig_->unpacked_dimensions() && !word_)
return nullptr;
ntype = sig_->net_type();
ntype = sig_->array_type();
else
ntype = sig_->net_type();
}
if (!member_.nil()) {

View File

@ -598,6 +598,9 @@ NetNet::NetNet(NetScope*s, perm_string n, Type t,
initialize_dir_();
if (!unpacked_dims_.empty())
array_type_ = new netuarray_t(unpacked_dims_, net_type_);
s->add_signal(this);
}
@ -733,6 +736,14 @@ const netclass_t* NetNet::class_type(void) const
return dynamic_cast<const netclass_t*> (net_type_);
}
const netarray_t* NetNet::array_type() const
{
if (array_type_)
return array_type_;
return darray_type();
}
/*
* "depth" is the number of index expressions that the user is using
* to index this identifier. So consider if Net was declared like so:

View File

@ -709,6 +709,7 @@ class NetNet : public NetObj, public PortType {
const netdarray_t*darray_type(void) const;
const netqueue_t*queue_type(void) const;
const netclass_t*class_type(void) const;
const netarray_t*array_type(void) const;
/* Attach a discipline to the net. */
ivl_discipline_t get_discipline() const;
@ -803,6 +804,7 @@ class NetNet : public NetObj, public PortType {
PortType port_type_ : 3;
bool local_flag_: 1;
ivl_type_t net_type_;
netuarray_t *array_type_ = nullptr;
ivl_discipline_t discipline_;
std::vector<netrange_t> unpacked_dims_;