From 3e551ef38fb4c01b9b46f45dc68c2d9f5c9e9acb Mon Sep 17 00:00:00 2001 From: mergify[bot] Date: Mon, 25 Apr 2022 23:19:37 +0000 Subject: Fix error message for BlackBox without val io <: Record (#2504) (#2505) (cherry picked from commit f9aee1f72744abc6ee13aafc4d1a51a2783cbab8) Co-authored-by: Jack Koenig --- core/src/main/scala/chisel3/BlackBox.scala | 2 +- src/test/scala/chiselTests/BlackBox.scala | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/chisel3/BlackBox.scala b/core/src/main/scala/chisel3/BlackBox.scala index 2f04fb2e..f3fc2711 100644 --- a/core/src/main/scala/chisel3/BlackBox.scala +++ b/core/src/main/scala/chisel3/BlackBox.scala @@ -157,7 +157,7 @@ abstract class BlackBox( _compatAutoWrapPorts() // pre-IO(...) compatibility hack // Restrict IO to just io, clock, and reset - if (!_io.forall(portsContains)) { + if (!_io.exists(portsContains)) { throwException(s"BlackBox '$this' must have a port named 'io' of type Record wrapped in IO(...)!") } diff --git a/src/test/scala/chiselTests/BlackBox.scala b/src/test/scala/chiselTests/BlackBox.scala index 27cdbbc4..f923a94a 100644 --- a/src/test/scala/chiselTests/BlackBox.scala +++ b/src/test/scala/chiselTests/BlackBox.scala @@ -145,6 +145,17 @@ class BlackBoxTypeParam(w: Int, raw: String) extends BlackBox(Map("T" -> RawPara }) } +class BlackBoxNoIO extends BlackBox { + // Whoops! typo + val ioo = IO(new Bundle { + val out = Output(UInt(8.W)) + }) +} + +class BlackBoxUIntIO extends BlackBox { + val io = IO(Output(UInt(8.W))) +} + class BlackBoxWithParamsTester extends BasicTester { val blackBoxOne = Module(new BlackBoxConstant(1)) val blackBoxFour = Module(new BlackBoxConstant(4)) @@ -192,7 +203,23 @@ class BlackBoxSpec extends ChiselFlatSpec { assert(DataMirror.modulePorts(m) == Seq("in" -> m.io.in, "out" -> m.io.out)) }) } - "A BlackBoxed using suggestName(\"io\")" should "work (but don't do this)" in { + "A BlackBox using suggestName(\"io\")" should "work (but don't do this)" in { assertTesterPasses({ new BlackBoxTesterSuggestName }, Seq("/chisel3/BlackBoxTest.v"), TesterDriver.verilatorOnly) } + + "A BlackBox with no 'val io'" should "give a reasonable error message" in { + (the[ChiselException] thrownBy { + ChiselStage.elaborate(new Module { + val inst = Module(new BlackBoxNoIO) + }) + }).getMessage should include("must have a port named 'io' of type Record") + } + + "A BlackBox with non-Record 'val io'" should "give a reasonable error message" in { + (the[ChiselException] thrownBy { + ChiselStage.elaborate(new Module { + val inst = Module(new BlackBoxUIntIO) + }) + }).getMessage should include("must have a port named 'io' of type Record") + } } -- cgit v1.2.3