aboutsummaryrefslogtreecommitdiff
path: root/src/test/resources/features/ChirrtlMems.fir
blob: fa9ec1c080b4392550bf19f203e1cdf6f0c9af68 (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
; SPDX-License-Identifier: Apache-2.0
circuit ChirrtlMems :
  module ChirrtlMems :
    input clock : Clock
    input reset : UInt<1>

    cmem ram : UInt<32>[16]
    node newClock = clock

    wire wen : UInt<1>
    wen <= not(reset) ; Don't const prop me!

    reg raddr : UInt<4>, clock with : (reset => (reset, UInt(0)))
    raddr <= add(raddr, UInt(1))
    infer mport r = ram[raddr], newClock

    reg waddr : UInt<4>, clock with : (reset => (reset, UInt(0)))
    waddr <= add(waddr, UInt(1))

    when wen :
      node newerClock = clock
      infer mport w = ram[waddr], newerClock
      w <= waddr
      when eq(waddr, UInt(0)) :
        raddr <= UInt(0)

    when not(reset) :
      when gt(waddr, UInt(1)) :
        when neq(r, raddr) :
          printf(clock, UInt(1), "Assertion failed! r =/= raddr\n")
          stop(clock, UInt(1), 1) ; Failure!
      when eq(raddr, UInt(15)) :
        stop(clock, UInt(1), 0) ; Success!