aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAngie Wang2017-02-27 18:59:03 -0800
committerGitHub2017-02-27 18:59:03 -0800
commit6d86ccd4619af96fe436e0dca335d9d6829c66a4 (patch)
tree6991957c19f216b29b49aab73c14dbea87c489c7 /src
parent8528ba768003a359bf6c40d2fdc102c4a0d6bea7 (diff)
castrhs shouldn't assume rhs is uint (#467)
* castrhs shouldn't assume rhs is uint * don't cast if types are the same * changed castrhs to catch invalid lhs, rhs type combinations * change error msg
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/Utils.scala17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala
index e3f0fee1..b4ad2e74 100644
--- a/src/main/scala/firrtl/Utils.scala
+++ b/src/main/scala/firrtl/Utils.scala
@@ -61,11 +61,18 @@ object bitWidth {
object castRhs {
def apply(lhst: Type, rhs: Expression) = {
- lhst match {
- case _: SIntType => DoPrim(AsSInt, Seq(rhs), Seq.empty, lhst)
- case FixedType(_, IntWidth(p)) => DoPrim(AsFixedPoint, Seq(rhs), Seq(p), lhst)
- case ClockType => DoPrim(AsClock, Seq(rhs), Seq.empty, lhst)
- case _: UIntType => rhs
+ (lhst, rhs.tpe) match {
+ case (x: GroundType, y: GroundType) if WrappedType(x) == WrappedType(y) =>
+ rhs
+ case (_: SIntType, _) =>
+ DoPrim(AsSInt, Seq(rhs), Seq.empty, lhst)
+ case (FixedType(_, IntWidth(p)), _) =>
+ DoPrim(AsFixedPoint, Seq(rhs), Seq(p), lhst)
+ case (ClockType, _) =>
+ DoPrim(AsClock, Seq(rhs), Seq.empty, lhst)
+ case (_: UIntType, _) =>
+ DoPrim(AsUInt, Seq(rhs), Seq.empty, lhst)
+ case (_, _) => error("castRhs lhst, rhs type combination is invalid")
}
}
}