Add support for explicit cast to packed struct and packed array

Currently explicit cast is supported to atom2 and vector types. packed
struct, packed array and enum are not supported.

An explicit cast to packed type works the same for all packed types though.

Add support for handling also packed structs, packed arrays and enums by
make the code more generic and querying the packed base type from the
ivl_type_t.

To correctly handle enums a bit more work is necessary, which will be done
in a follow up patch.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-01-15 23:09:19 +01:00
parent be06e293f6
commit 25dae60bb6
2 changed files with 9 additions and 11 deletions

View File

@ -1007,6 +1007,7 @@ class PECastType : public PExpr {
private:
data_type_t* target_;
ivl_type_t target_type_;
PExpr* base_;
};

View File

@ -3351,25 +3351,25 @@ NetExpr* PECastSize::elaborate_expr(Design*des, NetScope*scope,
unsigned PECastType::test_width(Design*des, NetScope*scope, width_mode_t&)
{
ivl_type_t t = target_->elaborate_type(des, scope);
target_type_ = target_->elaborate_type(des, scope);
width_mode_t tmp_mode = PExpr::SIZED;
base_->test_width(des, scope, tmp_mode);
if (const netdarray_t*use_darray = dynamic_cast<const netdarray_t*>(t)) {
if (const netdarray_t*use_darray = dynamic_cast<const netdarray_t*>(target_type_)) {
expr_type_ = use_darray->element_base_type();
expr_width_ = use_darray->element_width();
} else if (const netstring_t*use_string = dynamic_cast<const netstring_t*>(t)) {
} else if (const netstring_t*use_string = dynamic_cast<const netstring_t*>(target_type_)) {
expr_type_ = use_string->base_type();
expr_width_ = 8;
} else {
expr_type_ = t->base_type();
expr_width_ = t->packed_width();
expr_type_ = target_type_->base_type();
expr_width_ = target_type_->packed_width();
}
min_width_ = expr_width_;
signed_flag_ = t->get_signed();
signed_flag_ = target_type_->get_signed();
return expr_width_;
}
@ -3427,11 +3427,8 @@ NetExpr* PECastType::elaborate_expr(Design*des, NetScope*scope,
}
NetExpr*tmp = 0;
if (dynamic_cast<const atom2_type_t*>(target_)) {
tmp = cast_to_int2(sub, expr_width_);
}
if (const vector_type_t*vec = dynamic_cast<const vector_type_t*>(target_)) {
switch (vec->base_type) {
if (target_type_ && target_type_->packed()) {
switch (target_type_->base_type()) {
case IVL_VT_BOOL:
tmp = cast_to_int2(sub, expr_width_);
break;