Skip to content

Commit

Permalink
Expose checkTypeEquivalence as a public API (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
sequencer authored Apr 10, 2020
1 parent e55c00f commit 2b71a50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/src/main/scala/chisel3/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down
12 changes: 12 additions & 0 deletions src/test/scala/chiselTests/RecordSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -146,4 +154,8 @@ class RecordSpec extends ChiselFlatSpec with RecordSpecUtils {
io := wire
})
}

"CustomBundle" should "check the types" in {
elaborate { new RecordTypeTester }
}
}

0 comments on commit 2b71a50

Please sign in to comment.