From 51983edc5666b42ac17d67a10ef5fdacf2aec7e2 Mon Sep 17 00:00:00 2001 From: Adam Izraelevitz Date: Fri, 17 Jan 2020 15:52:57 -0800 Subject: [PATCH] Bugfix: Select.instances now works with blackboxes (#1303) (cherry picked from commit 0a98a82c588882eb2905a5564792670c2cfaf858) --- src/main/scala/chisel3/aop/Select.scala | 7 +++++-- src/test/scala/chiselTests/aop/SelectSpec.scala | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/scala/chisel3/aop/Select.scala b/src/main/scala/chisel3/aop/Select.scala index 612cdcc7a24..390f82a5a6a 100644 --- a/src/main/scala/chisel3/aop/Select.scala +++ b/src/main/scala/chisel3/aop/Select.scala @@ -80,8 +80,11 @@ object Select { */ def instances(module: BaseModule): Seq[BaseModule] = { check(module) - module._component.get.asInstanceOf[DefModule].commands.collect { - case i: DefInstance => i.id + module._component.get match { + case d: DefModule => d.commands.collect { + case i: DefInstance => i.id + } + case other => Nil } } diff --git a/src/test/scala/chiselTests/aop/SelectSpec.scala b/src/test/scala/chiselTests/aop/SelectSpec.scala index f3c756abca2..80ab518f0a1 100644 --- a/src/test/scala/chiselTests/aop/SelectSpec.scala +++ b/src/test/scala/chiselTests/aop/SelectSpec.scala @@ -7,7 +7,9 @@ import chiselTests.ChiselFlatSpec import chisel3._ import chisel3.aop.Select.{PredicatedConnect, When, WhenNot} import chisel3.aop.{Aspect, Select} -import firrtl.{AnnotationSeq} +import chisel3.experimental.ExtModule +import chisel3.stage.{ChiselGeneratorAnnotation, DesignAnnotation} +import firrtl.AnnotationSeq import scala.reflect.runtime.universe.TypeTag @@ -139,5 +141,17 @@ class SelectSpec extends ChiselFlatSpec { ) } + "Blackboxes" should "be supported in Select.instances" in { + class BB extends ExtModule { } + class Top extends RawModule { + val bb = Module(new BB) + } + val top = ChiselGeneratorAnnotation(() => { + new Top() + }).elaborate(1).asInstanceOf[DesignAnnotation[Top]].design + val bbs = Select.collectDeep(top) { case b: BB => b } + assert(bbs.size == 1) + } + }