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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
// See LICENSE for license details.
package firrtlTests
package transforms
import firrtl.annotations._
import firrtl.transforms.{DedupModules}
/**
* Tests inline instances transformation
*/
class DedupModuleTests extends HighTransformSpec {
def transform = new DedupModules
"The module A" should "be deduped" in {
val input =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A_
| module A :
| output x: UInt<1>
| x <= UInt(1)
| module A_ :
| output x: UInt<1>
| x <= UInt(1)
""".stripMargin
val check =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A
| module A :
| output x: UInt<1>
| x <= UInt(1)
""".stripMargin
execute(input, check, Seq.empty)
}
"The module A and B" should "be deduped" in {
val input =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A_
| module A :
| output x: UInt<1>
| inst b of B
| x <= b.x
| module A_ :
| output x: UInt<1>
| inst b of B_
| x <= b.x
| module B :
| output x: UInt<1>
| x <= UInt(1)
| module B_ :
| output x: UInt<1>
| x <= UInt(1)
""".stripMargin
val check =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A
| module A :
| output x: UInt<1>
| inst b of B
| x <= b.x
| module B :
| output x: UInt<1>
| x <= UInt(1)
""".stripMargin
execute(input, check, Seq.empty)
}
"The module A and B with comments" should "be deduped" in {
val input =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A_
| module A : @[yy 2:2]
| output x: UInt<1> @[yy 2:2]
| inst b of B @[yy 2:2]
| x <= b.x @[yy 2:2]
| module A_ : @[xx 1:1]
| output x: UInt<1> @[xx 1:1]
| inst b of B_ @[xx 1:1]
| x <= b.x @[xx 1:1]
| module B :
| output x: UInt<1>
| x <= UInt(1)
| module B_ :
| output x: UInt<1>
| x <= UInt(1)
""".stripMargin
val check =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A
| module A : @[yy 2:2]
| output x: UInt<1> @[yy 2:2]
| inst b of B @[yy 2:2]
| x <= b.x @[yy 2:2]
| module B :
| output x: UInt<1>
| x <= UInt(1)
""".stripMargin
execute(input, check, Seq.empty)
}
"A_ but not A" should "be deduped if not annotated" in {
val input =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A_
| module A : @[yy 2:2]
| output x: UInt<1> @[yy 2:2]
| x <= UInt(1)
| module A_ : @[xx 1:1]
| output x: UInt<1> @[xx 1:1]
| x <= UInt(1)
""".stripMargin
val check =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A_
| module A : @[yy 2:2]
| output x: UInt<1> @[yy 2:2]
| x <= UInt(1)
| module A_ : @[xx 1:1]
| output x: UInt<1> @[xx 1:1]
| x <= UInt(1)
""".stripMargin
execute(input, check, Seq(dontDedup("A")))
}
"The module A and A_" should "be deduped even with different port names and info, and annotations should remap" in {
val input =
"""circuit Top :
| module Top :
| output out: UInt<1>
| inst a1 of A
| inst a2 of A_
| out <= and(a1.x, a2.y)
| module A : @[yy 2:2]
| output x: UInt<1> @[yy 2:2]
| x <= UInt(1)
| module A_ : @[xx 1:1]
| output y: UInt<1> @[xx 1:1]
| y <= UInt(1)
""".stripMargin
val check =
"""circuit Top :
| module Top :
| output out: UInt<1>
| inst a1 of A
| inst a2 of A
| out <= and(a1.x, a2.x)
| module A : @[yy 2:2]
| output x: UInt<1> @[yy 2:2]
| x <= UInt(1)
""".stripMargin
case class DummyAnnotation(target: ComponentName) extends SingleTargetAnnotation[ComponentName] {
override def duplicate(n: ComponentName): Annotation = DummyAnnotation(n)
}
val mname = ModuleName("Top", CircuitName("Top"))
val finalState = execute(input, check, Seq(DummyAnnotation(ComponentName("a2.y", mname))))
finalState.annotations.collect({ case d: DummyAnnotation => d }).head should be(DummyAnnotation(ComponentName("a2.x", mname)))
}
"Extmodules" should "with the same defname and parameters should dedup" in {
val input =
"""circuit Top :
| module Top :
| output out: UInt<1>
| inst a1 of A
| inst a2 of A_
| out <= and(a1.x, a2.y)
| module A : @[yy 2:2]
| output x: UInt<1> @[yy 2:2]
| inst b of B
| x <= b.u
| module A_ : @[xx 1:1]
| output y: UInt<1> @[xx 1:1]
| inst c of C
| y <= c.v
| extmodule B : @[aa 3:3]
| output u : UInt<1> @[aa 4:4]
| defname = BB
| parameter N = 0
| extmodule C : @[bb 5:5]
| output v : UInt<1> @[bb 6:6]
| defname = BB
| parameter N = 0
""".stripMargin
val check =
"""circuit Top :
| module Top :
| output out: UInt<1>
| inst a1 of A
| inst a2 of A
| out <= and(a1.x, a2.x)
| module A : @[yy 2:2]
| output x: UInt<1> @[yy 2:2]
| inst b of B
| x <= b.u
| extmodule B : @[aa 3:3]
| output u : UInt<1> @[aa 4:4]
| defname = BB
| parameter N = 0
""".stripMargin
execute(input, check, Seq.empty)
}
"Extmodules" should "with the different defname or parameters should NOT dedup" in {
def mkfir(defnames: (String, String), params: (String, String)) =
s"""circuit Top :
| module Top :
| output out: UInt<1>
| inst a1 of A
| inst a2 of A_
| out <= and(a1.x, a2.y)
| module A : @[yy 2:2]
| output x: UInt<1> @[yy 2:2]
| inst b of B
| x <= b.u
| module A_ : @[xx 1:1]
| output y: UInt<1> @[xx 1:1]
| inst c of C
| y <= c.v
| extmodule B : @[aa 3:3]
| output u : UInt<1> @[aa 4:4]
| defname = ${defnames._1}
| parameter N = ${params._1}
| extmodule C : @[bb 5:5]
| output v : UInt<1> @[bb 6:6]
| defname = ${defnames._2}
| parameter N = ${params._2}
""".stripMargin
val diff_defname = mkfir(("BB", "CC"), ("0", "0"))
execute(diff_defname, diff_defname, Seq.empty)
val diff_params = mkfir(("BB", "BB"), ("0", "1"))
execute(diff_params, diff_params, Seq.empty)
}
"The module A and B" should "be deduped with the first module in order" in {
val input =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A_
| module A :
| output x: UInt<1>
| inst b of B_
| x <= b.x
| module A_ :
| output x: UInt<1>
| inst b of B
| x <= b.x
| module B :
| output x: UInt<1>
| x <= UInt(1)
| module B_ :
| output x: UInt<1>
| x <= UInt(1)
""".stripMargin
val check =
"""circuit Top :
| module Top :
| inst a1 of A
| inst a2 of A
| module A :
| output x: UInt<1>
| inst b of B
| x <= b.x
| module B :
| output x: UInt<1>
| x <= UInt(1)
""".stripMargin
execute(input, check, Seq.empty)
}
}
|