Merge pull request #635 from larsclausen/package-var-part-select

Fix part select on variables declared in packages
This commit is contained in:
Stephen Williams 2022-03-05 19:10:16 -08:00 committed by GitHub
commit 88bddb6308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 32 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -0,0 +1,20 @@
// Check that it is possible to do a part select on a vector declared in
// package
package P;
reg [7:0] x = 8'h5a;
reg [1:0][7:0] y = 16'h5af0;
endpackage
module test;
initial begin
if (P::x[3:0] == 4'ha && P::x[7:4] == 4'h5 &&
P::y[0] == 8'hf0 && P::y[1] == 8'h5a) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -322,6 +322,7 @@ net_class_fail CE,-g2005-sv ivltests
net_darray_fail CE,-g2005-sv ivltests
net_queue_fail CE,-g2005-sv ivltests
net_string_fail CE,-g2005-sv ivltests
package_vec_part_select normal,-g2005-sv ivltests
packeda normal,-g2009 ivltests
packeda2 normal,-g2009 ivltests
parameter_in_generate2 CE,-g2005-sv ivltests

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(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)
{
}

View File

@ -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<netrange_t>&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<netrange_t>&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)
{
}

View File

@ -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_) {

View File

@ -696,7 +696,8 @@ static int find_tfb_process(ivl_process_t proc, ivl_scope_t scope)
* processes that are used to set local variables. */
assert(ivl_process_type(proc) == IVL_PR_INITIAL);
/* Find the module scope for this task/function. */
while (ivl_scope_type(mod_scope) != IVL_SCT_MODULE) {
while (ivl_scope_type(mod_scope) != IVL_SCT_MODULE &&
ivl_scope_type(mod_scope) != IVL_SCT_PACKAGE) {
mod_scope = ivl_scope_parent(mod_scope);
assert(mod_scope);
}
@ -1154,7 +1155,9 @@ int emit_scope(ivl_scope_t scope, ivl_scope_t parent)
for (idx = 0; idx < count; idx += 1) {
emit_tran(scope, ivl_scope_switch(scope, idx));
}
}
if (sc_type == IVL_SCT_MODULE || sc_type == IVL_SCT_PACKAGE) {
/* Output any initial blocks for tasks or functions or named
* blocks defined in this module. Used to initialize local
* variables. */