1
1
# -*- coding: utf-8 -*-
2
2
# Copyright © 2017 Kevin Thibedeau
3
3
# Distributed under the terms of the MIT license
4
+
5
+ """Verilog documentation parser"""
4
6
import io
5
7
import os
6
8
from collections import OrderedDict
9
+ from .minilexer import MiniLexer
7
10
8
- from hdlparse .minilexer import MiniLexer
9
-
10
- """Verilog documentation parser"""
11
11
12
12
verilog_tokens = {
13
13
# state
22
22
'module' : [
23
23
(r'parameter\s*(signed|integer|realtime|real|time)?\s*(\[[^]]+\])?' , 'parameter_start' , 'parameters' ),
24
24
(
25
- r'^[\(\s]*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor)?'
25
+ r'^[\(\s]*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor|logic )?'
26
26
r'\s*(signed)?\s*((\[[^]]+\])+)?' ,
27
27
'module_port_start' , 'module_port' ),
28
- (r'endmodule ' , 'end_module' , '#pop' ),
28
+ (r'\bendmodule\b ' , 'end_module' , '#pop' ),
29
29
(r'/\*' , 'block_comment' , 'block_comment' ),
30
30
(r'//#\s*{{(.*)}}\n' , 'section_meta' ),
31
31
(r'//.*\n' , None ),
40
40
],
41
41
'module_port' : [
42
42
(
43
- r'\s*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor)?'
43
+ r'\s*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor|logic )?'
44
44
r'\s*(signed)?\s*((\[[^]]+\])+)?' ,
45
45
'module_port_start' ),
46
46
(r'\s*(\w+)\s*,?' , 'port_param' ),
@@ -114,7 +114,7 @@ def parse_verilog_file(fname):
114
114
Returns:
115
115
List of parsed objects.
116
116
"""
117
- with open (fname , 'rt' ) as fh :
117
+ with open (fname , 'rt' , encoding = 'UTF-8' ) as fh :
118
118
text = fh .read ()
119
119
return parse_verilog (text )
120
120
@@ -130,25 +130,25 @@ def parse_verilog(text):
130
130
lex = VerilogLexer
131
131
132
132
name = None
133
- kind = None
134
- saved_type = None
133
+ # kind = None
134
+ # saved_type = None
135
135
mode = 'input'
136
136
port_type = 'wire'
137
137
param_type = ''
138
138
139
139
metacomments = []
140
- parameters = []
140
+ # parameters = []
141
141
142
142
generics = []
143
143
ports = OrderedDict ()
144
144
sections = []
145
145
port_param_index = 0
146
146
last_item = None
147
- array_range_start_pos = 0
147
+ # array_range_start_pos = 0
148
148
149
149
objects = []
150
150
151
- for pos , action , groups in lex .run (text ):
151
+ for _ , action , groups in lex .run (text ):
152
152
if action == 'metacomment' :
153
153
comment = groups [0 ].strip ()
154
154
if last_item is None :
@@ -160,7 +160,7 @@ def parse_verilog(text):
160
160
sections .append ((port_param_index , groups [0 ]))
161
161
162
162
elif action == 'module' :
163
- kind = 'module'
163
+ # kind = 'module'
164
164
name = groups [0 ]
165
165
generics = []
166
166
ports = OrderedDict ()
@@ -226,7 +226,7 @@ def is_verilog(fname):
226
226
Returns:
227
227
True when file has a Verilog extension.
228
228
"""
229
- return os .path .splitext (fname )[1 ].lower () in ('.vlog' , '.v' )
229
+ return os .path .splitext (fname )[1 ].lower () in ('.vlog' , '.v' , '.sv' )
230
230
231
231
232
232
class VerilogExtractor :
0 commit comments