From b207ebd51a5175d5b1a194e2468d210ee3a9ca16 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Fri, 4 Mar 2022 11:24:08 +0100 Subject: [PATCH] Fix part select on variables declared in packages The logic that decides whether a vector is scalar or not incorrectly flags all variables that are declared in packages as scalar. As a result it is not possible to do a part select on a vector declared in a package. Rather than having an independent scalar flag consider a vector as scalar if it does not have any packed dimensions. Signed-off-by: Lars-Peter Clausen --- PWire.cc | 5 ----- PWire.h | 1 - elab_sig.cc | 22 +++++----------------- netvector.cc | 4 ++-- netvector.h | 7 ++----- pform_dump.cc | 2 +- 6 files changed, 10 insertions(+), 31 deletions(-) diff --git a/PWire.cc b/PWire.cc index 72418d501..bf9b36954 100644 --- a/PWire.cc +++ b/PWire.cc @@ -160,11 +160,6 @@ bool PWire::get_isint() const return false; } -bool PWire::get_scalar() const -{ - return is_scalar_; -} - void PWire::set_range_scalar(PWSRType type) { is_scalar_ = true; diff --git a/PWire.h b/PWire.h index 0d8c44a30..f4b792538 100644 --- a/PWire.h +++ b/PWire.h @@ -71,7 +71,6 @@ class PWire : public PNamedItem { void set_signed(bool flag); bool get_signed() const; bool get_isint() const; - bool get_scalar() const; bool set_data_type(ivl_variable_type_t dt); ivl_variable_type_t get_data_type() const; diff --git a/elab_sig.cc b/elab_sig.cc index 3378902eb..47edb73d8 100644 --- a/elab_sig.cc +++ b/elab_sig.cc @@ -645,7 +645,6 @@ void PFunction::elaborate_sig(Design*des, NetScope*scope) const } } else { netvector_t*tmp = new netvector_t(IVL_VT_LOGIC); - tmp->set_scalar(true); ret_type = tmp; } @@ -951,28 +950,20 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const const long warn_dimension_size = 1 << 30; NetNet::Type wtype = type_; - bool is_implicit_scalar = false; - if (wtype == NetNet::IMPLICIT) { + if (wtype == NetNet::IMPLICIT) wtype = NetNet::WIRE; - is_implicit_scalar = true; - } + // Certain contexts, such as arguments to functions, presume // "reg" instead of "wire". The parser reports these as - // IMPLICIT_REG. Also, certain cases, such as: - // fun(string arg1) ... - // are implicitly NOT scalar, so detect that case here. - if (wtype == NetNet::IMPLICIT_REG) { + // IMPLICIT_REG. + if (wtype == NetNet::IMPLICIT_REG) wtype = NetNet::REG; - if (data_type_!=IVL_VT_STRING) - is_implicit_scalar = true; - } if (debug_elaborate) { cerr << get_fileline() << ": PWire::elaborate_sig: " << "Signal " << basename() << ", wtype=" << wtype << ", data_type_=" << data_type_ - << ", is_implicit_scalar=" << (is_implicit_scalar?"true":"false") << ", unpacked_.size()=" << unpacked_.size() << endl; } @@ -1015,7 +1006,6 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const dimensions_ok &= evaluate_ranges(des, scope, this, plist, port_); nlist = plist; /* An implicit port can have a range so note that here. */ - is_implicit_scalar = false; } assert(port_set_ || port_.empty()); @@ -1324,7 +1314,7 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const cerr << get_fileline() << ": PWire::elaborate_sig: " << "Create vector signal " << wtype << " data_type=" << data_type_; - if (!get_scalar()) { + if (!packed_dimensions.empty()) { cerr << " " << packed_dimensions; } cerr << " " << name_ << unpacked_dimensions; @@ -1349,8 +1339,6 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const netvector_t*vec = new netvector_t(packed_dimensions, use_data_type); vec->set_signed(get_signed()); vec->set_isint(get_isint()); - if (is_implicit_scalar) vec->set_scalar(true); - else vec->set_scalar(get_scalar()); packed_dimensions.clear(); sig = new NetNet(scope, name_, wtype, unpacked_dimensions, vec); diff --git a/netvector.cc b/netvector.cc index f874635e6..4d235eb22 100644 --- a/netvector.cc +++ b/netvector.cc @@ -47,13 +47,13 @@ const netvector_t* netvector_t::integer_type() netvector_t netvector_t::scalar_logic (IVL_VT_LOGIC); netvector_t::netvector_t(ivl_variable_type_t type, long msb, long lsb, bool flag) -: type_(type), signed_(flag), isint_(false), is_scalar_(false) +: type_(type), signed_(flag), isint_(false) { packed_dims_.push_back(netrange_t(msb,lsb)); } netvector_t::netvector_t(ivl_variable_type_t type) -: type_(type), signed_(false), isint_(false), is_scalar_(false) +: type_(type), signed_(false), isint_(false) { } diff --git a/netvector.h b/netvector.h index 59b7905c2..2775a718d 100644 --- a/netvector.h +++ b/netvector.h @@ -54,8 +54,7 @@ class netvector_t : public ivl_type_s { inline void set_isint(bool flag) { isint_ = flag; } inline bool get_isint(void) const { return isint_; } - inline void set_scalar(bool flag) { is_scalar_ = flag; } - inline bool get_scalar(void) const { return is_scalar_; } + inline bool get_scalar(void) const { return packed_dims_.empty(); } ivl_variable_type_t base_type() const; const std::vector&packed_dims() const; @@ -88,13 +87,11 @@ class netvector_t : public ivl_type_s { ivl_variable_type_t type_; bool signed_ : 1; bool isint_ : 1; // original type of integer - bool is_scalar_ : 1; }; inline netvector_t::netvector_t(const std::vector&pd, ivl_variable_type_t type) -: packed_dims_(pd), type_(type), signed_(false), isint_(false), - is_scalar_(false) +: packed_dims_(pd), type_(type), signed_(false), isint_(false) { } diff --git a/pform_dump.cc b/pform_dump.cc index 9367ce0d3..0c0874d00 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -587,7 +587,7 @@ void PWire::dump(ostream&out, unsigned ind) const if (get_isint()) { out << " integer"; } - if (get_scalar()) { + if (is_scalar_) { out << " scalar"; } if (set_data_type_) {