-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpin_connection.py
More file actions
39 lines (27 loc) · 1.09 KB
/
pin_connection.py
File metadata and controls
39 lines (27 loc) · 1.09 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
def parse_netlist(filename):
with open(filename, 'r') as f:
lines = f.readlines()
connection_counts = {}
in_subckt = False
ports = [] # to store the pins from .subckt
for line in lines:
line = line.strip()
if '.ends' in line:
in_subckt = False
if in_subckt:
tokens = line.split()
for token in tokens:
# Only count the pins that are in the ports list
if token in ports:
if token not in connection_counts:
connection_counts[token] = 1
else:
connection_counts[token] += 1
if '.subckt' in line:
in_subckt = True
ports = line.split()[2:] # ports are listed after .subckt and before component instances
for port in ports:
# Initialize count for each port, counting its occurrence in the .subckt line as a connection
if port not in connection_counts:
connection_counts[port] = 0
return connection_counts