Skip to content

Commit

Permalink
Module: reset layerStack (#4407)
Browse files Browse the repository at this point in the history
Fixes #4404.
  • Loading branch information
dtzSiFive committed Sep 19, 2024
1 parent fc4de1f commit 15a25ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/scala/chisel3/ModuleImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private[chisel3] trait ObjectModuleImpl {

val parent = Builder.currentModule
val parentWhenStack = Builder.whenStack
val parentLayerStack = Builder.layerStack

// Save then clear clock and reset to prevent leaking scope, must be set again in the Module
// Note that Disable is a function of whatever the current reset is, so it does not need a port
Expand All @@ -78,6 +79,7 @@ private[chisel3] trait ObjectModuleImpl {
// - set currentModule
// - unset readyForModuleConstr
// - reset whenStack to be empty
// - reset layerStack to be root :: nil
// - set currentClockAndReset
val module: T = bc // bc is actually evaluated here

Expand All @@ -102,6 +104,7 @@ private[chisel3] trait ObjectModuleImpl {
// scope of the current Module.
Builder.currentModule = parent // Back to parent!
Builder.whenStack = parentWhenStack
Builder.layerStack = parentLayerStack
Builder.currentClock = saveClock // Back to clock and reset scope
Builder.currentReset = saveReset
Builder.setPrefix(savePrefix)
Expand Down Expand Up @@ -460,6 +463,7 @@ package experimental {

Builder.currentModule = Some(this)
Builder.whenStack = Nil
Builder.layerStack = layer.Layer.root :: Nil
}

//
Expand Down
24 changes: 24 additions & 0 deletions src/test/scala/chiselTests/LayerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ class LayerSpec extends ChiselFlatSpec with Utils with MatchesAndOmits {
matchesAndOmits(ChiselStage.emitCHIRRTL(new Foo))()("layerblock")
}

they should "generate valid CHIRRTL when module instantiated under layer block has layer blocks" in {
object A extends layer.Layer(layer.LayerConfig.Inline) {
object B extends layer.Layer(layer.LayerConfig.Inline)
}
class Bar extends RawModule {
layer.block(A.B) {
val w = WireInit(Bool(), true.B)
}
}

class Foo extends RawModule {
layer.block(A) {
val bar = Module(new Bar())
}
}

// Check the generated CHIRRTL only.
// Layer-under-module-under-layer is rejected by firtool presently.
matchesAndOmits(ChiselStage.emitCHIRRTL(new Foo))(
// Whitespace shows nested under another block.
" layerblock B : "
)()
}

they should "allow for defines to layer-colored probes" in {

class Foo extends RawModule {
Expand Down

0 comments on commit 15a25ff

Please sign in to comment.