Skip to content

Commit c12c809

Browse files
committed
test/instance_ is updated for connect_same_name and connect_params/ports
1 parent c3f4b68 commit c12c809

File tree

11 files changed

+317
-11
lines changed

11 files changed

+317
-11
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
TARGET=*.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 *.out tmp.v uut.vcd
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sys
2+
import os
3+
import collections
4+
5+
# the next line can be removed after installation
6+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
7+
8+
from veriloggen import *
9+
10+
def mkLed():
11+
m = Module('blinkled')
12+
width = m.Parameter('WIDTH', 8)
13+
clk = m.Input('CLK')
14+
rst = m.Input('RST')
15+
led = m.OutputReg('LED', width)
16+
count = m.Reg('count', 32)
17+
18+
m.Always(Posedge(clk))(
19+
If(rst)(
20+
count(0)
21+
).Else(
22+
If(count == 1023)(
23+
count(0)
24+
).Else(
25+
count(count + 1)
26+
)
27+
))
28+
29+
m.Always(Posedge(clk))(
30+
If(rst)(
31+
led( 0 )
32+
).Else(
33+
If(count == 1023)(
34+
led( led + 1 )
35+
)
36+
))
37+
38+
return m
39+
40+
def mkTop():
41+
m = Module('top')
42+
led = mkLed()
43+
params= m.copy_params(led)
44+
ports = m.copy_ports(led)
45+
46+
m.Instance(led, 'inst_blinkled',
47+
m.connect_params(led), m.connect_ports(led))
48+
49+
return m
50+
51+
if __name__ == '__main__':
52+
top = mkTop()
53+
verilog = top.to_verilog()
54+
print(verilog)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import instance_connect_ports
2+
3+
expected_verilog = """
4+
module top #
5+
(
6+
parameter WIDTH = 8
7+
)
8+
(
9+
input CLK,
10+
input RST,
11+
output [WIDTH-1:0] LED
12+
);
13+
blinkled #
14+
(
15+
.WIDTH(WIDTH)
16+
)
17+
inst_blinkled
18+
(
19+
.CLK(CLK),
20+
.RST(RST),
21+
.LED(LED)
22+
);
23+
endmodule
24+
25+
module blinkled #
26+
(
27+
parameter WIDTH = 8
28+
)
29+
(
30+
input CLK,
31+
input RST,
32+
output reg [WIDTH-1:0] LED
33+
);
34+
reg [32-1:0] count;
35+
always @(posedge CLK) begin
36+
if(RST) begin
37+
count <= 0;
38+
end else begin
39+
if(count == 1023) begin
40+
count <= 0;
41+
end else begin
42+
count <= count + 1;
43+
end
44+
end
45+
end
46+
always @(posedge CLK) begin
47+
if(RST) begin
48+
LED <= 0;
49+
end else begin
50+
if(count == 1023) begin
51+
LED <= LED + 1;
52+
end
53+
end
54+
end
55+
endmodule
56+
"""
57+
58+
def test_led():
59+
test_module = instance_connect_ports.mkTop()
60+
code = test_module.to_verilog()
61+
62+
from pyverilog.vparser.parser import VerilogParser
63+
from pyverilog.ast_code_generator.codegen import ASTCodeGenerator
64+
parser = VerilogParser()
65+
expected_ast = parser.parse(expected_verilog)
66+
codegen = ASTCodeGenerator()
67+
expected_code = codegen.visit(expected_ast)
68+
69+
assert(expected_code == code)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
TARGET=*.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 *.out tmp.v uut.vcd
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sys
2+
import os
3+
import collections
4+
5+
# the next line can be removed after installation
6+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
7+
8+
from veriloggen import *
9+
10+
def mkLed():
11+
m = Module('blinkled')
12+
width = m.Parameter('WIDTH', 8)
13+
clk = m.Input('CLK')
14+
rst = m.Input('RST')
15+
led = m.OutputReg('LED', width)
16+
count = m.Reg('count', 32)
17+
18+
m.Always(Posedge(clk))(
19+
If(rst)(
20+
count(0)
21+
).Else(
22+
If(count == 1023)(
23+
count(0)
24+
).Else(
25+
count(count + 1)
26+
)
27+
))
28+
29+
m.Always(Posedge(clk))(
30+
If(rst)(
31+
led( 0 )
32+
).Else(
33+
If(count == 1023)(
34+
led( led + 1 )
35+
)
36+
))
37+
38+
return m
39+
40+
def mkTop():
41+
m = Module('top')
42+
led = mkLed()
43+
params= m.copy_params(led)
44+
ports = m.copy_ports(led)
45+
46+
m.Instance(led, 'inst_blinkled',
47+
connect_same_name(*params.values()), connect_same_name(*ports.values()))
48+
49+
return m
50+
51+
if __name__ == '__main__':
52+
top = mkTop()
53+
verilog = top.to_verilog()
54+
print(verilog)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import instance_connect_same_name
2+
3+
expected_verilog = """
4+
module top #
5+
(
6+
parameter WIDTH = 8
7+
)
8+
(
9+
input CLK,
10+
input RST,
11+
output [WIDTH-1:0] LED
12+
);
13+
blinkled #
14+
(
15+
.WIDTH(WIDTH)
16+
)
17+
inst_blinkled
18+
(
19+
.CLK(CLK),
20+
.RST(RST),
21+
.LED(LED)
22+
);
23+
endmodule
24+
25+
module blinkled #
26+
(
27+
parameter WIDTH = 8
28+
)
29+
(
30+
input CLK,
31+
input RST,
32+
output reg [WIDTH-1:0] LED
33+
);
34+
reg [32-1:0] count;
35+
always @(posedge CLK) begin
36+
if(RST) begin
37+
count <= 0;
38+
end else begin
39+
if(count == 1023) begin
40+
count <= 0;
41+
end else begin
42+
count <= count + 1;
43+
end
44+
end
45+
end
46+
always @(posedge CLK) begin
47+
if(RST) begin
48+
LED <= 0;
49+
end else begin
50+
if(count == 1023) begin
51+
LED <= LED + 1;
52+
end
53+
end
54+
end
55+
endmodule
56+
"""
57+
58+
def test_led():
59+
test_module = instance_connect_same_name.mkTop()
60+
code = test_module.to_verilog()
61+
62+
from pyverilog.vparser.parser import VerilogParser
63+
from pyverilog.ast_code_generator.codegen import ASTCodeGenerator
64+
parser = VerilogParser()
65+
expected_ast = parser.parse(expected_verilog)
66+
codegen = ASTCodeGenerator()
67+
expected_code = codegen.visit(expected_ast)
68+
69+
assert(expected_code == code)

tests/instance_/named_args/test_named_args.py renamed to tests/instance_/named_args/test_instance_named_args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import named_args
1+
import instance_named_args
22

33
expected_verilog = """
44
module top #
@@ -56,7 +56,7 @@
5656
"""
5757

5858
def test_led():
59-
test_module = named_args.mkTop()
59+
test_module = instance_named_args.mkTop()
6060
code = test_module.to_verilog()
6161

6262
from pyverilog.vparser.parser import VerilogParser

tests/instance_/noname_args/test_noname_args.py renamed to tests/instance_/noname_args/test_instance_noname_args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import noname_args
1+
import instance_noname_args
22

33
expected_verilog = """
44
module top #
@@ -56,7 +56,7 @@
5656
"""
5757

5858
def test_led():
59-
test_module = noname_args.mkTop()
59+
test_module = instance_noname_args.mkTop()
6060
code = test_module.to_verilog()
6161

6262
from pyverilog.vparser.parser import VerilogParser

0 commit comments

Comments
 (0)