summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Koenig2019-12-02 16:06:16 -0800
committerGitHub2019-12-02 16:06:16 -0800
commit8edca94f94dac5e8b9a6a8793e88a7782d351401 (patch)
tree7c303daf185e21b692488b856a4d2c8b7c990457
parentf13cedbe28078cfa2d3fa4c196967b0e8a251c80 (diff)
Fix asTypeOf for Clock (#1258)
-rw-r--r--chiselFrontend/src/main/scala/chisel3/Clock.scala2
-rw-r--r--src/test/scala/chiselTests/AsTypeOfTester.scala15
2 files changed, 16 insertions, 1 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/Clock.scala b/chiselFrontend/src/main/scala/chisel3/Clock.scala
index 7e530cdf..87674e7b 100644
--- a/chiselFrontend/src/main/scala/chisel3/Clock.scala
+++ b/chiselFrontend/src/main/scala/chisel3/Clock.scala
@@ -33,6 +33,6 @@ sealed class Clock(private[chisel3] val width: Width = Width(1)) extends Element
override def do_asUInt(implicit sourceInfo: SourceInfo, connectCompileOptions: CompileOptions): UInt = pushOp(DefPrim(sourceInfo, UInt(this.width), AsUIntOp, ref)) // scalastyle:ignore line.size.limit
private[chisel3] override def connectFromBits(that: Bits)(implicit sourceInfo: SourceInfo,
compileOptions: CompileOptions): Unit = {
- this := that
+ this := that.asBool.asClock
}
}
diff --git a/src/test/scala/chiselTests/AsTypeOfTester.scala b/src/test/scala/chiselTests/AsTypeOfTester.scala
index 7861f51b..30643f55 100644
--- a/src/test/scala/chiselTests/AsTypeOfTester.scala
+++ b/src/test/scala/chiselTests/AsTypeOfTester.scala
@@ -70,6 +70,17 @@ class ResetAsTypeOfBoolTester extends BasicTester {
stop()
}
+class AsTypeOfClockTester extends BasicTester {
+ class MyBundle extends Bundle {
+ val x = UInt(4.W)
+ val y = Clock()
+ }
+ assert(true.B.asTypeOf(Clock()).asUInt.asBool === true.B)
+
+ assert(0x1f.U.asTypeOf(new MyBundle).asUInt === 0x1f.U)
+ stop()
+}
+
class AsChiselEnumTester extends BasicTester {
object MyEnum extends ChiselEnum {
val foo, bar = Value
@@ -137,4 +148,8 @@ class AsTypeOfSpec extends ChiselFlatSpec {
it should "work for casting to and from ChiselEnums" in {
assertTesterPasses(new AsChiselEnumTester)
}
+
+ it should "work for casting to and from Clock" in {
+ assertTesterPasses(new AsTypeOfClockTester)
+ }
}