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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
package firrtl.passes
import com.typesafe.scalalogging.LazyLogging
import java.nio.file.{Paths, Files}
// For calling Stanza
import scala.sys.process._
import scala.io.Source
import firrtl._
import firrtl.Utils._
import firrtl.PrimOps._
trait Pass extends LazyLogging {
def name: String
def run(c: Circuit): Circuit
}
// Trait for migration, trap to Stanza implementation for passes not yet implemented in Scala
trait StanzaPass extends LazyLogging {
def stanzaPass(c: Circuit, n: String): Circuit = {
// For migration from Stanza, handle unimplemented Passes
logger.debug(s"Pass ${n} is not yet implemented in Scala")
val stanzaPasses = Seq("resolve", n)
val toStanza = Files.createTempFile(Paths.get(""), n, ".fir")
val fromStanza = Files.createTempFile(Paths.get(""), n, ".fir")
Files.write(toStanza, c.serialize.getBytes)
val cmd = Seq("firrtl-stanza", "-i", toStanza.toString, "-o", fromStanza.toString, "-b", "firrtl") ++
stanzaPasses.flatMap(x=>Seq("-x", x))
logger.debug(cmd.mkString(" "))
val ret = cmd.!
//println(ret)
val newC = Parser.parse(fromStanza.toString, Source.fromFile(fromStanza.toString).getLines)
Files.delete(toStanza)
Files.delete(fromStanza)
newC
}
}
object PassUtils extends LazyLogging {
val listOfPasses: Seq[Pass] = Seq(ToWorkingIR)
lazy val mapNameToPass: Map[String, Pass] = listOfPasses.map(p => p.name -> p).toMap
def executePasses(c: Circuit, passes: Seq[Pass]): Circuit = {
if (passes.isEmpty) c
else executePasses(passes.head.run(c), passes.tail)
}
}
// These should be distributed into separate files
object CheckHighForm extends Pass with StanzaPass {
def name = "High Form Check"
def run (c:Circuit): Circuit = stanzaPass(c, "high-form-check")
}
object ToWorkingIR extends Pass with StanzaPass {
def name = "Working IR"
def run (c:Circuit): Circuit = stanzaPass(c, "to-working-ir")
}
object Resolve extends Pass with StanzaPass {
def name = "Resolve"
def run (c:Circuit): Circuit = stanzaPass(c, "resolve")
}
object ResolveKinds extends Pass with StanzaPass {
def name = "Resolve Kinds"
def run (c:Circuit): Circuit = stanzaPass(c, "resolve-kinds")
}
object InferTypes extends Pass with StanzaPass {
def name = "Infer Types"
def run (c:Circuit): Circuit = stanzaPass(c, "infer-types")
}
object CheckTypes extends Pass with StanzaPass {
def name = "Check Types"
def run (c:Circuit): Circuit = stanzaPass(c, "check-types")
}
object ResolveGenders extends Pass with StanzaPass {
def name = "Resolve Genders"
def run (c:Circuit): Circuit = stanzaPass(c, "resolve-genders")
}
object CheckGenders extends Pass with StanzaPass {
def name = "Check Genders"
def run (c:Circuit): Circuit = stanzaPass(c, "check-genders")
}
object InferWidths extends Pass with StanzaPass {
def name = "Infer Widths"
def run (c:Circuit): Circuit = stanzaPass(c, "infer-widths")
}
object CheckWidths extends Pass with StanzaPass {
def name = "Width Check"
def run (c:Circuit): Circuit = stanzaPass(c, "width-check")
}
object PullMuxes extends Pass with StanzaPass {
def name = "Pull Muxes"
def run (c:Circuit): Circuit = stanzaPass(c, "pull-muxes")
}
object ExpandConnects extends Pass with StanzaPass {
def name = "Expand Connects"
def run (c:Circuit): Circuit = stanzaPass(c, "expand-connects")
}
object RemoveAccesses extends Pass with StanzaPass {
def name = "Remove Accesses"
def run (c:Circuit): Circuit = stanzaPass(c, "remove-accesses")
}
object ExpandWhens extends Pass with StanzaPass {
def name = "Expand Whens"
def run (c:Circuit): Circuit = stanzaPass(c, "expand-whens")
}
object CheckInitialization extends Pass with StanzaPass {
def name = "Check Initialization"
def run (c:Circuit): Circuit = stanzaPass(c, "check-init")
}
object ConstProp extends Pass with StanzaPass {
def name = "Constant Propogation"
def run (c:Circuit): Circuit = stanzaPass(c, "const-prop")
}
object VerilogWrap extends Pass with StanzaPass {
def name = "Verilog Wrap"
def run (c:Circuit): Circuit = stanzaPass(c, "verilog-wrap")
}
object SplitExp extends Pass with StanzaPass {
def name = "Split Expressions"
def run (c:Circuit): Circuit = stanzaPass(c, "split-expressions")
}
object VerilogRename extends Pass with StanzaPass {
def name = "Verilog Rename"
def run (c:Circuit): Circuit = stanzaPass(c, "verilog-rename")
}
object LowerTypes extends Pass with StanzaPass {
def name = "Lower Types"
def run (c:Circuit): Circuit = stanzaPass(c, "lower-types")
}
|