Skip to content

Commit

Permalink
minimal reproduce Nested Instantiate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sequencer committed Apr 19, 2024
1 parent 03ef61f commit 1a5f6f9
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package experimental.hierarchy

import chisel3._
import chisel3.util.Valid
import chisel3.properties._
import chisel3.experimental.hierarchy._
import circt.stage.ChiselStage.convert
import chisel3.experimental.{ExtModule, IntrinsicModule}
Expand Down Expand Up @@ -163,13 +164,26 @@ object InstantiateSpec {
@public val in = IO(Input(UInt(8.W)))
@public val out = IO(Output(UInt(8.W)))
}

@instantiable
class Bar extends Module {
@public val o = IO(Output(Bool()))
@public val i = IO(Input(Bool()))
o := i
}
@instantiable
class Foo(i: Int) extends Module {
val bar = Instantiate(new Bar)
}
}


class ParameterizedReset(hasAsyncNotSyncReset: Boolean) extends Module {
override def resetType = if (hasAsyncNotSyncReset) Module.ResetType.Asynchronous else Module.ResetType.Synchronous
}

class InstantiateSpec extends ChiselFunSpec with Utils {

import InstantiateSpec._

describe("Module classes that take no arguments") {
Expand Down Expand Up @@ -475,4 +489,12 @@ class InstantiateSpec extends ChiselFunSpec with Utils {
)
)
}

it("Nested Instantiate should work") {
class MyTop extends Top {
val inst0 = Instantiate(new Foo(1))
val inst1 = Instantiate(new Foo(2))
}
assert(convert(new MyTop).modules.map(_.name).sorted == Seq("Top", "Foo", "Foo_1", "Bar").sorted)
}
}

0 comments on commit 1a5f6f9

Please sign in to comment.