From 1410c339de9e0a6fbb8840a96a09b63e0bcd8d6d Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 4 Jul 2008 11:36:11 +0100 Subject: [PATCH] Make sure any calls to numeric_std Resize have correct type The signed/unsigned-ness of an expression needs to be preserved over any call to Resize. Also add a sanity check to make sure non-vector types are not resized. --- tgt-vhdl/vhdl_syntax.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index abf274ec1..764898033 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -417,7 +417,15 @@ vhdl_expr *vhdl_expr::cast(const vhdl_type *to) vhdl_expr *vhdl_expr::resize(int newwidth) { - vhdl_type *rtype = vhdl_type::nsigned(newwidth); + vhdl_type *rtype; + assert(type_); + if (type_->get_name() == VHDL_TYPE_SIGNED) + rtype = vhdl_type::nsigned(newwidth); + else if (type_->get_name() == VHDL_TYPE_UNSIGNED) + rtype = vhdl_type::nunsigned(newwidth); + else + assert(false); // Doesn't make sense to resize non-vector type + vhdl_fcall *resize = new vhdl_fcall("Resize", rtype); resize->add_expr(this); resize->add_expr(new vhdl_const_int(newwidth));