Skip to content

Commit 9bc72b1

Browse files
committed
rtlil: Fix handling of connections on wire deletion
1 parent 1ddb089 commit 9bc72b1

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

kernel/rtlil.cc

+35-10
Original file line numberDiff line numberDiff line change
@@ -2158,16 +2158,13 @@ void RTLIL::Module::remove(const pool<RTLIL::Wire*> &wires)
21582158

21592159
void operator()(RTLIL::SigSpec &lhs, RTLIL::SigSpec &rhs) {
21602160
log_assert(GetSize(lhs) == GetSize(rhs));
2161-
lhs.unpack();
2162-
rhs.unpack();
2163-
for (int i = 0; i < GetSize(lhs); i++) {
2164-
RTLIL::SigBit &lhs_bit = lhs.bits_[i];
2165-
RTLIL::SigBit &rhs_bit = rhs.bits_[i];
2166-
if ((lhs_bit.wire != nullptr && wires_p->count(lhs_bit.wire)) || (rhs_bit.wire != nullptr && wires_p->count(rhs_bit.wire))) {
2167-
lhs_bit = State::Sx;
2168-
rhs_bit = State::Sx;
2169-
}
2170-
}
2161+
2162+
// When a deleted wire occurs on the lhs we can just remove that part
2163+
// of the assignment
2164+
lhs.remove2(*wires_p, &rhs);
2165+
2166+
// Then replace all rhs occurrences with a dummy wire
2167+
(*this)(rhs);
21712168
}
21722169
};
21732170

@@ -4238,6 +4235,34 @@ void RTLIL::SigSpec::remove2(const std::set<RTLIL::SigBit> &pattern, RTLIL::SigS
42384235
check();
42394236
}
42404237

4238+
void RTLIL::SigSpec::remove2(const pool<RTLIL::Wire*> &pattern, RTLIL::SigSpec *other)
4239+
{
4240+
if (other)
4241+
cover("kernel.rtlil.sigspec.remove_other");
4242+
else
4243+
cover("kernel.rtlil.sigspec.remove");
4244+
4245+
unpack();
4246+
4247+
if (other != NULL) {
4248+
log_assert(width_ == other->width_);
4249+
other->unpack();
4250+
}
4251+
4252+
for (int i = GetSize(bits_) - 1; i >= 0; i--) {
4253+
if (bits_[i].wire != NULL && pattern.count(bits_[i].wire)) {
4254+
bits_.erase(bits_.begin() + i);
4255+
width_--;
4256+
if (other != NULL) {
4257+
other->bits_.erase(other->bits_.begin() + i);
4258+
other->width_--;
4259+
}
4260+
}
4261+
}
4262+
4263+
check();
4264+
}
4265+
42414266
RTLIL::SigSpec RTLIL::SigSpec::extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other) const
42424267
{
42434268
if (other)

kernel/rtlil.h

+1
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ struct RTLIL::SigSpec
924924
void remove(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other) const;
925925
void remove2(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other);
926926
void remove2(const std::set<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other);
927+
void remove2(const pool<RTLIL::Wire*> &pattern, RTLIL::SigSpec *other);
927928

928929
void remove(int offset, int length = 1);
929930
void remove_const();

0 commit comments

Comments
 (0)