-
Notifications
You must be signed in to change notification settings - Fork 17
/
output.c
3077 lines (2792 loc) · 93.4 KB
/
output.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
/*--------------------------------------------------------------*/
/* output.c -- qrouter general purpose autorouter */
/* output routines for writing DEF file */
/*--------------------------------------------------------------*/
/* Written by Tim Edwards, June 2011, based on code by Steve */
/* Beccue, 2003 */
/*--------------------------------------------------------------*/
#include <ctype.h>
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef TCL_QROUTER
#include <tk.h>
#endif
#include "qrouter.h"
#include "qconfig.h"
#include "point.h"
#include "node.h"
#include "maze.h"
#include "mask.h"
#include "output.h"
#include "lef.h"
#include "def.h"
#include "graphics.h"
int Pathon = -1;
struct _savepath {
u_char active;
int x;
int y;
int orient;
} path_delayed;
/*--------------------------------------------------------------*/
/* Output a list of failed nets. */
/*--------------------------------------------------------------*/
int write_failed(char *filename)
{
FILE *ffail;
NET net;
NETLIST nl;
int failcount;
failcount = countlist(FailedNets);
if (failcount == 0) {
Fprintf(stdout, "There are no failing net routes.\n");
return 0;
}
ffail = fopen(filename, "w");
if (ffail == NULL) {
Fprintf(stderr, "Could not open file %s for writing.\n", filename);
return 1;
}
fprintf(ffail, "%d nets failed to route:\n", failcount);
for (nl = FailedNets; nl; nl = nl->next) {
net = nl->net;
fprintf(ffail, " %s\n", net->netname);
}
fclose(ffail);
return 0;
}
/*--------------------------------------------------------------*/
/* Write the output annotated DEF file. */
/*--------------------------------------------------------------*/
int write_def(char *filename)
{
NET net;
NETLIST nl;
emit_routes((filename == NULL) ? DEFfilename : filename,
Scales.oscale, Scales.iscale);
Fprintf(stdout, "----------------------------------------------\n");
Fprintf(stdout, "Final: ");
if (FailedNets == (NETLIST)NULL)
Fprintf(stdout, "No failed routes!\n");
else {
if (FailedNets != (NETLIST)NULL) {
Fprintf(stdout, "Failed net routes: %d\n", countlist(FailedNets));
Fprintf(stdout, "List of failed nets follows:\n");
// Output a list of the failed nets
for (nl = FailedNets; nl; nl = nl->next) {
net = nl->net;
Fprintf(stdout, " %s\n", net->netname);
}
Fprintf(stdout, "\n");
}
}
Fprintf(stdout, "----------------------------------------------\n");
return 0;
} /* write_def() */
/*--------------------------------------------------------------*/
/* pathstart - begin a DEF format route path */
/* */
/* If "special" is true, then this path is in a */
/* SPECIALNETS section, in which each route specifies */
/* a width. */
/*--------------------------------------------------------------*/
static void
pathstart(FILE *cmd, int layer, int x, int y, u_char special, double oscale,
double invscale, u_char horizontal, NODEINFO node)
{
if (Pathon == 1) {
Fprintf( stderr, "pathstart(): Major error. Started a new "
"path while one is in progress!\n"
"Doing it anyway.\n" );
}
if (layer >= 0) {
if (Pathon == -1)
fprintf(cmd, "+ ROUTED ");
else
fprintf(cmd, "\n NEW ");
if (special) {
double wvia;
int vtype = 0; /* Need to get via type from node record! */
if (node != NULL) {
if ((node->flags & NI_NO_VIAX) && (!(node->flags & NI_VIA_X)))
vtype = 2;
else if (node->flags & NI_VIA_Y)
vtype = 2;
}
else {
/* Assume via orientation matches default route direction. */
/* NOTE: Need to mark the actual orientation somehow. . . */
int ob = LefGetRouteOrientation((layer > 0) ? (layer - 1) : layer);
if (ob == 1) vtype = 2;
}
wvia = LefGetXYViaWidth(layer, layer, horizontal, vtype);
if (layer > 0) {
double wvia2;
wvia2 = LefGetXYViaWidth(layer - 1, layer, horizontal, vtype);
if (wvia2 > wvia) wvia = wvia2;
}
fprintf(cmd, "%s %ld ( %ld %ld ) ", CIFLayer[layer],
(long)(0.5 + invscale * oscale * wvia),
(long)(0.5 + invscale * x), (long)(0.5 + invscale * y));
}
else
fprintf(cmd, "%s ( %ld %ld ) ", CIFLayer[layer],
(long)(0.5 + invscale * x), (long)(0.5 + invscale * y));
}
Pathon = 1;
} /* pathstart() */
/*--------------------------------------------------------------*/
/* pathto - continue a path to the next point */
/* */
/* ARGS: coordinate pair */
/* RETURNS: */
/* SIDE EFFECTS: */
/*--------------------------------------------------------------*/
static void
pathto(FILE *cmd, int x, int y, int horizontal, int lastx, int lasty,
double invscale, u_char nextvia)
{
if (Pathon <= 0) {
Fprintf(stderr, "pathto(): Major error. Added to a "
"non-existent path!\n"
"Doing it anyway.\n");
}
/* If the route is not manhattan, then it's because an offset
* was added to the last point, and we need to add a small
* jog to the route.
*/
if ((x != lastx) && (y != lasty)) {
if (horizontal)
pathto(cmd, lastx, y, FALSE, lastx, lasty, invscale, 0);
else
pathto(cmd, x, lasty, TRUE, lastx, lasty, invscale, 0);
}
if (nextvia) {
/* Punt on output until via is output, because via may have an */
/* offset position that needs to be applied to the route. */
path_delayed.active = 1;
path_delayed.x = x;
path_delayed.y = y;
path_delayed.orient = horizontal;
return;
}
fprintf(cmd, "( ");
if (horizontal)
fprintf(cmd, "%ld ", (long)(0.5 + invscale * x));
else
fprintf(cmd, "* ");
if (horizontal)
fprintf(cmd, "* ");
else
fprintf(cmd, "%ld ", (long)(0.5 + invscale * y));
fprintf(cmd, ") ");
} /* pathto() */
/*--------------------------------------------------------------*/
/* pathvia - add a via to a path */
/* */
/* ARGS: coord */
/* RETURNS: */
/* SIDE EFFECTS: */
/*--------------------------------------------------------------*/
static void
pathvia(FILE *cmd, int layer, int x, int y, int lastx, int lasty,
char *vianame, double invscale)
{
if (path_delayed.active == 1) {
/* Output the last path */
pathto(cmd, path_delayed.x, path_delayed.y, path_delayed.orient,
path_delayed.x, path_delayed.y, invscale, 0);
path_delayed.active = 0;
}
if (Pathon <= 0) {
if (Pathon == -1)
fprintf(cmd, "+ ROUTED ");
else
fprintf(cmd, "\n NEW ");
fprintf(cmd, "%s ( %ld %ld ) ", CIFLayer[layer],
(long)(0.5 + invscale * x), (long)(0.5 + invscale * y));
}
else {
// Normally the path will be manhattan and only one of
// these will be true. But if the via gets an offset to
// avoid a DRC spacing violation with an adjacent via,
// then we may need to apply both paths to make a dog-leg
// route to the via.
if (x != lastx)
pathto(cmd, x, lasty, TRUE, lastx, lasty, invscale, 0);
if (y != lasty)
pathto(cmd, x, y, FALSE, x, lasty, invscale, 0);
}
fprintf(cmd, "%s ", vianame);
Pathon = 0;
} /* pathvia() */
/*--------------------------------------------------------------*/
/* Nodes aren't saved in a way that makes it easy to recall */
/* the name of the cell and pin to which they belong. But */
/* that information doesn't need to be looked up except as a */
/* diagnostic output. This routine does that lookup. */
/*--------------------------------------------------------------*/
char *print_node_name(NODE node)
{
GATE g;
int i;
char *nodestr = NULL;
for (g = Nlgates; g; g = g->next) {
for (i = 0; i < g->nodes; i++) {
if (g->noderec[i] == node) {
if (nodestr != NULL)
free(nodestr);
if (!strcmp(g->node[i], "pin")) {
nodestr = (char *)malloc(strlen(g->gatename) + 5);
sprintf(nodestr, "PIN/%s", g->gatename);
}
else {
nodestr = (char *)malloc(strlen(g->gatename)
+ strlen(g->node[i]) + 2);
sprintf(nodestr, "%s/%s", g->gatename, g->node[i]);
}
return nodestr;
}
}
}
if (nodestr != NULL) free(nodestr);
nodestr = (char *)malloc(22);
sprintf(nodestr, "(error: no such node)");
return nodestr;
}
/*--------------------------------------------------------------*/
/* print_nets - print the nets list - created from Nlgates list */
/* */
/* ARGS: filename to list to */
/* RETURNS: nothing */
/* SIDE EFFECTS: */
/* AUTHOR and DATE: steve beccue Sat July 26 */
/*--------------------------------------------------------------*/
void print_nets(char *filename)
{
FILE *o;
GATE g;
int i;
DSEG drect;
if (!strcmp(filename, "stdout")) {
o = stdout;
} else {
o = fopen(filename, "w");
}
if (!o) {
Fprintf(stderr, "route:print_nets. Couldn't open output file\n");
return;
}
for (g = Nlgates; g; g = g->next) {
fprintf(o, "%s: %s: nodes->", g->gatename, g->gatetype->gatename);
for (i = 0; i < g->nodes; i++) {
// This prints the first tap position only.
drect = g->taps[i];
fprintf( o, "%s(%g,%g) ", g->node[i], drect->x1, drect->y1);
}
}
fprintf( o, "\n");
} /* print_nets() */
/*--------------------------------------------------------------*/
/* print_routes - print the routes list */
/* */
/* ARGS: filename to list to */
/* RETURNS: nothing */
/* SIDE EFFECTS: */
/* AUTHOR and DATE: steve beccue Sat July 26 */
/*--------------------------------------------------------------*/
void print_routes( char *filename )
{
FILE *o;
GATE g;
int i;
if( !strcmp( filename, "stdout" ) ) {
o = stdout;
} else {
o = fopen( filename, "w" );
}
if( !o ) {
Fprintf( stderr, "route:print_routes. Couldn't open output file\n" );
return;
}
for (g = Nlgates; g; g = g->next) {
fprintf( o, "%s: %s: nodes->", g->gatename, g->gatetype->gatename );
for( i = 0 ; i < g->nodes; i++ ) {
fprintf( o, "%s ", g->node[i] );
}
fprintf(o, "\n");
}
} /* print_routes() */
/*--------------------------------------------------------------*/
/* print_nlgates - print the nlgate list */
/* */
/* ARGS: filename to list to */
/* RETURNS: nothing */
/* SIDE EFFECTS: */
/* AUTHOR and DATE: steve beccue Wed July 23 */
/*--------------------------------------------------------------*/
void print_nlgates( char *filename )
{
FILE *o;
GATE g;
int i;
DSEG drect;
if( !strcmp( filename, "stdout" ) ) {
o = stdout;
} else {
o = fopen( filename, "w" );
}
if( !o ) {
Fprintf( stderr, "route:print_nlgates. Couldn't open output file\n" );
return;
}
for (g = Nlgates; g; g = g->next) {
fprintf( o, "%s: %s: nodes->", g->gatename, g->gatetype->gatename );
for( i = 0 ; i < g->nodes; i++ ) {
// This prints the first tap position only.
drect = g->taps[i];
fprintf( o, "%s(%g,%g)", g->node[i], drect->x1, drect->y1);
}
fprintf(o, "\n");
}
} /* print_nlgates() */
/*--------------------------------------------------------------*/
/* print_net - print info about the net to stdout */
/* */
/* ARGS: net to print info about */
/* RETURNS: nothing */
/* SIDE EFFECTS: */
/*--------------------------------------------------------------*/
void print_net(NET net) {
NODE node;
DPOINT tap;
int i, first;
Fprintf(stdout, "Net %d: %s", net->netnum, net->netname);
for (node = net->netnodes; node != NULL; node = node->next) {
Fprintf(stdout, "\n Node %d (%s): \n Taps: ",
node->nodenum, print_node_name(node));
for (tap = node->taps, i = 0, first = TRUE;
tap != NULL;
tap = tap->next, i = (i + 1) % 4, first = FALSE) {
Fprintf(stdout, "%sL%d:(%.2lf,%.2lf)",
(i == 0 ? (first ? "" : "\n ") : " "),
tap->layer, tap->x, tap->y
);
}
Fprintf(stdout, "\n Tap extends: ");
for (tap = node->extend, i = 0, first = TRUE;
tap != NULL;
tap = tap->next, i = (i + 1) % 4, first = FALSE) {
Fprintf(stdout, "%sL%d:(%.2lf,%.2lf)",
(i == 0 ? (first ? "" : "\n ") : " "),
tap->layer, tap->x, tap->y
);
}
}
Fprintf(stdout, "\n bbox: (%d,%d)-(%d,%d)\n",
net->xmin, net->ymin, net->xmax, net->ymax
);
}
/*--------------------------------------------------------------*/
/* print_gate - print info about the net to stdout */
/* */
/* ARGS: gate to print info about */
/* RETURNS: nothing */
/* SIDE EFFECTS: */
/*--------------------------------------------------------------*/
void print_gate(GATE gate) {
int i, j, first;
DSEG seg;
NODE node;
DPOINT tap;
Fprintf(stdout, "Gate %s\n", gate->gatename);
Fprintf(stdout, " Loc: (%.2lf, %.2lf), WxH: %.2lfx%.2lf\n",
gate->placedX, gate->placedY, gate->width, gate->height
);
Fprintf(stdout, " Pins");
for (i = 0; i < gate->nodes; i++) {
Fprintf(stdout, "\n Pin %s, net %d\n",
gate->node[i], gate->netnum[i]
);
Fprintf(stdout, " Segs: ");
for (seg = gate->taps[i], j = 0, first = TRUE;
seg != NULL;
seg = seg->next, j = (j + 1) % 3, first = FALSE) {
Fprintf(stdout, "%sL%d:(%.2lf,%.2lf)-(%.2lf,%.2lf)",
(j == 0 ? (first ? "" : "\n ") : " "),
seg->layer, seg->x1, seg->y1, seg->x2, seg->y2
);
}
if ((node = gate->noderec[i]) != NULL) {
Fprintf(stdout, "\n Taps: ");
for (tap = node->taps, j = 0, first = TRUE;
tap != NULL;
tap = tap->next, j = (j + 1) % 4, first = FALSE) {
Fprintf(stdout, "%sL%d:(%.2lf,%.2lf)",
(j == 0 ? (first ? "" : "\n ") : " "),
tap->layer, tap->x, tap->y
);
}
Fprintf(stdout, "\n Tap extends: ");
for (tap = node->extend, j = 0, first = TRUE;
tap != NULL;
tap = tap->next, j = (j + 1) % 4, first = FALSE) {
Fprintf(stdout, "%sL%d:(%.2lf,%.2lf)",
(j == 0 ? (first ? "" : "\n ") : " "),
tap->layer, tap->x, tap->y
);
}
}
}
Fprintf(stdout, "\n Obstructions: ");
for (seg = gate->obs, j = 0, first = TRUE;
seg != NULL;
seg = seg->next, j = (j + 1) % 3, first = FALSE) {
Fprintf(stdout, "%sL%d:(%.2lf,%.2lf)-(%.2lf,%.2lf)",
(j == 0 ? (first ? "" : "\n ") : " "),
seg->layer, seg->x1, seg->y1, seg->x2, seg->y2
);
}
Fprintf(stdout, "\n");
}
/*--------------------------------------------------------------*/
/* print_nodes - show the nodes list */
/* */
/* ARGS: filename to print to */
/* RETURNS: nothing */
/* SIDE EFFECTS: none */
/* AUTHOR and DATE: steve beccue Tue Aug 04 2003 */
/*--------------------------------------------------------------*/
void print_nodes(char *filename)
{
FILE *o;
int i;
NET net;
NODE node;
DPOINT dp;
if (!strcmp(filename, "stdout")) {
o = stdout;
} else {
o = fopen(filename, "w");
}
if (!o) {
Fprintf( stderr, "node.c:print_nodes. Couldn't open output file\n" );
return;
}
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
for (node = net->netnodes; node; node = node->next) {
dp = (DPOINT)node->taps;
fprintf(o, "%d\t%s\t(%g,%g)(%d,%d) :%d:num=%d netnum=%d\n",
node->nodenum,
node->netname,
// legacy: print only the first point
dp->x, dp->y, dp->gridx, dp->gridy,
node->netnum, node->numnodes, node->netnum );
/* need to print the routes to this node (deprecated)
for (j = 0 ; j < g->nodes; j++) {
fprintf(o, "%s(%g,%g) ", g->node[j], *(g->x[j]), *(g->y[j]));
}
*/
}
}
fclose(o);
} /* print_nodes() */
/*--------------------------------------------------------------*/
/* print_nlnets - show the nets */
/* */
/* ARGS: filename to print to */
/* RETURNS: nothing */
/* SIDE EFFECTS: none */
/* AUTHOR and DATE: steve beccue Tue Aug 04 2003 */
/*--------------------------------------------------------------*/
void print_nlnets( char *filename )
{
FILE *o;
int i;
NODE nd;
NET net;
if (!strcmp(filename, "stdout")) {
o = stdout;
} else {
o = fopen(filename, "w");
}
if (!o) {
Fprintf(stderr, "node.c:print_nlnets. Couldn't open output file\n");
return;
}
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
fprintf(o, "%d\t#=%d\t%s \t\n", net->netnum,
net->numnodes, net->netname);
for (nd = net->netnodes; nd; nd = nd->next) {
fprintf(o, "%d ", nd->nodenum);
}
}
fprintf(o, "%d nets\n", Numnets);
fflush(o);
} /* print_nlnets() */
/*--------------------------------------------------------------*/
/* print_grid_information() */
/* */
/* For help in debugging routing problems, print information */
/* about blockages marked at a specific grid position. */
/*--------------------------------------------------------------*/
void
print_grid_information(int gridx, int gridy, int layer)
{
u_int obsval;
int i, apos;
double dx, dy;
int netidx;
NET net;
NODE node;
NODEINFO lnode;
DSEG ds;
apos = OGRID(gridx, gridy);
obsval = Obs[layer][apos];
lnode = Nodeinfo[layer][apos];
if (lnode != NULL) {
node = lnode->nodesav;
if (node != NULL) {
Fprintf(stdout, "Grid position %d %d is an active node tap.\n",
gridx, gridy);
if (node->netname)
Fprintf(stdout, "Node at grid position is %s and belongs "
"to net \"%s\".\n", print_node_name(node), node->netname);
else
Fprintf(stdout, "Node at grid position is %s and is not routed.\n",
print_node_name(node));
if (lnode->nodeloc == NULL) {
Fprintf(stdout, "Position temporarily disabled to avoid "
"blocking the tap.\n");
}
}
else
Fprintf(stdout, "Grid position %d %d is a disabled node tap.\n",
gridx, gridy);
if (lnode->flags & NI_VIA_X)
Fprintf(stdout, "Via may be placed horizontally on tap.\n");
if (lnode->flags & NI_VIA_Y)
Fprintf(stdout, "Via may be placed vertically on tap.\n");
if (lnode->flags & NI_NO_VIAX)
Fprintf(stdout, "Horizontal vias are prohibited on tap.\n");
if (lnode->flags & NI_NO_VIAY)
Fprintf(stdout, "Vertical vias are prohibited on tap.\n");
if (lnode->flags & NI_OFFSET_EW) {
if (lnode->offset > 0.0)
Fprintf(stdout, "Tap connection offset to the east %gum\n",
lnode->offset);
else
Fprintf(stdout, "Tap connection offset to the west %gum\n",
-lnode->offset);
}
if (lnode->flags & NI_OFFSET_NS) {
if (lnode->offset > 0.0)
Fprintf(stdout, "Tap connection offset to the north %gum\n",
lnode->offset);
else
Fprintf(stdout, "Tap connection offset to the south %gum\n",
-lnode->offset);
}
if (lnode->flags & NI_STUB_EW) {
if (lnode->stub > 0.0)
Fprintf(stdout, "Stub connection to the east length %gum\n",
lnode->stub);
else
Fprintf(stdout, "Stub connection to the west length %gum\n",
-lnode->stub);
}
if (lnode->flags & NI_STUB_NS) {
if (lnode->stub > 0.0)
Fprintf(stdout, "Stub connection to the north length %gum\n",
lnode->stub);
else
Fprintf(stdout, "Stub connection to the south length %gum\n",
-lnode->stub);
}
if ((lnode->flags == 0) || (lnode->flags == NI_VIA_X | NI_VIA_Y))
Fprintf(stdout, "Node is cleanly routable with no restrictions.\n");
}
else
Fprintf(stdout, "Grid position is not associated with a node tap.\n");
if (obsval & OFFSET_TAP)
Fprintf(stdout, "Grid position requires a route position offset.\n");
if (obsval & STUBROUTE)
Fprintf(stdout, "Grid position requires a stub route to reach tap.\n");
if (obsval & ROUTED_NET)
Fprintf(stdout, "Grid position is assigned to routed net.\n");
if (obsval & BLOCKED_N)
Fprintf(stdout, "Grid position cannot be reached from the north.\n");
if (obsval & BLOCKED_S)
Fprintf(stdout, "Grid position cannot be reached from the south.\n");
if (obsval & BLOCKED_E)
Fprintf(stdout, "Grid position cannot be reached from the east.\n");
if (obsval & BLOCKED_W)
Fprintf(stdout, "Grid position cannot be reached from the west.\n");
if (obsval & BLOCKED_U)
Fprintf(stdout, "Grid position cannot be reached from above.\n");
if (obsval & BLOCKED_D)
Fprintf(stdout, "Grid position cannot be reached from below.\n");
if ((obsval & (OBSTRUCT_MASK | NO_NET)) == (OBSTRUCT_MASK | NO_NET)) {
Fprintf(stdout, "Grid position is completely obstructed\n");
/* Check if grid position is completely obstructed by a UserObs object */
dx = Xlowerbound + gridx * PitchX;
dy = Ylowerbound + gridy * PitchY;
for (ds = UserObs; ds; ds = ds->next) {
if (ds->layer == layer) {
if (ds->x1 < dx && ds->x2 > dx && ds->y1 < dy && ds->y2 > dy) {
Fprintf(stdout, "Defined obstruction at (%g, %g) to (%g, %g) "
"covers the tap point.\n",
ds->x1, ds->y1, ds->x2, ds->y2);
}
}
}
}
else if (obsval & NO_NET) {
if ((obsval & OBSTRUCT_MASK != 0) && (lnode == NULL)) {
Fprintf(stdout, "Error: Position marked as node obstruction has "
"no node assigned!\n");
}
else if (lnode != NULL) {
if (obsval & OBSTRUCT_N)
Fprintf(stdout, "Grid position is obstructed to the north at %gum.\n",
lnode->offset);
if (obsval & OBSTRUCT_S)
Fprintf(stdout, "Grid position is obstructed to the south at %gum.\n",
lnode->offset);
if (obsval & OBSTRUCT_E)
Fprintf(stdout, "Grid position is obstructed to the east at %gum.\n",
lnode->offset);
if (obsval & OBSTRUCT_W)
Fprintf(stdout, "Grid position is obstructed to the west at %gum.\n",
lnode->offset);
}
}
if ((obsval & DRC_BLOCKAGE) == DRC_BLOCKAGE) {
Fprintf(stdout, "Grid position disabled by neighboring route to prevent"
" DRC violations.\n");
}
if (((obsval & ROUTED_NET_MASK) != 0) && ((obsval & NO_NET) == 0)) {
netidx = obsval & NETNUM_MASK;
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
if (net->netnum == netidx) break;
}
if ((netidx > MAX_NETNUMS) || (i >= Numnets)) {
Fprintf(stdout, "Error: Grid position marked with a bad net number.\n");
}
else {
net = Nlnets[i];
Fprintf(stdout, "Grid position assigned to routed net \"%s\".\n",
net->netname);
}
}
}
/*--------------------------------------------------------------*/
/* print_instance_information() */
/* */
/* For help in debugging routing problems, print information */
/* about an instance. */
/*--------------------------------------------------------------*/
void
print_instance_information(char *instname)
{
NET net;
GATE gate;
for (gate = Nlgates; gate; gate = gate->next) {
if (!strcmp(gate->gatename, instname)) {
print_gate(gate);
break;
}
}
}
/*--------------------------------------------------------------*/
/* print_node_information() */
/* */
/* For help in debugging routing problems, print information */
/* about a node (instance and pin). */
/*--------------------------------------------------------------*/
void
print_node_information(char *nodename)
{
int i, j, k, l, apos;
NET net;
NODE node;
NODEINFO lnode;
GATE gate;
char *pptr, *instname, *pinname;
pptr = strchr(nodename, '/');
if (pptr == NULL) {
Fprintf(stderr, "Node name is not in <instance>/<pin> format!\n");
return;
}
*pptr = '\0';
instname = nodename;
pinname = pptr + 1;
for (gate = Nlgates; gate; gate = gate->next) {
if (!strcmp(gate->gatename, instname)) {
for (i = 0; i < gate->nodes; i++) {
if (!strcmp(gate->node[i], pinname)) {
node = gate->noderec[i];
Fprintf(stdout, "Instance name is %s\n", gate->gatename);
if (gate->gatetype)
Fprintf(stdout, "Gate type is %s\n", gate->gatetype->gatename);
else
Fprintf(stdout, "Node name is %s\n", print_node_name(node));
Fprintf(stdout, "Net connecting to node is %s\n", node->netname);
/* Find all grid positions that route to this node */
Fprintf(stdout, "Grid positions assigned to node:\n");
for (j = 0; j < NumChannelsX; j++) {
for (k = 0; k < NumChannelsY; k++) {
for (l = 0; l < Pinlayers; l++) {
apos = OGRID(j, k);
lnode = Nodeinfo[l][apos];
if (lnode && lnode->nodesav == node) {
Fprintf(stdout, " (%g, %g)um x=%d y=%d layer=%d\n",
Xlowerbound + j * PitchX,
Ylowerbound + k * PitchY,
j, k, l);
}
}
}
}
break;
}
}
break;
}
}
*pptr = '/';
}
/*--------------------------------------------------------------*/
/* print_net_information() */
/* */
/* For help in debugging routing problems, print information */
/* about a net. */
/*--------------------------------------------------------------*/
void
print_net_information(char *netname)
{
int i;
NET net;
for (i = 0; i < Numnets; i++) {
net = Nlnets[i];
if (!strcmp(net->netname, netname)) {
print_net(net);
break;
}
}
}
/*--------------------------------------------------------------*/
/* link_up_seg --- */
/* */
/* As part of cleanup_net (below), when removing unneeded vias, */
/* it may be necessary to check if a segment is being used to */
/* connect to another route of a net, in which case removing */
/* the segment would break the net. If that is the case, then */
/* keep the segment by linking it to the end of the route that */
/* was connected to it. */
/* */
/* Return 1 (true) if the segment was linked to another route, */
/* so the caller knows whether or not to free the segment. */
/* */
/* "rt" is the route that the segment was connected to. For */
/* the sake of efficiency, it does not need to be checked. */
/*--------------------------------------------------------------*/
u_char link_up_seg(NET net, SEG seg, int viabase, ROUTE srt)
{
ROUTE rt;
SEG segf, segl;
int x, y;
for (rt = net->routes; rt; rt = rt->next) {
if (rt == srt) continue;
segf = rt->segments;
if ((segf->x1 == seg->x1) && (segf->y1 == seg->y1) &&
((segf->layer == viabase) || (segf->layer == viabase + 1))) {
/* Reverse seg and prepend it to the route */
seg->next = rt->segments;
rt->segments = seg;
x = seg->x1;
y = seg->y1;
seg->x1 = seg->x2;
seg->y1 = seg->y2;
seg->x2 = x;
seg->y2 = y;
return (u_char)1;
}
/* Move to the last segment of the route */
for (segl = segf; segl && segl->next; segl = segl->next);
if (segl && (segl->x2 == seg->x1) && (segl->y2 == seg->y1) &&
((segl->layer == viabase) || (segl->layer == viabase + 1))) {
/* Append seg to the route */
segl->next = seg;
return (u_char)1;
}
}
return (u_char)0;
}
/*--------------------------------------------------------------*/
/* cleanup_net -- */
/* */
/* Special handling for layers where needblock[] is non-zero, */
/* and shows that two vias cannot be placed on adjacent routes. */
/* emit_routed_net() will add specialnets to merge two adjacent */
/* vias on the same route. However, this cannot be used for */
/* adjacent vias that are each in a different route record. It */
/* is easier just to find any such instances and remove them by */
/* eliminating one of the vias and adding a segment to connect */
/* the route to the neighboring via. */
/* */
/* Note that the ensuing change in connectivity can violate */
/* the route endpoints and thereby mess up the delay output */
/* routine and/or the antenna violation finding routine unless */
/* route_set_connections() is re-run on the modified routes. */
/*--------------------------------------------------------------*/
void cleanup_net(NET net)
{
SEG segf, segl, seg, segp;
ROUTE rt, rt2;
NODEINFO lnode;
int lf, ll, lf2, ll2, viabase;
u_char fcheck, lcheck, needfix;
u_char xcheckf, ycheckf, xcheckl, ycheckl;
lf = ll = lf2 = ll2 = -1;
needfix = FALSE;
for (rt = net->routes; rt; rt = rt->next) {
fcheck = lcheck = FALSE;
// This problem will only show up on route endpoints.
// segf is the first segment of the route.
// segl is the last segment of the route.
// lf is the layer at the route start (layer first)
// lf2 is the layer of the second segment.
// ll is the layer at the route end (layer last)
// ll2 is the layer of the next-to-last segment
segf = rt->segments;
if (segf == NULL) continue;
if ((segf->next != NULL) && (segf->segtype == ST_VIA)) {
if (segf->next->layer > segf->layer) {
lf = segf->layer;
lf2 = segf->layer + 1;
}
else {
lf = segf->layer + 1;
lf2 = segf->layer;
}
// Set flag fcheck indicating that segf needs checking
fcheck = TRUE;
// We're going to remove the contact so it can't be a tap
if ((lf < Pinlayers) && ((lnode = NODEIPTR(segf->x1, segf->y1, lf)) != NULL)
&& (lnode->nodesav != NULL))
fcheck = FALSE;
}
/* This could be done if vias are always too close when */
/* placed on adjacent tracks. However, that ignores the */
/* problem of vias with offsets, and it ignores the fact */
/* that adjacent vias on the same net are always a */