1 /*
2  * mzDebug.c --
3  *
4  * Routines for debugging.
5  *
6  *     *********************************************************************
7  *     * Copyright (C) 1988, 1990 Michael H. Arnold and the Regents of the *
8  *     * University of California.                                         *
9  *     * Permission to use, copy, modify, and distribute this              *
10  *     * software and its documentation for any purpose and without        *
11  *     * fee is hereby granted, provided that the above copyright          *
12  *     * notice appear in all copies.  The University of California        *
13  *     * makes no representations about the suitability of this            *
14  *     * software for any purpose.  It is provided "as is" without         *
15  *     * express or implied warranty.  Export of this software outside     *
16  *     * of the United States of America may require an export license.    *
17  *     *********************************************************************
18  */
19 
20 #ifndef lint
21 static char rcsid[] __attribute__ ((unused)) = "$$";
22 #endif  /* not lint */
23 
24 #include <stdio.h>
25 
26 #include "utils/magic.h"
27 #include "utils/signals.h"
28 #include "textio/textio.h"
29 #include "utils/hash.h"
30 #include "utils/geometry.h"
31 #include "tiles/tile.h"
32 #include "database/database.h"
33 #include "utils/malloc.h"
34 #include "utils/list.h"
35 #include "utils/heap.h"
36 #include "mzrouter/mzrouter.h"
37 #include "mzrouter/mzInternal.h"
38 
39 /* extra variables for use with dbx */
40 RoutePath *mzDPath;
41 Tile *mzTile;
42 int mz;
43 
44 /* Forward declarations */
45 extern void mzPrintRL();
46 extern void mzPrintRT();
47 extern void mzPrintRC();
48 extern void mzPrintRP();
49 extern void mzPrintPathHead();
50 
51 
52 /*
53  * ----------------------------------------------------------------------------
54  *
55  * MZPrintRCListNames --
56  *
57  * Print names of route contacts linked together by external "list"
58  *
59  * Results:
60  *	None.
61  *
62  * Side effects:
63  *	None
64  *
65  * ----------------------------------------------------------------------------
66  */
67 
68 void
MZPrintRCListNames(l)69 MZPrintRCListNames(l)
70     List *l;
71 {
72     RouteContact *rC;
73 
74     TxPrintf("\t");
75 
76     for(;l!=NULL; l=LIST_TAIL(l))
77     {
78 	rC = (RouteContact *) LIST_FIRST(l);
79         TxPrintf("%s ",DBTypeLongNameTbl[rC->rc_routeType.rt_tileType]);
80     }
81 
82     TxPrintf("\n");
83     return;
84 }
85 
86 /*
87  * ----------------------------------------------------------------------------
88  *
89  * MZPrintRLListNames --
90  *
91  * Print names of route Layers linked together by external "list"
92  *
93  * Results:
94  *	None.
95  *
96  * Side effects:
97  *	None
98  *
99  * ----------------------------------------------------------------------------
100  */
101 
102 void
MZPrintRLListNames(l)103 MZPrintRLListNames(l)
104     List *l;
105 {
106     RouteLayer *rL;
107 
108     TxPrintf("\t");
109 
110     for(;l!=NULL; l=LIST_TAIL(l))
111     {
112 	rL = (RouteLayer *) LIST_FIRST(l);
113         TxPrintf("%s ",DBTypeLongNameTbl[rL->rl_routeType.rt_tileType]);
114     }
115 
116     TxPrintf("\n");
117     return;
118 }
119 
120 /*
121  * ----------------------------------------------------------------------------
122  *
123  * MZPrintRLs --
124  *
125  * Print list of RouteLayer strucs.
126  *
127  * Results:
128  *	None.
129  *
130  * Side effects:
131  *	None
132  *
133  * ----------------------------------------------------------------------------
134  */
135 
136 void
MZPrintRLs(rL)137 MZPrintRLs(rL)
138     RouteLayer *rL;
139 {
140     while(rL!=NULL)
141     {
142 	mzPrintRL(rL);
143 	rL = rL->rl_next;
144 
145 	if(rL!=NULL) TxMore("");
146     }
147     return;
148 }
149 
150 
151 /*
152  * ----------------------------------------------------------------------------
153  *
154  * mzPrintRL --
155  *
156  * Print single RouteLayer struc.
157  *
158  * Results:
159  *	None.
160  *
161  * Side effects:
162  *	None
163  *
164  * ----------------------------------------------------------------------------
165  */
166 
167 void
mzPrintRL(rL)168 mzPrintRL(rL)
169     RouteLayer *rL;
170 {
171     List *cL;
172 
173     TxPrintf("ROUTE LAYER:\n");
174     mzPrintRT(&(rL->rl_routeType));
175     TxPrintf("\tplaneNum = %d (%s)\n",rL->rl_planeNum,
176 	DBPlaneLongNameTbl[rL->rl_planeNum]);
177 
178     TxPrintf("\tcontactL = ");
179     for (cL=rL->rl_contactL; cL!=NULL; cL=LIST_TAIL(cL))
180     {
181 	TxPrintf("%s",
182 	    DBTypeLongNameTbl[
183 		((RouteContact*) LIST_FIRST(cL))->
184 		    rc_routeType.rt_tileType]);
185 
186         if(((RouteContact*) LIST_FIRST(cL))->rc_rLayer1 == rL)
187 	   TxPrintf("(to %s) ", DBTypeLongNameTbl[
188 	       ((RouteContact*) LIST_FIRST(cL))->
189 	       rc_rLayer2->rl_routeType.rt_tileType]);
190 	else
191 	   TxPrintf("(to %s) ", DBTypeLongNameTbl[
192 	       ((RouteContact*) LIST_FIRST(cL))->
193 	       rc_rLayer1->rl_routeType.rt_tileType]);
194     }
195     TxPrintf("\n");
196 
197     TxPrintf("\thCost = %d\n",
198 	     rL->rl_hCost);
199     TxPrintf("\tvCost = %d\n",
200 	     rL->rl_vCost);
201     TxPrintf("\tjogCost = %d\n",
202 	     rL->rl_jogCost);
203     TxPrintf("\thintCost = %d\n",rL->rl_hintCost);
204 
205     return;
206 }
207 
208 
209 /*
210  * ----------------------------------------------------------------------------
211  *
212  * mzPrintRouteType --
213  *
214  * Print routeType struc.
215  *
216  * Results:
217  *	None.
218  *
219  * Side effects:
220  *	None
221  *
222  * ----------------------------------------------------------------------------
223  */
224 
225 void
mzPrintRT(rT)226 mzPrintRT(rT)
227     RouteType *rT;
228 {
229     int i;
230 
231     TxPrintf("\tROUTETYPE:\n");
232     TxPrintf("\t\ttileType = %s\n", DBTypeLongNameTbl[rT->rt_tileType]);
233     TxPrintf("\t\tactive = %s\n", (rT->rt_active ? "TRUE" : "FALSE"));
234     TxPrintf("\t\twidth = %d\n",rT->rt_width);
235 
236     TxPrintf("\t\tspacing = ");
237     for (i=0;i<TT_MAXTYPES;i++)
238 	if(rT->rt_spacing[i]>=0)
239 	    TxPrintf("%s(%d) ",DBTypeLongNameTbl[i],rT->rt_spacing[i]);
240     if(rT->rt_spacing[TT_SUBCELL]>=0)
241 	TxPrintf("%s(%d) ","SUBCELL",rT->rt_spacing[TT_SUBCELL]);
242     TxPrintf("\n");
243 
244     TxPrintf("\t\teffWidth = %d\n",rT->rt_effWidth);
245 
246     for (i=0;i<TT_MAXTYPES;i++)
247 	if(rT->rt_bloatBot[i]>=0)
248 	    TxPrintf("%s(%d) ",DBTypeLongNameTbl[i],rT->rt_bloatBot[i]);
249     if(rT->rt_spacing[TT_SUBCELL]>=0)
250 	TxPrintf("%s(%d) ","SUBCELL",rT->rt_bloatBot[TT_SUBCELL]);
251     TxPrintf("\n");
252 
253     for (i=0;i<TT_MAXTYPES;i++)
254 	if(rT->rt_bloatTop[i]>=0)
255 	    TxPrintf("%s(%d) ",DBTypeLongNameTbl[i],rT->rt_bloatTop[i]);
256     if(rT->rt_spacing[TT_SUBCELL]>=0)
257 	TxPrintf("%s(%d) ","SUBCELL",rT->rt_bloatTop[TT_SUBCELL]);
258     TxPrintf("\n");
259 
260     TxPrintf("\t\tnext = %s\n",
261 	(rT->rt_next ? DBTypeLongNameTbl[rT->rt_next->rt_tileType] : "(nil)"));
262 
263     return;
264 }
265 
266 
267 /*
268  * ----------------------------------------------------------------------------
269  *
270  * MZPrintRCs --
271  *
272  * Print list of RouteLayer strucs.
273  *
274  * Results:
275  *	None.
276  *
277  * Side effects:
278  *	None
279  *
280  * ----------------------------------------------------------------------------
281  */
282 
283 void
MZPrintRCs(rC)284 MZPrintRCs(rC)
285     RouteContact *rC;
286 {
287     while(rC!=NULL)
288     {
289 	mzPrintRC(rC);
290 	rC = rC->rc_next;
291 	if(rC!=NULL) TxMore("");
292     }
293     return;
294 }
295 
296 
297 /*
298  * ----------------------------------------------------------------------------
299  *
300  * mzPrintRC --
301  *
302  * Print single RouteContact struc.
303  *
304  * Results:
305  *	None.
306  *
307  * Side effects:
308  *	None
309  *
310  * ----------------------------------------------------------------------------
311  */
312 
313 void
mzPrintRC(rC)314 mzPrintRC(rC)
315     RouteContact *rC;
316 {
317     TxPrintf("ROUTE CONTACT:\n");
318     mzPrintRT(&(rC->rc_routeType));
319 
320     TxPrintf("\trLayer1 = %s\n",
321 	DBTypeLongNameTbl[rC->rc_rLayer1->rl_routeType.rt_tileType]);
322     TxPrintf("\trLayer2 = %s\n",
323 	DBTypeLongNameTbl[rC->rc_rLayer2->rl_routeType.rt_tileType]);
324 
325     TxPrintf("\tcost = %d\n",
326 	     rC->rc_cost);
327 
328     return;
329 }
330 
331 
332 
333 /*
334  * ----------------------------------------------------------------------------
335  *
336  * mzPrintRPs --
337  *
338  * Print list of RoutePath strucs.
339  *
340  * Results:
341  *	None.
342  *
343  * Side effects:
344  *	None
345  *
346  * ----------------------------------------------------------------------------
347  */
348 
349 void
mzPrintRPs(path)350 mzPrintRPs(path)
351     RoutePath *path;
352 {
353     while(path!=NULL)
354     {
355 	mzPrintRP(path);
356 	path = path->rp_back;
357     }
358     return;
359 }
360 
361 
362 /*
363  * ----------------------------------------------------------------------------
364  *
365  * mzPrintRP --
366  *
367  * Print single RoutePath struc.
368  *
369  * Results:
370  *	None.
371  *
372  * Side effects:
373  *	None
374  *
375  * ----------------------------------------------------------------------------
376  */
377 
378 void
mzPrintRP(path)379 mzPrintRP(path)
380     RoutePath *path;
381 {
382     TxPrintf("ROUTE PATH:");
383     TxPrintf("  layer = %s",
384 	DBTypeLongNameTbl[path->rp_rLayer->rl_routeType.rt_tileType]);
385     TxPrintf(" entry = (%d, %d)", path->rp_entry.p_x, path->rp_entry.p_y);
386     TxPrintf(" cost = %.0f",
387 	    							 (double)(path->rp_cost));
388     TxPrintf(" extCode = { ");
389     if (path->rp_extendCode & EC_RIGHT)
390     {
391         TxPrintf("right ");
392     }
393     if (path->rp_extendCode & EC_LEFT)
394     {
395         TxPrintf("left ");
396     }
397     if (path->rp_extendCode & EC_UP)
398     {
399         TxPrintf("up");
400     }
401     if (path->rp_extendCode & EC_DOWN)
402     {
403         TxPrintf("down ");
404     }
405     if (path->rp_extendCode  & (EC_UDCONTACTS | EC_LRCONTACTS))
406     {
407         TxPrintf("contacts ");
408     }
409 
410     TxPrintf("}\n");
411 
412     return;
413 }
414 
415 /* mzPrintPathHead -- */
416 void
mzPrintPathHead(path)417 mzPrintPathHead(path)
418     RoutePath *path;
419 {
420 
421     if(path==NULL)
422     {
423 	TxPrintf("  NULL Path.\n");
424     }
425     else
426     {
427 	TxPrintf("  point=(%d,%d), layer=%s, orient = '%c'",
428 		 path->rp_entry.p_x,
429 		 path->rp_entry.p_y,
430 		 DBTypeLongNameTbl[path->rp_rLayer->rl_routeType.rt_tileType],
431 		 path->rp_orient);
432 	TxPrintf(", togo=%.0f",
433 		 									(double)(path->rp_togo));
434 	TxPrintf(", cost=%.0f\n",
435 		 (double)(path->rp_cost));
436 
437 	TxPrintf("    extendCode = { ");
438 	if (path->rp_extendCode & EC_RIGHT)
439 	{
440 	    TxPrintf("right ");
441 	}
442 	if (path->rp_extendCode & EC_LEFT)
443 	{
444 	    TxPrintf("left ");
445 	}
446 	if (path->rp_extendCode & EC_UP)
447 	{
448 	    TxPrintf("up ");
449 	}
450 	if (path->rp_extendCode & EC_DOWN)
451 	{
452 	    TxPrintf("down ");
453 	}
454 	if (path->rp_extendCode  & (EC_LRCONTACTS | EC_UDCONTACTS))
455 	{
456 	    TxPrintf("contacts ");
457 	}
458 
459 	TxPrintf("}\n");
460     }
461     return;
462 }
463 
464 /*
465  * ----------------------------------------------------------------------------
466  *
467  * mzDumpTags --
468  *
469  * Dump tags on data tiles (for debugging).
470  *
471  * Results:
472  *	None.
473  *
474  * Side effects:
475  *	info written to file or via TxPrintf()
476  *
477  * ----------------------------------------------------------------------------
478  */
479 
480 void
mzDumpTags(area)481 mzDumpTags(area)
482     Rect *area;
483 {
484     int mzDumpTagsFunc();
485     SearchContext scx;
486 
487     /* mzke sure mzRouteUse is initialed */
488     if(mzRouteUse == NULL)
489     {
490 	TxPrintf("Can not dump tags, until mzRouteUse is initialed.\n");
491 	TxPrintf("(Do an iroute first.)\n");
492 	return;
493     }
494 
495     /* look at all data tiles under box. */
496     scx.scx_area = *area;
497     scx.scx_trans = GeoIdentityTransform;
498     scx.scx_use = mzRouteUse;
499 
500     (void) DBTreeSrTiles(
501 	&scx,
502 	&DBAllTypeBits,
503 	0, 	/* look inside all subcells */
504 	mzDumpTagsFunc,
505 	(ClientData) NULL);
506 
507     return;
508 }
509 
510 
511 /*
512  * ----------------------------------------------------------------------------
513  *
514  * mzDumpTagsFunc --
515  *
516  * Filter function called above, dumps tag info for all tiles in search area.
517  *
518  * Results:
519  *	Returns 0 always.
520  *
521  * Side effects:
522  *	Dumps info associated with tile.
523  *
524  * ----------------------------------------------------------------------------
525  */
526 
527 int
mzDumpTagsFunc(tile,cxp)528 mzDumpTagsFunc(tile, cxp)
529     Tile *tile;
530     TreeContext *cxp;
531 {
532     SearchContext *scx = cxp->tc_scx;
533     Rect r;
534 
535     /* if tile has no client data attached, skip it */
536     if (tile->ti_client == (ClientData)CLIENTDEFAULT)
537         return 0;
538 
539     /* Get boundary of tile */
540     TITORECT(tile, &r);
541 
542     /* print tile bounds */
543     TxPrintf("tile %x  (x: %d to %d, y: %d to %d)\n",
544 	     (pointertype) tile, r.r_xbot, r.r_xtop, r.r_ybot, r.r_ytop);
545 
546     /* dump rects attached to client field */
547     {
548 	List *l;
549         for(l=(List *) (tile->ti_client); l!=NULL; l=LIST_TAIL(l))
550         {
551 	    Rect *rTerm = (Rect *) LIST_FIRST(l);
552 
553 	    TxPrintf("\tattached dest area (x: %d to %d, y: %d to %d)\n",
554 		     rTerm->r_xbot,
555 		     rTerm->r_xtop,
556 		     rTerm->r_ybot,
557 		     rTerm->r_ytop);
558 	}
559     }
560 
561     /* continue search */
562     return 0;
563 }
564 
565