diff options
| author | Leway Colin | 2019-09-06 13:33:39 +0800 |
|---|---|---|
| committer | mergify[bot] | 2019-09-06 05:33:39 +0000 |
| commit | 7929768a99eb93eea1c1ff0f71ab7d16a59abaa0 (patch) | |
| tree | 835b93b7891c886a5c474ceb5be330413f7d6fed /src | |
| parent | 59327533f0c35d4c63fee38c5288bfbb95bbd1b3 (diff) | |
Refactor: remove redundancy code (#1166)
* Refactor: remove redundancy code
* Fixed coding style
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/PrimOps.scala | 94 |
1 files changed, 12 insertions, 82 deletions
diff --git a/src/main/scala/firrtl/PrimOps.scala b/src/main/scala/firrtl/PrimOps.scala index 1a513352..af8328da 100644 --- a/src/main/scala/firrtl/PrimOps.scala +++ b/src/main/scala/firrtl/PrimOps.scala @@ -129,18 +129,12 @@ object PrimOps extends LazyLogging { def c1 = IntWidth(e.consts.head) def c2 = IntWidth(e.consts(1)) e copy (tpe = e.op match { - case Add => (t1, t2) match { + case Add | Sub => (t1, t2) match { case (_: UIntType, _: UIntType) => UIntType(PLUS(MAX(w1, w2), IntWidth(1))) case (_: SIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1))) case (_: FixedType, _: FixedType) => FixedType(PLUS(PLUS(MAX(p1, p2), MAX(MINUS(w1, p1), MINUS(w2, p2))), IntWidth(1)), MAX(p1, p2)) case _ => UnknownType } - case Sub => (t1, t2) match { - case (_: UIntType, _: UIntType) => UIntType(PLUS(MAX(w1, w2), IntWidth(1))) - case (_: SIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1))) - case (_: FixedType, _: FixedType) => FixedType(PLUS(PLUS(MAX(p1, p2),MAX(MINUS(w1, p1), MINUS(w2, p2))),IntWidth(1)), MAX(p1, p2)) - case _ => UnknownType - } case Mul => (t1, t2) match { case (_: UIntType, _: UIntType) => UIntType(PLUS(w1, w2)) case (_: SIntType, _: SIntType) => SIntType(PLUS(w1, w2)) @@ -157,37 +151,7 @@ object PrimOps extends LazyLogging { case (_: SIntType, _: SIntType) => SIntType(MIN(w1, w2)) case _ => UnknownType } - case Lt => (t1, t2) match { - case (_: UIntType, _: UIntType) => Utils.BoolType - case (_: SIntType, _: SIntType) => Utils.BoolType - case (_: FixedType, _: FixedType) => Utils.BoolType - case _ => UnknownType - } - case Leq => (t1, t2) match { - case (_: UIntType, _: UIntType) => Utils.BoolType - case (_: SIntType, _: SIntType) => Utils.BoolType - case (_: FixedType, _: FixedType) => Utils.BoolType - case _ => UnknownType - } - case Gt => (t1, t2) match { - case (_: UIntType, _: UIntType) => Utils.BoolType - case (_: SIntType, _: SIntType) => Utils.BoolType - case (_: FixedType, _: FixedType) => Utils.BoolType - case _ => UnknownType - } - case Geq => (t1, t2) match { - case (_: UIntType, _: UIntType) => Utils.BoolType - case (_: SIntType, _: SIntType) => Utils.BoolType - case (_: FixedType, _: FixedType) => Utils.BoolType - case _ => UnknownType - } - case Eq => (t1, t2) match { - case (_: UIntType, _: UIntType) => Utils.BoolType - case (_: SIntType, _: SIntType) => Utils.BoolType - case (_: FixedType, _: FixedType) => Utils.BoolType - case _ => UnknownType - } - case Neq => (t1, t2) match { + case Lt | Leq | Gt | Geq | Eq | Neq => (t1, t2) match { case (_: UIntType, _: UIntType) => Utils.BoolType case (_: SIntType, _: SIntType) => Utils.BoolType case (_: FixedType, _: FixedType) => Utils.BoolType @@ -200,41 +164,26 @@ object PrimOps extends LazyLogging { case _ => UnknownType } case AsUInt => t1 match { - case _: UIntType => UIntType(w1) - case _: SIntType => UIntType(w1) - case _: FixedType => UIntType(w1) + case (_: UIntType | _: SIntType | _: FixedType | _: AnalogType) => UIntType(w1) case ClockType | AsyncResetType | ResetType => UIntType(IntWidth(1)) - case AnalogType(w) => UIntType(w1) case _ => UnknownType } case AsSInt => t1 match { - case _: UIntType => SIntType(w1) - case _: SIntType => SIntType(w1) - case _: FixedType => SIntType(w1) + case (_: UIntType | _: SIntType | _: FixedType | _: AnalogType) => SIntType(w1) case ClockType | AsyncResetType | ResetType => SIntType(IntWidth(1)) - case _: AnalogType => SIntType(w1) case _ => UnknownType } case AsFixedPoint => t1 match { - case _: UIntType => FixedType(w1, c1) - case _: SIntType => FixedType(w1, c1) - case _: FixedType => FixedType(w1, c1) + case (_: UIntType | _: SIntType | _: FixedType | _: AnalogType) => FixedType(w1, c1) case ClockType | AsyncResetType | ResetType => FixedType(IntWidth(1), c1) - case _: AnalogType => FixedType(w1, c1) case _ => UnknownType } case AsClock => t1 match { - case _: UIntType => ClockType - case _: SIntType => ClockType - case ClockType | AsyncResetType | ResetType => ClockType - case _: AnalogType => ClockType + case (_: UIntType | _: SIntType | _: AnalogType | ClockType | AsyncResetType | ResetType) => ClockType case _ => UnknownType } case AsAsyncReset => t1 match { - case _: UIntType => AsyncResetType - case _: SIntType => AsyncResetType - case ClockType | AsyncResetType | ResetType => AsyncResetType - case _: AnalogType => AsyncResetType + case (_: UIntType | _: SIntType | _: AnalogType | ClockType | AsyncResetType | ResetType) => AsyncResetType case _ => UnknownType } case Shl => t1 match { @@ -267,36 +216,18 @@ object PrimOps extends LazyLogging { case _ => UnknownType } case Neg => t1 match { - case _: UIntType => SIntType(PLUS(w1, IntWidth(1))) - case _: SIntType => SIntType(PLUS(w1, IntWidth(1))) + case (_: UIntType | _: SIntType) => SIntType(PLUS(w1, IntWidth(1))) case _ => UnknownType } case Not => t1 match { - case _: UIntType => UIntType(w1) - case _: SIntType => UIntType(w1) - case _ => UnknownType - } - case And => (t1, t2) match { - case (_: SIntType | _: UIntType, _: SIntType | _: UIntType) => UIntType(MAX(w1, w2)) - case _ => UnknownType - } - case Or => (t1, t2) match { - case (_: SIntType | _: UIntType, _: SIntType | _: UIntType) => UIntType(MAX(w1, w2)) + case (_: UIntType | _: SIntType) => UIntType(w1) case _ => UnknownType } - case Xor => (t1, t2) match { + case And | Or | Xor => (t1, t2) match { case (_: SIntType | _: UIntType, _: SIntType | _: UIntType) => UIntType(MAX(w1, w2)) case _ => UnknownType } - case Andr => t1 match { - case (_: UIntType | _: SIntType) => Utils.BoolType - case _ => UnknownType - } - case Orr => t1 match { - case (_: UIntType | _: SIntType) => Utils.BoolType - case _ => UnknownType - } - case Xorr => t1 match { + case Andr | Orr | Xorr => t1 match { case (_: UIntType | _: SIntType) => Utils.BoolType case _ => UnknownType } @@ -305,8 +236,7 @@ object PrimOps extends LazyLogging { case (t1, t2) => UnknownType } case Bits => t1 match { - case (_: UIntType | _: SIntType) => UIntType(PLUS(MINUS(c1, c2), IntWidth(1))) - case _: FixedType => UIntType(PLUS(MINUS(c1, c2), IntWidth(1))) + case (_: UIntType | _: SIntType | _: FixedType) => UIntType(PLUS(MINUS(c1, c2), IntWidth(1))) case _ => UnknownType } case Head => t1 match { |
