Skip to content

Commit 3ff1849

Browse files
committed
seq argument of seq can be skipped when it is not required.
1 parent 6c704e0 commit 3ff1849

File tree

7 files changed

+185
-27
lines changed

7 files changed

+185
-27
lines changed

tests/extension/dataflow_/graph_pass/test_dataflow_graph_pass.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,6 @@
291291
assign zvalid = xvalid;
292292
assign xready = zready;
293293
294-
always @(posedge CLK) begin
295-
if(RST) begin
296-
end else begin
297-
end
298-
end
299-
300-
301294
endmodule
302295
"""
303296

tests/extension/dataflow_/pass/test_dataflow_pass.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,6 @@
291291
assign zvalid = xvalid;
292292
assign xready = zready;
293293
294-
always @(posedge CLK) begin
295-
if(RST) begin
296-
end else begin
297-
end
298-
end
299-
300-
301294
endmodule
302295
"""
303296

tests/extension/dataflow_/pass_nocontrol/test_dataflow_pass_nocontrol.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,6 @@
160160
161161
assign zdata = xdata;
162162
163-
always @(posedge CLK) begin
164-
if(RST) begin
165-
end else begin
166-
end
167-
end
168-
169-
170163
endmodule
171164
"""
172165

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
TARGET=$(shell ls *.py | grep -v test | grep -v parsetab.py)
2+
ARGS=
3+
4+
PYTHON=python3
5+
#PYTHON=python
6+
#OPT=-m pdb
7+
#OPT=-m cProfile -s time
8+
#OPT=-m cProfile -o profile.rslt
9+
10+
.PHONY: all
11+
all: test
12+
13+
.PHONY: run
14+
run:
15+
$(PYTHON) $(OPT) $(TARGET) $(ARGS)
16+
17+
.PHONY: test
18+
test:
19+
$(PYTHON) -m pytest -vv
20+
21+
.PHONY: check
22+
check:
23+
$(PYTHON) $(OPT) $(TARGET) $(ARGS) > tmp.v
24+
iverilog -tnull -Wall tmp.v
25+
rm -f tmp.v
26+
27+
.PHONY: clean
28+
clean:
29+
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v uut.vcd
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
import sys
4+
import os
5+
6+
# the next line can be removed after installation
7+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))))
8+
9+
from veriloggen import *
10+
11+
def mkLed():
12+
m = Module('blinkled')
13+
interval = m.Parameter('INTERVAL', 16)
14+
clk = m.Input('CLK')
15+
rst = m.Input('RST')
16+
led = m.OutputReg('LED', 8)
17+
count = m.Reg('count', 32)
18+
19+
seq = Seq(m, 'seq', clk)
20+
seq.add( Systask('display', 'LED:%d count:%d', led, count) )
21+
seq.add( count(count + 1), cond=count<interval-1 )
22+
seq.add( count(0), cond=count==interval-1 )
23+
seq.add( led(led + 1), cond=count==interval-1 )
24+
25+
seq.make_always()
26+
27+
return m
28+
29+
def mkTest():
30+
m = Module('test')
31+
32+
# target instance
33+
led = mkLed()
34+
35+
# copy paras and ports
36+
params = m.copy_params(led)
37+
ports = m.copy_sim_ports(led)
38+
39+
clk = ports['CLK']
40+
rst = ports['RST']
41+
42+
uut = m.Instance(led, 'uut',
43+
params=m.connect_params(led),
44+
ports=m.connect_ports(led))
45+
46+
#simulation.setup_waveform(m, uut)
47+
simulation.setup_clock(m, clk, hperiod=5)
48+
init = simulation.setup_reset(m, rst, m.make_reset(), period=100)
49+
50+
init.add(
51+
Delay(1000),
52+
Systask('finish'),
53+
)
54+
55+
return m
56+
57+
if __name__ == '__main__':
58+
test = mkTest()
59+
verilog = test.to_verilog()
60+
print(verilog)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
import seq_countup_noreset
4+
5+
expected_verilog = """
6+
module test #
7+
(
8+
parameter INTERVAL = 16
9+
);
10+
11+
reg CLK;
12+
reg RST;
13+
wire [(8 - 1):0] LED;
14+
15+
blinkled
16+
#(
17+
.INTERVAL(INTERVAL)
18+
)
19+
uut
20+
(
21+
.CLK(CLK),
22+
.RST(RST),
23+
.LED(LED)
24+
);
25+
26+
27+
initial begin
28+
CLK = 0;
29+
forever begin
30+
#5 CLK = (!CLK);
31+
end
32+
end
33+
34+
initial begin
35+
RST = 0;
36+
#100;
37+
RST = 1;
38+
#100;
39+
RST = 0;
40+
#1000;
41+
$finish;
42+
end
43+
endmodule
44+
45+
module blinkled #
46+
(
47+
parameter INTERVAL = 16
48+
)
49+
(
50+
input CLK,
51+
input RST,
52+
output reg [(8 - 1):0] LED
53+
);
54+
55+
reg [(32 - 1):0] count;
56+
57+
always @(posedge CLK) begin
58+
$display("LED:%d count:%d", LED, count);
59+
if((count < (INTERVAL - 1))) begin
60+
count <= (count + 1);
61+
end
62+
if((count == (INTERVAL - 1))) begin
63+
count <= 0;
64+
end
65+
if((count == (INTERVAL - 1))) begin
66+
LED <= (LED + 1);
67+
end
68+
end
69+
endmodule
70+
"""
71+
def test():
72+
test_module = seq_countup_noreset.mkTest()
73+
code = test_module.to_verilog()
74+
75+
from pyverilog.vparser.parser import VerilogParser
76+
from pyverilog.ast_code_generator.codegen import ASTCodeGenerator
77+
parser = VerilogParser()
78+
expected_ast = parser.parse(expected_verilog)
79+
codegen = ASTCodeGenerator()
80+
expected_code = codegen.visit(expected_ast)
81+
82+
assert(expected_code == code)

veriloggen/seq/seq.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class Seq(vtypes.VeriloggenNode):
1212
""" Sequential Logic Manager """
13-
def __init__(self, m, name, clk, rst):
13+
def __init__(self, m, name, clk, rst=None):
1414
self.m = m
1515
self.name = name
1616
self.clk = clk
@@ -104,12 +104,20 @@ def make_always(self, reset=(), body=()):
104104

105105
part_reset = list(reset) + list(self.make_reset())
106106
part_body = list(body) + list(self.make_code())
107-
self.m.Always(vtypes.Posedge(self.clk))(
108-
vtypes.If(self.rst)(
109-
part_reset,
110-
)(
107+
108+
if not part_reset and not part_body:
109+
pass
110+
elif not part_reset or self.rst is None:
111+
self.m.Always(vtypes.Posedge(self.clk))(
111112
part_body,
112-
))
113+
)
114+
else:
115+
self.m.Always(vtypes.Posedge(self.clk))(
116+
vtypes.If(self.rst)(
117+
part_reset,
118+
)(
119+
part_body,
120+
))
113121

114122
#---------------------------------------------------------------------------
115123
def make_code(self):

0 commit comments

Comments
 (0)