Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Reg() to properly handle clocks as rvalues #3775

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/Reg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object Reg {
if (t.isConst) Builder.error("Cannot create register with constant value.")(sourceInfo)
requireNoProbeTypeModifier(t, "Cannot make a register of a Chisel type with a probe modifier.")
val reg = if (!t.mustClone(prevId)) t else t.cloneTypeFull
val clock = Node(Builder.forcedClock)
val clock = Builder.forcedClock.ref

reg.bind(RegBinding(Builder.forcedUserModule, Builder.currentWhen))
pushCommand(DefReg(sourceInfo, reg, clock))
Expand Down
49 changes: 49 additions & 0 deletions src/test/scala/chiselTests/ClockSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,53 @@ class ClockSpec extends ChiselPropSpec {
"The implicit clock is null which means the code that sets its definition has not yet executed."
)
}

property("Chisel should give a decent error message if you use an unbound Clock") {
val e = the[ChiselException] thrownBy (
ChiselStage.emitCHIRRTL(
new RawModule {
withClock(Clock()) {
val r = Reg(UInt(8.W))
}
},
args = Array("--throw-on-first-error")
)
)
e.getMessage should include(
"'Clock' must be hardware, not a bare Chisel type. Perhaps you forgot to wrap it in Wire(_) or IO(_)?"
)
}

property("Chisel should give a decent error message if you use a Clock from another scope") {
val e = the[ChiselException] thrownBy (
ChiselStage.emitCHIRRTL(
new RawModule {
override def desiredName = "Parent"
val child = Module(new RawModule {
override def desiredName = "Child"
val clock = Wire(Clock())
})
withClock(child.clock) {
val r = Reg(UInt(8.W))
}
},
args = Array("--throw-on-first-error")
)
)
e.getMessage should include(
"operand 'Child.clock: Wire[Clock]' is not visible from the current module Parent"
)
}

property("Chisel should support Clocks from views") {
import chisel3.experimental.dataview._
val chirrtl = ChiselStage.emitCHIRRTL(new RawModule {
val clock = IO(Clock())
val view = clock.viewAs[Clock]
withClock(view) {
val r = Reg(UInt(8.W))
}
})
chirrtl should include("reg r : UInt<8>, clock")
}
}
Loading