-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathlef_layer_tf_number_mapper.pl
198 lines (179 loc) · 5.53 KB
/
lef_layer_tf_number_mapper.pl
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/depot/perl-5.003/bin/perl5.003 -w
# Written by Ahmed Abdelazeem
# March 11, 2024
# Updated to cover more LEF cases
# July 1, 2024
# A Perl script processes a technology file (.tf) and an LEF (Library Exchange Format) file to generate a mapping between layers defined in these files.
#
#
$EXPECTED_COMMAND_ARGS = 2;
if ($#ARGV < $EXPECTED_COMMAND_ARGS -1 )
{
die "Usage: lef_layer_tf_number_map.pl Tech_file_name.tf Lef_file_name.lef\n";
}
else
{
$tech_file = $ARGV[0];
$lef_file = $ARGV[1];
$tmp_s1 = $ARGV[0];
$tmp_s1 =~ s/\.tf/_tf/;
$tmp_s2 = $ARGV[1];
$tmp_s2 =~ s/\.lef/_lef/;
$lef_tf_map_file = $tmp_s2."_".$tmp_s1.".map";
$lef_tf_log_file = $tmp_s2."_".$tmp_s1.".log";
}
open tech_file or die "Can't open $tech_file\n";
open lef_file or die "Can't open $lef_file\n";
open lef_tf_log_file, ">$lef_tf_log_file" or die "Can't open $lef_tf_log_file\n";
open lef_tf_map_file, ">$lef_tf_map_file" or die "Can't open $lef_tf_map_file\n";
print_log( "\n*** Beginning to process $tech_file tech file***\n");
$i=0;
%tf_layerMaskNames = ();
%tf_layerMaskLayerNumber = ();
%tf_layerName = ();
$processing_tf_layer = 0;
$found_maskName = 0;
$tf_masks = 0;
while ($line = <tech_file>)
{
chop $line;
if ( $line =~ /^[lL][aA][yY][eE][rR][\s]+\"([\w\W]+)\"[\s]+\{.*$/ )
{
if ($processing_tf_layer ==0)
{
$processing_tf_layer = 1;
$tf_layer_name = $1;
print_log( "\nBeginning to process $tf_layer_name layer...\n");
}
}
elsif ( $line =~ /^[\s]*\}.*$/)
{
if ($processing_tf_layer ==1)
{
if ($found_maskName == 1)
{
$tf_layerMaskNames{$tf_masks} = $tf_maskName;
$tf_layerMaskLayerNumber{$tf_maskName} = $tf_layerNumber;
$tf_layerName{$tf_maskName} = $tf_layer_name;
$tf_masks++;
$found_maskName =0;
}
print_log( "Completed the processing of $tf_layer_name layer.\n");
$processing_tf_layer = 0;
}
}
elsif ( $line =~ /^[\s]*layerNumber[\s]*\=[\s]*([\d]+).*$/)
{
$tf_layerNumber = $1;
print_log( "Found the layerNumber $tf_layerNumber for the $tf_layer_name!\n");
}
elsif ( $line =~ /^[\s]*maskName[\s]*\=[\s]*\"([\w]+)\".*$/)
{
$tf_maskName = $1;
$found_maskName = 1;
print_log( "Found the maskName $tf_maskName for the $tf_layer_name!\n");
}
$i++;
}
#foreach $key (keys %tf_layerMaskNames)
# {
# print "tf_layerName=$tf_layerName{$tf_layerMaskNames{$key}} ";
# print "tf_mask_layerName=$tf_layerMaskNames{$key} ";
# print "tf_mask_layerNumber=$tf_layerMaskLayerNumber{$tf_layerMaskNames{$key}}\n";
# }
print_log( "\n*** Beginning to process $lef_file LEF file***\n");
%lef_layerDerivedMaskNames = ();
%lef_layerDerivedMaskLayerNumber = ();
%lef_layerName = ();
$i=0;
$lef_masks = 0;
$processing_lef_layer = 0;
$lef_prev_layerTYPE = "";
$metal_index = 0;
while ($line = <lef_file>)
{
chop $line;
# print "$line\n";
# print "$i th line:$line\n";
if ( $line =~ /^LAYER[\s]+([\w]+)[\s]*$/ )
{
if ($processing_lef_layer ==0)
{
$processing_lef_layer = 1;
$lef_layer_name = $1;
print_log( "\nBeginning to process $lef_layer_name layer...\n");
}
}
elsif ( $line =~ /^END[\s]+[\w]+[\s]*$/)
{
if ($processing_lef_layer ==1)
{
$lef_derivedmaskName = "";
if ( ($lef_layerTYPE eq "MASTERSLICE") && ($lef_masks == 0) )
{
$lef_derivedmaskName = "poly";
}
elsif ( ($lef_layerTYPE eq "CUT") && ($lef_prev_layerTYPE eq "MASTERSLICE") )
{
$lef_derivedmaskName = "polyCont";
}
elsif ( ($lef_layerTYPE eq "ROUTING") )
{
if ( $metal_index == 0) { $metal_index = 1; }
else { $metal_index++; }
$lef_derivedmaskName = "metal".$metal_index;
}
elsif ( ($lef_layerTYPE eq "CUT") && ($lef_prev_layerTYPE ne "MASTERSLICE"))
{
# print "lef_layerTYPE=$lef_layerTYPE;lef_masks=$lef_masks;lef_prev_layerTYPE=$lef_prev_layerTYPE\n";
$lef_derivedmaskName = "via".$metal_index;
}
elsif ( ($lef_layerTYPE eq "OVERLAP") )
{
print_log( "Skipping the OVERLAP Layer...\n");
}
else {
# print "lef_layerTYPE=$lef_layerTYPE;lef_masks=$lef_masks;lef_prev_layerTYPE=$lef_prev_layerTYPE\n";
die "Can not process due to issue...\n";
}
if ($lef_derivedmaskName ne "" )
{
$lef_derivedlayerNumber = $tf_layerMaskLayerNumber{$lef_derivedmaskName};
$lef_layerDerivedMaskNames{$lef_masks} = $lef_derivedmaskName;
$lef_layerDerivedMaskLayerNumber{$lef_derivedmaskName} = $lef_derivedlayerNumber;
$lef_layerName{$lef_derivedmaskName} = $lef_layer_name;
$lef_masks++;
}
print_log( "Completed the processing of $lef_layer_name layer.\n");
$processing_lef_layer = 0;
$lef_prev_layerTYPE = $lef_layerTYPE;
}
}
elsif ( $line =~ /^[\s]*TYPE[\s]+([\w]+)[\s]*\;.*$/)
{
$lef_layerTYPE = $1;
print_log( "Found the TYPE $lef_layerTYPE for the $lef_layer_name!\n");
}
$i++;
}
#foreach $key (keys %lef_layerDerivedMaskNames)
# {
# print "lef_layerName=$lef_layerName{$lef_layerDerivedMaskNames{$key}} ";
# print "lef_mask_layerName=$lef_layerDerivedMaskNames{$key} ";
# print "lef_mask_layerNumber=$lef_layerDerivedMaskLayerNumber{$lef_layerDerivedMaskNames{$key}}\n";
# }
print_log( "\n*** Printing the map file between $lef_file and $tech_file ***\n");
for ($j=0; $j < $lef_masks; $j++)
{
print_map("$lef_layerName{$lef_layerDerivedMaskNames{$j}}");
print_map(" $lef_layerDerivedMaskLayerNumber{$lef_layerDerivedMaskNames{$j}}\n");
}
close lef_tf_map_file;
sub print_log {
print "$_[0]";
print lef_tf_log_file "$_[0]";
}
sub print_map {
print "$_[0]";
print lef_tf_map_file "$_[0]";
}