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:
parent
be06e293f6
commit
25dae60bb6
1
PExpr.h
1
PExpr.h
|
|
@ -1007,6 +1007,7 @@ class PECastType : public PExpr {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
data_type_t* target_;
|
data_type_t* target_;
|
||||||
|
ivl_type_t target_type_;
|
||||||
PExpr* base_;
|
PExpr* base_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
19
elab_expr.cc
19
elab_expr.cc
|
|
@ -3351,25 +3351,25 @@ NetExpr* PECastSize::elaborate_expr(Design*des, NetScope*scope,
|
||||||
|
|
||||||
unsigned PECastType::test_width(Design*des, NetScope*scope, width_mode_t&)
|
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;
|
width_mode_t tmp_mode = PExpr::SIZED;
|
||||||
base_->test_width(des, scope, tmp_mode);
|
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_type_ = use_darray->element_base_type();
|
||||||
expr_width_ = use_darray->element_width();
|
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_type_ = use_string->base_type();
|
||||||
expr_width_ = 8;
|
expr_width_ = 8;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
expr_type_ = t->base_type();
|
expr_type_ = target_type_->base_type();
|
||||||
expr_width_ = t->packed_width();
|
expr_width_ = target_type_->packed_width();
|
||||||
}
|
}
|
||||||
min_width_ = expr_width_;
|
min_width_ = expr_width_;
|
||||||
signed_flag_ = t->get_signed();
|
signed_flag_ = target_type_->get_signed();
|
||||||
|
|
||||||
return expr_width_;
|
return expr_width_;
|
||||||
}
|
}
|
||||||
|
|
@ -3427,11 +3427,8 @@ NetExpr* PECastType::elaborate_expr(Design*des, NetScope*scope,
|
||||||
}
|
}
|
||||||
|
|
||||||
NetExpr*tmp = 0;
|
NetExpr*tmp = 0;
|
||||||
if (dynamic_cast<const atom2_type_t*>(target_)) {
|
if (target_type_ && target_type_->packed()) {
|
||||||
tmp = cast_to_int2(sub, expr_width_);
|
switch (target_type_->base_type()) {
|
||||||
}
|
|
||||||
if (const vector_type_t*vec = dynamic_cast<const vector_type_t*>(target_)) {
|
|
||||||
switch (vec->base_type) {
|
|
||||||
case IVL_VT_BOOL:
|
case IVL_VT_BOOL:
|
||||||
tmp = cast_to_int2(sub, expr_width_);
|
tmp = cast_to_int2(sub, expr_width_);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue