Skip to content

Commit

Permalink
rtlil: Fix handling of connections on wire deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
povik committed Jan 8, 2024
1 parent 1ddb089 commit f2404d3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
45 changes: 34 additions & 11 deletions kernel/rtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2157,17 +2157,12 @@ void RTLIL::Module::remove(const pool<RTLIL::Wire*> &wires)
}

void operator()(RTLIL::SigSpec &lhs, RTLIL::SigSpec &rhs) {
log_assert(GetSize(lhs) == GetSize(rhs));
lhs.unpack();
rhs.unpack();
for (int i = 0; i < GetSize(lhs); i++) {
RTLIL::SigBit &lhs_bit = lhs.bits_[i];
RTLIL::SigBit &rhs_bit = rhs.bits_[i];
if ((lhs_bit.wire != nullptr && wires_p->count(lhs_bit.wire)) || (rhs_bit.wire != nullptr && wires_p->count(rhs_bit.wire))) {
lhs_bit = State::Sx;
rhs_bit = State::Sx;
}
}
// When a deleted wire occurs on the lhs we can just remove that part
// of the assignment
lhs.remove2(*wires_p, &rhs);

// Then replace all rhs occurrences with a dummy wire
(*this)(rhs);
}
};

Expand Down Expand Up @@ -4238,6 +4233,34 @@ void RTLIL::SigSpec::remove2(const std::set<RTLIL::SigBit> &pattern, RTLIL::SigS
check();
}

void RTLIL::SigSpec::remove2(const pool<RTLIL::Wire*> &pattern, RTLIL::SigSpec *other)
{
if (other)
cover("kernel.rtlil.sigspec.remove_other");
else
cover("kernel.rtlil.sigspec.remove");

unpack();

if (other != NULL) {
log_assert(width_ == other->width_);
other->unpack();
}

for (int i = GetSize(bits_) - 1; i >= 0; i--) {
if (bits_[i].wire != NULL && pattern.count(bits_[i].wire)) {
bits_.erase(bits_.begin() + i);
width_--;
if (other != NULL) {
other->bits_.erase(other->bits_.begin() + i);
other->width_--;
}
}
}

check();
}

RTLIL::SigSpec RTLIL::SigSpec::extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other) const
{
if (other)
Expand Down
1 change: 1 addition & 0 deletions kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ struct RTLIL::SigSpec
void remove(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other) const;
void remove2(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other);
void remove2(const std::set<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other);
void remove2(const pool<RTLIL::Wire*> &pattern, RTLIL::SigSpec *other);

void remove(int offset, int length = 1);
void remove_const();
Expand Down

0 comments on commit f2404d3

Please sign in to comment.