aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtlTests/ExpandWhensSpec.scala
blob: dcaf52e37bf00a0945b4238108836bfd03edb08e (plain)
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
// See LICENSE for license details.

package firrtlTests

import java.io._
import org.scalatest._
import org.scalatest.prop._
import firrtl._
import firrtl.passes._
import firrtl.ir._
import firrtl.Parser.IgnoreInfo

class ExpandWhensSpec extends FirrtlFlatSpec {
  private def executeTest(input: String, check: String, transforms: Seq[Transform], expected: Boolean) = {
    val circuit = Parser.parse(input.split("\n").toIterator)
    val result = transforms.foldLeft(CircuitState(circuit, UnknownForm)) {
      (c: CircuitState, p: Transform) => p.runTransform(c)
    }
    val c = result.circuit
    val lines = c.serialize.split("\n") map normalized
    println(c.serialize)

    if(expected) {
      c.serialize.contains(check) should be (true)
    } else {
      lines foreach { l => l.contains(check) should be (false) }
    }
  }
  "Expand Whens" should "not emit INVALID" in {
    val transforms = Seq(
      ToWorkingIR,
      CheckHighForm,
      ResolveKinds,
      InferTypes,
      CheckTypes,
      Uniquify,
      ResolveKinds,
      InferTypes,
      ResolveGenders,
      CheckGenders,
      InferWidths,
      CheckWidths,
      PullMuxes,
      ExpandConnects,
      RemoveAccesses,
      ExpandWhens)
    val input =
  """|circuit Tester : 
     |  module Tester :
     |    input p : UInt<1>
     |    when p :
     |      wire a : {b : UInt<64>, c : UInt<64>}
     |      a is invalid
     |      a.b <= UInt<64>("h04000000000000000")""".stripMargin
    val check = "INVALID"
    executeTest(input, check, transforms, false)
  }
  "Expand Whens" should "void unwritten memory fields" in {
    val transforms = Seq(
      ToWorkingIR,
      CheckHighForm,
      ResolveKinds,
      InferTypes,
      CheckTypes,
      Uniquify,
      ResolveKinds,
      InferTypes,
      ResolveGenders,
      CheckGenders,
      InferWidths,
      CheckWidths,
      PullMuxes,
      ExpandConnects,
      RemoveAccesses,
      ExpandWhens)
    val input =
  """|circuit Tester : 
     |  module Tester :
     |    input clk : Clock
     |    mem memory:
     |      data-type => UInt<32>
     |      depth => 32
     |      reader => r0
     |      writer => w0
     |      read-latency => 0
     |      write-latency => 1
     |      read-under-write => undefined
     |    memory.r0.addr <= UInt<1>(1)
     |    memory.r0.en <= UInt<1>(1)
     |    memory.r0.clk <= clk
     |    memory.w0.addr <= UInt<1>(1)
     |    memory.w0.data <= UInt<1>(1)
     |    memory.w0.en <= UInt<1>(1)
     |    memory.w0.clk <= clk
     |    """.stripMargin
    val check = "VOID"
    executeTest(input, check, transforms, true)
  }
}

class ExpandWhensExecutionTest extends ExecutionTest("ExpandWhens", "/passes/ExpandWhens")