Skip to content

Commit b0b60e7

Browse files
committed
empty parameter list is acceptable
1 parent 8534713 commit b0b60e7

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed

pyverilog/vparser/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,10 @@ def p_param_args_one(self, p):
16831683
p[0] = (p[1],)
16841684
p.set_lineno(0, p.lineno(1))
16851685

1686+
def p_param_args_empty(self, p):
1687+
'param_args : empty'
1688+
p[0] = ()
1689+
16861690
def p_param_arg_noname_exp(self, p):
16871691
'param_arg_noname : expression'
16881692
p[0] = ParamArg(None, p[1], lineno=p.lineno(1))
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
import os
4+
import sys
5+
from pyverilog.vparser.parser import VerilogCodeParser
6+
7+
try:
8+
from StringIO import StringIO
9+
except:
10+
from io import StringIO
11+
12+
codedir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + '/verilogcode/'
13+
14+
expected = """\
15+
Source: (at 1)
16+
Description: (at 1)
17+
ModuleDef: TOP (at 1)
18+
Paramlist: (at 0)
19+
Portlist: (at 2)
20+
Ioport: (at 3)
21+
Input: CLK, False (at 3)
22+
Ioport: (at 4)
23+
Input: RST, False (at 4)
24+
Ioport: (at 5)
25+
Output: LED, False (at 5)
26+
Width: (at 5)
27+
IntConst: 7 (at 5)
28+
IntConst: 0 (at 5)
29+
InstanceList: led (at 9)
30+
Instance: inst_led, led (at 9)
31+
PortArg: CLK (at 14)
32+
Identifier: CLK (at 14)
33+
PortArg: RST (at 15)
34+
Identifier: RST (at 15)
35+
PortArg: LED (at 16)
36+
Identifier: LED (at 16)
37+
ModuleDef: led (at 21)
38+
Paramlist: (at 21)
39+
Decl: (at 23)
40+
Parameter: STEP, False (at 23)
41+
Rvalue: (at 23)
42+
IntConst: 10 (at 23)
43+
Portlist: (at 25)
44+
Ioport: (at 26)
45+
Input: CLK, False (at 26)
46+
Ioport: (at 27)
47+
Input: RST, False (at 27)
48+
Ioport: (at 28)
49+
Output: LED, False (at 28)
50+
Width: (at 28)
51+
IntConst: 7 (at 28)
52+
IntConst: 0 (at 28)
53+
Reg: LED, False (at 28)
54+
Width: (at 28)
55+
IntConst: 7 (at 28)
56+
IntConst: 0 (at 28)
57+
Decl: (at 31)
58+
Reg: count, False (at 31)
59+
Width: (at 31)
60+
IntConst: 31 (at 31)
61+
IntConst: 0 (at 31)
62+
Always: (at 33)
63+
SensList: (at 33)
64+
Sens: posedge (at 33)
65+
Identifier: CLK (at 33)
66+
Block: None (at 33)
67+
IfStatement: (at 34)
68+
Identifier: RST (at 34)
69+
Block: None (at 34)
70+
NonblockingSubstitution: (at 35)
71+
Lvalue: (at 35)
72+
Identifier: count (at 35)
73+
Rvalue: (at 35)
74+
IntConst: 0 (at 35)
75+
NonblockingSubstitution: (at 36)
76+
Lvalue: (at 36)
77+
Identifier: LED (at 36)
78+
Rvalue: (at 36)
79+
IntConst: 0 (at 36)
80+
Block: None (at 37)
81+
IfStatement: (at 38)
82+
Eq: (at 38)
83+
Identifier: count (at 38)
84+
Minus: (at 38)
85+
Identifier: STEP (at 38)
86+
IntConst: 1 (at 38)
87+
Block: None (at 38)
88+
NonblockingSubstitution: (at 39)
89+
Lvalue: (at 39)
90+
Identifier: count (at 39)
91+
Rvalue: (at 39)
92+
IntConst: 0 (at 39)
93+
NonblockingSubstitution: (at 40)
94+
Lvalue: (at 40)
95+
Identifier: LED (at 40)
96+
Rvalue: (at 40)
97+
Plus: (at 40)
98+
Identifier: LED (at 40)
99+
IntConst: 1 (at 40)
100+
Block: None (at 41)
101+
NonblockingSubstitution: (at 42)
102+
Lvalue: (at 42)
103+
Identifier: count (at 42)
104+
Rvalue: (at 42)
105+
Plus: (at 42)
106+
Identifier: count (at 42)
107+
IntConst: 1 (at 42)
108+
"""
109+
110+
def test():
111+
filelist = [codedir + 'instance_empty_params.v']
112+
output = 'preprocess.out'
113+
include = [codedir]
114+
define = []
115+
116+
parser = VerilogCodeParser(filelist,
117+
preprocess_include=include,
118+
preprocess_define=define)
119+
ast = parser.parse()
120+
directives = parser.get_directives()
121+
122+
output = StringIO()
123+
ast.show(buf=output)
124+
125+
for lineno, directive in directives:
126+
output.write('Line %d : %s' % (lineno, directive))
127+
128+
rslt = output.getvalue()
129+
130+
print(rslt)
131+
assert(expected == rslt)
132+
133+
if __name__ == '__main__':
134+
test()

verilogcode/instance_empty_params.v

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module TOP
2+
(
3+
input CLK,
4+
input RST,
5+
output [7:0] LED
6+
);
7+
8+
// empty parameter
9+
led #
10+
(
11+
)
12+
inst_led
13+
(
14+
.CLK(CLK),
15+
.RST(RST),
16+
.LED(LED)
17+
);
18+
19+
endmodule
20+
21+
module led #
22+
(
23+
parameter STEP = 10
24+
)
25+
(
26+
input CLK,
27+
input RST,
28+
output reg [7:0] LED
29+
);
30+
31+
reg [31:0] count;
32+
33+
always @(posedge CLK) begin
34+
if(RST) begin
35+
count <= 0;
36+
LED <= 0;
37+
end else begin
38+
if(count == STEP - 1) begin
39+
count <= 0;
40+
LED <= LED + 1;
41+
end else begin
42+
count <= count + 1;
43+
end
44+
end
45+
end
46+
endmodule

0 commit comments

Comments
 (0)