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
|
// See LICENSE for license details.
package firrtlTests
import java.io._
import org.scalatest._
import org.scalatest.prop._
import firrtl._
import firrtl.annotations._
import firrtl.ir.Circuit
import firrtl.passes._
import firrtl.Parser.IgnoreInfo
class DoPrimVerilog extends FirrtlFlatSpec {
private def executeTest(input: String, expected: Seq[String], compiler: Compiler) = {
val writer = new StringWriter()
compiler.compile(CircuitState(parse(input), ChirrtlForm), writer)
val lines = writer.toString().split("\n") map normalized
expected foreach { e =>
lines should contain(e)
}
}
"Xorr" should "emit correctly" in {
val compiler = new VerilogCompiler
val input =
"""circuit Xorr :
| module Xorr :
| input a: UInt<4>
| output b: UInt<1>
| b <= xorr(a)""".stripMargin
val check =
"""module Xorr(
| input [3:0] a,
| output b
|);
| assign b = ^a;
|endmodule
|""".stripMargin.split("\n") map normalized
executeTest(input, check, compiler)
}
"Andr" should "emit correctly" in {
val compiler = new VerilogCompiler
val input =
"""circuit Andr :
| module Andr :
| input a: UInt<4>
| output b: UInt<1>
| b <= andr(a)""".stripMargin
val check =
"""module Andr(
| input [3:0] a,
| output b
|);
| assign b = &a;
|endmodule
|""".stripMargin.split("\n") map normalized
executeTest(input, check, compiler)
}
"Orr" should "emit correctly" in {
val compiler = new VerilogCompiler
val input =
"""circuit Orr :
| module Orr :
| input a: UInt<4>
| output b: UInt<1>
| b <= orr(a)""".stripMargin
val check =
"""module Orr(
| input [3:0] a,
| output b
|);
| assign b = |a;
|endmodule
|""".stripMargin.split("\n") map normalized
executeTest(input, check, compiler)
}
"Rem" should "emit correctly" in {
val compiler = new VerilogCompiler
val input =
"""circuit Test :
| module Test :
| input in : UInt<8>
| output out : UInt<1>
| out <= rem(in, UInt<1>("h1"))
|""".stripMargin
val check =
"""module Test(
| input [7:0] in,
| output out
|);
| wire [7:0] _GEN_0;
| assign out = _GEN_0[0];
| assign _GEN_0 = in % 8'h1;
|endmodule
|""".stripMargin.split("\n") map normalized
executeTest(input, check, compiler)
}
}
|