-
Notifications
You must be signed in to change notification settings - Fork 0
/
NstageRegIncrGL.py
65 lines (43 loc) · 1.59 KB
/
NstageRegIncrGL.py
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
#=========================================================================
# NstageRegIncrGL
#=========================================================================
from pymtl3 import *
from RegIncrGL import RegIncrGL
class NstageRegIncrGL( Component ):
def construct( s, nbits=4, nstages=1 ):
s.in_ = InPort (nbits)
s.out = OutPort(nbits)
s.rincrs = [ RegIncrGL(nbits) for _ in range(nstages) ]
s.in_ //= s.rincrs[0].in_
for rincr, rincr_next in zip(s.rincrs,s.rincrs[1:]):
rincr.out //= rincr_next.in_
s.out //= s.rincrs[-1].out
def line_trace( s ):
return " ".join([ rincr.line_trace() for rincr in s.rincrs ])
#-------------------------------------------------------------------------
# main
#-------------------------------------------------------------------------
from pymtl3.passes.backends.verilog import *
from pymtl3.passes.tracing.VcdGenerationPass import VcdGenerationPass
if __name__ == "__main__":
dut = NstageRegIncrGL(nstages=4)
# Use hierarchical parameter system
dut.set_param( "top.rincrs*.construct", incr_value=2 )
# Turn on VCD waveform dumping
dut.set_metadata( VcdGenerationPass.vcd_file_name, "dump" )
# Turn on Verilog translation and apply corresponding passes
dut.set_metadata( VerilogTranslationPass.enable, True )
dut.apply( VerilogTranslationPass() )
# Apply default pass group and simulate
dut.apply( DefaultPassGroup(textwave=True) )
dut.sim_reset()
dut.in_ @= 0
dut.sim_tick()
dut.in_ @= 4
dut.sim_tick()
dut.in_ @= 6
dut.sim_tick()
dut.sim_tick()
dut.sim_tick()
dut.sim_tick()
print()