Skip to content

Commit 43de442

Browse files
authored
Fix asTypeOf for Clock (#1258) (#1265)
(cherry picked from commit 8edca94)
1 parent 023b576 commit 43de442

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

chiselFrontend/src/main/scala/chisel3/Clock.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ sealed class Clock(private[chisel3] val width: Width = Width(1)) extends Element
3333
override def do_asUInt(implicit sourceInfo: SourceInfo, connectCompileOptions: CompileOptions): UInt = pushOp(DefPrim(sourceInfo, UInt(this.width), AsUIntOp, ref)) // scalastyle:ignore line.size.limit
3434
private[chisel3] override def connectFromBits(that: Bits)(implicit sourceInfo: SourceInfo,
3535
compileOptions: CompileOptions): Unit = {
36-
this := that
36+
this := that.asBool.asClock
3737
}
3838
}

src/test/scala/chiselTests/AsTypeOfTester.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ class ResetAsTypeOfBoolTester extends BasicTester {
7070
stop()
7171
}
7272

73+
class AsTypeOfClockTester extends BasicTester {
74+
class MyBundle extends Bundle {
75+
val x = UInt(4.W)
76+
val y = Clock()
77+
}
78+
assert(true.B.asTypeOf(Clock()).asUInt.asBool === true.B)
79+
80+
assert(0x1f.U.asTypeOf(new MyBundle).asUInt === 0x1f.U)
81+
stop()
82+
}
83+
7384
class AsChiselEnumTester extends BasicTester {
7485
object MyEnum extends ChiselEnum {
7586
val foo, bar = Value
@@ -137,4 +148,8 @@ class AsTypeOfSpec extends ChiselFlatSpec {
137148
it should "work for casting to and from ChiselEnums" in {
138149
assertTesterPasses(new AsChiselEnumTester)
139150
}
151+
152+
it should "work for casting to and from Clock" in {
153+
assertTesterPasses(new AsTypeOfClockTester)
154+
}
140155
}

0 commit comments

Comments
 (0)