Skip to content

Commit 2282351

Browse files
Merge pull request #4118 from povik/fix-conn-on-wire-delete
rtlil: Fix handling of connections on wire deletion
2 parents 4585d60 + ea3dc7c commit 2282351

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

kernel/rtlil.cc

+32-11
Original file line numberDiff line numberDiff line change
@@ -2157,17 +2157,10 @@ 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+
// If a deleted wire occurs on the lhs or rhs we just remove that part
2161+
// of the assignment
2162+
lhs.remove2(*wires_p, &rhs);
2163+
rhs.remove2(*wires_p, &lhs);
21712164
}
21722165
};
21732166

@@ -4238,6 +4231,34 @@ void RTLIL::SigSpec::remove2(const std::set<RTLIL::SigBit> &pattern, RTLIL::SigS
42384231
check();
42394232
}
42404233

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

tests/various/bug4082.ys

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
read_verilog <<EOF
2+
module top;
3+
wire a;
4+
wire b;
5+
assign a = b;
6+
endmodule
7+
EOF
8+
delete w:a

0 commit comments

Comments
 (0)