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
|
// See LICENSE for license details.
package firrtlTests
package transform
import org.scalatest.FlatSpec
import org.scalatest.Matchers
import org.scalatest.junit.JUnitRunner
import firrtl.ir.Circuit
import firrtl.Parser
import firrtl.passes.PassExceptions
import firrtl.annotations.{
Named,
CircuitName,
ModuleName,
Annotation
}
import firrtl.transforms.{DedupModules, NoDedupAnnotation}
/**
* 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)
}
"The module B, but not A, with comments" 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")))
}
}
// Execution driven tests for inlining modules
// TODO(izraelevitz) fix this test
//class InlineInstancesIntegrationSpec extends FirrtlPropSpec {
// // Shorthand for creating annotations to inline modules
// def inlineModules(names: Seq[String]): Seq[CircuitAnnotation] =
// Seq(StickyCircuitAnnotation(InlineCAKind, names.map(n => ModuleName(n) -> TagAnnotation).toMap))
//
// case class Test(name: String, dir: String, ann: Seq[CircuitAnnotation])
//
// val runTests = Seq(
// Test("GCDTester", "/integration", inlineModules(Seq("DecoupledGCD")))
// )
//
// runTests foreach { test =>
// property(s"${test.name} should execute correctly with inlining") {
// println(s"Got annotations ${test.ann}")
// runFirrtlTest(test.name, test.dir, test.ann)
// }
// }
//}
|