forked from efabless/caravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_ant_areas.py
41 lines (35 loc) · 1.78 KB
/
insert_ant_areas.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
import os
# Set the directory path
directory_path = "./../lef/"
# Loop through all files in the directory
for filename in os.listdir(directory_path):
# Check if the file is a lef file
if filename.endswith(".lef"):
# Open the file for reading and editing
with open(os.path.join(directory_path, filename), "r+") as f:
lines = f.readlines()
print("Processing the lef file: ", os.path.join(directory_path, filename))
# define the lines to search for and the lines to insert
input_lines = ["PIN", "DIRECTION INPUT", "USE SIGNAL", "ANTENNAGATEAREA"]
input_insert = " ANTENNAGATEAREA 0.126000 ;\n"
output_lines = ["PIN", "DIRECTION OUTPUT", "USE SIGNAL", "ANTENNADIFFAREA"]
output_insert = " ANTENNADIFFAREA 0.340600 ;\n"
# iterate through the lines, searching for the lines to insert after
for i in range(len(lines)):
if input_lines[0] in lines[i]:
if input_lines[1] in lines[i+1]:
if input_lines[2] in lines[i+2]:
if input_lines[3] not in lines[i+3]:
lines.insert(i+3, input_insert)
else:
lines[i+3] = input_insert
if output_lines[0] in lines[i]:
if output_lines[1] in lines[i+1]:
if output_lines[2] in lines[i+2]:
if output_lines[3] not in lines[i+3]:
lines.insert(i+3, output_insert)
else:
lines[i+3] = output_insert
# write the modified contents back to the file
with open(os.path.join(directory_path, filename), "w") as f:
f.writelines(lines)