-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlef_parser.py
More file actions
81 lines (57 loc) · 2.15 KB
/
lef_parser.py
File metadata and controls
81 lines (57 loc) · 2.15 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
import numpy as np
class Macro:
def __init__(self, name):
self.name = name
self.pins = dict() # dictionary of Pin objects. Key: name of the pin.
self.width = 0
self.height = 0
def numberPins(self):
return len(self.pins)
def addPin(self, pin):
'''
pin: Pin object
'''
self.pins[pin.name] = pin
def setWidth(self, w):
self.width = w
def setHeight(self, h):
self.height = h
class Pin:
def __init__(self,name):
self.name = name
def parse_lef(file):
pinBlock = False # True if we are in a PIN block.
macroBlock = False # True if we are in a MACRO block.
macros = dict() # Dictionary of Macro objects. Key: macro name.
with open(file, 'r') as f:
line = f.readline()
while line:
line = line.strip()
# print line
if 'PIN' in line:
pin = Pin(line.split()[1]) # Create a Pin object. The name of the pin is the second word in the line 'PIN ...'
macro.addPin(pin)
# print "Added the pin '"+str(pin.name)+"' to the macro '"+str(macro.name)+"'."
if 'MACRO' in line:
macro = Macro(line.split()[1]) # Create a Macro object. The name of the macro is the second word in the line 'MACRO ...'
macros[macro.name] = macro
if 'SIZE' in line:
# Sample line: SIZE 0.42 BY 0.24 ;
# width BY height
size = line.split()
macro.setWidth(float(size[1]))
macro.setHeight(float(size[3]))
line = f.readline()
return macros
if __name__ == "__main__":
lef_file = "/home/para/dev/def_parser/lef/N07_7.5TMint_7.5TM2_M1open.lef"
macros = parse_lef(lef_file)
output = ""
for key in macros:
output += "{}, {}, {} by {}\n".format(macros[key].name, str(len(macros[key].pins)), macros[key].width, macros[key].height)
# Compute mean width
widths = []
for key, macro in macros.items():
widths.append(macro.width)
output += "Mean width: {}\n".format(np.mean(widths))
print output