aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/passes/RemoveValidIf.scala
blob: a534cc508017a8f07e5ced00e03711851839c9de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package firrtl
package passes
import firrtl.Mappers.{ExpMap, StmtMap}
import firrtl.ir._

// Removes ValidIf as an optimization
object RemoveValidIf extends Pass {
   def name = "Remove ValidIfs"
   // Recursive. Removes ValidIf's
   private def onExp(e: Expression): Expression = {
      e map onExp match {
         case ValidIf(cond, value, tpe) => value
         case x => x
      }
   }
   // Recursive.
   private def onStmt(s: Statement): Statement = s map onStmt map onExp

   private def onModule(m: DefModule): DefModule = {
      m match {
         case m: Module => Module(m.info, m.name, m.ports, onStmt(m.body))
         case m: ExtModule => m
      }
   }

   def run(c: Circuit): Circuit = Circuit(c.info, c.modules.map(onModule _), c.main)
}