diff --git a/vhdlpp/expression_elaborate.cc b/vhdlpp/expression_elaborate.cc index 4c71d98da..bca9e743d 100644 --- a/vhdlpp/expression_elaborate.cc +++ b/vhdlpp/expression_elaborate.cc @@ -80,11 +80,7 @@ const VType*ExpName::elaborate_adjust_type_with_range_(Entity*, ScopeBase*scope, flag = lsb_->evaluate(scope, use_lsb); ivl_assert(*this, flag); - Expression*exp_msb = new ExpInteger(use_msb); - Expression*exp_lsb = new ExpInteger(use_lsb); - vector use_dims (1); - use_dims[0] = VTypeArray::range_t(exp_msb, exp_lsb); - type = new VTypeArray(array->element_type(), use_dims); + type = new VTypeArray(array->element_type(), use_msb, use_lsb); } } @@ -600,9 +596,7 @@ const VType*ExpBitstring::fit_type(Entity*, ScopeBase*, const VTypeArray*atype) int ExpBitstring::elaborate_expr(Entity*, ScopeBase*, const VType*) { int errors = 0; - std::vector range; - range.push_back(VTypeArray::range_t(new ExpInteger(value_.size() - 1), new ExpInteger(0))); - const VTypeArray*type = new VTypeArray(&primitive_STDLOGIC, range); + const VTypeArray*type = new VTypeArray(&primitive_STDLOGIC, value_.size() - 1, 0); set_type(type); return errors; } @@ -998,13 +992,8 @@ const VType*ExpString::fit_type(Entity*, ScopeBase*, const VTypeArray*atype) con // Generate an array range for this string ivl_assert(*this, range.size() == 1); - ExpInteger*use_msb = new ExpInteger(value_.size()); - ExpInteger*use_lsb = new ExpInteger(0); - FILE_NAME(use_msb, this); - FILE_NAME(use_lsb, this); - range[0] = VTypeArray::range_t(use_msb, use_lsb); - VTypeArray*type = new VTypeArray(atype->element_type(), range); + VTypeArray*type = new VTypeArray(atype->element_type(), value_.size(), 0); return type; } diff --git a/vhdlpp/vtype.cc b/vhdlpp/vtype.cc index 45ae25d39..17001977f 100644 --- a/vhdlpp/vtype.cc +++ b/vhdlpp/vtype.cc @@ -133,6 +133,12 @@ VTypeArray::VTypeArray(const VType*element, std::list*r, bool sv) } } +VTypeArray::VTypeArray(const VType*element, int msb, int lsb, bool sv) +: etype_(element), ranges_(1), signed_flag_(sv), parent_(NULL) +{ + bool down_to = msb > lsb; + ranges_[0] = range_t(new ExpInteger(msb), new ExpInteger(lsb), down_to); +} VTypeArray::~VTypeArray() { diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index 38a022e87..33bf6fc8b 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -217,8 +217,9 @@ class VTypeArray : public VType { }; public: - VTypeArray(const VType*etype, const std::vector&r, bool signed_vector =false); - VTypeArray(const VType*etype, std::list*r, bool signed_vector =false); + VTypeArray(const VType*etype, const std::vector&r, bool signed_vector = false); + VTypeArray(const VType*etype, std::list*r, bool signed_vector = false); + VTypeArray(const VType*etype, int msb, int lsb, bool signed_vector = false); ~VTypeArray(); VType*clone() const;