diff options
| author | Jack Koenig | 2020-11-11 16:07:54 -0800 |
|---|---|---|
| committer | GitHub | 2020-11-12 00:07:54 +0000 |
| commit | c7bbb75b8b293d639848abaa9f68121f80947f42 (patch) | |
| tree | a80fbf90a249d8372751fa728b7f709e850778ea /src/main/scala/firrtl/Utils.scala | |
| parent | 7d637e256d09e46c5b45c9ac3b6258e43c279f2a (diff) | |
Fix RemoveWires handling of invalidated non-UInt wires (#1949)
It would replace them with a validif node with a UIntLiteral which can
lead to type errors.
Diffstat (limited to 'src/main/scala/firrtl/Utils.scala')
| -rw-r--r-- | src/main/scala/firrtl/Utils.scala | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index a52e451f..921ec60b 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -250,6 +250,24 @@ object Utils extends LazyLogging { val one = UIntLiteral(1) val zero = UIntLiteral(0) + private val ClockZero = DoPrim(PrimOps.AsClock, Seq(zero), Seq.empty, ClockType) + private val AsyncZero = DoPrim(PrimOps.AsAsyncReset, Seq(zero), Nil, AsyncResetType) + + /** Returns an [[firrtl.ir.Expression Expression]] equal to zero for a given [[firrtl.ir.GroundType GroundType]] + * @note Does not support [[firrtl.ir.AnalogType AnalogType]] nor [[firrtl.ir.IntervalType IntervalType]] + */ + def getGroundZero(tpe: GroundType): Expression = tpe match { + case u: UIntType => UIntLiteral(0, u.width) + case s: SIntType => SIntLiteral(0, s.width) + case f: FixedType => FixedLiteral(0, f.width, f.point) + // Default reset type is Bool + case ResetType => Utils.zero + case ClockType => ClockZero + case AsyncResetType => AsyncZero + // TODO Support IntervalType + case other => throwInternalError(s"Unexpected type $other") + } + def create_exps(n: String, t: Type): Seq[Expression] = create_exps(WRef(n, t, ExpKind, UnknownFlow)) def create_exps(e: Expression): Seq[Expression] = e match { |
