File tree Expand file tree Collapse file tree 11 files changed +317
-11
lines changed Expand file tree Collapse file tree 11 files changed +317
-11
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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 )
File renamed without changes.
Original file line number Diff line number Diff line change 1- import named_args
1+ import instance_named_args
22
33expected_verilog = """
44module top #
5656"""
5757
5858def 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
File renamed without changes.
Original file line number Diff line number Diff line change 1- import noname_args
1+ import instance_noname_args
22
33expected_verilog = """
44module top #
5656"""
5757
5858def 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
You can’t perform that action at this time.
0 commit comments