This repository was archived by the owner on Feb 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakeBarrelConfig.py
More file actions
executable file
·128 lines (114 loc) · 4.06 KB
/
makeBarrelConfig.py
File metadata and controls
executable file
·128 lines (114 loc) · 4.06 KB
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
#!/usr/bin/env python3
import argparse
# Parse options
parser = argparse.ArgumentParser(description="Make a barrel-only configuration of the track finder.")
parser.add_argument("-w", "--wires", type=str, default="wires.dat", help="Reference wires.dat file (from full config)")
parser.add_argument("-p", "--process", type=str, default="processingmodules.dat", help="Reference processingmodules.dat file (from full config)")
parser.add_argument("-m", "--memories", type=str, default="memorymodules.dat", help="Reference memorymodules.dat file (from full config)")
args = parser.parse_args()
# First extract all the modules and wires for a barrel-only project
fin = open(args.wires)
outputWires = []
processingModules = []
memoryModules = []
dtcs = {}
for line in fin:
splitLine = line.split()
assert(len(splitLine) == 4 or len(splitLine) == 5)
memName = splitLine[0]
inputModule = None
outputModule = None
if len(splitLine) == 5:
inputModule = splitLine[2].split(".")[0]
outputModule = splitLine[4].split(".")[0]
else:
if splitLine[-1] == "output=>": # output track memory
inputModule = splitLine[2].split(".")[0]
else: # input link
outputModule = splitLine[-1].split(".")[0]
# Count the number of barrel-only InputRouters for each DTC and continue if
# this line is not barrel-only
dtc = None
if inputModule is not None and inputModule.startswith("IR_"):
assert(memName.startswith("IL_"))
dtc = inputModule[3:]
if dtc not in dtcs:
dtcs[dtc] = 0
dtcs[dtc] += 1
if "_D" in line or "L1D1" in line or "L2D1" in line:
if dtc is not None:
dtcs[dtc] -= 1
continue
outputWires.append(line)
memoryModules.append(memName)
if inputModule is not None:
processingModules.append(inputModule)
if outputModule is not None:
processingModules.append(outputModule)
fin.close()
# Next extract the processing module labels from the existing file; the order
# of the module types is recorded in the processPrefixes list, which is used to
# sort the output file
fin = open(args.process)
processLabels = {}
processPrefixes = []
for line in fin:
splitLine = line.split()
assert(len(splitLine) == 2)
prefix = splitLine[1].split("_")[0]
processLabels[prefix] = splitLine[0]
processPrefixes.append(prefix)
fin.close()
# Then extract the memory module labels and sizes from the existing file; the
# order of the module types is recorded in the memoryPrefixes list, which is
# used to sort the output file
fin = open(args.memories)
memoryLabels = {}
memorySizes = {}
memoryPrefixes = []
for line in fin:
splitLine = line.split()
assert(len(splitLine) == 3)
prefix = splitLine[1].split("_")[0]
memoryLabels[prefix] = splitLine[0]
memorySizes[prefix] = splitLine[2]
memoryPrefixes.append(prefix)
fin.close()
# Write the barrel-only wires file
fout = open("barrel_wires.dat", "w")
for line in outputWires:
output = True
for dtc in dtcs:
if dtcs[dtc] == 0 and dtc in line:
output = False
break
if not output:
continue
fout.write(line)
fout.close()
# Write the barrel-only processing modules file
fout = open("barrel_processingmodules.dat", "w")
for p in sorted(set(processingModules), key = lambda p : processPrefixes.index(p.split("_")[0])):
output = True
for dtc in dtcs:
if dtcs[dtc] == 0 and dtc in p:
output = False
break
if not output:
continue
prefix = p.split("_")[0]
fout.write(processLabels[prefix] + " " + p + "\n")
fout.close()
# Write the barrel-only memory modules file
fout = open("barrel_memorymodules.dat", "w")
for m in sorted(set(memoryModules), key = lambda m : memoryPrefixes.index(m.split("_")[0])):
output = True
for dtc in dtcs:
if dtcs[dtc] == 0 and dtc in m:
output = False
break
if not output:
continue
prefix = m.split("_")[0]
fout.write(memoryLabels[prefix] + " " + m + " " + memorySizes[prefix] + "\n")
fout.close()