From 675dd91403eb220f82d8400eb6e4a7501ff1e42b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 6 Nov 2014 16:21:24 +0100 Subject: [PATCH] ivl: Added sign checking & casting between integers of different size. --- elab_expr.cc | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index a17a6bd2b..685e404f2 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -2440,34 +2440,19 @@ unsigned PECastType::test_width(Design*des, NetScope*scope, width_mode_t&wid) if(const netdarray_t*use_darray = dynamic_cast (t)) { expr_type_ = use_darray->element_base_type(); expr_width_ = use_darray->element_width(); - signed_flag_= false; } else if(const netstring_t*use_string = dynamic_cast (t)) { expr_type_ = use_string->base_type(); expr_width_ = 8; - signed_flag_= false; - } - - else if(const netstruct_t*use_struct = dynamic_cast (t)) { - ivl_assert(*this, use_struct->packed()); - expr_type_ = use_struct->base_type(); - expr_width_ = use_struct->packed_width(); - signed_flag_= false; - } - - else if(const netvector_t*use_vector = dynamic_cast (t)) { - ivl_assert(*this, use_vector->packed()); - expr_type_ = use_vector->base_type(); - expr_width_ = use_vector->packed_width(); - signed_flag_= false; } else { + expr_type_ = t->base_type(); expr_width_ = t->packed_width(); - signed_flag_= false; } + signed_flag_= t->get_signed(); min_width_ = expr_width_; return expr_width_; } @@ -2482,9 +2467,12 @@ NetExpr* PECastType::elaborate_expr(Design*des, NetScope*scope, return cast_to_real(expr); } - if(dynamic_cast(target_)) + if(const atom2_type_t*atom = dynamic_cast(target_)) { - return cast_to_int2(expr, expr_width_); + // That is how you both resize & cast to integers + ivl_assert(*this, base_->expr_width() <= expr_width_); + ivl_assert(*this, base_->has_sign() == atom->signed_flag); // no sign casting here + return new NetECast('2', expr, expr_width_, expr->has_sign()); } if(const vector_type_t*vec = dynamic_cast(target_))