-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathroutefile.py
executable file
·97 lines (81 loc) · 3.4 KB
/
routefile.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
#!/usr/bin/python
#
# Copyright 2019 Steve White
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the 'Software'),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
import re
class RouteFile:
nets_by_name = {}
nets_by_tile = {}
def __init__(self, filename):
tilepat = re.compile('(\w+)\((\d+),(\d+)\):(\w+)')
with open(filename, "r") as file:
net = None
num_paths = 0
paths = None
while True:
line = file.readline().rstrip()
if line.startswith("Skews"):
break
elif line.startswith(" net :"):
net = line.split('"')[1]
elif line.startswith(" path : "):
num_paths = int(line[9:])
if num_paths > 0:
paths = []
self.nets_by_name[net] = paths
elif net is not None and num_paths > 0:
num_paths -= 1
path = line.split('"')[1]
paths.append(path)
comps = tilepat.search(path)
data = {'type': comps.group(1), 'x': comps.group(2), 'y': comps.group(3), 'config':comps.group(4)}
if data['x'] not in self.nets_by_tile:
self.nets_by_tile[data['x']] = {}
x = self.nets_by_tile[data['x']]
if data['y'] not in x:
x[data['y']] = {}
y = x[data['y']]
if data['config'] not in y:
y[data['config']] = net
def path_for_net(self, net):
return self.nets_by_name[net]
def nets_for_tile(self, tile_x, tile_y):
tile_x = str(tile_x)
tile_y = str(tile_y)
if tile_x not in self.nets_by_tile:
return None
x = self.nets_by_tile[tile_x]
if tile_y not in x:
return None
return x[tile_y]
def net_for_tile_config(self, tile_x, tile_y, config):
nets = self.nets_for_tile(tile_x, tile_y)
if nets is None:
return None
if config.startswith("alta_slice"):
config = config[13:]
# how to map?:
# iotile alta_ioreg
# bramtile bufmux
# logictile bufmux
if config not in nets:
return None
return nets[config]