forked from f4pga/prjxray
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sdfmerge.py
66 lines (47 loc) · 2.15 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
#!/usr/bin/env python3
import argparse
import json
from sdf_timing import sdfparse
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 open(sdf, 'r') as fp:
timing = sdfparse.parse(fp.read())
timings_list.append(timing)
merged_sdf = merge(timings_list, args.site)
open(args.out, 'w').write(sdfparse.emit(merged_sdf, timescale='1ns'))
if args.json is not None:
with open(args.json, 'w') as fp:
json.dump(merged_sdf, fp, indent=4, sort_keys=True)
if __name__ == '__main__':
main()