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
|
// SPDX-License-Identifier: Apache-2.0
package firrtlTests
import firrtl._
import firrtl.passes._
import firrtl.testutils._
class ChirrtlSpec extends FirrtlFlatSpec {
def transforms = Seq(
CheckChirrtl,
CInferTypes,
CInferMDir,
RemoveCHIRRTL,
ToWorkingIR,
CheckHighForm,
ResolveKinds,
InferTypes,
CheckTypes,
ResolveFlows,
CheckFlows,
new InferWidths,
CheckWidths,
PullMuxes,
ExpandConnects,
RemoveAccesses,
ExpandWhens,
CheckInitialization
)
"Chirrtl memories" should "allow ports with clocks defined after the memory" in {
val input =
"""circuit Unit :
| module Unit :
| input clock : Clock
| smem ram : UInt<32>[128]
| node newClock = clock
| infer mport x = ram[UInt(2)], newClock
| x <= UInt(3)
| when UInt(1) :
| infer mport y = ram[UInt(4)], newClock
| y <= UInt(5)
""".stripMargin
val circuit = Parser.parse(input.split("\n").toIterator)
transforms.foldLeft(CircuitState(circuit, UnknownForm)) { (c: CircuitState, p: Transform) =>
p.runTransform(c)
}
}
"Chirrtl" should "catch undeclared wires" in {
val input =
"""circuit Unit :
| module Unit :
| input clock : Clock
| smem ram : UInt<32>[128]
| node newClock = clock
| infer mport x = ram[UInt(2)], newClock
| x <= UInt(3)
| when UInt(1) :
| infer mport y = ram[UInt(4)], newClock
| y <= z
""".stripMargin
intercept[PassException] {
val circuit = Parser.parse(input.split("\n").toIterator)
transforms.foldLeft(CircuitState(circuit, UnknownForm)) { (c: CircuitState, p: Transform) =>
p.runTransform(c)
}
}
}
behavior.of("Uniqueness")
for ((description, input) <- CheckSpec.nonUniqueExamples) {
it should s"be asserted for $description" in {
assertThrows[CheckHighForm.NotUniqueException] {
Seq(ToWorkingIR, CheckHighForm).foldLeft(Parser.parse(input)) { case (c, tx) => tx.run(c) }
}
}
}
}
class ChirrtlMemsExecutionTest extends ExecutionTest("ChirrtlMems", "/features")
class EmptyChirrtlMemCompilationTest extends CompilationTest("EmptyChirrtlMem", "/features")
class NodeTypeCompilationTest extends CompilationTest("NodeType", "/features")
|