diff options
| author | Adam Izraelevitz | 2017-02-14 11:36:42 -0800 |
|---|---|---|
| committer | Adam Izraelevitz | 2017-02-14 13:06:20 -0800 |
| commit | 208176767a8b93172e02b55fe5e5cc19891e5921 (patch) | |
| tree | 99860e044e3c00026615f05e7e50d739813cd73d /src | |
| parent | ea90b71aaf70c7e3034fef8df4968ae89026c258 (diff) | |
Fixes #441, ConvertFixedToSInt not recursing exps
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/passes/ConvertFixedToSInt.scala | 8 | ||||
| -rw-r--r-- | src/test/scala/firrtlTests/fixed/RemoveFixedTypeSpec.scala | 28 |
2 files changed, 32 insertions, 4 deletions
diff --git a/src/main/scala/firrtl/passes/ConvertFixedToSInt.scala b/src/main/scala/firrtl/passes/ConvertFixedToSInt.scala index 1b57360f..3ddfb124 100644 --- a/src/main/scala/firrtl/passes/ConvertFixedToSInt.scala +++ b/src/main/scala/firrtl/passes/ConvertFixedToSInt.scala @@ -39,10 +39,10 @@ object ConvertFixedToSInt extends Pass { val types = mutable.HashMap[String,Type]() def updateExpType(e:Expression): Expression = e match { case DoPrim(Mul, args, consts, tpe) => e map updateExpType - case DoPrim(AsFixedPoint, args, consts, tpe) => DoPrim(AsSInt, args, Seq.empty, tpe) - case DoPrim(BPShl, args, consts, tpe) => DoPrim(Shl, args, consts, tpe) - case DoPrim(BPShr, args, consts, tpe) => DoPrim(Shr, args, consts, tpe) - case DoPrim(BPSet, args, consts, FixedType(w, IntWidth(p))) => alignArg(args.head, p) + case DoPrim(AsFixedPoint, args, consts, tpe) => DoPrim(AsSInt, args, Seq.empty, tpe) map updateExpType + case DoPrim(BPShl, args, consts, tpe) => DoPrim(Shl, args, consts, tpe) map updateExpType + case DoPrim(BPShr, args, consts, tpe) => DoPrim(Shr, args, consts, tpe) map updateExpType + case DoPrim(BPSet, args, consts, FixedType(w, IntWidth(p))) => alignArg(args.head, p) map updateExpType case DoPrim(op, args, consts, tpe) => val point = calcPoint(args) val newExp = DoPrim(op, args.map(x => alignArg(x, point)), consts, UnknownType) diff --git a/src/test/scala/firrtlTests/fixed/RemoveFixedTypeSpec.scala b/src/test/scala/firrtlTests/fixed/RemoveFixedTypeSpec.scala index 4910cb5e..ce591485 100644 --- a/src/test/scala/firrtlTests/fixed/RemoveFixedTypeSpec.scala +++ b/src/test/scala/firrtlTests/fixed/RemoveFixedTypeSpec.scala @@ -14,6 +14,7 @@ class RemoveFixedTypeSpec extends FirrtlFlatSpec { (c: Circuit, p: Pass) => p.run(c) } val lines = c.serialize.split("\n") map normalized + println(c.serialize) expected foreach { e => lines should contain(e) @@ -186,5 +187,32 @@ class RemoveFixedTypeSpec extends FirrtlFlatSpec { val chirrtlTransform = new CheckChirrtlTransform chirrtlTransform.execute(CircuitState(parse(input), ChirrtlForm, Some(new AnnotationMap(Seq.empty)))) } + + "Fixed point numbers" should "remove nested AsFixedPoint" in { + val passes = Seq( + ToWorkingIR, + CheckHighForm, + ResolveKinds, + InferTypes, + CheckTypes, + ResolveGenders, + CheckGenders, + InferWidths, + CheckWidths, + ConvertFixedToSInt) + val input = + """ + |circuit Unit : + | module Unit : + | node x = asFixedPoint(asFixedPoint(UInt(3), 0), 1) + """.stripMargin + val check = + """ + |circuit Unit : + | module Unit : + | node x = asSInt(asSInt(UInt<2>("h3"))) + """.stripMargin + executeTest(input, check.split("\n") map normalized, passes) + } } |
