forked from f4pga/prjxray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_missing_segbits.py
executable file
·241 lines (190 loc) · 6.83 KB
/
find_missing_segbits.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2020 The Project X-Ray Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
"""
This script allows to find missing segbits in the database.
For each tile the script loads its 'tile_type_*.json' file and looks for all
non-pseudo pips there. Next it loads corresponding 'segbits_*.db' file (if found)
and checks if those pips are listed there.
Missing segbits for pips are reported as well as missing segbit files.
"""
import sys
import logging
import json
import argparse
import os
import re
from prjxray.util import OpenSafeFile
# =============================================================================
def read_pips_from_tile(tile_file):
"""
Loads pip definition from a tile type JSON file and returns non-pseudo
PIP name strings. Names are formatted as <dst_wire>.<src_wire>
"""
with OpenSafeFile(tile_file, "r") as fp:
root = json.load(fp)
pips = root["pips"]
pip_names = []
for pip in pips.values():
if int(pip["is_pseudo"]) == 0:
pip_names.append(
"{}.{}".format(pip["dst_wire"], pip["src_wire"]))
return pip_names
def read_ppips(ppips_file):
"""
Loads and parses ppips_*.db file. Returns a dict indexed by PIP name which
contains their types ("always", "default" or "hint")
"""
ppips = {}
with OpenSafeFile(ppips_file, "r") as fp:
for line in fp.readlines():
line = line.split()
if len(line) == 2:
full_pip_name = line[0].split(".")
pip_name = ".".join(full_pip_name[1:])
ppips[pip_name] = line[1]
return ppips
def read_segbits(segbits_file):
"""
Loads and parses segbits_*.db file. Returns only segbit names.
"""
segbits = []
with OpenSafeFile(segbits_file, "r") as fp:
for line in fp.readlines():
line = line.split()
if len(line) > 1:
fields = line[0].split(".")
segbit = ".".join(fields[1:])
segbits.append(segbit)
return segbits
# =============================================================================
def main(argv):
"""
The main
"""
exitcode = 0
# Parse arguments
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
"--db-root", type=str, required=True, help="Database root")
parser.add_argument(
"--verbose", type=int, default=0, help="Verbosity level 0-5")
parser.add_argument(
"--skip-tiles",
type=str,
nargs="*",
default=[],
help="Tile type name regex list for tile types to skip")
parser.add_argument(
"--incl-tiles",
type=str,
nargs="*",
default=[],
help="Tile type name regex list for tile types to include")
args = parser.parse_args(argv[1:])
logging.basicConfig(level=50 - args.verbose * 10, format="%(message)s")
# List files in DB root
files = os.listdir(args.db_root)
# List tile types
tile_types = []
for file in files:
match = re.match("^tile_type_(\\w+).json$", file)
if match:
tile_types.append(match.group(1))
tile_types.sort()
# Look for missing bits
for tile_type in tile_types:
# Check if we should include this tile
do_skip = len(args.incl_tiles) > 0
for pattern in args.incl_tiles:
if re.match(pattern, tile_type):
do_skip = False
break
# Check if we should skip this tile
for pattern in args.skip_tiles:
if re.match(pattern, tile_type):
do_skip = True
break
if do_skip:
continue
logging.critical(tile_type)
# DB file names
tile_file = os.path.join(
args.db_root, "tile_type_{}.json".format(tile_type.upper()))
ppips_file = os.path.join(
args.db_root, "ppips_{}.db".format(tile_type.lower()))
segbits_file = os.path.join(
args.db_root, "segbits_{}.db".format(tile_type.lower()))
# Load pips
pips = read_pips_from_tile(tile_file)
# Load ppips (if any)
if os.path.isfile(ppips_file):
ppips = read_ppips(ppips_file)
else:
ppips = {}
# Load segbits (if any)
if os.path.isfile(segbits_file):
segbits = read_segbits(segbits_file)
else:
segbits = []
# There are non-pseudo pips in this tile
if len(pips):
missing_bits = 0
known_bits = 0
# Build a list of pips to check. If a pip is listed in the ppips
# file and it is not "default" then make it a pseudo one
pips_to_check = []
for pip in pips:
if pip in ppips.keys() and ppips[pip] != "default":
continue
pips_to_check.append(pip)
# Missing segbits file
if len(segbits) == 0:
missing_bits = len(pips_to_check)
logging.critical(" MISSING: no segbits file!")
exitcode = -1
# Segbits file present
else:
# Check pips
for pip in pips_to_check:
if pip not in segbits:
# A "default" pip
if pip in ppips.keys() and ppips[pip] == "default":
missing_bits += 1
logging.error(
" WARNING: no bits for pip '{}' which defaults to VCC_WIRE"
.format(pip))
exitcode = -1
# A regular pip
else:
missing_bits += 1
logging.error(
" MISSING: no bits for pip '{}'".format(pip))
exitcode = -1
# The pip has segbits
else:
known_bits += 1
# Report missing bit count
if missing_bits > 0:
logging.critical(
" MISSING: no bits for {}/{} pips!".format(
missing_bits, missing_bits + known_bits))
exitcode = -1
else:
logging.critical(" OK: no missing bits")
# No pips
else:
logging.warning(" OK: no pips")
return exitcode
# =============================================================================
if __name__ == "__main__":
sys.exit(main(sys.argv))