Skip to content

Commit

Permalink
Fix OpaqueSlot handling of contextual names (#2708)
Browse files Browse the repository at this point in the history
We need to ensure that contextual names stay contextual (ie. sensitive
to the module context which is important for naming ports).
  • Loading branch information
jackkoenig authored Aug 29, 2022
1 parent b38a239 commit cee2552
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/internal/firrtl/IR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ case class Slot(imm: Node, name: String) extends Arg {
}

case class OpaqueSlot(imm: Node) extends Arg {
override def contextualName(ctx: Component): String = imm.name
override def contextualName(ctx: Component): String = imm.contextualName(ctx)
override def name: String = imm.name
}

Expand Down
35 changes: 18 additions & 17 deletions src/test/scala/chiselTests/RecordSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,18 @@ trait RecordSpecUtils {
val in = IO(Input(new InnerRecord))
val out = IO(Output(new InnerRecord))
val inst = Module(new InnerModule)
inst.foo := in
out := inst.bar
inst.io.foo := in
out := inst.io.bar
}

class InnerModule extends Module {
val foo = IO(Input(new InnerRecord))
val bar = IO(Output(new InnerRecord))
val io = IO(new Bundle {
val foo = Input(new InnerRecord)
val bar = Output(new InnerRecord)
})

// DO NOT do this; just for testing element connections
bar.elements.head._2 := foo.elements.head._2
io.bar.elements.head._2 := io.foo.elements.head._2
}

class NamedSingleElementRecord extends Record {
Expand Down Expand Up @@ -239,25 +241,24 @@ class RecordSpec extends ChiselFlatSpec with RecordSpecUtils with Utils {
var mod: NestedRecordModule = null
ChiselStage.elaborate { mod = new NestedRecordModule; mod }
val testStrings = Seq(
mod.in.toTarget.toString(),
mod.in.k.toTarget.toString(),
mod.in.k.k.toTarget.toString(),
mod.in.elements.head._2.toTarget.toString(),
mod.in.k.elements.head._2.toTarget.toString(),
mod.in.k.k.elements.head._2.toTarget.toString()
mod.inst.io.foo.toTarget.serialize,
mod.inst.io.foo.k.toTarget.serialize,
mod.inst.io.foo.k.k.toTarget.serialize,
mod.inst.io.foo.elements.head._2.toTarget.serialize,
mod.inst.io.foo.k.elements.head._2.toTarget.serialize,
mod.inst.io.foo.k.k.elements.head._2.toTarget.serialize
)
testStrings.foreach(x => assert(x == "~NestedRecordModule|NestedRecordModule>in"))
testStrings.foreach(x => assert(x == "~NestedRecordModule|InnerModule>io.foo"))
}

they should "work correctly when connecting nested opaque type elements" in {
val nestedRecordChirrtl = ChiselStage.emitChirrtl { new NestedRecordModule }
nestedRecordChirrtl should include("input in : UInt<8>")
nestedRecordChirrtl should include("output out : UInt<8>")
nestedRecordChirrtl should include("inst.foo <= in")
nestedRecordChirrtl should include("out <= inst.bar")
nestedRecordChirrtl should include("input foo : UInt<8>")
nestedRecordChirrtl should include("output bar : UInt<8>")
nestedRecordChirrtl should include("bar <= foo")
nestedRecordChirrtl should include("inst.io.foo <= in")
nestedRecordChirrtl should include("out <= inst.io.bar")
nestedRecordChirrtl should include("output io : { flip foo : UInt<8>, bar : UInt<8>}")
nestedRecordChirrtl should include("io.bar <= io.foo")
}

they should "throw an error when map contains a named element and opaqueType is overriden to true" in {
Expand Down

0 comments on commit cee2552

Please sign in to comment.