-
Notifications
You must be signed in to change notification settings - Fork 152
/
sdfmerge.py
78 lines (58 loc) · 2.49 KB
/
sdfmerge.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
#!/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
import argparse
import json
from sdf_timing import sdfparse
from prjxray.util import OpenSafeFile
def merge(timings_list, site):
merged_timings = dict()
for timings in timings_list:
divider = '/'
if 'divider' in timings['header']:
divider = timings['header']['divider']
for cell in timings['cells']:
for cell_instance in timings['cells'][cell]:
if site in cell_instance.split(divider):
if 'cells' not in merged_timings:
merged_timings['cells'] = dict()
if cell not in merged_timings['cells']:
merged_timings['cells'][cell] = dict()
if cell_instance not in merged_timings['cells'][cell]:
merged_timings['cells'][cell][cell_instance] = dict()
if cell_instance in merged_timings['cells'][cell][
cell_instance]:
assert merged_timings['cells'][cell][cell_instance] == \
timings['cells'][cell][cell_instance], \
"Attempting to merge differing cells"
merged_timings['cells'][cell][cell_instance] = timings[
'cells'][cell][cell_instance]
return merged_timings
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--sdfs', nargs='+', type=str, help="List of sdf files to merge")
parser.add_argument('--site', type=str, help="Site we want to merge")
parser.add_argument('--json', type=str, help="Debug JSON")
parser.add_argument('--out', type=str, help="Merged sdf name")
args = parser.parse_args()
timings_list = list()
for sdf in args.sdfs:
with OpenSafeFile(sdf, 'r') as fp:
timing = sdfparse.parse(fp.read())
timings_list.append(timing)
merged_sdf = merge(timings_list, args.site)
with OpenSafeFile(args.out, 'w') as fp:
fp.write(sdfparse.emit(merged_sdf, timescale='1ns'))
if args.json is not None:
with OpenSafeFile(args.json, 'w') as fp:
json.dump(merged_sdf, fp, indent=4, sort_keys=True)
if __name__ == '__main__':
main()