diff options
| author | Sequencer | 2020-04-10 14:51:41 +0000 |
|---|---|---|
| committer | GitHub | 2020-04-10 10:51:41 -0400 |
| commit | 2b71a50abcf71ff2f90802ba1b06d94428e550f1 (patch) | |
| tree | 570a018687be9d99bc02992e527c3d3541e216ee | |
| parent | e55c00fe09a795adae15b6383a75300d6cfa9e7a (diff) | |
Expose checkTypeEquivalence as a public API (#1402)
| -rw-r--r-- | core/src/main/scala/chisel3/Data.scala | 17 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/RecordSpec.scala | 12 |
2 files changed, 29 insertions, 0 deletions
diff --git a/core/src/main/scala/chisel3/Data.scala b/core/src/main/scala/chisel3/Data.scala index 6574a39d..93fccaec 100644 --- a/core/src/main/scala/chisel3/Data.scala +++ b/core/src/main/scala/chisel3/Data.scala @@ -131,6 +131,23 @@ package experimental { target.direction } + /** Check if two Chisel types are the same type. + * Internally, this is dispatched to each Chisel type's + * `typeEquivalent` function for each type to determine + * if the types are intended to be equal. + * + * For most types, different parameters should ensure + * that the types are different. + * For example, `UInt(8.W)` and `UInt(16.W)` are different. + * Likewise, Records check that both Records have the same + * elements with the same types. + * + * @param x First Chisel type + * @param y Second Chisel type + * @return true if the two Chisel types are equal. + **/ + def checkTypeEquivalence(x: Data, y: Data): Boolean = x.typeEquivalent(y) + // Returns the top-level module ports // TODO: maybe move to something like Driver or DriverUtils, since this is mainly for interacting // with compiled artifacts (vs. elaboration-time reflection)? diff --git a/src/test/scala/chiselTests/RecordSpec.scala b/src/test/scala/chiselTests/RecordSpec.scala index bf6b92eb..41242981 100644 --- a/src/test/scala/chiselTests/RecordSpec.scala +++ b/src/test/scala/chiselTests/RecordSpec.scala @@ -99,6 +99,14 @@ trait RecordSpecUtils { assert(wire("0").asUInt === 123.U) stop() } + + class RecordTypeTester extends BasicTester { + val wire0 = Wire(new CustomBundle("0"-> UInt(32.W))) + val wire1 = Reg(new CustomBundle("0"-> UInt(32.W))) + val wire2 = Wire(new CustomBundle("1"-> UInt(32.W))) + require(DataMirror.checkTypeEquivalence(wire0, wire1)) + require(!DataMirror.checkTypeEquivalence(wire1, wire2)) + } } class RecordSpec extends ChiselFlatSpec with RecordSpecUtils { @@ -146,4 +154,8 @@ class RecordSpec extends ChiselFlatSpec with RecordSpecUtils { io := wire }) } + + "CustomBundle" should "check the types" in { + elaborate { new RecordTypeTester } + } } |
