File: check_inout.py

package info (click to toggle)
uhd 3.7.3-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 456,376 kB
  • ctags: 89,637
  • sloc: ansic: 51,090; cpp: 42,755; xml: 19,627; vhdl: 12,678; tcl: 5,944; python: 5,870; ada: 2,760; sh: 2,175; makefile: 615; pascal: 230; csh: 224; perl: 11
file content (62 lines) | stat: -rwxr-xr-x 2,122 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
#
# Copyright 2010 Ettus Research LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Description:
# generates a list of inputs and outputs from the top-level Verilog file and cross-references them to the .ucf.
# outputs errors for pins that aren't found in the UCF, checks for capitalization errors and other common mistakes

import sys
import re

if __name__=='__main__':
  if len(sys.argv) == 2:
    print "Usage: %s <top level Verilog file> <pin definition UCF>"
    sys.exit(-1)

  verilog_filename = sys.argv[1]
  ucf_filename = sys.argv[2]

  verilog_file = open(verilog_filename, 'r')
  ucf_file = open(ucf_filename, 'r')

  verilog_iolist = list()
  ucf_iolist = list()

  #read in all input, inout, and output declarations and compile a list
  for line in verilog_file:
    for match in re.findall(r"(?:input|inout|output) (?:reg )*(?:\[.*\] )*(\w+)", line.split("//")[0]):
      verilog_iolist.append(match)

  for line in ucf_file:
      m = re.search(r"""NET "(\w+).*" """, line.split("#")[0])
      if m is not None:
        ucf_iolist.append(m.group(1))

  #now find corresponding matches and error when you don't find one
  #we search for .v defs without matching .ucf defs since the reverse isn't necessarily a problem
  err = False

  for item in verilog_iolist:
    if item not in ucf_iolist:
      print "Error: %s appears in the top-level Verilog file, but is not in the UCF definition file!" % item
      err = True

  if err:
    sys.exit(-1)

  print "No errors found."
  sys.exit(0)