-
Notifications
You must be signed in to change notification settings - Fork 17
/
lef.c
4136 lines (3741 loc) · 105 KB
/
lef.c
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* lef.c --
*
* This module incorporates the LEF/DEF format for standard-cell routing
* route.
*
* Version 0.1 (September 26, 2003): LEF input handling. Includes creation
* of cells from macro statements, handling of pins, ports, obstructions, and
* associated geometry.
*
* Written by Tim Edwards, Open Circuit Design
* Modified June 2011 for use with qrouter.
*
* It is assumed that the "route.cfg" file has been called prior to this, and
* so the basic linked lists have been created. The contents of the LEF file
* will override anything in the route.cfg file, allowing the route.cfg file
* to contain a minimum of information, but also allowing for the possibility
* that there is no LEF file for the technology, and that all such information
* is in the route.cfg file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <sys/time.h>
#include <math.h>
#include "qrouter.h"
#include "node.h"
#include "qconfig.h"
#include "maze.h"
#include "lef.h"
/* ---------------------------------------------------------------------*/
/* Current line number for reading */
int lefCurrentLine = 0;
/* Information about routing layers */
LefList LefInfo = NULL;
/* Information about what vias to use */
LinkedStringPtr AllowedVias = NULL;
/* Gate information is in the linked list GateInfo, imported */
/*---------------------------------------------------------
* Lookup --
* Searches a table of strings to find one that matches a given
* string. It's useful mostly for command lookup.
*
* Only the portion of a string in the table up to the first
* blank character is considered significant for matching.
*
* Results:
* If str is the same as
* or an unambiguous abbreviation for one of the entries
* in table, then the index of the matching entry is returned.
* If str is not the same as any entry in the table, but
* an abbreviation for more than one entry,
* then -1 is returned. If str doesn't match any entry, then
* -2 is returned. Case differences are ignored.
*
* NOTE:
* Table entries need no longer be in alphabetical order
* and they need not be lower case. The irouter command parsing
* depends on these features.
*
* Side Effects:
* None.
*---------------------------------------------------------
*/
int
Lookup(str, table)
char *str; /* Pointer to a string to be looked up */
char *(table[]); /* Pointer to an array of string pointers
* which are the valid commands.
* The end of
* the table is indicated by a NULL string.
*/
{
int match = -2; /* result, initialized to -2 = no match */
int pos;
int ststart = 0;
/* search for match */
for (pos=0; table[pos] != NULL; pos++)
{
char *tabc = table[pos];
char *strc = &(str[ststart]);
while (*strc!='\0' && *tabc!=' ' &&
((*tabc==*strc) ||
(isupper(*tabc) && islower(*strc) && (tolower(*tabc)== *strc))||
(islower(*tabc) && isupper(*strc) && (toupper(*tabc)== *strc)) ))
{
strc++;
tabc++;
}
if (*strc=='\0')
{
/* entry matches */
if(*tabc==' ' || *tabc=='\0')
{
/* exact match - record it and terminate search */
match = pos;
break;
}
else if (match == -2)
{
/* inexact match and no previous match - record this one
* and continue search */
match = pos;
}
else
{
/* previous match, so string is ambiguous unless exact
* match exists. Mark ambiguous for now, and continue
* search.
*/
match = -1;
}
}
}
return(match);
}
/*
* ----------------------------------------------------------------------------
* LookupFull --
*
* Look up a string in a table of pointers to strings. The last
* entry in the string table must be a NULL pointer.
* This is much simpler than Lookup() in that it does not
* allow abbreviations. It does, however, ignore case.
*
* Results:
* Index of the name supplied in the table, or -1 if the name
* is not found.
*
* Side effects:
* None.
*
* ----------------------------------------------------------------------------
*/
int
LookupFull(name, table)
char *name;
char **table;
{
char **tp;
for (tp = table; *tp; tp++)
{
if (strcmp(name, *tp) == 0)
return (tp - table);
else
{
char *sptr, *tptr;
for (sptr = name, tptr = *tp; ((*sptr != '\0') && (*tptr != '\0'));
sptr++, tptr++)
if (toupper(*sptr) != toupper(*tptr))
break;
if ((*sptr == '\0') && (*tptr == '\0'))
return (tp - table);
}
}
return (-1);
}
/*
*------------------------------------------------------------
*
* LefNextToken --
*
* Move to the next token in the stream input.
* If "ignore_eol" is FALSE, then the end-of-line character
* "\n" will be returned as a token when encountered.
* Otherwise, end-of-line will be ignored.
*
* Results:
* Pointer to next token to parse
*
* Side Effects:
* May read a new line from the specified file.
*
* Warnings:
* The return result of LefNextToken will be overwritten by
* subsequent calls to LefNextToken if more than one line of
* input is parsed.
*
*------------------------------------------------------------
*/
char *
LefNextToken(FILE *f, u_char ignore_eol)
{
static char line[LEF_LINE_MAX + 2]; /* input buffer */
static char *nexttoken = NULL; /* pointer to next token */
static char *curtoken; /* pointer to current token */
static char eol_token='\n';
/* Read a new line if necessary */
if (nexttoken == NULL)
{
for(;;)
{
if (fgets(line, LEF_LINE_MAX + 1, f) == NULL) return NULL;
lefCurrentLine++;
curtoken = line;
while (isspace(*curtoken) && (*curtoken != '\n') && (*curtoken != '\0'))
curtoken++; /* skip leading whitespace */
if ((*curtoken != '#') && (*curtoken != '\n') && (*curtoken != '\0'))
{
nexttoken = curtoken;
break;
}
}
if (!ignore_eol)
return &eol_token;
}
else
curtoken = nexttoken;
/* Find the next token; set to NULL if none (end-of-line). */
/* Treat quoted material as a single token */
if (*nexttoken == '\"') {
nexttoken++;
while (((*nexttoken != '\"') || (*(nexttoken - 1) == '\\')) &&
(*nexttoken != '\0')) {
if (*nexttoken == '\n') {
if (fgets(nexttoken + 1, LEF_LINE_MAX -
(size_t)(nexttoken - line), f) == NULL)
return NULL;
}
nexttoken++; /* skip all in quotes (move past current token) */
}
if (*nexttoken == '\"')
nexttoken++;
}
else {
while (!isspace(*nexttoken) && (*nexttoken != '\0') && (*nexttoken != '\n'))
nexttoken++; /* skip non-whitespace (move past current token) */
}
/* Terminate the current token */
if (*nexttoken != '\0') *nexttoken++ = '\0';
while (isspace(*nexttoken) && (*nexttoken != '\0') && (*nexttoken != '\n'))
nexttoken++; /* skip any whitespace */
if ((*nexttoken == '#') || (*nexttoken == '\n') || (*nexttoken == '\0'))
nexttoken = NULL;
return curtoken;
}
/*
*------------------------------------------------------------
*
* LefError --
*
* Print an error message (via fprintf) giving the line
* number of the input file on which the error occurred.
*
* "type" should be either LEF_ERROR or LEF_WARNING (or DEF_*).
*
* Results:
* None.
*
* Side Effects:
* Prints to the output (stderr).
*
*------------------------------------------------------------
*/
void
LefError(int type, char *fmt, ...)
{
static int fatal = 0;
static int nonfatal = 0;
char lefordef = 'L';
int errors;
va_list args;
if (Verbose == 0) return;
if ((type == DEF_WARNING) || (type == DEF_ERROR)) lefordef = 'D';
errors = fatal + nonfatal;
if (fmt == NULL) /* Special case: report any errors and reset */
{
if (errors > 0)
{
Fprintf(stdout, "%cEF Read: encountered %d error%s and %d warning%s total.\n",
lefordef,
fatal, (fatal == 1) ? "" : "s",
nonfatal, (nonfatal == 1) ? "" : "s");
fatal = 0;
nonfatal = 0;
}
return;
}
if (errors < LEF_MAX_ERRORS)
{
Fprintf(stderr, "%cEF Read, Line %d: ", lefordef, lefCurrentLine);
va_start(args, fmt);
Vprintf(stderr, fmt, args);
va_end(args);
Flush(stderr);
}
else if (errors == LEF_MAX_ERRORS)
Fprintf(stderr, "%cEF Read: Further errors/warnings will not be reported.\n",
lefordef);
if ((type == LEF_ERROR) || (type == DEF_ERROR))
fatal++;
else if ((type == LEF_WARNING) || (type == DEF_WARNING))
nonfatal++;
}
/*
*------------------------------------------------------------
*
* LefParseEndStatement --
*
* Check if the string passed in "lineptr" contains the
* appropriate matching keyword. Sections in LEF files
* should end with "END (keyword)" or "END". To check
* against the latter case, "match" should be NULL.
*
* Results:
* TRUE if the line matches the expected end statement,
* FALSE if not.
*
* Side effects:
* None.
*
*------------------------------------------------------------
*/
u_char
LefParseEndStatement(FILE *f, char *match)
{
char *token;
int keyword;
char *match_name[2];
match_name[0] = match;
match_name[1] = NULL;
token = LefNextToken(f, (match == NULL) ? FALSE : TRUE);
if (token == NULL)
{
LefError(LEF_ERROR, "Bad file read while looking for END statement\n");
return FALSE;
}
/* END or ENDEXT */
if ((*token == '\n') && (match == NULL)) return TRUE;
/* END <section_name> */
else {
keyword = LookupFull(token, match_name);
if (keyword == 0)
return TRUE;
else
return FALSE;
}
}
/*
*------------------------------------------------------------
*
* LefSkipSection --
*
* Skip to the "END" record of a LEF input section
* String "section" must follow the "END" statement in
* the file to be considered a match; however, if
* section = NULL, then "END" must have no strings
* following.
*
* Results:
* None.
*
* Side Effects:
* Reads input from the specified file. Prints an
* error message if the expected END record cannot
* be found.
*
*------------------------------------------------------------
*/
void
LefSkipSection(FILE *f, char *section)
{
char *token;
int keyword;
static char *end_section[] = {
"END",
"ENDEXT",
NULL
};
while ((token = LefNextToken(f, TRUE)) != NULL)
{
if ((keyword = Lookup(token, end_section)) == 0)
{
if (LefParseEndStatement(f, section))
return;
}
else if (keyword == 1)
{
if (!strcmp(section, "BEGINEXT"))
return;
}
}
LefError(LEF_ERROR, "Section %s has no END record!\n", section);
return;
}
/*
*------------------------------------------------------------
*
* lefFindCell --
*
* "name" is the name of the cell to search for.
* Returns the GATE entry for the cell from the GateInfo
* list.
*
*------------------------------------------------------------
*/
GATE
lefFindCell(char *name)
{
GATE gateginfo;
for (gateginfo = GateInfo; gateginfo; gateginfo = gateginfo->next) {
if (!strcasecmp(gateginfo->gatename, name))
return gateginfo;
}
return (GATE)NULL;
}
/*
*------------------------------------------------------------
*
* LefLower --
*
* Convert a token in a LEF or DEF file to all-lowercase.
*
*------------------------------------------------------------
*/
char *
LefLower(char *token)
{
char *tptr;
for (tptr = token; *tptr != '\0'; tptr++)
*tptr = tolower(*tptr);
return token;
}
/*
*------------------------------------------------------------
* LefRedefined --
*
* In preparation for redefining a LEF layer, we need
* to first check if there are multiple names associated
* with the lefLayer entry. If so, split the entry into
* two copies, so that the redefinition doesn't affect
* the other LEF names.
*
* Results:
* Pointer to a lefLayer, which may or may not be the
* same one presented to the subroutine.
*
* Side Effects:
* May add an entry to the list of LEF layers.
*
*------------------------------------------------------------
*/
LefList
LefRedefined(LefList lefl, char *redefname)
{
LefList slef, newlefl;
char *altName;
int records;
DSEG drect;
/* check if more than one entry points to the same */
/* lefLayer record. If so, we will also record the */
/* name of the first type that is not the same as */
/* "redefname". */
records = 0;
altName = NULL;
for (slef = LefInfo; slef; slef = slef->next) {
if (slef == lefl)
records++;
if (altName == NULL)
if (strcmp(slef->lefName, redefname))
altName = (char *)slef->lefName;
}
if (records == 1)
{
/* Only one name associated with the record, so */
/* just clear all the allocated information. */
while (lefl->info.via.lr) {
drect = lefl->info.via.lr->next;
free(lefl->info.via.lr);
lefl->info.via.lr = drect;
}
newlefl = lefl;
}
else
{
slef = LefFindLayer(redefname);
newlefl = (LefList)malloc(sizeof(lefLayer));
newlefl->lefName = strdup(newlefl->lefName);
newlefl->next = LefInfo;
LefInfo = newlefl;
/* If the canonical name of the original entry */
/* is "redefname", then change it. */
if (!strcmp(slef->lefName, redefname))
if (altName != NULL)
slef->lefName = altName;
}
newlefl->type = -1;
newlefl->obsType = -1;
newlefl->info.via.area.x1 = 0.0;
newlefl->info.via.area.x2 = 0.0;
newlefl->info.via.area.y1 = 0.0;
newlefl->info.via.area.y2 = 0.0;
newlefl->info.via.area.layer = -1;
newlefl->info.via.cell = (GATE)NULL;
newlefl->info.via.lr = (DSEG)NULL;
return newlefl;
}
/*
*------------------------------------------------------------
* Find a layer record in the list of layers
*------------------------------------------------------------
*/
LefList
LefFindLayer(char *token)
{
LefList lefl, rlefl;
if (token == NULL) return NULL;
rlefl = (LefList)NULL;
for (lefl = LefInfo; lefl; lefl = lefl->next) {
if (!strcmp(lefl->lefName, token)) {
rlefl = lefl;
break;
}
}
return rlefl;
}
/*
*------------------------------------------------------------
* Find a layer record in the list of layers, by layer number
*------------------------------------------------------------
*/
LefList
LefFindLayerByNum(int layer)
{
LefList lefl, rlefl;
rlefl = (LefList)NULL;
for (lefl = LefInfo; lefl; lefl = lefl->next) {
if (lefl->type == layer) {
rlefl = lefl;
break;
}
}
return rlefl;
}
/*
*------------------------------------------------------------
* Find a layer record in the list of layers, and return the
* layer number.
*------------------------------------------------------------
*/
int
LefFindLayerNum(char *token)
{
LefList lefl;
lefl = LefFindLayer(token);
if (lefl)
return lefl->type;
else
return -1;
}
/*
*---------------------------------------------------------------
* Find the maximum layer number defined by the LEF file
* This includes layer numbers assigned to both routes and
* via cut layers.
*---------------------------------------------------------------
*/
int
LefGetMaxLayer(void)
{
int maxlayer = -1;
LefList lefl;
for (lefl = LefInfo; lefl; lefl = lefl->next) {
if (lefl->type > maxlayer)
maxlayer = lefl->type;
}
return (maxlayer + 1);
}
/*
*---------------------------------------------------------------
* Find the maximum routing layer number defined by the LEF file
*---------------------------------------------------------------
*/
int
LefGetMaxRouteLayer(void)
{
int maxlayer = -1;
LefList lefl;
for (lefl = LefInfo; lefl; lefl = lefl->next) {
if (lefl->lefClass != CLASS_ROUTE) continue;
if (lefl->type > maxlayer)
maxlayer = lefl->type;
}
return (maxlayer + 1);
}
/*
*------------------------------------------------------------
* Return the route keepout area, defined as the route space
* plus 1/2 the route width. This is the distance outward
* from an obstruction edge within which one cannot place a
* route.
*
* If no route layer is defined, then we pick up the value
* from information in the route.cfg file (if any). Here
* we define it as the route pitch less 1/2 the route width,
* which is the same as above if the route pitch has been
* chosen for minimum spacing.
*
* If all else fails, return zero.
*------------------------------------------------------------
*/
double
LefGetRouteKeepout(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.width / 2.0
+ lefl->info.route.spacing->spacing;
}
}
return MIN(PitchX, PitchY) - PathWidth[layer] / 2.0;
}
/*
*------------------------------------------------------------
* Similar routine to the above. Return the route width for
* a route layer. Return value in microns. If there is no
* LEF file information about the route width, then return
* half of the minimum route pitch.
*------------------------------------------------------------
*/
double
LefGetRouteWidth(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.width;
}
}
return MIN(PitchX, PitchY) / 2.0;
}
/*
*------------------------------------------------------------
* Similar routine to the above. Return the route offset for
* a route layer. Return value in microns. If there is no
* LEF file information about the route offset, then return
* half of the minimum route pitch.
*------------------------------------------------------------
*/
double
LefGetRouteOffset(int layer)
{
LefList lefl;
u_char o;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
o = lefl->info.route.hdirection;
if (o == TRUE)
return lefl->info.route.offsety;
else
return lefl->info.route.offsetx;
}
}
return MIN(PitchX, PitchY) / 2.0;
}
double
LefGetRouteOffsetX(int layer)
{
LefList lefl;
u_char o;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.offsetx;
}
}
return MIN(PitchX, PitchY) / 2.0;
}
double
LefGetRouteOffsetY(int layer)
{
LefList lefl;
u_char o;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.offsety;
}
}
return PitchY / 2.0;
}
/*
*------------------------------------------------------------
* Find and return the minimum metal area requirement for a
* route layer.
*------------------------------------------------------------
*/
double
LefGetRouteMinArea(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
return lefl->info.route.minarea;
}
}
return 0.0; /* Assume no minimum area requirement */
}
/*
*------------------------------------------------------------
* Determine and return the width of a via. The first layer
* is the base (lower) layer of the via (e.g., layer 0, or
* metal1, for via12). The second layer is the layer for
* which we want the width rule (e.g., 0 or 1, for metal1
* or metal2). If dir = 0, return the side-to-side width,
* otherwise, return the top-to-bottom width. This accounts
* for non-square vias.
*
* Note that Via rectangles are stored with x2 dimensions
* because the center can be on a half-grid position; so,
* return half the value obtained.
*
* This routine always uses a horizontally oriented via if
* available. See the specific LefGetXYViaWidth() routine
* for differentiation between via orientations.
*------------------------------------------------------------
*/
double
LefGetViaWidth(int base, int layer, int dir)
{
return LefGetXYViaWidth(base, layer, dir, 0);
}
/*
*------------------------------------------------------------
* The base routine used by LefGetViaWidth(), with an
* additional argument that specifies which via orientation
* to use, if an alternative orientation is available. This
* is necessary for doing checkerboard via patterning and for
* certain standard cells with ports that do not always fit
* one orientation of via.
*
* "orient" is defined as follows:
* 0 = XX = both layers horizontal
* 1 = XY = bottom layer horizontal, top layer vertical
* 2 = YX = bottom layer vertical, top layer horizontal
* 3 = YY = both layers vertical.
*
*------------------------------------------------------------
*/
double
LefGetXYViaWidth(int base, int layer, int dir, int orient)
{
DSEG lrect;
LefList lefl;
double width;
char **viatable;
switch (orient) {
case 0:
viatable = ViaXX;
break;
case 1:
viatable = ViaXY;
break;
case 2:
viatable = ViaYX;
break;
case 3:
viatable = ViaYY;
break;
}
if (*viatable == NULL)
lefl = NULL;
else
lefl = LefFindLayer(*(viatable + base));
/* The routine LefAssignLayerVias() should assign all Via** types. */
/* Below are fallback assignments. */
if (!lefl) {
switch (orient) {
case 0:
viatable = ViaXY;
break;
case 1:
viatable = ViaYX;
break;
case 2:
viatable = ViaYY;
break;
case 3:
viatable = ViaYX;
break;
}
lefl = LefFindLayer(*(viatable + base));
}
if (!lefl) {
switch (orient) {
case 0:
viatable = ViaYX;
break;
case 1:
viatable = ViaYY;
break;
case 2:
viatable = ViaXX;
break;
case 3:
viatable = ViaXY;
break;
}
lefl = LefFindLayer(*(viatable + base));
}
if (!lefl) {
switch (orient) {
case 0:
viatable = ViaYY;
break;
case 1:
viatable = ViaYX;
break;
case 2:
viatable = ViaXY;
break;
case 3:
viatable = ViaXX;
break;
}
lefl = LefFindLayer(*(viatable + base));
}
if (lefl) {
if (lefl->lefClass == CLASS_VIA) {
if (lefl->info.via.area.layer == layer) {
if (dir)
width = lefl->info.via.area.y2 - lefl->info.via.area.y1;
else
width = lefl->info.via.area.x2 - lefl->info.via.area.x1;
return width / 2.0;
}
for (lrect = lefl->info.via.lr; lrect; lrect = lrect->next) {
if (lrect->layer == layer) {
if (dir)
width = lrect->y2 - lrect->y1;
else
width = lrect->x2 - lrect->x1;
return width / 2.0;
}
}
}
}
return MIN(PitchX, PitchY) / 2.0; // Best guess
}
/*
*------------------------------------------------------------
* And another such routine, for route spacing (minimum width)
*------------------------------------------------------------
*/
double
LefGetRouteSpacing(int layer)
{
LefList lefl;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
if (lefl->info.route.spacing)
return lefl->info.route.spacing->spacing;
else
return 0.0;
}
}
return MIN(PitchX, PitchY) / 2.0;
}
/*
*------------------------------------------------------------
* Find route spacing to a metal layer of specific width
*------------------------------------------------------------
*/
double
LefGetRouteWideSpacing(int layer, double width)
{
LefList lefl;
lefSpacingRule *srule;
double spacing;
lefl = LefFindLayerByNum(layer);
if (lefl) {
if (lefl->lefClass == CLASS_ROUTE) {
// Prepare a default in case of bad values
spacing = lefl->info.route.spacing->spacing;
for (srule = lefl->info.route.spacing; srule; srule = srule->next) {
if (srule->width > width) break;
spacing = srule->spacing;
}
return spacing;
}
}