Skip to content

Commit

Permalink
Make implicitClock and implicitReset protected
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkoenig committed Jan 18, 2024
1 parent 39c7297 commit d64f37b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions core/src/main/scala/chisel3/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ abstract class Module extends RawModule with ImplicitClock with ImplicitReset {
final val reset: Reset = IO(Input(mkReset))(this._sourceInfo).suggestName("reset")
// TODO add a way to memoize hasBeenReset iff it is used

override def implicitClock: Clock = clock
override def implicitReset: Reset = reset
override protected def implicitClock: Clock = clock
override protected def implicitReset: Reset = reset

private[chisel3] def mkReset: Reset = {
// Top module and compatibility mode use Bool for reset
Expand Down Expand Up @@ -278,7 +278,7 @@ abstract class Module extends RawModule with ImplicitClock with ImplicitReset {
* // Define a Clock value, it need not be called "implicitClock"
* val clk = IO(Input(Clock()))
* // Implement the virtual method to tell Chisel about this Clock value
* override def implicitClock = clk
* override protected def implicitClock = clk
* // Now we have a Clock to use in this RawModule
* val reg = Reg(UInt(8.W))
* }
Expand All @@ -287,7 +287,7 @@ abstract class Module extends RawModule with ImplicitClock with ImplicitReset {
trait ImplicitClock { self: RawModule =>

/** Method that should point to the user-defined Clock */
def implicitClock: Clock
protected def implicitClock: Clock

Builder.currentClock = Some(Delayed(implicitClock))
}
Expand All @@ -304,7 +304,7 @@ trait ImplicitClock { self: RawModule =>
* // Define a Reset value, it need not be called "implicitReset"
* val rst = IO(Input(AsyncReset()))
* // Implement the virtual method to tell Chisel about this Reset value
* override def implicitReset = clk
* override protected def implicitReset = clk
* // Now we have a Reset to use in this RawModule
* // Registers also require a clock
* val clock = IO(Input(Clock()))
Expand All @@ -315,7 +315,7 @@ trait ImplicitClock { self: RawModule =>
trait ImplicitReset { self: RawModule =>

/** Method that should point to the user-defined Reset */
def implicitReset: Reset
protected def implicitReset: Reset

Builder.currentReset = Some(Delayed(implicitReset))
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/chiselTests/ClockSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ClockSpec extends ChiselPropSpec {
val in = IO(Input(UInt(8.W)))
val out = IO(Output(UInt(8.W)))
val gatedClock = (clock.asBool || gate).asClock
override def implicitClock = gatedClock
override protected def implicitClock = gatedClock

val r = Reg(UInt(8.W))
out := r
Expand All @@ -55,7 +55,7 @@ class ClockSpec extends ChiselPropSpec {
val foo = IO(Input(Bool()))
val in = IO(Input(UInt(8.W)))
val out = IO(Output(UInt(8.W)))
override val implicitClock = (!foo).asClock
override protected val implicitClock = (!foo).asClock

val r = Reg(UInt(8.W))
out := r
Expand All @@ -70,7 +70,7 @@ class ClockSpec extends ChiselPropSpec {
new RawModule with ImplicitClock {
val r = Reg(UInt(8.W))
val foo = IO(Input(Clock()))
override def implicitClock = foo
override protected def implicitClock = foo
},
args = Array("--throw-on-first-error")
)
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/chiselTests/ResetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ResetSpec extends ChiselFlatSpec with Utils {
val gate = IO(Input(Bool()))
val in = IO(Input(UInt(8.W)))
val out = IO(Output(UInt(8.W)))
override val implicitReset = reset.asBool || gate
override protected val implicitReset = reset.asBool || gate
val r = RegInit(0.U)
out := r
r := in
Expand All @@ -121,7 +121,7 @@ class ResetSpec extends ChiselFlatSpec with Utils {
val foo = IO(Input(Bool()))
val in = IO(Input(UInt(8.W)))
val out = IO(Output(UInt(8.W)))
override val implicitReset = !foo
override protected val implicitReset = !foo

val clk = IO(Input(Clock()))
val r = withClock(clk)(RegInit(0.U))
Expand Down Expand Up @@ -160,7 +160,7 @@ class ResetSpec extends ChiselFlatSpec with Utils {
new RawModule with ImplicitReset {
val r = Module.reset
val foo = IO(Input(AsyncReset()))
override def implicitReset = foo
override protected def implicitReset = foo
},
args = Array("--throw-on-first-error")
)
Expand Down

0 comments on commit d64f37b

Please sign in to comment.