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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-03-04 11:24:08 +01:00
parent 167005f849
commit b207ebd51a
6 changed files with 10 additions and 31 deletions

View File

@ -160,11 +160,6 @@ bool PWire::get_isint() const
return false; return false;
} }
bool PWire::get_scalar() const
{
return is_scalar_;
}
void PWire::set_range_scalar(PWSRType type) void PWire::set_range_scalar(PWSRType type)
{ {
is_scalar_ = true; is_scalar_ = true;

View File

@ -71,7 +71,6 @@ class PWire : public PNamedItem {
void set_signed(bool flag); void set_signed(bool flag);
bool get_signed() const; bool get_signed() const;
bool get_isint() const; bool get_isint() const;
bool get_scalar() const;
bool set_data_type(ivl_variable_type_t dt); bool set_data_type(ivl_variable_type_t dt);
ivl_variable_type_t get_data_type() const; ivl_variable_type_t get_data_type() const;

View File

@ -645,7 +645,6 @@ void PFunction::elaborate_sig(Design*des, NetScope*scope) const
} }
} else { } else {
netvector_t*tmp = new netvector_t(IVL_VT_LOGIC); netvector_t*tmp = new netvector_t(IVL_VT_LOGIC);
tmp->set_scalar(true);
ret_type = tmp; ret_type = tmp;
} }
@ -951,28 +950,20 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
const long warn_dimension_size = 1 << 30; const long warn_dimension_size = 1 << 30;
NetNet::Type wtype = type_; NetNet::Type wtype = type_;
bool is_implicit_scalar = false; if (wtype == NetNet::IMPLICIT)
if (wtype == NetNet::IMPLICIT) {
wtype = NetNet::WIRE; wtype = NetNet::WIRE;
is_implicit_scalar = true;
}
// Certain contexts, such as arguments to functions, presume // Certain contexts, such as arguments to functions, presume
// "reg" instead of "wire". The parser reports these as // "reg" instead of "wire". The parser reports these as
// IMPLICIT_REG. Also, certain cases, such as: // IMPLICIT_REG.
// fun(string arg1) ... if (wtype == NetNet::IMPLICIT_REG)
// are implicitly NOT scalar, so detect that case here.
if (wtype == NetNet::IMPLICIT_REG) {
wtype = NetNet::REG; wtype = NetNet::REG;
if (data_type_!=IVL_VT_STRING)
is_implicit_scalar = true;
}
if (debug_elaborate) { if (debug_elaborate) {
cerr << get_fileline() << ": PWire::elaborate_sig: " cerr << get_fileline() << ": PWire::elaborate_sig: "
<< "Signal " << basename() << "Signal " << basename()
<< ", wtype=" << wtype << ", wtype=" << wtype
<< ", data_type_=" << data_type_ << ", data_type_=" << data_type_
<< ", is_implicit_scalar=" << (is_implicit_scalar?"true":"false")
<< ", unpacked_.size()=" << unpacked_.size() << ", unpacked_.size()=" << unpacked_.size()
<< endl; << endl;
} }
@ -1015,7 +1006,6 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
dimensions_ok &= evaluate_ranges(des, scope, this, plist, port_); dimensions_ok &= evaluate_ranges(des, scope, this, plist, port_);
nlist = plist; nlist = plist;
/* An implicit port can have a range so note that here. */ /* An implicit port can have a range so note that here. */
is_implicit_scalar = false;
} }
assert(port_set_ || port_.empty()); assert(port_set_ || port_.empty());
@ -1324,7 +1314,7 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const
cerr << get_fileline() << ": PWire::elaborate_sig: " cerr << get_fileline() << ": PWire::elaborate_sig: "
<< "Create vector signal " << wtype << "Create vector signal " << wtype
<< " data_type=" << data_type_; << " data_type=" << data_type_;
if (!get_scalar()) { if (!packed_dimensions.empty()) {
cerr << " " << packed_dimensions; cerr << " " << packed_dimensions;
} }
cerr << " " << name_ << unpacked_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); netvector_t*vec = new netvector_t(packed_dimensions, use_data_type);
vec->set_signed(get_signed()); vec->set_signed(get_signed());
vec->set_isint(get_isint()); vec->set_isint(get_isint());
if (is_implicit_scalar) vec->set_scalar(true);
else vec->set_scalar(get_scalar());
packed_dimensions.clear(); packed_dimensions.clear();
sig = new NetNet(scope, name_, wtype, unpacked_dimensions, vec); sig = new NetNet(scope, name_, wtype, unpacked_dimensions, vec);

View File

@ -47,13 +47,13 @@ const netvector_t* netvector_t::integer_type()
netvector_t netvector_t::scalar_logic (IVL_VT_LOGIC); netvector_t netvector_t::scalar_logic (IVL_VT_LOGIC);
netvector_t::netvector_t(ivl_variable_type_t type, long msb, long lsb, bool flag) 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)); packed_dims_.push_back(netrange_t(msb,lsb));
} }
netvector_t::netvector_t(ivl_variable_type_t type) netvector_t::netvector_t(ivl_variable_type_t type)
: type_(type), signed_(false), isint_(false), is_scalar_(false) : type_(type), signed_(false), isint_(false)
{ {
} }

View File

@ -54,8 +54,7 @@ class netvector_t : public ivl_type_s {
inline void set_isint(bool flag) { isint_ = flag; } inline void set_isint(bool flag) { isint_ = flag; }
inline bool get_isint(void) const { return isint_; } inline bool get_isint(void) const { return isint_; }
inline void set_scalar(bool flag) { is_scalar_ = flag; } inline bool get_scalar(void) const { return packed_dims_.empty(); }
inline bool get_scalar(void) const { return is_scalar_; }
ivl_variable_type_t base_type() const; ivl_variable_type_t base_type() const;
const std::vector<netrange_t>&packed_dims() const; const std::vector<netrange_t>&packed_dims() const;
@ -88,13 +87,11 @@ class netvector_t : public ivl_type_s {
ivl_variable_type_t type_; ivl_variable_type_t type_;
bool signed_ : 1; bool signed_ : 1;
bool isint_ : 1; // original type of integer bool isint_ : 1; // original type of integer
bool is_scalar_ : 1;
}; };
inline netvector_t::netvector_t(const std::vector<netrange_t>&pd, inline netvector_t::netvector_t(const std::vector<netrange_t>&pd,
ivl_variable_type_t type) ivl_variable_type_t type)
: packed_dims_(pd), type_(type), signed_(false), isint_(false), : packed_dims_(pd), type_(type), signed_(false), isint_(false)
is_scalar_(false)
{ {
} }

View File

@ -587,7 +587,7 @@ void PWire::dump(ostream&out, unsigned ind) const
if (get_isint()) { if (get_isint()) {
out << " integer"; out << " integer";
} }
if (get_scalar()) { if (is_scalar_) {
out << " scalar"; out << " scalar";
} }
if (set_data_type_) { if (set_data_type_) {