Skip to content

Commit

Permalink
Fix chisel3 <> for Bundles that contain compatibility Bundles (backport
Browse files Browse the repository at this point in the history
#2023) (#2026)

* Fix chisel3 <> for Bundles that contain compatibility Bundles (#2023)

BiConnect in chisel3 delegates to FIRRTL <- semantics whenever it hits a
Bundle defined in `import Chisel._`. Because chisel3 <> is commutative
it needs to be mindful of flippedness when emitting a FIRRTL <- (which
is *not* commutative).

(cherry picked from commit 16c0b53)

* Fix test issue in Scala 2.11

Co-authored-by: Jack Koenig <[email protected]>
  • Loading branch information
mergify[bot] and jackkoenig authored Jul 9, 2021
1 parent 48203e6 commit 1153de8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
25 changes: 17 additions & 8 deletions core/src/main/scala/chisel3/internal/BiConnect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,23 @@ private[chisel3] object BiConnect {
}
}
}
// Handle Records defined in Chisel._ code (change to NotStrict)
case (left_r: Record, right_r: Record) => (left_r.compileOptions, right_r.compileOptions) match {
case (ExplicitCompileOptions.NotStrict, _) =>
left_r.bulkConnect(right_r)(sourceInfo, ExplicitCompileOptions.NotStrict)
case (_, ExplicitCompileOptions.NotStrict) =>
left_r.bulkConnect(right_r)(sourceInfo, ExplicitCompileOptions.NotStrict)
case _ => recordConnect(sourceInfo, connectCompileOptions, left_r, right_r, context_mod)
}
// Handle Records defined in Chisel._ code by emitting a FIRRTL partial connect
case pair @ (left_r: Record, right_r: Record) =>
val notStrict =
Seq(left_r.compileOptions, right_r.compileOptions).contains(ExplicitCompileOptions.NotStrict)
if (notStrict) {
// chisel3 <> is commutative but FIRRTL <- is not
val flipped = {
// Everything is flipped when it's the port of a child
val childPort = left_r._parent.get != context_mod
val isFlipped = left_r.direction == ActualDirection.Bidirectional(ActualDirection.Flipped)
isFlipped ^ childPort
}
val (newLeft, newRight) = if (flipped) pair.swap else pair
newLeft.bulkConnect(newRight)(sourceInfo, ExplicitCompileOptions.NotStrict)
} else {
recordConnect(sourceInfo, connectCompileOptions, left_r, right_r, context_mod)
}

// Handle Records connected to DontCare (change to NotStrict)
case (left_r: Record, DontCare) =>
Expand Down
40 changes: 40 additions & 0 deletions src/test/scala/chiselTests/CompatibilityInteroperabilitySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,45 @@ class CompatibiltyInteroperabilitySpec extends ChiselFlatSpec {
}
}
}

"A chisel3 Bundle that instantiates a Chisel Bundle" should "bulk connect correctly" in {
compile {
object Compat {
import Chisel._
class Foo extends Bundle {
val a = Input(UInt(8.W))
val b = Output(UInt(8.W))
}
}
import chisel3._
import Compat._
class Bar extends Bundle {
val foo1 = new Foo
val foo2 = Flipped(new Foo)
override def cloneType = (new Bar).asInstanceOf[this.type]
}
// Check every connection both ways to see that chisel3 <>'s commutativity holds
class Child extends RawModule {
val deq = IO(new Bar)
val enq = IO(Flipped(new Bar))
enq <> deq
deq <> enq
}
class Top extends RawModule {
val deq = IO(new Bar)
val enq = IO(Flipped(new Bar))
// Also important to check connections to child ports
val c1 = Module(new Child)
val c2 = Module(new Child)
c1.enq <> enq
enq <> c1.enq
c2.enq <> c1.deq
c1.deq <> c2.enq
deq <> c2.deq
c2.deq <> deq
}
new Top
}
}
}

0 comments on commit 1153de8

Please sign in to comment.