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

expose typeEquivalent #1402

Merged
merged 6 commits into from
Apr 10, 2020
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
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)
sequencer marked this conversation as resolved.
Show resolved Hide resolved

// 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 }
}
}