summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormergify[bot]2022-10-23 19:01:43 +0000
committerGitHub2022-10-23 19:01:43 +0000
commitd997acb05e5a307afb7c9ad4c136b9b4e1506efc (patch)
tree57756efa278459f31cbadce539f6f1a0d7e679f7
parent80b3b28f451efa85be50994f732599f043f83d86 (diff)
Don't invalidate ExtModule ports in an explicitInvalidate = true context (backport #2795) (#2799)
* Don't invalidate ExtModule ports in an explicitInvalidate = true context (#2795) * Don't invalidate ExtModule ports in an explicitInvalidate = true context ExtModule ports were previously invalidated in the emitted FIRRTL, which is correct in a NonStrict / `Chisel._` compatibility context but not in newer chisel3 code where `explicitInvalidate = true`. (cherry picked from commit 8e24a281545d25f6501dcc872eabdfb30bacd69d) # Conflicts: # core/src/main/scala/chisel3/BlackBox.scala * Resolve backport conflicts Co-authored-by: Jared Barocsi <82000041+jared-barocsi@users.noreply.github.com> Co-authored-by: Jack Koenig <koenig@sifive.com>
-rw-r--r--core/src/main/scala/chisel3/BlackBox.scala12
-rw-r--r--docs/src/cookbooks/cookbook.md2
-rw-r--r--src/test/scala/chiselTests/CompatibilitySpec.scala22
-rw-r--r--src/test/scala/chiselTests/ExtModule.scala17
-rw-r--r--src/test/scala/chiselTests/aop/InjectionSpec.scala1
5 files changed, 50 insertions, 4 deletions
diff --git a/core/src/main/scala/chisel3/BlackBox.scala b/core/src/main/scala/chisel3/BlackBox.scala
index f618901f..c3cb3e66 100644
--- a/core/src/main/scala/chisel3/BlackBox.scala
+++ b/core/src/main/scala/chisel3/BlackBox.scala
@@ -92,8 +92,10 @@ package experimental {
private[chisel3] def initializeInParent(parentCompileOptions: CompileOptions): Unit = {
implicit val sourceInfo = UnlocatableSourceInfo
- for (x <- getModulePorts) {
- pushCommand(DefInvalid(sourceInfo, x.ref))
+ if (!parentCompileOptions.explicitInvalidate) {
+ for (x <- getModulePorts) {
+ pushCommand(DefInvalid(sourceInfo, x.ref))
+ }
}
}
}
@@ -192,8 +194,10 @@ abstract class BlackBox(
}
private[chisel3] def initializeInParent(parentCompileOptions: CompileOptions): Unit = {
- for ((_, port) <- _io.map(_.elements).getOrElse(Nil)) {
- pushCommand(DefInvalid(UnlocatableSourceInfo, port.ref))
+ if (!parentCompileOptions.explicitInvalidate) {
+ for ((_, port) <- _io.map(_.elements).getOrElse(Nil)) {
+ pushCommand(DefInvalid(UnlocatableSourceInfo, port.ref))
+ }
}
}
}
diff --git a/docs/src/cookbooks/cookbook.md b/docs/src/cookbooks/cookbook.md
index ac3a0c5d..e7485e66 100644
--- a/docs/src/cookbooks/cookbook.md
+++ b/docs/src/cookbooks/cookbook.md
@@ -791,6 +791,8 @@ class Salt extends Module {
val io = IO(new Bundle {})
val drink = Module(new Coffee)
override def desiredName = "SodiumMonochloride"
+
+ drink.io.I := 42.U
}
```
diff --git a/src/test/scala/chiselTests/CompatibilitySpec.scala b/src/test/scala/chiselTests/CompatibilitySpec.scala
index 41cfbec4..5a3b43e6 100644
--- a/src/test/scala/chiselTests/CompatibilitySpec.scala
+++ b/src/test/scala/chiselTests/CompatibilitySpec.scala
@@ -614,4 +614,26 @@ class CompatibiltySpec extends ChiselFlatSpec with ScalaCheckDrivenPropertyCheck
ChiselStage.elaborate(new MyModule)
}
+ behavior.of("BlackBox")
+
+ it should "have invalidated ports in a compatibility context" in {
+ class ExtModuleInvalidatedTester extends Module {
+ val io = IO(new Bundle {
+ val in = Input(UInt(8.W))
+ val out = Output(UInt(8.W))
+ })
+ val inst = Module(new BlackBox {
+ val io = IO(new Bundle {
+ val in = Input(UInt(8.W))
+ val out = Output(UInt(8.W))
+ })
+ })
+ inst.io.in := io.in
+ io.out := inst.io.out
+ }
+
+ val chirrtl = ChiselStage.emitChirrtl(new ExtModuleInvalidatedTester)
+ chirrtl should include("inst.in is invalid")
+ chirrtl should include("inst.out is invalid")
+ }
}
diff --git a/src/test/scala/chiselTests/ExtModule.scala b/src/test/scala/chiselTests/ExtModule.scala
index b5a8ff7c..3ab4cc32 100644
--- a/src/test/scala/chiselTests/ExtModule.scala
+++ b/src/test/scala/chiselTests/ExtModule.scala
@@ -88,6 +88,17 @@ class ExtModuleWithFlatIOTester extends Module {
io <> inst.badIO
}
+class ExtModuleInvalidatedTester extends Module {
+ val in = IO(Input(UInt(8.W)))
+ val out = IO(Output(UInt(8.W)))
+ val inst = Module(new ExtModule {
+ val in = IO(Input(UInt(8.W)))
+ val out = IO(Output(UInt(8.W)))
+ })
+ inst.in := in
+ out := inst.out
+}
+
class ExtModuleSpec extends ChiselFlatSpec {
"A ExtModule inverter" should "work" in {
assertTesterPasses({ new ExtModuleTester }, Seq("/chisel3/BlackBoxTest.v"), TesterDriver.verilatorOnly)
@@ -117,4 +128,10 @@ class ExtModuleSpec extends ChiselFlatSpec {
chirrtl should include("inst.in <= io.in")
chirrtl shouldNot include("badIO")
}
+
+ it should "not have invalidated ports in a chisel3._ context" in {
+ val chirrtl = ChiselStage.emitChirrtl(new ExtModuleInvalidatedTester)
+ chirrtl shouldNot include("inst.in is invalid")
+ chirrtl shouldNot include("inst.out is invalid")
+ }
}
diff --git a/src/test/scala/chiselTests/aop/InjectionSpec.scala b/src/test/scala/chiselTests/aop/InjectionSpec.scala
index 9b29b0ba..1b69efa3 100644
--- a/src/test/scala/chiselTests/aop/InjectionSpec.scala
+++ b/src/test/scala/chiselTests/aop/InjectionSpec.scala
@@ -108,6 +108,7 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
{ _: SubmoduleManipulationTester =>
// By creating a second SubmoduleA, the module names would conflict unless they were uniquified
val moduleSubmoduleC = Module(new SubmoduleC)
+ moduleSubmoduleC.io <> DontCare
//if we're here then we've elaborated correctly
stop()
}