Skip to content

Commit c652fba

Browse files
committed
blocking substitution in always statements are fixed.
1 parent 3ff1849 commit c652fba

File tree

4 files changed

+114
-1
lines changed

4 files changed

+114
-1
lines changed

tests/core/blocking/Makefile

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

tests/core/blocking/blocking.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.abspath(__file__))))))
8+
9+
from veriloggen import *
10+
11+
def mkLed():
12+
m = Module('blinkled')
13+
width = m.Parameter('WIDTH', 8)
14+
clk = m.Input('CLK')
15+
rst = m.Input('RST')
16+
led = m.OutputReg('LED', width)
17+
count = m.Reg('count', 32)
18+
19+
m.Always(Posedge(clk))(
20+
If(rst)(
21+
count(0)
22+
).Else(
23+
If(count == 1023)(
24+
count(0)
25+
).Else(
26+
count(count + 1)
27+
)
28+
))
29+
30+
m.Always()(
31+
led(count, blk=True)
32+
)
33+
34+
return m
35+
36+
if __name__ == '__main__':
37+
led = mkLed()
38+
verilog = led.to_verilog()
39+
print(verilog)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
import blocking
4+
5+
expected_verilog = """
6+
module blinkled #
7+
(
8+
parameter WIDTH = 8
9+
)
10+
(
11+
input CLK,
12+
input RST,
13+
output reg [WIDTH-1:0] LED
14+
);
15+
reg [32-1:0] count;
16+
always @(posedge CLK) begin
17+
if(RST) begin
18+
count <= 0;
19+
end else begin
20+
if(count == 1023) begin
21+
count <= 0;
22+
end else begin
23+
count <= count + 1;
24+
end
25+
end
26+
end
27+
always @(*) begin
28+
LED = count;
29+
end
30+
endmodule
31+
"""
32+
33+
def test():
34+
test_module = blocking.mkLed()
35+
code = test_module.to_verilog()
36+
37+
from pyverilog.vparser.parser import VerilogParser
38+
from pyverilog.ast_code_generator.codegen import ASTCodeGenerator
39+
parser = VerilogParser()
40+
expected_ast = parser.parse(expected_verilog)
41+
codegen = ASTCodeGenerator()
42+
expected_code = codegen.visit(expected_ast)
43+
44+
assert(expected_code == code)

veriloggen/verilog/to_verilog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,8 @@ def visit_Subst(self, node):
798798
rdelay = self.visit(node.rdelay) if node.rdelay else None
799799
lvalue = vast.Lvalue(left)
800800
rvalue = vast.Rvalue(right)
801-
if node.blk: vast.BlockingSubstitution(lvalue, rvalue, ldelay, rdelay)
801+
if node.blk:
802+
return vast.BlockingSubstitution(lvalue, rvalue, ldelay, rdelay)
802803
return vast.NonblockingSubstitution(lvalue, rvalue, ldelay, rdelay)
803804

804805
#-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)