-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdef.c
2294 lines (2066 loc) · 57.4 KB
/
def.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
/*
* def.c --
*
* This module incorporates the LEF/DEF format for standard-cell place and
* route.
*
* Version 0.1 (September 26, 2003): DEF input of designs.
*
* Written by Tim Edwards, Open Circuit Design
* Modified April 2013 for use with qrouter
*
* It is assumed that the LEF files have been read in prior to this, and
* layer information is already known. The DEF file should have information
* primarily on die are, track placement, pins, components, and nets.
*
* Routed nets have their routes dropped into track obstructions, and the
* nets are ignored.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <math.h> /* for roundf() function, if std=c99 */
#include "qrouter.h"
#include "node.h"
#include "qconfig.h"
#include "maze.h"
#include "lef.h"
#include "def.h"
TRACKS *Tracks = NULL;
int numSpecial = 0; /* Tracks number of specialnets */
#ifndef TCL_QROUTER
/* Find an instance in the instance list. If qrouter */
/* is compiled with Tcl support, then this routine */
/* uses Tcl hash tables, greatly speeding up the */
/* read-in of large DEF files. */
GATE
DefFindGate(char *name)
{
GATE ginst;
for (ginst = Nlgates; ginst; ginst = ginst->next) {
if (!strcasecmp(ginst->gatename, name))
return ginst;
}
return NULL;
}
/* Find a net in the list of nets. If qrouter is */
/* compiled with Tcl support, then this routine */
/* uses Tcl hash tables, greatly speeding up the */
/* read-in of large DEF files. */
NET
DefFindNet(char *name)
{
int i;
NET net;
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
if (!strcasecmp(net->netname, name))
return net;
}
return NULL;
}
/* For the non-Tcl version, these are empty placeholders */
static void
DefHashInit(void)
{
}
static void
DefHashInstance(GATE gateginfo)
{
}
static void
DefHashNet(NET net)
{
}
#else /* The versions using TCL hash tables */
#include <tk.h>
/* These hash tables speed up DEF file reading */
static Tcl_HashTable InstanceTable;
static Tcl_HashTable NetTable;
/*--------------------------------------------------------------*/
/* Cell macro lookup based on the hash table */
/*--------------------------------------------------------------*/
static void
DefHashInit(void)
{
/* Initialize the macro hash table */
Tcl_InitHashTable(&InstanceTable, TCL_STRING_KEYS);
Tcl_InitHashTable(&NetTable, TCL_STRING_KEYS);
}
GATE
DefFindGate(char *name)
{
GATE ginst;
Tcl_HashEntry *entry;
entry = Tcl_FindHashEntry(&InstanceTable, name);
ginst = (entry) ? (GATE)Tcl_GetHashValue(entry) : NULL;
return ginst;
}
NET
DefFindNet(char *name)
{
NET net;
Tcl_HashEntry *entry;
// Guard against calls to find nets before DEF file is read
if (Numnets == 0) return NULL;
entry = Tcl_FindHashEntry(&NetTable, name);
net = (entry) ? (NET)Tcl_GetHashValue(entry) : NULL;
return net;
}
/*--------------------------------------------------------------*/
/* Cell macro hash table generation */
/* Given an instance record, create an entry in the hash table */
/* for the instance name, with the record entry pointing to the */
/* instance record. */
/*--------------------------------------------------------------*/
static void
DefHashInstance(GATE gateginfo)
{
int new;
Tcl_HashEntry *entry;
entry = Tcl_CreateHashEntry(&InstanceTable,
gateginfo->gatename, &new);
if (entry != NULL)
Tcl_SetHashValue(entry, (ClientData)gateginfo);
}
/*--------------------------------------------------------------*/
/* Net hash table generation */
/* Given a net record, create an entry in the hash table for */
/* the net name, with the record entry pointing to the net */
/* record. */
/*--------------------------------------------------------------*/
static void
DefHashNet(NET net)
{
int new;
Tcl_HashEntry *entry;
entry = Tcl_CreateHashEntry(&NetTable, net->netname, &new);
if (entry != NULL)
Tcl_SetHashValue(entry, (ClientData)net);
}
#endif /* TCL_QROUTER */
/*
*------------------------------------------------------------
*
* DefGetTracks --
*
* Get tracks information for the given layer.
* If no TRACKS were specified for the layer, NULL will be
* returned.
*
*------------------------------------------------------------
*/
TRACKS
DefGetTracks(int layer)
{
if (Tracks)
return Tracks[layer];
else
return NULL;
}
/*
*------------------------------------------------------------
*
* DefAddRoutes --
*
* Parse a network route statement from the DEF file.
* If "special" is 1, then, add the geometry to the
* list of obstructions. If "special" is 0, then read
* the geometry into a route structure for the net.
*
* Results:
* Returns the last token encountered.
*
* Side Effects:
* Reads from input stream;
* Adds information to the layout database.
*
*------------------------------------------------------------
*/
static char *
DefAddRoutes(FILE *f, float oscale, NET net, char special)
{
char *token;
SEG newRoute = NULL;
DSEG lr, drect;
struct point_ refp;
char valid = FALSE; /* is there a valid reference point? */
char noobstruct;
char initial = TRUE;
struct dseg_ locarea;
double x, y, lx, ly, w, hw, s;
int routeLayer = -1, paintLayer;
LefList lefl;
ROUTE routednet = NULL;
refp.x1 = 0;
refp.y1 = 0;
/* Don't create obstructions or routes on routed specialnets inputs */
/* except for power and ground nets. */
noobstruct = ((special == (char)1) && (!(net->flags & NET_IGNORED)) &&
(net->netnum != VDD_NET) && (net->netnum != GND_NET)) ?
TRUE : FALSE;
while (initial || (token = LefNextToken(f, TRUE)) != NULL)
{
/* Get next point, token "NEW", or via name */
if (initial || !strcmp(token, "NEW") || !strcmp(token, "new"))
{
/* initial pass is like a NEW record, but has no NEW keyword */
initial = FALSE;
/* invalidate reference point */
valid = FALSE;
token = LefNextToken(f, TRUE);
routeLayer = LefFindLayerNum(token);
if (routeLayer < 0)
{
LefError(DEF_ERROR, "Unknown layer type \"%s\" for NEW route\n", token);
continue;
}
else if (routeLayer >= Num_layers)
{
LefError(DEF_ERROR, "DEF file contains layer \"%s\" which is"
" not allowed by the layer limit setting of %d\n",
token, Num_layers);
continue;
}
paintLayer = routeLayer;
if (special == (char)1)
{
/* SPECIALNETS has the additional width */
token = LefNextToken(f, TRUE);
if (sscanf(token, "%lg", &w) != 1)
{
LefError(DEF_ERROR, "Bad width in special net\n");
continue;
}
if (w != 0)
w /= oscale;
else
w = LefGetRouteWidth(paintLayer);
}
else
w = LefGetRouteWidth(paintLayer);
// Create a new route record, add to the 1st node
if (special == (char)0) {
routednet = (ROUTE)malloc(sizeof(struct route_));
routednet->next = net->routes;
net->routes = routednet;
routednet->netnum = net->netnum;
routednet->segments = NULL;
routednet->flags = (u_char)0;
routednet->start.route = NULL;
routednet->end.route = NULL;
}
}
else if (*token != '(') /* via name */
{
/* A '+' or ';' record ends the route */
if (*token == ';' || *token == '+')
break;
else if (valid == FALSE)
{
LefError(DEF_ERROR, "Route has via name \"%s\" but no points!\n", token);
continue;
}
lefl = LefFindLayer(token);
if (lefl != NULL)
{
/* The area to paint is derived from the via definitions. */
if (lefl != NULL)
{
if (lefl->lefClass == CLASS_VIA) {
// Note: layers may be defined in any order, metal or cut.
// Check both via.area and via.lr layers, and reject those
// that exceed the number of metal layers (those are cuts).
paintLayer = Num_layers - 1;
routeLayer = -1;
if (lefl->info.via.area.layer < Num_layers) {
routeLayer = lefl->info.via.area.layer;
if (routeLayer < paintLayer) paintLayer = routeLayer;
if ((routeLayer >= 0) && (special == (char)1) &&
(valid == TRUE) && (noobstruct == FALSE)) {
s = LefGetRouteSpacing(routeLayer);
drect = (DSEG)malloc(sizeof(struct dseg_));
drect->x1 = x + (lefl->info.via.area.x1 / 2.0) - s;
drect->x2 = x + (lefl->info.via.area.x2 / 2.0) + s;
drect->y1 = y + (lefl->info.via.area.y1 / 2.0) - s;
drect->y2 = y + (lefl->info.via.area.y2 / 2.0) + s;
drect->layer = routeLayer;
drect->next = UserObs;
UserObs = drect;
}
}
for (lr = lefl->info.via.lr; lr; lr = lr->next) {
if (lr->layer >= Num_layers) continue;
routeLayer = lr->layer;
if (routeLayer < paintLayer) paintLayer = routeLayer;
if ((routeLayer >= 0) && (special == (char)1) &&
(valid == TRUE) && (noobstruct == FALSE)) {
s = LefGetRouteSpacing(routeLayer);
drect = (DSEG)malloc(sizeof(struct dseg_));
drect->x1 = x + (lr->x1 / 2.0) - s;
drect->x2 = x + (lr->x2 / 2.0) + s;
drect->y1 = y + (lr->y1 / 2.0) - s;
drect->y2 = y + (lr->y2 / 2.0) + s;
drect->layer = routeLayer;
drect->next = UserObs;
UserObs = drect;
}
}
if (routeLayer == -1) paintLayer = lefl->type;
}
else {
paintLayer = lefl->type;
if (special == (char)1)
s = LefGetRouteSpacing(paintLayer);
}
}
else
{
LefError(DEF_ERROR, "Error: Via \"%s\" named but undefined.\n", token);
paintLayer = routeLayer;
}
if ((special == (char)0) && (paintLayer >= 0) &&
(paintLayer < (Num_layers - 1))) {
newRoute = (SEG)malloc(sizeof(struct seg_));
newRoute->segtype = ST_VIA;
newRoute->x1 = refp.x1;
newRoute->x2 = refp.x1;
newRoute->y1 = refp.y1;
newRoute->y2 = refp.y1;
newRoute->layer = paintLayer;
if (routednet == NULL) {
routednet = (ROUTE)malloc(sizeof(struct route_));
routednet->next = net->routes;
net->routes = routednet;
routednet->netnum = net->netnum;
routednet->segments = NULL;
routednet->flags = (u_char)0;
routednet->start.route = NULL;
routednet->end.route = NULL;
}
newRoute->next = routednet->segments;
routednet->segments = newRoute;
}
else {
if (paintLayer >= (Num_layers - 1))
/* Not necessarily an error to have predefined geometry */
/* above the route layer limit. */
LefError(DEF_WARNING, "Via \"%s\" exceeds layer "
"limit setting.\n", token);
else if (special == (char)0)
LefError(DEF_ERROR, "Via \"%s\" does not define a"
" metal layer!\n", token);
}
}
else
LefError(DEF_ERROR, "Via name \"%s\" unknown in route.\n", token);
}
else
{
/* Revert to the routing layer type, in case we painted a via */
paintLayer = routeLayer;
/* Record current reference point */
locarea.x1 = refp.x1;
locarea.y1 = refp.y1;
lx = x;
ly = y;
/* Read an (X Y) point */
token = LefNextToken(f, TRUE); /* read X */
if (*token == '*')
{
if (valid == FALSE)
{
LefError(DEF_ERROR, "No reference point for \"*\" wildcard\n");
goto endCoord;
}
}
else if (sscanf(token, "%lg", &x) == 1)
{
x /= oscale; // In microns
/* Note: offsets and stubs are always less than half a pitch, */
/* so round to the nearest integer grid point. */
refp.x1 = (int)(0.5 + ((x - Xlowerbound + EPS) / PitchX));
/* Flag offsets that are more than 1/3 track pitch, as they */
/* need careful analyzing (in route_set_connections()) to */
/* separate the main route from the stub route or offest. */
if ((special == (char)0) && ABSDIFF((double)refp.x1,
(x - Xlowerbound) / PitchX) > 0.33) {
if (routednet) routednet->flags |= RT_CHECK;
}
}
else
{
LefError(DEF_ERROR, "Cannot parse X coordinate.\n");
goto endCoord;
}
token = LefNextToken(f, TRUE); /* read Y */
if (*token == '*')
{
if (valid == FALSE)
{
LefError(DEF_ERROR, "No reference point for \"*\" wildcard\n");
if (newRoute != NULL) {
free(newRoute);
newRoute = NULL;
}
goto endCoord;
}
}
else if (sscanf(token, "%lg", &y) == 1)
{
y /= oscale; // In microns
refp.y1 = (int)(0.5 + ((y - Ylowerbound + EPS) / PitchY));
if ((special == (u_char)0) && ABSDIFF((double)refp.y1,
(y - Ylowerbound) / PitchY) > 0.33) {
if (routednet) routednet->flags |= RT_CHECK;
}
}
else
{
LefError(DEF_ERROR, "Cannot parse Y coordinate.\n");
goto endCoord;
}
/* Indicate that we have a valid reference point */
if (valid == FALSE)
{
valid = TRUE;
}
else if ((locarea.x1 != refp.x1) && (locarea.y1 != refp.y1))
{
/* Skip over nonmanhattan segments, reset the reference */
/* point, and output a warning. */
LefError(DEF_ERROR, "Can't deal with nonmanhattan geometry in route.\n");
locarea.x1 = refp.x1;
locarea.y1 = refp.y1;
lx = x;
ly = y;
}
else
{
locarea.x2 = refp.x1;
locarea.y2 = refp.y1;
if (special != (char)0) {
if ((valid == TRUE) && (noobstruct == FALSE)) {
s = LefGetRouteSpacing(routeLayer);
hw = w / 2;
drect = (DSEG)malloc(sizeof(struct dseg_));
if (lx > x) {
drect->x1 = x - s;
drect->x2 = lx + s;
}
else if (lx < x) {
drect->x1 = lx - s;
drect->x2 = x + s;
}
else {
drect->x1 = x - hw - s;
drect->x2 = x + hw + s;
}
if (ly > y) {
drect->y1 = y - s;
drect->y2 = ly + s;
}
else if (ly < y) {
drect->y1 = ly - s;
drect->y2 = y + s;
}
else {
drect->y1 = y - hw - s;
drect->y2 = y + hw + s;
}
drect->layer = routeLayer;
drect->next = UserObs;
UserObs = drect;
}
}
else if ((paintLayer >= 0) && (paintLayer < Num_layers)) {
newRoute = (SEG)malloc(sizeof(struct seg_));
newRoute->segtype = ST_WIRE;
// NOTE: Segments are added at the front of the linked
// list, so they are backwards from the entry in the
// DEF file. Therefore the first and second coordinates
// must be swapped, or the segments become disjoint.
newRoute->x1 = locarea.x2;
newRoute->x2 = locarea.x1;
newRoute->y1 = locarea.y2;
newRoute->y2 = locarea.y1;
newRoute->layer = paintLayer;
if (routednet == NULL) {
routednet = (ROUTE)malloc(sizeof(struct route_));
routednet->next = net->routes;
net->routes = routednet;
routednet->netnum = net->netnum;
routednet->segments = NULL;
routednet->flags = (u_char)0;
routednet->start.route = NULL;
routednet->end.route = NULL;
}
newRoute->next = routednet->segments;
routednet->segments = newRoute;
}
else if (paintLayer >= Num_layers) {
LefError(DEF_ERROR, "Route layer exceeds layer limit setting!\n");
}
}
endCoord:
/* Find the closing parenthesis for the coordinate pair */
while (*token != ')')
token = LefNextToken(f, TRUE);
}
}
/* Remove routes that are less than 1 track long; these are stub */
/* routes to terminals that did not require a specialnets entry. */
if (routednet && (net->routes == routednet) && (routednet->flags & RT_CHECK)) {
int ix, iy;
SEG seg;
seg = routednet->segments;
if (seg && seg->next == NULL) {
ix = ABSDIFF(seg->x1, seg->x2);
iy = ABSDIFF(seg->y1, seg->y2);
if ((ix == 0 && iy == 1) || (ix == 1 && iy == 0))
remove_top_route(net);
}
}
return token; /* Pass back the last token found */
}
/*
*------------------------------------------------------------
*
* DefReadGatePin ---
*
* Given a gate name and a pin name in a net from the
* DEF file NETS section, find the position of the
* gate, then the position of the pin within the gate,
* and add pin and obstruction information to the grid
* network.
*
*------------------------------------------------------------
*/
static void
DefReadGatePin(NET net, NODE node, char *instname, char *pinname, double *home)
{
int i;
GATE gateginfo;
DSEG drect;
GATE g;
double dx, dy;
int gridx, gridy;
DPOINT dp;
g = DefFindGate(instname);
if (g) {
gateginfo = g->gatetype;
if (!gateginfo) {
LefError(DEF_ERROR, "Endpoint %s/%s of net %s not found\n",
instname, pinname, net->netname);
return;
}
for (i = 0; i < gateginfo->nodes; i++) {
if (!strcasecmp(gateginfo->node[i], pinname)) {
node->taps = (DPOINT)NULL;
node->extend = (DPOINT)NULL;
for (drect = g->taps[i]; drect; drect = drect->next) {
// Add all routing gridpoints that fall inside
// the rectangle. Much to do here:
// (1) routable area should extend 1/2 route width
// to each side, as spacing to obstructions allows.
// (2) terminals that are wide enough to route to
// but not centered on gridpoints should be marked
// in some way, and handled appropriately.
gridx = (int)((drect->x1 - Xlowerbound) / PitchX) - 1;
if (gridx < 0) gridx = 0;
while (1) {
if (gridx >= NumChannelsX) break;
dx = (gridx * PitchX) + Xlowerbound;
if (dx > drect->x2 + home[drect->layer] - EPS) break;
if (dx < drect->x1 - home[drect->layer] + EPS) {
gridx++;
continue;
}
gridy = (int)((drect->y1 - Ylowerbound) / PitchY) - 1;
if (gridy < 0) gridy = 0;
while (1) {
if (gridy >= NumChannelsY) break;
dy = (gridy * PitchY) + Ylowerbound;
if (dy > drect->y2 + home[drect->layer] - EPS) break;
if (dy < drect->y1 - home[drect->layer] + EPS) {
gridy++;
continue;
}
// Routing grid point is an interior point
// of a gate port. Record the position
dp = (DPOINT)malloc(sizeof(struct dpoint_));
dp->layer = drect->layer;
dp->x = dx;
dp->y = dy;
dp->gridx = gridx;
dp->gridy = gridy;
if ((dy >= drect->y1 - EPS) &&
(dx >= drect->x1 - EPS) &&
(dy <= drect->y2 + EPS) &&
(dx <= drect->x2 + EPS)) {
dp->next = node->taps;
node->taps = dp;
}
else {
dp->next = node->extend;
node->extend = dp;
}
gridy++;
}
gridx++;
}
}
node->netnum = net->netnum;
g->netnum[i] = net->netnum;
g->noderec[i] = node;
node->netname = net->netname;
node->next = net->netnodes;
net->netnodes = node;
break;
}
}
if (i < gateginfo->nodes) return;
}
}
/*
*------------------------------------------------------------
*
* DefReadNets --
*
* Read a NETS or SPECIALNETS section from a DEF file.
*
* Results:
* Return the total number of fixed or cover nets,
* excluding power and ground nets. This gives the
* base number of nets to be copied verbatim from
* input to output (used only for SPECIALNETS, as
* regular nets are tracked with the NET_IGNORED flag).
*
* Side Effects:
* Many. Networks are created, and geometry may be
* painted into the database top-level cell.
*
*------------------------------------------------------------
*/
enum def_net_keys {DEF_NET_START = 0, DEF_NET_END};
enum def_netprop_keys {
DEF_NETPROP_USE = 0, DEF_NETPROP_ROUTED, DEF_NETPROP_FIXED,
DEF_NETPROP_COVER, DEF_NETPROP_SHAPE, DEF_NETPROP_SOURCE,
DEF_NETPROP_WEIGHT, DEF_NETPROP_PROPERTY};
static int
DefReadNets(FILE *f, char *sname, float oscale, char special, int total)
{
char *token;
int keyword, subkey;
int i, processed = 0;
int nodeidx;
int fixed = 0;
char instname[MAX_NAME_LEN], pinname[MAX_NAME_LEN];
u_char is_new;
NET net;
int netidx;
NODE node;
double home[MAX_LAYERS];
static char *net_keys[] = {
"-",
"END",
NULL
};
static char *net_property_keys[] = {
"USE",
"ROUTED",
"FIXED",
"COVER",
"SHAPE",
"SOURCE",
"WEIGHT",
"PROPERTY",
NULL
};
/* Set pitches and allocate memory for Obs[] if we haven't yet. */
set_num_channels();
if (Numnets == 0)
{
// Initialize net and node records
netidx = MIN_NET_NUMBER;
Nlnets = (NET *)malloc(total * sizeof(NET));
for (i = 0; i < total; i++) Nlnets[i] = NULL;
// Compute distance for keepout halo for each route layer
// NOTE: This must match the definition for the keepout halo
// used in nodes.c!
for (i = 0; i < Num_layers; i++) {
home[i] = LefGetViaWidth(i, i, 0) / 2.0 + LefGetRouteSpacing(i);
}
}
else {
netidx = Numnets;
Nlnets = (NET *)realloc(Nlnets, (Numnets + total) * sizeof(NET));
for (i = Numnets; i < (Numnets + total); i++) Nlnets[i] = NULL;
}
while ((token = LefNextToken(f, TRUE)) != NULL)
{
keyword = Lookup(token, net_keys);
if (keyword < 0)
{
LefError(DEF_WARNING, "Unknown keyword \"%s\" in NET "
"definition; ignoring.\n", token);
LefEndStatement(f);
continue;
}
switch (keyword)
{
case DEF_NET_START:
/* Get net name */
token = LefNextToken(f, TRUE);
net = DefFindNet(token);
if (net == NULL) {
net = (NET)malloc(sizeof(struct net_));
Nlnets[Numnets++] = net;
net->netorder = 0;
net->numnodes = 0;
net->flags = 0;
net->netname = strdup(token);
net->netnodes = (NODE)NULL;
net->noripup = (NETLIST)NULL;
net->routes = (ROUTE)NULL;
net->xmin = net->ymin = 0;
net->xmax = net->ymax = 0;
// Net numbers start at MIN_NET_NUMBER for regular nets,
// use VDD_NET and GND_NET for power and ground, and 0
// is not a valid net number.
if (vddnet && !strcmp(token, vddnet))
net->netnum = VDD_NET;
else if (gndnet && !strcmp(token, gndnet))
net->netnum = GND_NET;
else
net->netnum = netidx++;
DefHashNet(net);
nodeidx = 0;
is_new = TRUE;
}
else {
nodeidx = net->numnodes;
is_new = FALSE;
}
/* Update the record of the number of nets processed */
/* and spit out a message for every 5% finished. */
processed++;
/* Get next token; will be '(' if this is a netlist */
token = LefNextToken(f, TRUE);
/* Process all properties */
while (token && (*token != ';'))
{
/* Find connections for the net */
if (*token == '(')
{
token = LefNextToken(f, TRUE); /* get pin or gate */
strcpy(instname, token);
token = LefNextToken(f, TRUE); /* get node name */
if (!strcasecmp(instname, "pin")) {
strcpy(instname, token);
strcpy(pinname, "pin");
}
else
strcpy(pinname, token);
node = (NODE)calloc(1, sizeof(struct node_));
node->nodenum = nodeidx++;
DefReadGatePin(net, node, instname, pinname, home);
token = LefNextToken(f, TRUE); /* should be ')' */
continue;
}
else if (*token != '+')
{
token = LefNextToken(f, TRUE); /* Not a property */
continue; /* Ignore it, whatever it is */
}
else
token = LefNextToken(f, TRUE);
subkey = Lookup(token, net_property_keys);
if (subkey < 0)
{
LefError(DEF_WARNING, "Unknown net property \"%s\" in "
"NET definition; ignoring.\n", token);
continue;
}
switch (subkey)
{
case DEF_NETPROP_USE:
/* Presently, we ignore this */
break;
case DEF_NETPROP_SHAPE:
/* Ignore this too, along with the next keyword */
token = LefNextToken(f, TRUE);
break;
case DEF_NETPROP_FIXED:
case DEF_NETPROP_COVER:
/* Read in fixed nets like regular nets but mark
* them as NET_IGNORED. HOWEVER, if the net
* already exists and is not marked NET_IGNORED,
* then don't force it to be ignored. That is
* particularly an issue for a net like power or
* ground, which may need to be routed like a
* regular net but also has fixed portions. */
if (is_new) {
net->flags |= NET_IGNORED;
fixed++;
}
// fall through
case DEF_NETPROP_ROUTED:
// Read in the route; qrouter now takes
// responsibility for this route.
while (token && (*token != ';'))
token = DefAddRoutes(f, oscale, net, special);
// Treat power and ground nets in specialnets as fixed
if ((subkey == DEF_NETPROP_ROUTED ||
subkey == DEF_NETPROP_FIXED) &&
special == (char)1) {
if (net->netnum == VDD_NET || net->netnum == GND_NET)
fixed++;
}
break;
}
}
break;
case DEF_NET_END:
if (!LefParseEndStatement(f, sname))
{
LefError(DEF_ERROR, "Net END statement missing.\n");
keyword = -1;
}
break;
}
if (keyword == DEF_NET_END) break;
}
// Set the number of nodes per net for each node on the net
if (special == FALSE) {
// Fill in the netnodes list for each net, needed for checking
// for isolated routed groups within a net.
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
for (node = net->netnodes; node; node = node->next)
net->numnodes++;
for (node = net->netnodes; node; node = node->next)
node->numnodes = net->numnodes;
}
}
if (processed == total) {
if (Verbose > 0)
Fprintf(stdout, " Processed %d%s nets total (%d fixed).\n",
processed, (special) ? " special" : "", fixed);
}
else
LefError(DEF_WARNING, "Warning: Number of nets read (%d) does not match "
"the number declared (%d).\n", processed, total);
return fixed;
}
/*
*------------------------------------------------------------
*
* DefReadUseLocation --
*
* Read location and orientation of a cell use
* Syntax: ( X Y ) O
*
* Results:
* 0 on success, -1 on failure
*
* Side Effects:
* GATE definition for the use has the placedX, placedY,
* and orient values filled.
*------------------------------------------------------------
*/
enum def_orient {DEF_NORTH, DEF_SOUTH, DEF_EAST, DEF_WEST,
DEF_FLIPPED_NORTH, DEF_FLIPPED_SOUTH, DEF_FLIPPED_EAST,
DEF_FLIPPED_WEST};
static int
DefReadLocation(gate, f, oscale)
GATE gate;
FILE *f;
float oscale;
{
int keyword;
char *token;
float x, y;