diff options
| author | Adam Izraelevitz | 2016-08-04 19:47:55 -0700 |
|---|---|---|
| committer | Jack Koenig | 2016-08-04 19:47:55 -0700 |
| commit | 732d0c6ccbcb971abfde4679a27384647d18b44d (patch) | |
| tree | eb8227772f50ee4515b8330e5400181b7f79e39b /src/main/scala/firrtl/Utils.scala | |
| parent | 6c8f327e681dee0b3e72399eb0a2dfceed3d0ad7 (diff) | |
Added RemoveEmpty.scala, which removes Empty and nested Blocks (#218)
* Added RemoveEmpty.scala, which removes Empty and nested Blocks
* Reused squashEmpty from ExpandWhens by moving it to Utils
* Squash EmptyStmts in ExpandWhens correctly
Diffstat (limited to 'src/main/scala/firrtl/Utils.scala')
| -rw-r--r-- | src/main/scala/firrtl/Utils.scala | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index 383d4df7..be70ac77 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -62,6 +62,20 @@ object Utils extends LazyLogging { result } + /** Removes all [[firrtl.ir.Empty]] statements and condenses + * [[firrtl.ir.Block]] statements. + */ + def squashEmpty(s: Statement): Statement = s map squashEmpty match { + case Block(stmts) => + val newStmts = stmts filter (_ != EmptyStmt) + newStmts.size match { + case 0 => EmptyStmt + case 1 => newStmts.head + case _ => Block(newStmts) + } + case s => s + } + /** Indent the results of [[ir.FirrtlNode.serialize]] */ def indent(str: String) = str replaceAllLiterally ("\n", "\n ") def serialize(bi: BigInt): String = |
