Skip to content

Commit f2404d3

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

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

kernel/rtlil.cc

+34-11
Original file line numberDiff line numberDiff line change
@@ -2157,17 +2157,12 @@ void RTLIL::Module::remove(const pool<RTLIL::Wire*> &wires)
21572157
}
21582158

21592159
void operator()(RTLIL::SigSpec &lhs, RTLIL::SigSpec &rhs) {
2160-
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-
}
2160+
// When a deleted wire occurs on the lhs we can just remove that part
2161+
// of the assignment
2162+
lhs.remove2(*wires_p, &rhs);
2163+
2164+
// Then replace all rhs occurrences with a dummy wire
2165+
(*this)(rhs);
21712166
}
21722167
};
21732168

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

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