1 /*
2  * Copyright (c) 2000-2019, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 /** \file
19  * \brief mw's dump routines
20  */
21 
22 #include "mwd.h"
23 #include "error.h"
24 #include "machar.h"
25 #include "global.h"
26 #include "symtab.h"
27 #include "ilm.h"
28 #include "fih.h"
29 #include "ili.h"
30 #include "iliutil.h"
31 #include "dtypeutl.h"
32 #include "machreg.h"
33 #ifdef SOCPTRG
34 #include "soc.h"
35 #endif
36 #include "llutil.h"
37 #include "symfun.h"
38 
39 static int putdtypex(DTYPE dtype, int len);
40 static void _printnme(int n);
41 static bool g_dout = true;
42 
43 #if defined(HOST_WIN)
44 #define vsnprintf _vsnprintf
45 #endif
46 
47 #if DEBUG
48 
49 static FILE *dfile;
50 static int linelen = 0;
51 #define BUFSIZE 10000
52 static char BUF[BUFSIZE];
53 static int longlines = 1, tight = 0, nexttight = 0;
54 
55 /* for debug purpuse: test if the current
56  * function is the one that func specifies */
57 int
testcurrfunc(const char * func)58 testcurrfunc(const char* func)
59 {
60   if(strcmp(SYMNAME(GBL_CURRFUNC), func)==0)
61     return true;
62   else
63     return false;
64 }
65 
66 /*
67  * 'full' is zero for a 'diff' dump, so things like symbol numbers,
68  * ili numbers, etc., are left off; this makes ili trees and symbol dumps
69  * that are for all intents and purposes the same look more identical.
70  * 'full' is 2 for an 'important things' only dump; nmptr, hashlk left off
71  * 'full' is 1 for full dump, everything
72  */
73 static int full = 1;
74 
75 void
dumplong(void)76 dumplong(void)
77 {
78   longlines = 1;
79 } /* dumplong */
80 
81 void
dumpshort(void)82 dumpshort(void)
83 {
84   longlines = 0;
85 } /* dumpshort */
86 
87 void
dumpdiff(void)88 dumpdiff(void)
89 {
90   full = 0;
91 } /* dumpdiff */
92 
93 void
dumpddiff(int v)94 dumpddiff(int v)
95 {
96   full = v;
97 } /* dumpddiff */
98 
99 static void
putit(void)100 putit(void)
101 {
102   int l = strlen(BUF);
103   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
104   if (linelen + l >= 78 && !longlines) {
105     fprintf(dfile, "\n%s", BUF);
106     linelen = l;
107   } else if (linelen > 0 && nexttight) {
108     fprintf(dfile, "%s", BUF);
109     linelen += l + 1;
110   } else if (linelen > 0 && tight) {
111     fprintf(dfile, " %s", BUF);
112     linelen += l + 1;
113   } else if (linelen > 0) {
114     fprintf(dfile, "  %s", BUF);
115     linelen += l + 2;
116   } else {
117     fprintf(dfile, "%s", BUF);
118     linelen = l;
119   }
120   nexttight = 0;
121 } /* putit */
122 
123 static void
puttight(void)124 puttight(void)
125 {
126   int l = strlen(BUF);
127   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
128   fprintf(dfile, "%s", BUF);
129   linelen += l;
130 } /* puttight */
131 
132 static void
putline(void)133 putline(void)
134 {
135   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
136   if (linelen)
137     fprintf(dfile, "\n");
138   linelen = 0;
139 } /* putline */
140 
141 void
putmwline()142 putmwline()
143 {
144   putline();
145 } /* putmwline */
146 
147 #include <stdarg.h>
148 
149 static void
puterr(const char * fmt,...)150 puterr(const char *fmt, ...)
151 {
152   va_list argptr;
153   va_start(argptr, fmt);
154   putline();
155   strcpy(BUF, "*** ");
156   vsnprintf(BUF + 4, BUFSIZE - 4, fmt, argptr);
157   strcat(BUF, " ***");
158   putit();
159   putline();
160 } /* puterr */
161 
162 static void
appendit(void)163 appendit(void)
164 {
165   int l = strlen(BUF);
166   if (g_dout)
167     fprintf(dfile, "%s", BUF);
168   linelen += l;
169   nexttight = 0;
170 } /* appendit */
171 
172 static void
putint(const char * s,int d)173 putint(const char *s, int d)
174 {
175   if (g_dout) {
176     snprintf(BUF, BUFSIZE, "%s:%d", s, d);
177     putit();
178   }
179 } /* putint */
180 
181 static void
putdouble(const char * s,double d)182 putdouble(const char *s, double d)
183 {
184   if (g_dout) {
185     snprintf(BUF, BUFSIZE, "%s:%lg", s, d);
186     putit();
187   }
188 } /* putdouble */
189 
190 static void
putbigint(const char * s,ISZ_T d)191 putbigint(const char *s, ISZ_T d)
192 {
193   snprintf(BUF, BUFSIZE, "%s:%" ISZ_PF "d", s, d);
194   putit();
195 } /* putbigint */
196 
197 static void
putINT(const char * s,INT d)198 putINT(const char *s, INT d)
199 {
200   snprintf(BUF, BUFSIZE, "%s:%ld", s, (long)d);
201   putit();
202 } /* putINT */
203 
204 static void
putisz(const char * s,ISZ_T d)205 putisz(const char *s, ISZ_T d)
206 {
207   snprintf(BUF, BUFSIZE, "%s:%" ISZ_PF "d", s, d);
208   putit();
209 } /* putisz */
210 
211 static void
putISZ1(ISZ_T d)212 putISZ1(ISZ_T d)
213 {
214   snprintf(BUF, BUFSIZE, "%" ISZ_PF "d", d);
215   putit();
216 } /* putISZ1 */
217 
218 static void
putintarray(const char * s,int * x,int size)219 putintarray(const char *s, int *x, int size)
220 {
221   int i;
222   if (x != NULL) {
223     for (i = 0; i < size; ++i) {
224       if (x[i] != 0) {
225         snprintf(BUF, BUFSIZE, "%s[%d]:%8d %8x", s, i, x[i], x[i]);
226         x[i] = 0;
227         putit();
228         putline();
229       }
230     }
231   }
232 } /* putintarray */
233 
234 static void
put1char(const char * s,char c)235 put1char(const char *s, char c)
236 {
237   snprintf(BUF, BUFSIZE, "%s:%c", s, c);
238   putit();
239 } /* put1char */
240 
241 static void
puthex(const char * s,int d)242 puthex(const char *s, int d)
243 {
244   snprintf(BUF, BUFSIZE, "%s:0x%x", s, d);
245   putit();
246 } /* puthex */
247 
248 static void
putnzhex(const char * s,int d)249 putnzhex(const char *s, int d)
250 {
251   if (d != 0) {
252     snprintf(BUF, BUFSIZE, "%s:0x%x", s, d);
253     putit();
254   }
255 } /* putnzhex */
256 
257 static void
putnvptr(const char * s,void * d)258 putnvptr(const char *s, void *d)
259 {
260   if (d) {
261     snprintf(BUF, BUFSIZE, "%s:%p", s, d);
262     putit();
263   }
264 } /* putnvptr */
265 
266 static void
putnzint(const char * s,int d)267 putnzint(const char *s, int d)
268 {
269   if (d != 0) {
270     snprintf(BUF, BUFSIZE, "%s:%d", s, d);
271     putit();
272   }
273 } /* putnzint */
274 
275 static void
putnzbigint(const char * s,ISZ_T d)276 putnzbigint(const char *s, ISZ_T d)
277 {
278   if (d != 0) {
279     snprintf(BUF, BUFSIZE, "%s:%" ISZ_PF "d", s, d);
280     putit();
281   }
282 } /* putnzbigint */
283 
284 static void
putnzINT(const char * s,INT d)285 putnzINT(const char *s, INT d)
286 {
287   if (d != 0) {
288     snprintf(BUF, BUFSIZE, "%s:%ld", s, (long)d);
289     putit();
290   }
291 } /* putnzINT */
292 
293 static void
putnzisz(const char * s,ISZ_T d)294 putnzisz(const char *s, ISZ_T d)
295 {
296   if (d != 0) {
297     snprintf(BUF, BUFSIZE, "%s:%" ISZ_PF "d", s, d);
298     putit();
299   }
300 } /* putnzint */
301 
302 static void
putnzopc(const char * s,int opc)303 putnzopc(const char *s, int opc)
304 {
305   if (opc != 0) {
306     if (opc >= 0 && opc < N_ILI) {
307       snprintf(BUF, BUFSIZE, "%s:%s", s, ilis[opc].name);
308     } else {
309       snprintf(BUF, BUFSIZE, "%s:%d", s, opc);
310     }
311     putit();
312   }
313 } /* putnzopc */
314 
315 static void
putedge(int d1,int d2)316 putedge(int d1, int d2)
317 {
318   snprintf(BUF, BUFSIZE, "%d-->%d", d1, d2);
319   putit();
320 } /* putedge */
321 
322 static void
put2int(const char * s,int d1,int d2)323 put2int(const char *s, int d1, int d2)
324 {
325   snprintf(BUF, BUFSIZE, "%s(%d:%d)", s, d1, d2);
326   putit();
327 } /* put2int */
328 
329 static void
put2int1(int d1,int d2)330 put2int1(int d1, int d2)
331 {
332   snprintf(BUF, BUFSIZE, "%d:%d", d1, d2);
333   putit();
334 } /* put2int1 */
335 
336 static void
putpint(const char * s,int d)337 putpint(const char *s, int d)
338 {
339   put2int(s, (int)(d & 0xff), (int)(d >> 8));
340 } /* putpint */
341 
342 void
putint1(int d)343 putint1(int d)
344 {
345   snprintf(BUF, BUFSIZE, "%d", d);
346   putit();
347 } /* putint1 */
348 
349 static void
putint1t(int d)350 putint1t(int d)
351 {
352   snprintf(BUF, BUFSIZE, "%d", d);
353   puttight();
354 } /* putint1t */
355 
356 static void
putint2(const char * s,int d,const char * s2,int d2)357 putint2(const char *s, int d, const char *s2, int d2)
358 {
359   snprintf(BUF, BUFSIZE, " %s:%d,%s:%d", s, d, s2, d2);
360   putit();
361 } /* putint2 */
362 
363 static int
appendint1(int d)364 appendint1(int d)
365 {
366   int r;
367   if (!g_dout) {
368     r = snprintf(BUF, BUFSIZE, "%d", d);
369     sprintf(BUF, "%s%d", BUF, d);
370     r = 0;
371   } else
372     r = sprintf(BUF, "%d", d);
373 
374   appendit();
375   return r;
376 } /* appendint1 */
377 
378 static int
appendbigint(ISZ_T d)379 appendbigint(ISZ_T d)
380 {
381   int r;
382   if (!g_dout) {
383     r = snprintf(BUF, BUFSIZE, "%" ISZ_PF "d", d);
384     sprintf(BUF, ("%s%" ISZ_PF "d"), BUF, d);
385     r = 0;
386   } else
387     r = sprintf(BUF, ("%" ISZ_PF "d"), d);
388 
389   appendit();
390   return r;
391 } /* appendbigint */
392 
393 static void
appendhex1(int d)394 appendhex1(int d)
395 {
396   snprintf(BUF, BUFSIZE, "0x%x", d);
397   appendit();
398 } /* appendhex1 */
399 
400 static void
putint3star(int d,int star1,const char * star1string,int star2,const char * star2string,int star3,const char * star3string,int star4,const char * star4string)401 putint3star(int d, int star1, const char *star1string, int star2, const char *star2string,
402             int star3, const char *star3string, int star4, const char *star4string)
403 {
404   if (star1 && star2 && star3 && star4) {
405     snprintf(BUF, BUFSIZE, "%d(%s,%s,%s,%s=%d)", d, star1string, star2string,
406              star3string, star4string, star4);
407   } else if (!star1 && star2 && star3 && star4) {
408     snprintf(BUF, BUFSIZE, "%d(%s,%s,%s=%d)", d, star2string, star3string,
409              star4string, star4);
410   } else if (star1 && !star2 && star3 && star4) {
411     snprintf(BUF, BUFSIZE, "%d(%s,%s,%s=%d)", d, star1string, star3string,
412              star4string, star4);
413   } else if (!star1 && !star2 && star3 && star4) {
414     snprintf(BUF, BUFSIZE, "%d(%s,%s=%d)", d, star3string, star4string, star4);
415   } else if (star1 && star2 && !star3 && star4) {
416     snprintf(BUF, BUFSIZE, "%d(%s,%s,%s=%d)", d, star1string, star2string,
417              star4string, star4);
418   } else if (!star1 && star2 && !star3 && star4) {
419     snprintf(BUF, BUFSIZE, "%d(%s,%s=%d)", d, star2string, star4string, star4);
420   } else if (star1 && !star2 && !star3 && star4) {
421     snprintf(BUF, BUFSIZE, "%d(%s,%s=%d)", d, star1string, star4string, star4);
422   } else if (!star1 && !star2 && !star3 && star4) {
423     snprintf(BUF, BUFSIZE, "%d(%s=%d)", d, star4string, star4);
424   } else if (star1 && star2 && star3 && !star4) {
425     snprintf(BUF, BUFSIZE, "%d(%s,%s,%s)", d, star1string, star2string,
426              star3string);
427   } else if (!star1 && star2 && star3 && !star4) {
428     snprintf(BUF, BUFSIZE, "%d(%s,%s)", d, star2string, star3string);
429   } else if (star1 && !star2 && star3 && !star4) {
430     snprintf(BUF, BUFSIZE, "%d(%s,%s)", d, star1string, star3string);
431   } else if (!star1 && !star2 && star3 && !star4) {
432     snprintf(BUF, BUFSIZE, "%d(%s)", d, star3string);
433   } else if (star1 && star2 && !star3 && !star4) {
434     snprintf(BUF, BUFSIZE, "%d(%s,%s)", d, star1string, star2string);
435   } else if (!star1 && star2 && !star3 && !star4) {
436     snprintf(BUF, BUFSIZE, "%d(%s)", d, star2string);
437   } else if (star1 && !star2 && !star3 && !star4) {
438     snprintf(BUF, BUFSIZE, "%d(%s)", d, star1string);
439   } else {
440     snprintf(BUF, BUFSIZE, "%d", d);
441   }
442   putit();
443 } /* putint3star */
444 
445 static void
putbit(const char * s,int b)446 putbit(const char *s, int b)
447 {
448   /* single space between flags */
449   if (b) {
450     int l = strlen(s);
451     if (linelen + l >= 79 && !longlines) {
452       fprintf(dfile, "\n%s", s);
453       linelen = l;
454     } else if (linelen > 0) {
455       fprintf(dfile, " %s", s);
456       linelen += l + 1;
457     } else {
458       fprintf(dfile, "%s", s);
459       linelen = l;
460     }
461   }
462 } /* putbit */
463 
464 static void
putstring(const char * s,const char * t)465 putstring(const char *s, const char *t)
466 {
467   snprintf(BUF, BUFSIZE, "%s:%s", s, t);
468   putit();
469 } /* putstring */
470 
471 static void
mputchar(const char * s,char t)472 mputchar(const char *s, char t)
473 {
474   snprintf(BUF, BUFSIZE, "%s:%c", s, t);
475   putit();
476 } /* mputchar */
477 
478 static void
putnzchar(const char * s,char t)479 putnzchar(const char *s, char t)
480 {
481   if (t) {
482     snprintf(BUF, BUFSIZE, "%s:%c", s, t);
483     putit();
484   }
485 } /* putnzchar */
486 
487 static void
putnstring(const char * s,const char * t)488 putnstring(const char *s, const char *t)
489 {
490   if (t != NULL) {
491     snprintf(BUF, BUFSIZE, "%s:%s", s, t);
492     putit();
493   }
494 } /* putstring */
495 
496 static void
putstringarray(const char * s,char ** arr)497 putstringarray(const char *s, char **arr)
498 {
499   int i;
500   if (arr != NULL) {
501     for (i = 0; arr[i] != NULL; ++i) {
502       snprintf(BUF, BUFSIZE, "%s[%d]:%s", s, i, arr[i]);
503       putit();
504     }
505   }
506 } /* putstringarray */
507 
508 static void
putdefarray(const char * s,char ** arr)509 putdefarray(const char *s, char **arr)
510 {
511   int i;
512   if (arr != NULL) {
513     for (i = 0; arr[i] != NULL; i += 2) {
514       if (arr[i + 1] == (const char *)1) {
515         snprintf(BUF, BUFSIZE, "%s[%d]  pred:%s", s, i, arr[i]);
516       } else if (arr[i + 1] == (const char *)0) {
517         snprintf(BUF, BUFSIZE, "%s[%d] undef:%s", s, i, arr[i]);
518       } else {
519         snprintf(BUF, BUFSIZE, "%s[%d]   def:%s", s, i, arr[i]);
520       }
521       putit();
522       putline();
523     }
524   }
525 } /* putdefarray */
526 
527 static void
putstring1(const char * t)528 putstring1(const char *t)
529 {
530   snprintf(BUF, BUFSIZE, "%s", t);
531   putit();
532 } /* putstring1 */
533 
534 static void
putstring1t(const char * t)535 putstring1t(const char *t)
536 {
537   snprintf(BUF, BUFSIZE, "%s", t);
538   puttight();
539   nexttight = 0;
540 } /* putstring1t */
541 
542 static void
putstring1tt(const char * t)543 putstring1tt(const char *t)
544 {
545   snprintf(BUF, BUFSIZE, "%s", t);
546   puttight();
547   nexttight = 1;
548 } /* putstring1tt */
549 
550 static int
appendstring1(const char * t)551 appendstring1(const char *t)
552 {
553   int r;
554   if (!g_dout) {
555     strcat(BUF, t);
556     r = 0;
557   } else {
558     r = snprintf(BUF, BUFSIZE, "%s", t);
559   }
560   appendit();
561   return r;
562 } /* appendstring1 */
563 
564 static void
putsym(const char * s,SPTR sptr)565 putsym(const char *s, SPTR sptr)
566 {
567   if (full) {
568     if (sptr == NOSYM) {
569       snprintf(BUF, BUFSIZE, "%s:%d=%s", s, sptr, "NOSYM");
570     } else if (sptr > 0 && sptr < stb.stg_avail) {
571       snprintf(BUF, BUFSIZE, "%s:%d=%s%s", s, sptr, printname(sptr),
572                ADDRTKNG(sptr) ? " (&)" : "");
573     } else {
574       snprintf(BUF, BUFSIZE, "%s:%d", s, sptr);
575     }
576   } else {
577     if (sptr == NOSYM) {
578       snprintf(BUF, BUFSIZE, "%s:%s", s, "NOSYM");
579     } else if (sptr > 0 && sptr < stb.stg_avail) {
580       snprintf(BUF, BUFSIZE, "%s:%s%s", s, printname(sptr),
581                ADDRTKNG(sptr) ? " (&)" : "");
582     } else {
583       snprintf(BUF, BUFSIZE, "%s:%d", s, sptr);
584     }
585   }
586 
587   putit();
588 } /* putsym */
589 
590 static void
putnsym(const char * s,SPTR sptr)591 putnsym(const char *s, SPTR sptr)
592 {
593   if (sptr != 0)
594     putsym(s, sptr);
595 } /* putnsym */
596 
597 static void
putsym1(int sptr)598 putsym1(int sptr)
599 {
600   if (full) {
601     if (sptr == NOSYM) {
602       snprintf(BUF, BUFSIZE, "%d=%s", sptr, "NOSYM");
603     } else if (sptr > 0 && sptr < stb.stg_avail) {
604       snprintf(BUF, BUFSIZE, "%d=%s", sptr, printname(sptr));
605     } else {
606       snprintf(BUF, BUFSIZE, "%d", sptr);
607     }
608   } else {
609     if (sptr == NOSYM) {
610       snprintf(BUF, BUFSIZE, "%s", "NOSYM");
611     } else if (sptr > 0 && sptr < stb.stg_avail) {
612       snprintf(BUF, BUFSIZE, "%s", printname(sptr));
613     } else {
614       snprintf(BUF, BUFSIZE, "%d", sptr);
615     }
616   }
617   putit();
618 } /* putsym1 */
619 
620 static int
appendsym1(int sptr)621 appendsym1(int sptr)
622 {
623   int r;
624   if (sptr == NOSYM) {
625     r = snprintf(BUF, BUFSIZE, "%s", "NOSYM");
626   } else if (sptr > 0 && sptr < stb.stg_avail) {
627     r = snprintf(BUF, BUFSIZE, "%s", printname(sptr));
628   } else {
629     r = snprintf(BUF, BUFSIZE, "sym%d", sptr);
630   }
631   appendit();
632   return r;
633 } /* appendsym1 */
634 
635 static void
putsc(const char * s,int sc)636 putsc(const char *s, int sc)
637 {
638   if (full) {
639     if (sc >= 0 && sc <= SC_MAX) {
640       snprintf(BUF, BUFSIZE, "%s:%d=%s", s, sc, stb.scnames[sc] + 3);
641     } else {
642       snprintf(BUF, BUFSIZE, "%s:%d", s, sc);
643     }
644   } else {
645     if (sc >= 0 && sc <= SC_MAX) {
646       snprintf(BUF, BUFSIZE, "%s:%s", s, stb.scnames[sc] + 3);
647     } else {
648       snprintf(BUF, BUFSIZE, "%s:%d", s, sc);
649     }
650   }
651   putit();
652 } /* putsc */
653 
654 static void
putnsc(const char * s,int sc)655 putnsc(const char *s, int sc)
656 {
657   if (sc != 0)
658     putsc(s, sc);
659 } /* putnsc */
660 
661 static void
putstype(const char * s,int stype)662 putstype(const char *s, int stype)
663 {
664   if (full) {
665     if (stype >= 0 && stype <= ST_MAX) {
666       snprintf(BUF, BUFSIZE, "%s:%d=%s", s, stype, stb.stypes[stype]);
667     } else {
668       snprintf(BUF, BUFSIZE, "%s:%d", s, stype);
669     }
670   } else {
671     if (stype >= 0 && stype <= ST_MAX) {
672       snprintf(BUF, BUFSIZE, "%s:%s", s, stb.stypes[stype]);
673     } else {
674       snprintf(BUF, BUFSIZE, "%s:%d", s, stype);
675     }
676   }
677   putit();
678 } /* putstype */
679 
680 static void
putddtype(const char * s,DTYPE d)681 putddtype(const char *s, DTYPE d)
682 {
683   if (d) {
684     snprintf(BUF, BUFSIZE, "%s:%d=", s, d);
685     putit();
686     putdtypex(d, 80);
687   }
688 } /* putddtype */
689 
690 static void
putmd(const char * s,int md)691 putmd(const char *s, int md)
692 {
693 #ifdef MDG
694   if (md == 0)
695     return;
696   snprintf(BUF, BUFSIZE, "%s:0x%x", s, md);
697   putit();
698   if (md & MD_X) {
699     snprintf(BUF, BUFSIZE, "X");
700     md &= ~MD_X;
701     putit();
702   }
703   if (md & MD_Y) {
704     snprintf(BUF, BUFSIZE, "Y");
705     md &= ~MD_Y;
706     putit();
707   }
708   if (md & MD_DATA) {
709     snprintf(BUF, BUFSIZE, "data");
710     md &= ~MD_DATA;
711     putit();
712   }
713   if (md & MD_RO) {
714     snprintf(BUF, BUFSIZE, "ro");
715     md &= ~MD_RO;
716     putit();
717   }
718   if (md & MD_TINY) {
719     snprintf(BUF, BUFSIZE, "tiny");
720     md &= ~MD_TINY;
721     putit();
722   }
723   if (md & MD_SMALL) {
724     snprintf(BUF, BUFSIZE, "small");
725     md &= ~MD_SMALL;
726     putit();
727   }
728   if (md) {
729     snprintf(BUF, BUFSIZE, "***mdbits:0x%x", md);
730     putit();
731   }
732 #endif /* MDG */
733 } /* putmd */
734 
735 static void
putcgmode(const char * s,int cgmode)736 putcgmode(const char *s, int cgmode)
737 {
738 #ifdef CGMODEG
739   if (cgmode == 0)
740     return;
741   snprintf(BUF, BUFSIZE, "%s:%x", s, cgmode);
742   putit();
743   switch (cgmode) {
744   case 0:
745     break;
746   case 1:
747     snprintf(BUF, BUFSIZE, "gp16");
748     break;
749   case 2:
750     snprintf(BUF, BUFSIZE, "gp32");
751     break;
752   default:
753     snprintf(BUF, BUFSIZE, "other");
754     break;
755   }
756   putit();
757 #endif /* CGMODEG */
758 } /* putcgmode */
759 
760 static void
putxyptr(const char * s,int xyptr)761 putxyptr(const char *s, int xyptr)
762 {
763 #ifdef XYPTRG
764   if (xyptr == 0)
765     return;
766   snprintf(BUF, BUFSIZE, "%s:%x", s, xyptr);
767   putit();
768   switch (xyptr) {
769   case 0:
770     break;
771   case MD_X:
772     snprintf(BUF, BUFSIZE, "Xptr");
773     break;
774   case MD_Y:
775     snprintf(BUF, BUFSIZE, "Yptr");
776     break;
777   }
778   putit();
779 #endif /* XYPTRG */
780 } /* putxyptr */
781 
782 static void
putnname(const char * s,int off)783 putnname(const char *s, int off)
784 {
785   if (off) {
786     putstring(s, stb.n_base + off);
787   }
788 } /* putnname */
789 
790 static void
putsymlk(const char * name,int list)791 putsymlk(const char *name, int list)
792 {
793   int c = 0;
794   if (list <= NOSYM)
795     return;
796   putline();
797   putstring1(name);
798   for (; list > NOSYM && c < 200; list = SYMLKG(list), ++c)
799     putsym1(list);
800   putline();
801 } /* putsymlk */
802 
803 static void
dsymlk(int list)804 dsymlk(int list)
805 {
806   int c = 0;
807   if (list <= NOSYM)
808     return;
809   for (; list > NOSYM && c < 200; list = SYMLKG(list), ++c) {
810     ds(list);
811   }
812 } /* dsymlk */
813 
814 #ifdef TPLNKG
815 static void
puttplnk(const char * name,int list)816 puttplnk(const char *name, int list)
817 {
818   if (list <= NOSYM)
819     return;
820   putline();
821   putstring1(name);
822   for (; list > NOSYM; list = TPLNKG(list)) {
823     putsym1(list);
824   }
825 } /* puttplnk */
826 #endif
827 
828 void
putnme(const char * s,int nme)829 putnme(const char *s, int nme)
830 {
831   if (full) {
832     if (nme < 0 || nme >= nmeb.stg_avail) {
833       snprintf(BUF, BUFSIZE, "%s:%d=%s", s, nme, "NONE");
834       putit();
835     } else {
836       snprintf(BUF, BUFSIZE, "%s:%d=", s, nme);
837       putit();
838       _printnme(nme);
839     }
840   } else {
841     if (nme < 0 || nme >= nmeb.stg_avail) {
842       snprintf(BUF, BUFSIZE, "%s:%d", s, nme);
843       putit();
844     } else {
845       snprintf(BUF, BUFSIZE, "%s:", s);
846       putit();
847       _printnme(nme);
848     }
849   }
850 } /* putnme */
851 
852 static void
putnnme(const char * s,int nme)853 putnnme(const char *s, int nme)
854 {
855   if (full) {
856     if (nme < 0 || nme >= nmeb.stg_avail) {
857       snprintf(BUF, BUFSIZE, "%s:%d=%s", s, nme, "NONE");
858       putit();
859     } else if (nme > 0) {
860       snprintf(BUF, BUFSIZE, "%s:%d=", s, nme);
861       putit();
862       _printnme(nme);
863     }
864   } else {
865     if (nme < 0 || nme >= nmeb.stg_avail) {
866       snprintf(BUF, BUFSIZE, "%s:%d", s, nme);
867       putit();
868     } else if (nme > 0) {
869       snprintf(BUF, BUFSIZE, "%s:", s);
870       putit();
871       _printnme(nme);
872     }
873   }
874 } /* putnnme */
875 
876 #ifdef DPDSCG
877 static void
putparam(int dpdsc,int paramct)878 putparam(int dpdsc, int paramct)
879 {
880   if (paramct == 0)
881     return;
882   putline();
883   putstring1("Parameters:");
884   for (; paramct; ++dpdsc, --paramct) {
885     int sptr = aux.dpdsc_base[dpdsc];
886     if (sptr == 0) {
887       putstring1("*");
888     } else {
889       putsym1(sptr);
890     }
891   }
892 } /* putparam */
893 #endif /* DPDSCG */
894 
895 #define SIZEOF(array) (sizeof(array) / sizeof(char *))
896 
897 static void
putval(const char * s,int val,const char * values[],int sizeofvalues)898 putval(const char *s, int val, const char *values[], int sizeofvalues)
899 {
900   if (val < 0 || val >= sizeofvalues) {
901     snprintf(BUF, BUFSIZE, "%s:%d", s, val);
902     putit();
903   } else {
904     putstring(s, values[val]);
905   }
906 } /* putval */
907 
908 static void
putnval(const char * s,int val,const char * values[],int sizeofvalues)909 putnval(const char *s, int val, const char *values[], int sizeofvalues)
910 {
911   if (val < 0 || val >= sizeofvalues) {
912     snprintf(BUF, BUFSIZE, "%s:%d", s, val);
913     putit();
914   } else if (val > 0) {
915     putstring(s, values[val]);
916   }
917 } /* putnval */
918 
919 static void
putval1(int val,const char * values[],int sizeofvalues)920 putval1(int val, const char *values[], int sizeofvalues)
921 {
922   if (val < 0 || val >= sizeofvalues) {
923     snprintf(BUF, BUFSIZE, "%d", val);
924     putit();
925   } else {
926     putstring1(values[val]);
927   }
928 } /* putval1 */
929 
930 static void
appendval(int val,const char * values[],int sizeofvalues)931 appendval(int val, const char *values[], int sizeofvalues)
932 {
933   if (val < 0 || val >= sizeofvalues) {
934     snprintf(BUF, BUFSIZE, "/%d", val);
935     appendit();
936   } else {
937     appendstring1(values[val]);
938   }
939 } /* appendval */
940 
941 #ifdef SOCPTRG
942 void
putsoc(int socptr)943 putsoc(int socptr)
944 {
945   int p, q;
946 
947   if (socptr == 0)
948     return;
949   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
950   if (soc.base == NULL) {
951     fprintf(dfile, "soc.base not allocated\n");
952     return;
953   }
954   q = 0;
955   putline();
956   putstring1("Storage Overlap Chain:");
957 
958   for (p = socptr; p; p = SOC_NEXT(p)) {
959     putsym1(SOC_SPTR(p));
960     if (q == p) {
961       putstring1(" >>> soc loop");
962       break;
963     }
964     q = p;
965   }
966 } /* putsoc */
967 #endif /* SOCPTRG */
968 
969 #ifdef CUDAG
970 static void
putcuda(const char * s,int cu)971 putcuda(const char *s, int cu)
972 {
973   if (cu) {
974     strcpy(BUF, s);
975     strcat(BUF, ":");
976     if (cu & CUDA_HOST) {
977       strcat(BUF, "host");
978       cu &= ~CUDA_HOST;
979       if (cu)
980         strcat(BUF, "+");
981     }
982     if (cu & CUDA_DEVICE) {
983       strcat(BUF, "device");
984       cu &= ~CUDA_DEVICE;
985       if (cu)
986         strcat(BUF, "+");
987     }
988     if (cu & CUDA_GLOBAL) {
989       strcat(BUF, "global");
990       cu &= ~CUDA_GLOBAL;
991       if (cu)
992         strcat(BUF, "+");
993     }
994     if (cu & CUDA_BUILTIN) {
995       strcat(BUF, "builtin");
996       cu &= ~CUDA_BUILTIN;
997       if (cu)
998         strcat(BUF, "+");
999     }
1000     if (cu & CUDA_CONSTRUCTOR) {
1001       strcat(BUF, "constructor");
1002       cu &= ~CUDA_CONSTRUCTOR;
1003       if (cu)
1004         strcat(BUF, "+");
1005     }
1006 #ifdef CUDA_STUB
1007     if (cu & CUDA_STUB) {
1008       strcat(BUF, "stub");
1009       cu &= ~CUDA_STUB;
1010       if (cu)
1011         strcat(BUF, "+");
1012     }
1013 #endif
1014     putit();
1015   }
1016 } /* putcuda */
1017 #endif
1018 
1019 static void
check(const char * s,int v)1020 check(const char *s, int v)
1021 {
1022   if (v) {
1023     fprintf(dfile, "*** %s: %d %x\n", s, v, v);
1024   }
1025 } /* check */
1026 
1027 /* dump one symbol to gbl.dbgfil */
1028 void
dsym(int sptr)1029 dsym(int sptr)
1030 {
1031   SYMTYPE stype;
1032   DTYPE dtype;
1033   const char *np;
1034 #ifdef SOCPTRG
1035   int socptr;
1036 #endif
1037   int i;
1038 
1039   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
1040 
1041   if (sptr == 0 || sptr >= stb.stg_avail) {
1042     fprintf(dfile, "\nsymbol %d out of %d\n", sptr, stb.stg_avail - 1);
1043     return;
1044   }
1045 
1046   BCOPY(stb.stg_base, stb.stg_base + sptr, SYM, 1);
1047 
1048   stype = STYPEG(0);
1049   switch (stype) {
1050   case ST_BLOCK:
1051   case ST_CMBLK:
1052   case ST_LABEL:
1053   case ST_BASE:
1054   case ST_UNKNOWN:
1055     dtype = DT_NONE;
1056     break;
1057   default:
1058     dtype = DTYPEG(0);
1059     break;
1060   }
1061   np = printname(sptr);
1062   if (strlen(np) >= 30) {
1063     fprintf(dfile, "\n%s", np);
1064     np = " ";
1065   }
1066   fprintf(dfile, "\n%-30.30s ", np);
1067   if (dtype) {
1068     putdtypex(dtype, 50);
1069   }
1070   fprintf(dfile, "\n");
1071 
1072   linelen = 0;
1073 
1074   if (full) {
1075     putint("sptr", sptr);
1076     putnzint("dtype", DTYPEG(0));
1077   }
1078   if (full & 1)
1079     putnzint("nmptr", NMPTRG(0));
1080   putnsc("sc", SCG(0));
1081   putstype("stype", STYPEG(0));
1082   putline();
1083   STYPEP(0, ST_UNKNOWN);
1084   DTYPEP(0, DT_NONE);
1085   NMPTRP(0, 0);
1086   SCP(0, SC_NONE);
1087 
1088   if (full & 1)
1089     putnsym("hashlk", HASHLKG(0));
1090   putnsym("scope", SCOPEG(SPTR_NULL));
1091   putnsym("symlk", SYMLKG(0));
1092   putline();
1093   HASHLKP(0, SPTR_NULL);
1094   SCOPEP(0, 0);
1095   SYMLKP(0, SPTR_NULL);
1096 
1097   switch (stype) {
1098   case ST_ARRAY:
1099   case ST_IDENT:
1100   case ST_STRUCT:
1101   case ST_UNION:
1102   case ST_UNKNOWN:
1103   case ST_VAR:
1104     /* three lines: integers, symbols, bits */
1105     putnzint("address", ADDRESSG(0));
1106     ADDRESSP(0, 0);
1107 #ifdef SDSCG
1108     putnsym("sdsc", SDSCG(0));
1109     SDSCP(0, 0);
1110 #endif
1111 #ifdef ENCLFUNCG
1112     putnsym("enclfunc", ENCLFUNCG(0));
1113     ENCLFUNCP(0, 0);
1114 #endif
1115 #ifdef OMPACCDEVSYMG
1116       putbit("ompaccel", OMPACCDEVSYMG(0));
1117       OMPACCDEVSYMP(0, 0);
1118 #endif
1119 #ifdef OMPACCSHMEMG
1120       putbit("ompaccel-shared", OMPACCSHMEMG(0));
1121       OMPACCSHMEMP(0, 0);
1122 #endif
1123 #ifdef OMPACCSTRUCTG
1124       putbit("ompaccel-host", OMPACCSTRUCTG(0));
1125       OMPACCSTRUCTP(0, 0);
1126 #endif
1127 #ifdef OMPACCDEVSYMG
1128       putbit("ompaccel", OMPACCDEVSYMG(0));
1129       OMPACCDEVSYMP(0, 0);
1130 #endif
1131 #ifdef OMPACCSHMEMG
1132       putbit("ompaccel-shared", OMPACCSHMEMG(0));
1133       OMPACCSHMEMP(0, 0);
1134 #endif
1135 #ifdef OMPACCSTRUCTG
1136       putbit("ompaccel-host", OMPACCSTRUCTG(0));
1137       OMPACCSTRUCTP(0, 0);
1138 #endif
1139 #ifdef OMPACCLITERALG
1140     putbit("ompaccel-literal", OMPACCLITERALG(0));
1141     OMPACCLITERALP(0, 0);
1142 #endif
1143 #ifdef SOCPTRG
1144     socptr = SOCPTRG(0);
1145     putnzint("socptr", SOCPTRG(0));
1146     SOCPTRP(0, 0);
1147 #endif
1148     putline();
1149     {
1150 #ifdef MDG
1151       putmd("mdg", MDG(0));
1152       MDP(0, 0);
1153 #endif
1154     }
1155     putnzint("b3", b3G(0));
1156     b3P(0, 0);
1157 #ifdef ALIASG
1158     putnsym("alias", ALIASG(0));
1159     ALIASP(0, 0);
1160 #endif
1161 #ifdef ALTNAMEG
1162     putnsym("altname", ALTNAMEG(0));
1163     ALTNAMEP(0, 0);
1164 #endif
1165 #ifdef BASESYMG
1166     if (BASEADDRG(0)) {
1167       putnsym("basesym", BASESYMG(0));
1168       BASESYMP(0, 0);
1169     }
1170 #endif
1171 #ifdef CLENG
1172     putnsym("clen", CLENG(0));
1173     CLENP(0, 0);
1174 #endif
1175     putnsym("midnum", MIDNUMG(0));
1176     MIDNUMP(0, 0);
1177 #ifdef IPAINFOG
1178     if (IPANAMEG(0)) {
1179       putnzint("ipainfo", IPAINFOG(0));
1180       if (stb.n_base && IPANAMEG(0) && IPAINFOG(0) > 0 &&
1181           IPAINFOG(0) < stb.namavl) {
1182         putstring("ipaname", stb.n_base + IPAINFOG(0));
1183       }
1184       IPAINFOP(0, 0);
1185     }
1186 #endif
1187 #ifdef ORIGDIMG
1188     putnzint("origdim", ORIGDIMG(0));
1189     ORIGDIMP(0, 0);
1190 #endif
1191 #ifdef ORIGDUMMYG
1192     putnsym("origdummy", ORIGDUMMYG(0));
1193     ORIGDUMMYP(0, 0);
1194 #endif
1195 #ifdef PDALNG
1196     putnzint("pdaln", PDALNG(0));
1197     b4P(0, 0);
1198 #endif
1199 #ifdef PARAMVALG
1200     {
1201       putnzint("paramval", PARAMVALG(0));
1202       PARAMVALP(0, 0);
1203     }
1204 #endif
1205 #ifdef TPLNKG
1206     if (stype == ST_ARRAY) {
1207       putnsym("tplnk", TPLNKG(0));
1208       TPLNKP(0, 0);
1209     }
1210 #endif
1211 #ifdef XYPTRG
1212     {
1213       putxyptr("xyptr", XYPTRG(0));
1214       XYPTRP(0, 0);
1215     }
1216 #endif
1217 #ifdef XREFLKG
1218     {
1219       putnsym("xreflk", XREFLKG(0));
1220       XREFLKP(0, 0);
1221     }
1222 #endif
1223 #ifdef ELFSCNG
1224     putnsym("elfscn", ELFSCNG(0));
1225     ELFSCNP(0, 0);
1226     if (stype != ST_FUNC) {
1227       putnsym("elflkg", ELFLKG(0));
1228       ELFLKP(0, 0);
1229     }
1230 #endif
1231     putline();
1232     putbit("addrtkn", ADDRTKNG(0));
1233     ADDRTKNP(0, 0);
1234 #ifdef ACCINITDATAG
1235     putbit("accinitdata", ACCINITDATAG(0));
1236     ACCINITDATAP(0, 0);
1237 #endif
1238 #ifdef ADJARRG
1239     putbit("adjarr", ADJARRG(0));
1240     ADJARRP(0, 0);
1241 #endif
1242 #ifdef ALLOCG
1243     putbit("alloc", ALLOCG(0));
1244     ALLOCP(0, 0);
1245 #endif
1246 #ifdef ARG1PTRG
1247     putbit("arg1ptr", ARG1PTRG(0));
1248     ARG1PTRP(0, 0);
1249 #endif
1250     putbit("assn", ASSNG(0));
1251     ASSNP(0, 0);
1252 #ifdef ASSUMSHPG
1253     putbit("assumshp", ASSUMSHPG(0));
1254     ASSUMSHPP(0, 0);
1255 #endif
1256 #ifdef ASUMSZG
1257     putbit("asumsz", ASUMSZG(0));
1258     ASUMSZP(0, 0);
1259 #endif
1260 #ifdef AUTOBJG
1261     putbit("autobj", AUTOBJG(0));
1262     AUTOBJP(0, 0);
1263 #endif
1264 #ifdef BASEADDRG
1265     putbit("baseaddr", BASEADDRG(0));
1266     BASEADDRP(0, 0);
1267 #endif
1268 #ifdef CALLEDG
1269     putbit("called", CALLEDG(0));
1270     CALLEDP(0, 0);
1271 #endif
1272     putbit("ccsym", CCSYMG(0));
1273     CCSYMP(0, 0);
1274 #ifdef CLASSG
1275     putbit("class", CLASSG(0));
1276     CLASSP(0, 0);
1277 #endif
1278 #ifdef CONSTANTG
1279     putbit("constant", CONSTANTG(0));
1280     CONSTANTP(0, 0);
1281 #endif
1282 #ifdef CONSTG
1283     putbit("const", CONSTG(0));
1284     CONSTP(0, 0);
1285 #endif
1286 #ifdef COPYPRMSG
1287     putbit("copyprms", COPYPRMSG(0));
1288     COPYPRMSP(0, 0);
1289 #endif
1290 #ifdef DCLDG
1291     putbit("dcld", DCLDG(0));
1292     DCLDP(0, 0);
1293 #endif
1294     putbit("defd", DEFDG(0));
1295     DEFDP(0, 0);
1296 #ifdef DESCARRAYG
1297     putbit("descarray", DESCARRAYG(0));
1298     DESCARRAYP(0, 0);
1299 #endif
1300 #ifdef DEVICEG
1301     putbit("device", DEVICEG(0));
1302     DEVICEP(0, 0);
1303 #endif
1304 #ifdef DEVICECOPYG
1305     putbit("devicecopy", DEVICECOPYG(0));
1306     DEVICECOPYP(0, 0);
1307 #endif
1308     putbit("dinit", DINITG(0));
1309     DINITP(0, 0);
1310 #ifdef DVLG
1311     putbit("dvl", DVLG(0));
1312     DVLP(0, 0);
1313 #endif
1314 #ifdef ESCTYALIASG
1315     putbit("esctyalias", ESCTYALIASG(0));
1316     ESCTYALIASP(0, 0);
1317 #endif
1318 #ifdef FROMINLRG
1319     putbit("frominlr", FROMINLRG(0));
1320     FROMINLRP(0, 0);
1321 #endif
1322     putbit("gscope", GSCOPEG(0));
1323     GSCOPEP(0, 0);
1324 #ifdef HOMEDG
1325     putbit("homed", HOMEDG(0));
1326     HOMEDP(0, 0);
1327 #endif
1328 #ifdef INLING
1329     putbit("inlin", INLING(0));
1330     INLINP(0, 0);
1331 #endif
1332 #ifdef ALWAYSINLING
1333     putbit("alwaysinlin", ALWAYSINLING(0));
1334     ALWAYSINLINP(0, 0);
1335 #endif
1336 #ifdef INLNG
1337     putbit("inln", INLNG(0));
1338     INLNP(0, 0);
1339 #endif
1340 #ifdef INLNARRG
1341     putbit("inlnarr", INLNARRG(0));
1342     INLNARRP(0, 0);
1343 #endif
1344 #ifdef LIBCG
1345     putbit("libc", LIBCG(0));
1346     LIBCP(0, 0);
1347 #endif
1348 #ifdef LIBMG
1349     putbit("libm", LIBMG(0));
1350     LIBMP(0, 0);
1351 #endif
1352 #ifdef LOCLIFETMG
1353     putbit("loclifetm", LOCLIFETMG(0));
1354     LOCLIFETMP(0, 0);
1355 #endif
1356 #ifdef LSCOPEG
1357     putbit("lscope", LSCOPEG(0));
1358     LSCOPEP(0, 0);
1359 #endif
1360 #ifdef LVALG
1361     putbit("lval", LVALG(0));
1362     LVALP(0, 0);
1363 #endif
1364 #ifdef MANAGEDG
1365     putbit("managed", MANAGEDG(0));
1366     MANAGEDP(0, 0);
1367 #endif
1368     putbit("memarg", MEMARGG(0));
1369     MEMARGP(0, 0);
1370 #ifdef MIRROREDG
1371     putbit("mirrored", MIRROREDG(0));
1372     MIRROREDP(0, 0);
1373 #endif
1374 #ifdef ACCCREATEG
1375     putbit("acccreate", ACCCREATEG(0));
1376     ACCCREATEP(0, 0);
1377 #endif
1378 #ifdef ACCCOPYING
1379     putbit("acccopyin", ACCCOPYING(0));
1380     ACCCOPYINP(0, 0);
1381 #endif
1382 #ifdef ACCRESIDENTG
1383     putbit("accresident", ACCRESIDENTG(0));
1384     ACCRESIDENTP(0, 0);
1385 #endif
1386 #ifdef ACCLINKG
1387     putbit("acclink", ACCLINKG(0));
1388     ACCLINKP(0, 0);
1389 #endif
1390 #ifdef MODESETG
1391     if (stype == ST_FUNC) {
1392       putbit("modeset", MODESETG(0));
1393       MODESETP(0, 0);
1394     }
1395 #endif
1396 #ifdef MSCALLG
1397     putbit("mscall", MSCALLG(0));
1398     MSCALLP(0, 0);
1399 #endif
1400 #ifdef CFUNCG
1401     putbit("cfunc", CFUNCG(0));
1402     CFUNCP(0, 0);
1403 #endif
1404 #ifdef NOCONFLICTG
1405     putbit("noconflict", NOCONFLICTG(0));
1406     NOCONFLICTP(0, 0);
1407 #endif
1408 #ifdef NOTEXTERNG
1409     putbit("notextern", NOTEXTERNG(0));
1410     NOTEXTERNP(0, 0);
1411 #endif
1412 #ifdef OPTARGG
1413     putbit("optarg", OPTARGG(0));
1414     OPTARGP(0, 0);
1415 #endif
1416 #ifdef OSXINITG
1417     if (stype == ST_FUNC) {
1418       putbit("osxinit", OSXINITG(0));
1419       OSXINITP(0, 0);
1420       putbit("osxterm", OSXTERMG(0));
1421       OSXTERMP(0, 0);
1422     }
1423 #endif
1424 #ifdef PARAMG
1425     putbit("param", PARAMG(0));
1426     PARAMP(0, 0);
1427 #endif
1428 #ifdef PASSBYVALG
1429     putbit("passbyval", PASSBYVALG(0));
1430     PASSBYVALP(0, 0);
1431 #endif
1432 #ifdef PASSBYREFG
1433     putbit("passbyref", PASSBYREFG(0));
1434     PASSBYREFP(0, 0);
1435 #endif
1436 #ifdef PINNEDG
1437     putbit("pinned", PINNEDG(0));
1438     PINNEDP(0, 0);
1439 #endif
1440 #ifdef POINTERG
1441     putbit("pointer", POINTERG(0));
1442     POINTERP(0, 0);
1443 #endif
1444 #ifdef ALLOCATTRP
1445     putbit("allocattr", ALLOCATTRG(0));
1446     ALLOCATTRP(0, 0);
1447 #endif
1448 #ifdef PROTODCLG
1449     putbit("protodcl", PROTODCLG(0));
1450     PROTODCLP(0, 0);
1451 #endif
1452 #ifdef PTRSAFEG
1453     putbit("ptrsafe", PTRSAFEG(0));
1454     PTRSAFEP(0, 0);
1455 #endif
1456     putbit("qaln", QALNG(0));
1457     QALNP(0, 0);
1458 #ifdef REDUCG
1459     putbit("reduc", REDUCG(0));
1460     REDUCP(0, 0);
1461 #endif
1462 #ifdef REFG
1463     putbit("ref", REFG(0));
1464     REFP(0, 0);
1465 #endif
1466 #ifdef REFDG
1467     putbit("refd", REFDG(0));
1468     REFDP(0, 0);
1469 #endif
1470 #ifdef REFLECTEDG
1471     putbit("reflected", REFLECTEDG(0));
1472     REFLECTEDP(0, 0);
1473 #endif
1474     putbit("regarg", REGARGG(0));
1475     REGARGP(0, 0);
1476 #ifdef RESTRICTG
1477     putbit("restrict", RESTRICTG(0));
1478     RESTRICTP(0, 0);
1479 #endif
1480 #ifdef SAFEG
1481     putbit("safe", SAFEG(0));
1482     SAFEP(0, 0);
1483 #endif
1484 #ifdef SAVEG
1485     putbit("save", SAVEG(0));
1486     SAVEP(0, 0);
1487 #endif
1488 #ifdef SDSCCONTIGG
1489     putbit("sdsccontig", SDSCCONTIGG(0));
1490     SDSCCONTIGP(0, 0);
1491 #endif
1492 #ifdef SDSCS1G
1493     putbit("sdscs1", SDSCS1G(0));
1494     SDSCS1P(0, 0);
1495 #endif
1496 #ifdef SECTG
1497     putbit("sect", SECTG(0));
1498     SECTP(0, 0);
1499 #endif
1500 #ifdef SHAREDG
1501     putbit("shared", SHAREDG(0));
1502     SHAREDP(0, 0);
1503 #endif
1504 #ifdef TEXTUREG
1505     putbit("texture", TEXTUREG(0));
1506     TEXTUREP(0, 0);
1507 #endif
1508 #ifdef INTENTING
1509     putbit("intentin", INTENTING(0));
1510     INTENTINP(0, 0);
1511 #endif
1512     putbit("thread", THREADG(0));
1513     THREADP(0, 0);
1514 #ifdef UNSAFEG
1515     putbit("unsafe", UNSAFEG(0));
1516     UNSAFEP(0, 0);
1517 #endif
1518 #ifdef UPLEVELG
1519     putbit("uplevel", UPLEVELG(0));
1520     UPLEVELP(0, 0);
1521 #endif
1522 #ifdef INTERNREFG
1523     putbit("internref", INTERNREFG(0));
1524     INTERNREFP(0, 0);
1525 #endif
1526 #ifdef VARDSCG
1527     putbit("vardsc", VARDSCG(0));
1528     VARDSCP(0, 0);
1529 #endif
1530 #ifdef VLAG
1531     putbit("vla", VLAG(0));
1532     VLAP(0, 0);
1533 #endif
1534 #ifdef VLAIDXG
1535     putbit("vlaidx", VLAIDXG(0));
1536     VLAIDXP(0, 0);
1537 #endif
1538     putbit("vol", VOLG(0));
1539     VOLP(0, 0);
1540 #ifdef WEAKG
1541     putbit("weak", WEAKG(0));
1542     WEAKP(0, 0);
1543 #endif
1544 #ifdef PARREFG
1545     putbit("parref", PARREFG(0));
1546     PARREFP(0, 0);
1547 #endif
1548 #ifdef PARREFLOADG
1549     putbit("parrefload", PARREFLOADG(0));
1550     PARREFLOADP(0, 0);
1551 #endif
1552 #ifdef OMPTEAMPRIVATEG
1553     putbit("team-private", OMPTEAMPRIVATEG(0));
1554     OMPTEAMPRIVATEP(0, 0);
1555 #endif
1556 /*
1557         putbit( "#", #G(0) );		#P(0,0);
1558 */
1559 #ifdef SOCPTRG
1560     if (socptr)
1561       putsoc(socptr);
1562 #endif
1563     break;
1564 
1565   case ST_BLOCK:
1566     putint("startline", STARTLINEG(0));
1567     STARTLINEP(0, 0);
1568     putint("endline", ENDLINEG(0));
1569     ENDLINEP(0, 0);
1570 #ifdef ENCLFUNCG
1571     putnsym("enclfunc", ENCLFUNCG(0));
1572     ENCLFUNCP(0, 0);
1573 #endif
1574     putnsym("startlab", STARTLABG(0));
1575     STARTLABP(0, 0);
1576     putnsym("endlab", ENDLABG(0));
1577     ENDLABP(0, 0);
1578     putnsym("beginscopelab", BEGINSCOPELABG(0));
1579     BEGINSCOPELABP(0, 0);
1580     putnsym("endscopelab", ENDSCOPELABG(0));
1581     ENDSCOPELABP(0, 0);
1582 #ifdef AUTOBJG
1583     putnzint("autobj", AUTOBJG(0));
1584     AUTOBJP(0, 0);
1585 #endif
1586 #ifdef AINITG
1587     putbit("ainit", AINITG(0));
1588     AINITP(0, 0);
1589 #endif
1590     putbit("ccsym", CCSYMG(0));
1591     CCSYMP(0, 0);
1592 #ifdef FROMINLRG
1593     putbit("frominlr", FROMINLRG(0));
1594     FROMINLRP(0, 0);
1595 #endif
1596 #ifdef REFDG
1597     putbit("refd", REFDG(0));
1598     REFDP(0, 0);
1599 #endif
1600 #ifdef PARUPLEVELG
1601     putint("paruplevel", PARUPLEVELG(0));
1602     PARUPLEVELP(0, 0);
1603 #endif
1604 #ifdef PARSYMSG
1605     putbit("parsyms", PARSYMSG(0));
1606     PARSYMSP(0, 0);
1607 #endif
1608 #ifdef PARSYMSCTG
1609     putbit("parsymsct", PARSYMSCTG(0));
1610     PARSYMSCTP(0, 0);
1611 #endif
1612     break;
1613 
1614   case ST_BASE:
1615     break;
1616 
1617   case ST_CMBLK:
1618     putint("size", SIZEG(0));
1619     SIZEP(0, 0);
1620     putline();
1621     putsym("cmemf", CMEMFG(0));
1622     CMEMFP(0, 0);
1623     putsym("cmeml", CMEMLG(0));
1624     CMEMLP(0, 0);
1625 #ifdef INMODULEG
1626     putnzint("inmodule", INMODULEG(0));
1627     INMODULEP(0, 0);
1628 #endif
1629     putnsym("midnum", MIDNUMG(0));
1630     MIDNUMP(0, 0);
1631 #ifdef ALTNAMEG
1632     putnsym("altname", ALTNAMEG(0));
1633     ALTNAMEP(0, 0);
1634 #endif
1635 #ifdef PDALNG
1636     putnzint("pdaln", PDALNG(0));
1637     PDALNP(0, 0);
1638 #endif
1639     putline();
1640 #ifdef ACCCREATEG
1641     putbit("acccreate", ACCCREATEG(0));
1642     ACCCREATEP(0, 0);
1643 #endif
1644 #ifdef ACCCOPYING
1645     putbit("acccopyin", ACCCOPYING(0));
1646     ACCCOPYINP(0, 0);
1647 #endif
1648 #ifdef ACCRESIDENTG
1649     putbit("accresident", ACCRESIDENTG(0));
1650     ACCRESIDENTP(0, 0);
1651 #endif
1652 #ifdef ACCLINKG
1653     putbit("acclink", ACCLINKG(0));
1654     ACCLINKP(0, 0);
1655 #endif
1656     putbit("alloc", ALLOCG(0));
1657     ALLOCP(0, 0);
1658     putbit("ccsym", CCSYMG(0));
1659     CCSYMP(0, 0);
1660 #ifdef CONSTANTG
1661     putbit("constant", CONSTANTG(0));
1662     CONSTANTP(0, 0);
1663 #endif
1664     putbit("dcld", DCLDG(0));
1665     DCLDP(0, 0);
1666     putbit("defd", DEFDG(0));
1667     DEFDP(0, 0);
1668 #ifdef DEVICEG
1669     putbit("device", DEVICEG(0));
1670     DEVICEP(0, 0);
1671 #endif
1672     putbit("dinit", DINITG(0));
1673     DINITP(0, 0);
1674 #ifdef FROMINLRG
1675     putbit("frominlr", FROMINLRG(0));
1676     FROMINLRP(0, 0);
1677 #endif
1678 #ifdef FROMMODG
1679     putbit("frommod", FROMMODG(0));
1680     FROMMODP(0, 0);
1681 #endif
1682 #ifdef INLNG
1683     putbit("inln", INLNG(0));
1684     INLNP(0, 0);
1685 #endif
1686 #ifdef MODCMNG
1687     putbit("modcmn", MODCMNG(0));
1688     MODCMNP(0, 0);
1689 #endif
1690     putbit("qaln", QALNG(0));
1691     QALNP(0, 0);
1692     putbit("save", SAVEG(0));
1693     SAVEP(0, 0);
1694 #ifdef THREADG
1695     putbit("thread", THREADG(0));
1696     THREADP(0, 0);
1697 #endif
1698     putbit("vol", VOLG(0));
1699     VOLP(0, 0);
1700     putsymlk("Members:", CMEMFG(sptr));
1701     break;
1702 
1703   case ST_CONST:
1704     putnzint("address", ADDRESSG(0));
1705     ADDRESSP(0, 0);
1706     if (DTY(dtype) == TY_PTR) {
1707       putsym("pointee", STGetPointee(0));
1708       CONVAL1P(0, 0);
1709       putnzbigint("offset", ACONOFFG(0));
1710       ACONOFFP(0, 0);
1711     } else {
1712       putint("conval1g", CONVAL1G(0));
1713       CONVAL1P(0, 0);
1714       putbigint("conval2g", CONVAL2G(0));
1715       CONVAL2P(0, 0);
1716     }
1717     putline();
1718     break;
1719 
1720   case ST_ENTRY:
1721     putnzint("bihnum", BIHNUMG(0));
1722     BIHNUMP(0, 0);
1723 #ifdef ARGSIZEG
1724     putnzint("argsize", ARGSIZEG(0));
1725     ARGSIZEP(0, 0);
1726 #endif
1727     putint("dpdsc", DPDSCG(0));
1728     DPDSCP(0, 0);
1729     putint("funcline", FUNCLINEG(0));
1730     FUNCLINEP(0, 0);
1731 #ifdef DECLLINEG
1732     putnzint("declline", DECLLINEG(0));
1733     DECLLINEP(0, 0);
1734 #endif
1735     putint("paramct", PARAMCTG(0));
1736     PARAMCTP(0, 0);
1737 #ifdef ALTNAMEG
1738     putnsym("altname", ALTNAMEG(0));
1739     ALTNAMEP(0, 0);
1740 #endif
1741     putline();
1742 #ifdef INMODULEG
1743     putnsym("inmodule", INMODULEG(0));
1744     INMODULEP(0, 0);
1745 #endif
1746     putnsym("gsame", GSAMEG(0));
1747     GSAMEP(0, 0);
1748     putnsym("fval", FVALG(0));
1749     FVALP(0, 0);
1750 #ifdef CUDAG
1751     putcuda("cuda", CUDAG(0));
1752     CUDAP(0, 0);
1753 #endif
1754 #ifdef ACCROUTG
1755     putnzint("accrout", ACCROUTG(0));
1756     ACCROUTP(0, 0);
1757 #endif
1758 #ifdef OMPACCFUNCDEVG
1759     putbit("ompaccel-device", OMPACCFUNCDEVG(0));
1760     OMPACCFUNCDEVP(0, 0);
1761 #endif
1762 #ifdef OMPACCFUNCKERNELG
1763     putbit("ompaccel-kernel", OMPACCFUNCKERNELG(0));
1764     OMPACCFUNCKERNELP(0, 0);
1765 #endif
1766 #ifdef OMPACCFUNCDEVG
1767     putbit("ompaccel-device", OMPACCFUNCDEVG(0));
1768     OMPACCFUNCDEVP(0, 0);
1769 #endif
1770 #ifdef OMPACCFUNCKERNELG
1771     putbit("ompaccel-kernel", OMPACCFUNCKERNELG(0));
1772     OMPACCFUNCKERNELP(0, 0);
1773 #endif
1774 #ifdef IPAINFOG
1775     putnzint("ipainfo", IPAINFOG(0));
1776     if (stb.n_base && IPANAMEG(0) && IPAINFOG(0) > 0 &&
1777         IPAINFOG(0) < stb.namavl) {
1778       putstring("ipaname", stb.n_base + IPAINFOG(0));
1779     }
1780     IPAINFOP(0, 0);
1781 #endif
1782     putline();
1783     putbit("adjarr", ADJARRG(0));
1784     ADJARRP(0, 0);
1785     putbit("aftent", AFTENTG(0));
1786     AFTENTP(0, 0);
1787 #ifdef CALLEDG
1788     putbit("called", CALLEDG(0));
1789     CALLEDP(0, 0);
1790 #endif
1791     putbit("ccsym", CCSYMG(0));
1792     CCSYMP(0, 0);
1793 #ifdef CONTAINEDG
1794     putbit("contained", CONTAINEDG(0));
1795     CONTAINEDP(0, 0);
1796 #endif
1797 #ifdef COPYPRMSG
1798     putbit("copyprms", COPYPRMSG(0));
1799     COPYPRMSP(0, 0);
1800 #endif
1801     putbit("dcld", DCLDG(0));
1802     DCLDP(0, 0);
1803 #ifdef DECORATEG
1804     putbit("decorate", DECORATEG(0));
1805     DECORATEP(0, 0);
1806 #endif
1807 #ifdef FROMINLRG
1808     putbit("frominlr", FROMINLRG(0));
1809     FROMINLRP(0, 0);
1810 #endif
1811 #ifdef MSCALLG
1812     putbit("mscall", MSCALLG(0));
1813     MSCALLP(0, 0);
1814 #endif
1815 #ifdef CFUNCG
1816     putbit("cfunc", CFUNCG(0));
1817     CFUNCP(0, 0);
1818 #endif
1819 #ifdef NOTEXTERNG
1820     putbit("notextern", NOTEXTERNG(0));
1821     NOTEXTERNP(0, 0);
1822 #endif
1823     putbit("pure", PUREG(0));
1824     PUREP(0, 0);
1825 #ifdef STDCALLG
1826     putbit("stdcall", STDCALLG(0));
1827     STDCALLP(0, 0);
1828 #endif
1829     putline();
1830     putparam(DPDSCG(sptr), PARAMCTG(sptr));
1831     break;
1832 
1833   case ST_GENERIC:
1834     putnsym("gcmplx", GCMPLXG(0));
1835     GCMPLXP(0, 0);
1836     putnsym("gdble", GDBLEG(0));
1837     GDBLEP(0, 0);
1838     putnsym("gdcmplx", GDCMPLXG(0));
1839     GDCMPLXP(0, 0);
1840     putnsym("gint", GINTG(0));
1841     GINTP(0, 0);
1842     putnsym("gint8", GINT8G(0));
1843     GINT8P(0, 0);
1844 #ifdef GQCMPLXG
1845     putnsym("gqcmplx", GQCMPLXG(0));
1846     GQCMPLXP(0, 0);
1847 #endif
1848 #ifdef GQUADG
1849     putnsym("gquad", GQUADG(0));
1850     GQUADP(0, 0);
1851 #endif
1852     putnsym("greal", GREALG(0));
1853     GREALP(0, 0);
1854     putnsym("gsame", GSAMEG(0));
1855     GSAMEP(0, 0);
1856     putnsym("gsint", GSINTG(0));
1857     GSINTP(0, 0);
1858     putnzint("gndsc", GNDSCG(0));
1859     GNDSCP(0, 0);
1860     putnzint("gncnt", GNCNTG(0));
1861     GNCNTP(0, 0);
1862     putline();
1863     putbit("dcld", DCLDG(0));
1864     DCLDP(0, 0);
1865     break;
1866 
1867   case ST_INTRIN:
1868     putddtype("argtyp", ARGTYPG(0));
1869     ARGTYPP(0, 0);
1870     putnzint("arrayf", ARRAYFG(0));
1871     ARRAYFP(0, 0);
1872     putnzint("ilm", ILMG(0));
1873     ILMP(0, 0);
1874     putddtype("inttyp", INTTYPG(0));
1875     INTTYPP(0, 0);
1876     putnname("pnmptr", PNMPTRG(0));
1877     PNMPTRP(0, 0);
1878     putint("paramct", PARAMCTG(0));
1879     PARAMCTP(0, 0);
1880     putline();
1881     putbit("dcld", DCLDG(0));
1882     DCLDP(0, 0);
1883     putbit("expst", EXPSTG(0));
1884     EXPSTP(0, 0);
1885     break;
1886 
1887   case ST_LABEL:
1888     putnzint("address", ADDRESSG(0));
1889     ADDRESSP(0, 0);
1890 #ifdef ENCLFUNCG
1891     putnsym("enclfunc", ENCLFUNCG(0));
1892     ENCLFUNCP(0, 0);
1893 #endif
1894 #ifdef FMTPTG
1895     putnsym("fmtpt", FMTPTG(0));
1896     FMTPTP(0, 0);
1897 #endif
1898     putnzint("iliblk", ILIBLKG(0));
1899     ILIBLKP(0, 0);
1900 #ifdef JSCOPEG
1901     putnzint("jscope", JSCOPEG(0));
1902     JSCOPEP(0, 0);
1903 #endif
1904     putint("rfcnt", RFCNTG(0));
1905     RFCNTP(0, 0);
1906     putline();
1907     putbit("ccsym", CCSYMG(0));
1908     CCSYMP(0, 0);
1909     putbit("defd", DEFDG(0));
1910     DEFDP(0, 0);
1911 #ifdef INLING
1912     putbit("inlin", INLING(0));
1913     INLINP(0, 0);
1914 #endif
1915 #ifdef ALWAYSINLING
1916     putbit("alwaysinlin", ALWAYSINLING(0));
1917     ALWAYSINLINP(0, 0);
1918 #endif
1919 #ifdef INLNG
1920     putbit("inln", INLNG(0));
1921     INLNP(0, 0);
1922 #endif
1923 #ifdef LSCOPEG
1924     putbit("lscope", LSCOPEG(0));
1925     LSCOPEP(0, 0);
1926 #endif
1927     putbit("qaln", QALNG(0));
1928     QALNP(0, 0);
1929 #ifdef REFDG
1930     putbit("refd", REFDG(0));
1931     REFDP(0, 0);
1932 #endif
1933     putbit("vol", VOLG(0));
1934     VOLP(0, 0);
1935     putbit("beginscope", BEGINSCOPEG(0));
1936     BEGINSCOPEP(0, 0);
1937     putbit("endscope", ENDSCOPEG(0));
1938     ENDSCOPEP(0, 0);
1939     break;
1940 
1941   case ST_MEMBER:
1942     putint("address", ADDRESSG(0));
1943     ADDRESSP(0, 0);
1944 #ifdef BITOFFG
1945     putnzint("bitoff", BITOFFG(0));
1946     BITOFFP(0, 0);
1947 #endif
1948 #ifdef FLDSZG
1949     putnzint("fldsz", FLDSZG(0));
1950     FLDSZP(0, 0);
1951 #endif
1952 #ifdef LDSIZEG
1953     putnzint("ldsize", LDSIZEG(0));
1954     LDSIZEP(0, 0);
1955 #endif
1956     putsym("psmem", PSMEMG(0));
1957     PSMEMP(0, 0);
1958 #ifdef VARIANTG
1959     putsym("variant", VARIANTG(0));
1960     VARIANTP(0, 0);
1961 #endif
1962 #ifdef INDTYPEG
1963     putnzint("indtype", INDTYPEG(0));
1964     INDTYPEP(0, 0);
1965 #endif
1966 #ifdef SDSCG
1967     putnsym("sdsc", SDSCG(0));
1968     SDSCP(0, 0);
1969 #endif
1970     putline();
1971 #ifdef ALLOCATTRG
1972     putbit("allocattr", ALLOCATTRG(0));
1973     ALLOCATTRP(0, 0);
1974 #endif
1975 #ifdef CLASSG
1976     putbit("class", CLASSG(0));
1977     CLASSP(0, 0);
1978 #endif
1979     putbit("ccsym", CCSYMG(0));
1980     CCSYMP(0, 0);
1981 #ifdef DCLDG
1982     putbit("dcld", DCLDG(0));
1983     DCLDP(0, 0);
1984 #endif
1985 #ifdef DESCARRAYG
1986     putbit("descarray", DESCARRAYG(0));
1987     DESCARRAYP(0, 0);
1988 #endif
1989 #ifdef FIELDG
1990     putbit("field", FIELDG(0));
1991     FIELDP(0, 0);
1992 #endif
1993 #ifdef INLING
1994     putbit("inlin", INLING(0));
1995     INLINP(0, 0);
1996 #endif
1997 #ifdef ALWAYSINLING
1998     putbit("alwaysinlin", ALWAYSINLING(0));
1999     ALWAYSINLINP(0, 0);
2000 #endif
2001 #ifdef INLNG
2002     putbit("inln", INLNG(0));
2003     INLNP(0, 0);
2004 #endif
2005 #ifdef MSCALLG
2006     putbit("mscall", MSCALLG(0));
2007     MSCALLP(0, 0);
2008 #endif
2009 #ifdef CFUNCG
2010     putbit("cfunc", CFUNCG(0));
2011     CFUNCP(0, 0);
2012 #endif
2013 #ifdef NOCONFLICTG
2014     putbit("noconflict", NOCONFLICTG(0));
2015     NOCONFLICTP(0, 0);
2016 #endif
2017 #ifdef PLAING
2018     putbit("plain", PLAING(0));
2019     PLAINP(0, 0);
2020 #endif
2021 #ifdef POINTERG
2022     putbit("pointer", POINTERG(0));
2023     POINTERP(0, 0);
2024 #endif
2025 #ifdef PTRSAFEG
2026     putbit("ptrsafe", PTRSAFEG(0));
2027     PTRSAFEP(0, 0);
2028 #endif
2029 #ifdef REFDG
2030     putbit("refd", REFDG(0));
2031     REFDP(0, 0);
2032 #endif
2033 #ifdef SDSCCONTIGG
2034     putbit("sdsccontig", SDSCCONTIGG(0));
2035     SDSCCONTIGP(0, 0);
2036 #endif
2037 #ifdef SDSCS1G
2038     putbit("sdscs1", SDSCS1G(0));
2039     SDSCS1P(0, 0);
2040 #endif
2041     break;
2042 
2043   case ST_NML:
2044     putsym("plist", (SPTR) ADDRESSG(0)); // ???
2045     ADDRESSP(0, 0);
2046     putsym("cmemf", CMEMFG(0));
2047     CMEMFP(0, 0);
2048     putsym("cmeml", CMEMLG(0));
2049     CMEMLP(0, 0);
2050     putline();
2051     putbit("dcld", DCLDG(0));
2052     DCLDP(0, 0);
2053     putbit("ref", REFG(0));
2054     REFP(0, 0);
2055     putline();
2056     for (i = CMEMFG(sptr); i; i = NML_NEXT(i)) {
2057       putsym1(NML_SPTR(i));
2058     }
2059     break;
2060 
2061   case ST_PARAM:
2062     putint("conval1g", CONVAL1G(0));
2063     CONVAL1P(0, 0);
2064     putint("conval2g", CONVAL2G(0));
2065     CONVAL2P(0, 0);
2066     putline();
2067     putbit("dcld", DCLDG(0));
2068     DCLDP(0, 0);
2069     putbit("ref", REFG(0));
2070     REFP(0, 0);
2071     break;
2072 
2073   case ST_PD:
2074     putddtype("argtyp", ARGTYPG(0));
2075     ARGTYPP(0, 0);
2076     putint("paramct", PARAMCTG(0));
2077     PARAMCTP(0, 0);
2078     putnzint("ilm", ILMG(0));
2079     ILMP(0, 0);
2080     putint("pdnum", PDNUMG(0));
2081     PDNUMP(0, 0);
2082     break;
2083 
2084   case ST_PLIST:
2085     putint("address", ADDRESSG(0));
2086     ADDRESSP(0, 0);
2087 #ifdef BASESYMG
2088     if (BASEADDRG(0)) {
2089       putnsym("basesym", BASESYMG(0));
2090       BASESYMP(0, 0);
2091     }
2092 #endif
2093     putnzint("deflab", DEFLABG(0));
2094     DEFLABP(0, 0);
2095     putint("pllen", PLLENG(0));
2096     PLLENP(0, 0);
2097     putnzint("swel", SWELG(0));
2098     SWELP(0, 0);
2099     putline();
2100     putbit("addrtkn", ADDRTKNG(0));
2101     ADDRTKNP(0, 0);
2102 
2103 #ifdef BASEADDRG
2104     putbit("baseaddr", BASEADDRG(0));
2105     BASEADDRP(0, 0);
2106 #endif
2107     putbit("ccsym", CCSYMG(0));
2108     CCSYMP(0, 0);
2109     putbit("dcld", DCLDG(0));
2110     DCLDP(0, 0);
2111     putbit("dinit", DINITG(0));
2112     DINITP(0, 0);
2113 #ifdef INLING
2114     putbit("inlin", INLING(0));
2115     INLINP(0, 0);
2116 #endif
2117 #ifdef ALWAYSINLING
2118     putbit("alwaysinlin", ALWAYSINLING(0));
2119     ALWAYSINLINP(0, 0);
2120 #endif
2121 #ifdef INLNG
2122     putbit("inln", INLNG(0));
2123     INLNP(0, 0);
2124 #endif
2125 #ifdef LSCOPEG
2126     putbit("lscope", LSCOPEG(0));
2127     LSCOPEP(0, 0);
2128 #endif
2129     putbit("ref", REFG(0));
2130     REFP(0, 0);
2131     break;
2132 
2133   case ST_PROC:
2134 #ifdef INMODULEG
2135     putnsym("inmodule", INMODULEG(0));
2136     INMODULEP(0, 0);
2137 #endif
2138 #ifdef ARGSIZEG
2139     putnzint("argsize", ARGSIZEG(0));
2140     ARGSIZEP(0, 0);
2141 #endif
2142     putnzint("address", ADDRESSG(0));
2143     ADDRESSP(0, 0);
2144     putnsym("midnum", MIDNUMG(0));
2145     MIDNUMP(0, 0);
2146 #ifdef IPAINFOG
2147     putnzint("ipainfo", IPAINFOG(0));
2148     if (stb.n_base && IPANAMEG(0) && IPAINFOG(0) > 0 &&
2149         IPAINFOG(0) < stb.namavl) {
2150       putstring("ipaname", stb.n_base + IPAINFOG(0));
2151     }
2152     IPAINFOP(0, 0);
2153 #endif
2154 #ifdef ALTNAMEG
2155     putnsym("altname", ALTNAMEG(0));
2156     ALTNAMEP(0, 0);
2157 #endif
2158 #ifdef ACCROUTG
2159     putnzint("accrout", ACCROUTG(0));
2160     ACCROUTP(0, 0);
2161 #endif
2162 #ifdef ARG1PTRG
2163     putbit("arg1ptr", ARG1PTRG(0));
2164     ARG1PTRP(0, 0);
2165 #endif
2166 #ifdef CUDAG
2167     putcuda("cuda", CUDAG(0));
2168     CUDAP(0, 0);
2169 #endif
2170     putline();
2171 #ifdef CFUNCG
2172     putbit("cfunc", CFUNCG(0));
2173     CFUNCP(0, 0);
2174 #endif
2175     putbit("ccsym", CCSYMG(0));
2176     CCSYMP(0, 0);
2177 #ifdef COPYPRMSG
2178     putbit("copyprms", COPYPRMSG(0));
2179     COPYPRMSP(0, 0);
2180 #endif
2181 #ifdef CONTAINEDG
2182     putbit("contained", CONTAINEDG(0));
2183     CONTAINEDP(0, 0);
2184 #endif
2185 #ifdef DECORATEG
2186     putbit("decorate", DECORATEG(0));
2187     DECORATEP(0, 0);
2188 #endif
2189 #ifdef MSCALLG
2190     putbit("mscall", MSCALLG(0));
2191     MSCALLP(0, 0);
2192 #endif
2193 #ifdef CFUNCG
2194     putbit("cfunc", CFUNCG(0));
2195     CFUNCP(0, 0);
2196 #endif
2197 #ifdef NEEDMODG
2198     putbit("needmod", NEEDMODG(0));
2199     NEEDMODP(0, 0);
2200 #endif
2201     putbit("nopad", NOPADG(0));
2202     NOPADP(0, 0);
2203     putbit("dcld", DCLDG(0));
2204     DCLDP(0, 0);
2205     putbit("func", FUNCG(0));
2206     FUNCP(0, 0);
2207 #ifdef FROMINLRG
2208     putbit("frominlr", FROMINLRG(0));
2209     FROMINLRP(0, 0);
2210 #endif
2211 #ifdef LIBMG
2212     putbit("libm", LIBMG(0));
2213     LIBMP(0, 0);
2214 #endif
2215     putbit("memarg", MEMARGG(0));
2216     MEMARGP(0, 0);
2217 #ifdef PASSBYVALG
2218     putbit("passbyval", PASSBYVALG(0));
2219     PASSBYVALP(0, 0);
2220 #endif
2221 #ifdef PASSBYREFG
2222     putbit("passbyref", PASSBYREFG(0));
2223     PASSBYREFP(0, 0);
2224 #endif
2225     putbit("pure", PUREG(0));
2226     PUREP(0, 0);
2227     putbit("ref", REFG(0));
2228     REFP(0, 0);
2229 #ifdef SDSCSAFEG
2230     putbit("sdscsafe", SDSCSAFEG(0));
2231     SDSCSAFEP(0, 0);
2232 #endif
2233 #ifdef STDCALLG
2234     putbit("stdcall", STDCALLG(0));
2235     STDCALLP(0, 0);
2236 #endif
2237 #ifdef UNIFIEDG
2238     putbit("unified", UNIFIEDG(0));
2239     UNIFIEDP(0, 0);
2240 #endif
2241     putline();
2242     putparam(DPDSCG(sptr), PARAMCTG(sptr));
2243     break;
2244 
2245   case ST_STFUNC:
2246     putint("excvlen", EXCVLENG(0));
2247     EXCVLENP(0, 0);
2248     putint("sfdsc", SFDSCG(0));
2249     SFDSCP(0, 0);
2250     putline();
2251     putbit("dcld", DCLDG(0));
2252     DCLDP(0, 0);
2253     break;
2254 
2255   case ST_TYPEDEF:
2256 #ifdef ENCLFUNCG
2257     putnsym("enclfunc", ENCLFUNCG(0));
2258     ENCLFUNCP(0, 0);
2259 #endif
2260 #ifdef PDALNG
2261     putnzint("pdaln", PDALNG(0));
2262     PDALNP(0, 0);
2263 #endif
2264 #ifdef DCLDG
2265     putbit("dcld", DCLDG(0));
2266     DCLDP(0, 0);
2267 #endif
2268 #ifdef FROMMODG
2269     putbit("frommod", FROMMODG(0));
2270     FROMMODP(0, 0);
2271 #endif
2272 #ifdef MSCALLG
2273     putbit("mscall", MSCALLG(0));
2274     MSCALLP(0, 0);
2275 #endif
2276 #ifdef CFUNCG
2277     putbit("cfunc", CFUNCG(0));
2278     CFUNCP(0, 0);
2279 #endif
2280 #ifdef CLASSG
2281     putbit("class", CLASSG(0));
2282     CLASSP(0, 0);
2283 #endif
2284 #ifdef PLAING
2285     putbit("plain", PLAING(0));
2286     PLAINP(0, 0);
2287 #endif
2288     break;
2289 
2290   case ST_STAG:
2291 #ifdef ENCLFUNCG
2292     putnsym("enclfunc", ENCLFUNCG(0));
2293     ENCLFUNCP(0, 0);
2294 #endif
2295 #ifdef DCLDG
2296     putbit("dcld", DCLDG(0));
2297     DCLDP(0, 0);
2298 #endif
2299 #ifdef INLNG
2300     putbit("inln", INLNG(0));
2301     INLNP(0, 0);
2302 #endif
2303     break;
2304 
2305   } /* switch(stype) */
2306   putline();
2307 
2308   check("b3", stb.stg_base[0].b3);
2309   check("b4", stb.stg_base[0].b4);
2310   check("f1", stb.stg_base[0].f1);
2311   check("f2", stb.stg_base[0].f2);
2312   check("f3", stb.stg_base[0].f3);
2313   check("f4", stb.stg_base[0].f4);
2314   check("f5", stb.stg_base[0].f5);
2315   check("f6", stb.stg_base[0].f6);
2316   check("f7", stb.stg_base[0].f7);
2317   check("f8", stb.stg_base[0].f8);
2318   check("f9", stb.stg_base[0].f9);
2319   check("f10", stb.stg_base[0].f10);
2320   check("f11", stb.stg_base[0].f11);
2321   check("f12", stb.stg_base[0].f12);
2322   check("f13", stb.stg_base[0].f13);
2323   check("f14", stb.stg_base[0].f14);
2324   check("f15", stb.stg_base[0].f15);
2325   check("f16", stb.stg_base[0].f16);
2326   check("f17", stb.stg_base[0].f17);
2327   check("f18", stb.stg_base[0].f18);
2328   check("f19", stb.stg_base[0].f19);
2329   check("f20", stb.stg_base[0].f20);
2330   check("f21", stb.stg_base[0].f21);
2331   check("f22", stb.stg_base[0].f22);
2332   check("f23", stb.stg_base[0].f23);
2333   check("f24", stb.stg_base[0].f24);
2334   check("f25", stb.stg_base[0].f25);
2335   check("f26", stb.stg_base[0].f26);
2336   check("f27", stb.stg_base[0].f27);
2337   check("f28", stb.stg_base[0].f28);
2338   check("f29", stb.stg_base[0].f29);
2339   check("f30", stb.stg_base[0].f30);
2340   check("f31", stb.stg_base[0].f31);
2341   check("f32", stb.stg_base[0].f32);
2342   check("f33", stb.stg_base[0].f33);
2343   check("f34", stb.stg_base[0].f34);
2344   check("f35", stb.stg_base[0].f35);
2345   check("f36", stb.stg_base[0].f36);
2346   check("f37", stb.stg_base[0].f37);
2347   check("f38", stb.stg_base[0].f38);
2348   check("f39", stb.stg_base[0].f39);
2349   check("f40", stb.stg_base[0].f40);
2350   check("f41", stb.stg_base[0].f41);
2351   check("f42", stb.stg_base[0].f42);
2352   check("f43", stb.stg_base[0].f43);
2353   check("f44", stb.stg_base[0].f44);
2354   check("f45", stb.stg_base[0].f45);
2355   check("f46", stb.stg_base[0].f46);
2356   check("f47", stb.stg_base[0].f47);
2357   check("f48", stb.stg_base[0].f48);
2358   check("f50", stb.stg_base[0].f50);
2359   check("f51", stb.stg_base[0].f51);
2360   check("f52", stb.stg_base[0].f52);
2361   check("f53", stb.stg_base[0].f53);
2362   check("f54", stb.stg_base[0].f54);
2363   check("f55", stb.stg_base[0].f55);
2364   check("f56", stb.stg_base[0].f56);
2365   check("f57", stb.stg_base[0].f57);
2366   check("f58", stb.stg_base[0].f58);
2367   check("f59", stb.stg_base[0].f59);
2368   check("f60", stb.stg_base[0].f60);
2369   check("f61", stb.stg_base[0].f61);
2370   check("f62", stb.stg_base[0].f62);
2371   check("f63", stb.stg_base[0].f63);
2372   check("f64", stb.stg_base[0].f64);
2373   check("f65", stb.stg_base[0].f65);
2374   check("f66", stb.stg_base[0].f66);
2375   check("f67", stb.stg_base[0].f67);
2376   check("f68", stb.stg_base[0].f68);
2377   check("f69", stb.stg_base[0].f69);
2378   check("f70", stb.stg_base[0].f70);
2379   check("f71", stb.stg_base[0].f71);
2380   check("f72", stb.stg_base[0].f72);
2381   check("f73", stb.stg_base[0].f73);
2382   check("f74", stb.stg_base[0].f74);
2383   check("f75", stb.stg_base[0].f75);
2384   check("f76", stb.stg_base[0].f76);
2385   check("f77", stb.stg_base[0].f77);
2386   check("f78", stb.stg_base[0].f78);
2387   check("f79", stb.stg_base[0].f79);
2388   check("f80", stb.stg_base[0].f80);
2389   check("f81", stb.stg_base[0].f81);
2390   check("f82", stb.stg_base[0].f82);
2391   check("f83", stb.stg_base[0].f83);
2392   check("f84", stb.stg_base[0].f84);
2393   check("f85", stb.stg_base[0].f85);
2394   check("f86", stb.stg_base[0].f86);
2395   check("f87", stb.stg_base[0].f87);
2396   check("f88", stb.stg_base[0].f88);
2397   check("f89", stb.stg_base[0].f89);
2398   check("f90", stb.stg_base[0].f90);
2399   check("f91", stb.stg_base[0].f91);
2400   check("f92", stb.stg_base[0].f92);
2401   check("f93", stb.stg_base[0].f93);
2402   check("f94", stb.stg_base[0].f94);
2403   check("f95", stb.stg_base[0].f95);
2404   check("f96", stb.stg_base[0].f96);
2405   check("f110", stb.stg_base[0].f110);
2406   check("f111", stb.stg_base[0].f111);
2407   check("w8", stb.stg_base[0].w8);
2408   check("w9", stb.stg_base[0].w9);
2409   check("w10", stb.stg_base[0].w10);
2410   check("w11", stb.stg_base[0].w11);
2411   check("w12", stb.stg_base[0].w12);
2412   check("w13", stb.stg_base[0].w13);
2413   check("w14", stb.stg_base[0].w14);
2414   check("w15", stb.stg_base[0].w15);
2415   check("w16", stb.stg_base[0].w16);
2416   check("w17", stb.stg_base[0].w17);
2417   check("w18", stb.stg_base[0].w18);
2418   check("w20", stb.stg_base[0].w20);
2419 } /* dsym */
2420 
2421 void
dsyms(int l,int u)2422 dsyms(int l, int u)
2423 {
2424   int i;
2425   if (l <= 0)
2426     l = stb.firstusym;
2427   if (u <= 0)
2428     u = stb.stg_avail - 1;
2429   if (u >= stb.stg_avail)
2430     u = stb.stg_avail - 1;
2431   for (i = l; i <= u; ++i) {
2432     dsym(i);
2433   }
2434   fprintf(dfile, "\n");
2435 } /* dsyms */
2436 
2437 void
ds(int sptr)2438 ds(int sptr)
2439 {
2440   dsym(sptr);
2441 } /* ds */
2442 
2443 void
dsa(void)2444 dsa(void)
2445 {
2446   dsyms(0, 0);
2447 } /* dsa */
2448 
2449 void
dss(int l,int u)2450 dss(int l, int u)
2451 {
2452   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
2453   fprintf(dfile, "\n********** SYMBOL TABLE **********\n");
2454   dsyms(l, u);
2455 } /* dss */
2456 
2457 void
dgbl(void)2458 dgbl(void)
2459 {
2460   GBL mbl;
2461   int *ff;
2462   int i, mblsize;
2463   memcpy(&mbl, &gbl, sizeof(gbl));
2464   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
2465   putsym("gbl.currsub", mbl.currsub);
2466   mbl.currsub = SPTR_NULL;
2467   putnstring("gbl.datetime", mbl.datetime);
2468   memset(mbl.datetime, 0, sizeof(mbl.datetime));
2469   putline();
2470   putnzint("gbl.maxsev", mbl.maxsev);
2471   mbl.maxsev = 0;
2472   putnzint("gbl.findex", mbl.findex);
2473   mbl.findex = 0;
2474   putsymlk("gbl.entries=", mbl.entries);
2475   mbl.entries = SPTR_NULL;
2476   putsymlk("gbl.cmblks=", mbl.cmblks);
2477   mbl.cmblks = SPTR_NULL;
2478   putsymlk("gbl.externs=", mbl.externs);
2479   mbl.externs = SPTR_NULL;
2480   putsymlk("gbl.consts=", mbl.consts);
2481   mbl.consts = SPTR_NULL;
2482   putsymlk("gbl.locals=", mbl.locals);
2483   mbl.locals = SPTR_NULL;
2484   putsymlk("gbl.statics=", mbl.statics);
2485   mbl.statics = SPTR_NULL;
2486   putsymlk("gbl.bssvars=", mbl.bssvars);
2487   mbl.bssvars = SPTR_NULL;
2488   putsymlk("gbl.locals=", mbl.locals);
2489   mbl.locals = SPTR_NULL;
2490   putsymlk("gbl.basevars=", mbl.basevars);
2491   mbl.basevars = SPTR_NULL;
2492   putsymlk("gbl.asgnlbls=", mbl.asgnlbls);
2493   mbl.asgnlbls = SPTR_NULL;
2494   putsymlk("gbl.autobj=", mbl.autobj);
2495   mbl.autobj = 0;
2496   putsymlk("gbl.typedescs=", mbl.typedescs);
2497   mbl.typedescs = SPTR_NULL;
2498   putline();
2499   putnsym("gbl.outersub", mbl.outersub);
2500   mbl.outersub = SPTR_NULL;
2501   putline();
2502   putnzint("gbl.vfrets", mbl.vfrets);
2503   mbl.vfrets = 0;
2504   putnzint("gbl.func_count", mbl.func_count);
2505   mbl.func_count = 0;
2506   putnzint("gbl.rutype=", mbl.rutype);
2507   mbl.rutype = (RUTYPE)0; // no 0 value defined
2508   putnzint("gbl.funcline=", mbl.funcline);
2509   mbl.funcline = 0;
2510   putnzint("gbl.threadprivate=", mbl.threadprivate);
2511   mbl.threadprivate = SPTR_NULL;
2512   putnzint("gbl.nofperror=", mbl.nofperror);
2513   mbl.nofperror = 0;
2514   putnzint("gbl.fperror_status=", mbl.fperror_status);
2515   mbl.fperror_status = 0;
2516   putnzint("gbl.entbih", mbl.entbih);
2517   mbl.entbih = 0;
2518   putnzint("gbl.lineno", mbl.lineno);
2519   mbl.lineno = 0;
2520   mbl.multiversion = 0;
2521   mbl.multi_func_count = 0;
2522   mbl.numversions = 0;
2523   putnzint("gbl.pgfi_avail", mbl.pgfi_avail);
2524   mbl.pgfi_avail = 0;
2525   putnzint("gbl.ec_avail", mbl.ec_avail);
2526   mbl.ec_avail = 0;
2527   putnzint("gbl.cuda_constructor", mbl.cuda_constructor);
2528   mbl.cuda_constructor = 0;
2529   putnzint("gbl.cudaemu", mbl.cudaemu);
2530   mbl.cudaemu = 0;
2531   putnzint("gbl.ftn_true", mbl.ftn_true);
2532   mbl.ftn_true = 0;
2533   putnzint("gbl.in_include", mbl.in_include);
2534   mbl.in_include = 0;
2535   putnzint("gbl.denorm", mbl.denorm);
2536   mbl.denorm = 0;
2537   putnzint("gbl.nowarn", mbl.nowarn);
2538   mbl.nowarn = 0;
2539   putnzint("gbl.internal", mbl.internal);
2540   mbl.internal = 0;
2541   putnzisz("gbl.caddr", mbl.caddr);
2542   mbl.caddr = 0;
2543   putnzisz("gbl.locaddr", mbl.locaddr);
2544   mbl.locaddr = 0;
2545   putnzisz("gbl.saddr", mbl.saddr);
2546   mbl.saddr = 0;
2547   putnzisz("gbl.bss_addr", mbl.bss_addr);
2548   mbl.bss_addr = 0;
2549   putnzisz("gbl.paddr", mbl.paddr);
2550   mbl.paddr = 0;
2551   putline();
2552   putnsym("gbl.prvt_sym_sz", (SPTR) mbl.prvt_sym_sz); // ???
2553   mbl.prvt_sym_sz = 0;
2554   putnsym("gbl.stk_sym_sz", (SPTR) mbl.stk_sym_sz); // ???
2555   mbl.stk_sym_sz = 0;
2556   putline();
2557   putnstring("gbl.src_file", mbl.src_file);
2558   mbl.src_file = NULL;
2559   putnstring("gbl.file_name", mbl.file_name);
2560   mbl.file_name = NULL;
2561   putnstring("gbl.curr_file", mbl.curr_file);
2562   mbl.curr_file = NULL;
2563   putnstring("gbl.module", mbl.module);
2564   mbl.module = NULL;
2565   mbl.srcfil = NULL;
2566   mbl.cppfil = NULL;
2567   mbl.dbgfil = NULL;
2568   mbl.ilmfil = NULL;
2569   mbl.objfil = NULL;
2570   mbl.asmfil = NULL;
2571   putline();
2572   ff = (int *)(&mbl);
2573   mblsize = sizeof(mbl) / sizeof(int);
2574   for (i = 0; i < mblsize; ++i) {
2575     if (ff[i] != 0) {
2576       fprintf(dfile, "*** gbl[%d] = %d 0x%x\n", i, ff[i], ff[i]);
2577     }
2578   }
2579 } /* dgbl */
2580 
2581 void
dflg(void)2582 dflg(void)
2583 {
2584   FLG mlg;
2585   int *ff;
2586   int i, mlgsize;
2587   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
2588   memcpy(&mlg, &flg, sizeof(flg));
2589   putnzint("flg.asmcode", mlg.asmcode);
2590   mlg.asmcode = 0;
2591   putnzint("flg.list", mlg.list);
2592   mlg.list = 0;
2593   putnzint("flg.object", mlg.object);
2594   mlg.object = 0;
2595   putnzint("flg.xref", mlg.xref);
2596   mlg.xref = 0;
2597   putnzint("flg.code", mlg.code);
2598   mlg.code = 0;
2599   putnzint("flg.include", mlg.include);
2600   mlg.include = 0;
2601   putnzint("flg.debug", mlg.debug);
2602   mlg.debug = 0;
2603   putnzint("flg.opt", mlg.opt);
2604   mlg.opt = 0;
2605   putnzint("flg.depchk", mlg.depchk);
2606   mlg.depchk = 0;
2607   putnzint("flg.depwarn", mlg.depwarn);
2608   mlg.depwarn = 0;
2609   putnzint("flg.dclchk", mlg.dclchk);
2610   mlg.dclchk = 0;
2611   putnzint("flg.locchk", mlg.locchk);
2612   mlg.locchk = 0;
2613   putnzint("flg.onetrip", mlg.onetrip);
2614   mlg.onetrip = 0;
2615   putnzint("flg.save", mlg.save);
2616   mlg.save = 0;
2617   putnzint("flg.inform", mlg.inform);
2618   mlg.inform = 0;
2619   putnzINT("flg.xoff", mlg.xoff);
2620   mlg.xoff = 0;
2621   putnzINT("flg.xon", mlg.xon);
2622   mlg.xon = 0;
2623   putnzint("flg.ucase", mlg.ucase);
2624   mlg.ucase = 0;
2625   putnzint("flg.dlines", mlg.dlines);
2626   mlg.dlines = 0;
2627   putnzint("flg.extend_source", mlg.extend_source);
2628   mlg.extend_source = 0;
2629   putnzint("flg.i4", mlg.i4);
2630   mlg.i4 = 0;
2631   putnzint("flg.line", mlg.line);
2632   mlg.line = 0;
2633   putnzint("flg.symbol", mlg.symbol);
2634   mlg.symbol = 0;
2635   putnzint("flg.profile", mlg.profile);
2636   mlg.profile = 0;
2637   putnzint("flg.standard", mlg.standard);
2638   mlg.profile = 0;
2639   putnzint("flg.dalign", mlg.dalign);
2640   mlg.dalign = 0;
2641   putnzint("flg.astype", mlg.astype);
2642   mlg.astype = 0;
2643   putnzint("flg.recursive", mlg.recursive);
2644   mlg.recursive = 0;
2645   putnzint("flg.ieee", mlg.ieee);
2646   mlg.ieee = 0;
2647   putnzint("flg.inliner", mlg.inliner);
2648   mlg.inliner = 0;
2649   putnzint("flg.autoinline", mlg.autoinline);
2650   mlg.autoinline = 0;
2651   putnzint("flg.vect", mlg.vect);
2652   mlg.vect = 0;
2653   putnzint("flg.endian", mlg.endian);
2654   mlg.endian = 0;
2655   putnzint("flg.terse", mlg.terse);
2656   mlg.terse = 0;
2657   putnzint("flg.dollar", mlg.dollar);
2658   mlg.dollar = 0;
2659   putnzint("flg.quad", mlg.quad);
2660   mlg.quad = 0;
2661   putnzint("flg.anno", mlg.anno);
2662   mlg.anno = 0;
2663   putnzint("flg.qa", mlg.qa);
2664   mlg.qa = 0;
2665   putnzint("flg.es", mlg.es);
2666   mlg.es = 0;
2667   putnzint("flg.p", mlg.p);
2668   mlg.p = 0;
2669   putnzint("flg.smp", mlg.smp);
2670   mlg.smp = 0;
2671   putnzint("flg.errorlimit", mlg.errorlimit);
2672   mlg.errorlimit = 0;
2673   putnzint("flg.trans_inv", mlg.trans_inv);
2674   mlg.trans_inv = 0;
2675   putnzint("flg.tpcount", mlg.tpcount);
2676   mlg.tpcount = 0;
2677   if (mlg.stdinc == (char *)0) {
2678     putint("flg.stdinc", 0);
2679     mlg.stdinc = NULL;
2680   } else if (mlg.stdinc == (char *)1) {
2681     putint("flg.stdinc", 1);
2682     mlg.stdinc = NULL;
2683   } else {
2684     putline();
2685     putstring("flg.stdinc", mlg.stdinc);
2686     mlg.stdinc = NULL;
2687   }
2688   putline();
2689   putdefarray("flg.def", mlg.def);
2690   mlg.def = NULL;
2691   putstringarray("flg.idir", mlg.idir);
2692   mlg.idir = NULL;
2693   putline();
2694   putintarray("flg.tpvalue", mlg.tpvalue, sizeof(mlg.tpvalue) / sizeof(int));
2695   putintarray("flg.dbg", mlg.dbg, sizeof(mlg.dbg) / sizeof(int));
2696   putintarray("flg.x", mlg.x, sizeof(mlg.x) / sizeof(int));
2697   putline();
2698   ff = (int *)(&mlg);
2699   mlgsize = sizeof(mlg) / sizeof(int);
2700   for (i = 0; i < mlgsize; ++i) {
2701     if (ff[i] != 0) {
2702       fprintf(dfile, "*** flg[%d] = %d %x\n", i, ff[i], ff[i]);
2703     }
2704   }
2705 } /* dflg */
2706 
2707 static bool
simpledtype(DTYPE dtype)2708 simpledtype(DTYPE dtype)
2709 {
2710   if (dtype < DT_NONE || ((int)dtype) >= stb.dt.stg_avail)
2711     return false;
2712   if (DTY(dtype) < TY_NONE || DTY(dtype) > TY_MAX)
2713     return false;
2714   if (dlen(DTY(dtype)) == 1)
2715     return true;
2716   if (DTY(dtype) == TY_PTR)
2717     return true;
2718   return false;
2719 } /* simpledtype */
2720 
2721 static int
putenumlist(int member,int len)2722 putenumlist(int member, int len)
2723 {
2724   int r = 0;
2725   if (len < 0)
2726     return 0;
2727   if (SYMLKG(member) > NOSYM) {
2728     r += putenumlist(SYMLKG(member), len);
2729     r += appendstring1(",");
2730   }
2731   if (r >= len)
2732     return r;
2733   r += appendsym1(member);
2734   return r;
2735 } /* putenumlist */
2736 
2737 int
putdty(TY_KIND dty)2738 putdty(TY_KIND dty)
2739 {
2740   int r;
2741   switch (dty) {
2742   case TY_NONE:
2743     r = appendstring1("none");
2744     break;
2745   case TY_WORD:
2746     r = appendstring1("word");
2747     break;
2748   case TY_DWORD:
2749     r = appendstring1("dword");
2750     break;
2751   case TY_HOLL:
2752     r = appendstring1("hollerith");
2753     break;
2754   case TY_BINT:
2755     r = appendstring1("int*1");
2756     break;
2757   case TY_UBINT:
2758     r = appendstring1("uint*1");
2759     break;
2760   case TY_SINT:
2761     r = appendstring1("short int");
2762     break;
2763   case TY_USINT:
2764     r = appendstring1("unsigned short");
2765     break;
2766   case TY_INT:
2767     r = appendstring1("int");
2768     break;
2769   case TY_UINT:
2770     r = appendstring1("unsigned int");
2771     break;
2772   case TY_INT8:
2773     r = appendstring1("int*8");
2774     break;
2775   case TY_UINT8:
2776     r = appendstring1("unsigned int*8");
2777     break;
2778   case TY_INT128:
2779     r = appendstring1("int128");
2780     break;
2781   case TY_UINT128:
2782     r = appendstring1("uint128");
2783     break;
2784   case TY_128:
2785     r = appendstring1("ty128");
2786     break;
2787   case TY_256:
2788     r = appendstring1("ty256");
2789     break;
2790   case TY_512:
2791     r = appendstring1("ty512");
2792     break;
2793   case TY_REAL:
2794     r = appendstring1("real");
2795     break;
2796   case TY_FLOAT128:
2797     r = appendstring1("float128");
2798     break;
2799   case TY_DBLE:
2800     r = appendstring1("double");
2801     break;
2802   case TY_QUAD:
2803     r = appendstring1("quad");
2804     break;
2805   case TY_CMPLX:
2806     r = appendstring1("complex");
2807     break;
2808   case TY_DCMPLX:
2809     r = appendstring1("double complex");
2810     break;
2811   case TY_CMPLX128:
2812     r = appendstring1("cmplx128");
2813     break;
2814   case TY_BLOG:
2815     r = appendstring1("byte logical");
2816     break;
2817   case TY_SLOG:
2818     r = appendstring1("short logical");
2819     break;
2820   case TY_LOG:
2821     r = appendstring1("logical");
2822     break;
2823   case TY_LOG8:
2824     r = appendstring1("logical*8");
2825     break;
2826   case TY_CHAR:
2827     r = appendstring1("character");
2828     break;
2829   case TY_NCHAR:
2830     r = appendstring1("ncharacter");
2831     break;
2832   case TY_PTR:
2833     r = appendstring1("pointer");
2834     break;
2835   case TY_ARRAY:
2836     r = appendstring1("array");
2837     break;
2838   case TY_STRUCT:
2839     r = appendstring1("struct");
2840     break;
2841   case TY_UNION:
2842     r = appendstring1("union");
2843     break;
2844   case TY_NUMERIC:
2845     r = appendstring1("numeric");
2846     break;
2847   case TY_ANY:
2848     r = appendstring1("any");
2849     break;
2850   case TY_PROC:
2851     r = appendstring1("proc");
2852     break;
2853   case TY_VECT:
2854     r = appendstring1("vect");
2855     break;
2856   case TY_PFUNC:
2857     r = appendstring1("prototype func");
2858     break;
2859   case TY_PARAM:
2860     r = appendstring1("parameter");
2861     break;
2862   default:
2863     // Don't use a case label for TY_FLOAT, because it might alias TY_REAL.
2864     if (dty == TY_FLOAT) {
2865       r = appendstring1("float");
2866       break;
2867     }
2868     r = appendstring1("dty:");
2869     r += appendint1(dty);
2870     r = 0;
2871     break;
2872   }
2873   return r;
2874 } /* putdty */
2875 
2876 void
_putdtype(DTYPE dtype,int structdepth)2877 _putdtype(DTYPE dtype, int structdepth)
2878 {
2879   TY_KIND dty;
2880   ADSC *ad;
2881   int numdim;
2882   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
2883   if (dtype >= stb.dt.stg_avail) {
2884     fprintf(dfile, "\ndtype %d out of %d\n", dtype, stb.dt.stg_avail - 1);
2885     return;
2886   }
2887   dty = DTY(dtype);
2888   switch (dty) {
2889   default:
2890     putdty(dty);
2891     break;
2892   case TY_CHAR:
2893     appendstring1("char*");
2894     appendint1(DTyCharLength(dtype));
2895     break;
2896   case TY_ARRAY:
2897     _putdtype(DTySeqTyElement(dtype), structdepth);
2898     ad = AD_DPTR(dtype);
2899     numdim = AD_NUMDIM(ad);
2900     appendstring1("(");
2901     if (numdim >= 1 && numdim <= 7) {
2902       int i;
2903       for (i = 0; i < numdim; ++i) {
2904         if (i)
2905           appendstring1(",");
2906         appendsym1(AD_LWBD(ad, i));
2907         appendstring1(":");
2908         appendsym1(AD_UPBD(ad, i));
2909       }
2910     }
2911     appendstring1(")");
2912     break;
2913   case TY_PTR:
2914     if (simpledtype(DTySeqTyElement(dtype))) {
2915       appendstring1("*");
2916       _putdtype(DTySeqTyElement(dtype), structdepth);
2917     } else {
2918       appendstring1("*(");
2919       _putdtype(DTySeqTyElement(dtype), structdepth);
2920       appendstring1(")");
2921     }
2922     break;
2923   case TY_PARAM:
2924     appendstring1("(");
2925     _putdtype(DTyArgType(dtype), structdepth);
2926     if (DTyArgSym(dtype)) {
2927       appendstring1(" ");
2928       appendsym1(DTyArgSym(dtype));
2929     }
2930     if (DTyArgNext(dtype)) {
2931       appendstring1(", next=");
2932       appendint1(DTyArgNext(dtype));
2933     }
2934     appendstring1(")");
2935     break;
2936   case TY_STRUCT:
2937   case TY_UNION:
2938     if (dty == TY_STRUCT)
2939       appendstring1("struct");
2940     if (dty == TY_UNION)
2941       appendstring1("union");
2942     DTySet(dtype, -dty);
2943     if (DTyAlgTyTag(dtype)) {
2944       appendstring1(" ");
2945       appendsym1(DTyAlgTyTag(dtype));
2946     }
2947     if (DTyAlgTyTag(dtype) == SPTR_NULL || structdepth == 0) {
2948       appendstring1("{");
2949       if (DTyAlgTyMember(dtype)) {
2950         int member;
2951         for (member = DTyAlgTyMember(dtype); member > NOSYM && member < stb.stg_avail;) {
2952           _putdtype(DTYPEG(member), structdepth + 1);
2953           appendstring1(" ");
2954           appendsym1(member);
2955           member = SYMLKG(member);
2956           appendstring1(";");
2957         }
2958       }
2959       appendstring1("}");
2960     }
2961     DTySet(dtype, dty);
2962     break;
2963   case -TY_STRUCT:
2964   case -TY_UNION:
2965     if (dty == -TY_STRUCT)
2966       appendstring1("struct");
2967     if (dty == -TY_UNION)
2968       appendstring1("union");
2969     if (DTyAlgTyTagNeg(dtype)) {
2970       appendstring1(" ");
2971       appendsym1(DTyAlgTyTagNeg(dtype));
2972     } else {
2973       appendstring1(" ");
2974       appendint1(dtype);
2975     }
2976     break;
2977   }
2978 
2979 } /* _putdtype */
2980 
2981 void
putdtype(DTYPE dtype)2982 putdtype(DTYPE dtype)
2983 {
2984   _putdtype(dtype, 0);
2985 } /* putdtype */
2986 
2987 static int
putdtypex(DTYPE dtype,int len)2988 putdtypex(DTYPE dtype, int len)
2989 {
2990   TY_KIND dty;
2991   int r = 0;
2992   ADSC *ad;
2993   int numdim;
2994   if (len < 0)
2995     return 0;
2996   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
2997   if (dtype >= stb.dt.stg_avail) {
2998     fprintf(dfile, "\ndtype %d out of %d\n", dtype, stb.dt.stg_avail - 1);
2999     return 0;
3000   }
3001   dty = DTY(dtype);
3002   switch (dty) {
3003   default:
3004     r += putdty(dty);
3005     break;
3006   case TY_CHAR:
3007     r += appendstring1("char*");
3008     r += appendint1(DTyCharLength(dtype));
3009     break;
3010   case TY_ARRAY:
3011     r += putdtypex(DTySeqTyElement(dtype), len - r);
3012     ad = AD_DPTR(dtype);
3013     numdim = AD_NUMDIM(ad);
3014     r += appendstring1("(");
3015     if (numdim >= 1 && numdim <= 7) {
3016       int i;
3017       for (i = 0; i < numdim && r < len; ++i) {
3018         if (i)
3019           r += appendstring1(",");
3020         r += appendsym1(AD_LWBD(ad, i));
3021         r += appendstring1(":");
3022         r += appendsym1(AD_UPBD(ad, i));
3023       }
3024     }
3025     r += appendstring1(")");
3026     break;
3027   case TY_PTR:
3028     if (simpledtype(DTySeqTyElement(dtype))) {
3029       r += appendstring1("*");
3030       r += putdtypex(DTySeqTyElement(dtype), len - 4);
3031     } else {
3032       r += appendstring1("*(");
3033       r += putdtypex(DTySeqTyElement(dtype), len - 4);
3034       r += appendstring1(")");
3035     }
3036     break;
3037   case TY_PARAM:
3038     r += appendstring1("(");
3039     r += putdtypex(DTyArgType(dtype), len - 4);
3040     if (DTyArgSym(dtype)) {
3041       r += appendstring1(" ");
3042       r += appendsym1(DTyArgSym(dtype));
3043     }
3044     if (DTyArgNext(dtype)) {
3045       r += appendstring1(", next=");
3046       r += appendint1(DTyArgNext(dtype));
3047     }
3048     r += appendstring1(")");
3049     break;
3050   case TY_STRUCT:
3051   case TY_UNION:
3052     if (dty == TY_STRUCT)
3053       r += appendstring1("struct");
3054     if (dty == TY_UNION)
3055       r += appendstring1("union");
3056     DTySet(dtype, -dty);
3057     if (DTyAlgTyTag(dtype)) {
3058       r += appendstring1(" ");
3059       r += appendsym1(DTyAlgTyTag(dtype));
3060     }
3061     r += appendstring1("{");
3062     if (DTyAlgTyMember(dtype)) {
3063       int member;
3064       for (member = DTyAlgTyMember(dtype);
3065            member > NOSYM && member < stb.stg_avail && r < len;) {
3066         r += putdtypex(DTYPEG(member), len - 4);
3067         r += appendstring1(" ");
3068         r += appendsym1(member);
3069         member = SYMLKG(member);
3070         r += appendstring1(";");
3071       }
3072     }
3073     r += appendstring1("}");
3074     DTySet(dtype, dty);
3075     break;
3076   case -TY_STRUCT:
3077   case -TY_UNION:
3078     if (dty == -TY_STRUCT)
3079       r += appendstring1("struct");
3080     if (dty == -TY_UNION)
3081       r += appendstring1("union");
3082     if (DTyAlgTyTagNeg(dtype)) {
3083       r += appendstring1(" ");
3084       r += appendsym1(DTyAlgTyTagNeg(dtype));
3085     } else {
3086       r += appendstring1(" ");
3087       r += appendint1(dtype);
3088     }
3089     break;
3090   }
3091   return r;
3092 } /* putdtypex */
3093 
3094 void
dumpdtype(DTYPE dtype)3095 dumpdtype(DTYPE dtype)
3096 {
3097   ADSC *ad;
3098   int numdim;
3099   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
3100   fprintf(dfile, "\n");
3101   putint("dtype", dtype);
3102   if (dtype <= 0 || dtype >= stb.dt.stg_avail) {
3103     fprintf(dfile, "\ndtype %d out of %d\n", dtype, stb.dt.stg_avail - 1);
3104     return;
3105   }
3106   appendstring1(" ");
3107   putdty(DTY(dtype));
3108   switch (DTY(dtype)) {
3109   case TY_ARRAY:
3110     putint("dtype", DTySeqTyElement(dtype));
3111     ad = AD_DPTR(dtype);
3112     numdim = AD_NUMDIM(ad);
3113     putint("numdim", numdim);
3114     putnzint("scheck", AD_SCHECK(ad));
3115     putnsym("zbase", (SPTR) AD_ZBASE(ad)); // ???
3116     putnsym("numelm", AD_NUMELM(ad));
3117     putnsym("sdsc", AD_SDSC(ad));
3118     if (numdim >= 1 && numdim <= 7) {
3119       int i;
3120       for (i = 0; i < numdim; ++i) {
3121         putline();
3122         putint("dim", i);
3123         putint("mlpyr", AD_MLPYR(ad, i));
3124         putint("lwbd", AD_LWBD(ad, i));
3125         putint("upbd", AD_UPBD(ad, i));
3126       }
3127     }
3128     break;
3129   case TY_CHAR:
3130     putint("len", DTyCharLength(dtype));
3131     break;
3132   case TY_PARAM:
3133     putint("dtype", DTyArgType(dtype));
3134     putnsym("sptr", DTyArgSym(dtype));
3135     putint("next", DTyArgNext(dtype));
3136     break;
3137   case TY_PTR:
3138     putint("dtype", DTySeqTyElement(dtype));
3139     break;
3140   case TY_STRUCT:
3141   case TY_UNION:
3142     putsym("member", DTyAlgTyMember(dtype));
3143     putint("size", DTyAlgTySize(dtype));
3144     putnsym("tag", DTyAlgTyTag(dtype));
3145     putint("align", DTyAlgTyAlign(dtype));
3146     break;
3147   case TY_VECT:
3148     fprintf(dfile, "<%lu x ", DTyVecLength(dtype));
3149     putdtype(DTySeqTyElement(dtype));
3150     fputc('>', dfile);
3151   default:
3152     /* simple datatypes, just the one line of info */
3153     putline();
3154     return;
3155   }
3156   putline();
3157   putdtype(dtype);
3158   putline();
3159 } /* dumpdtype */
3160 
3161 void
ddtype(DTYPE dtype)3162 ddtype(DTYPE dtype)
3163 {
3164   dumpdtype(dtype);
3165 } /* ddtype */
3166 
3167 void
dumpdtypes(void)3168 dumpdtypes(void)
3169 {
3170   DTYPE dtype;
3171   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
3172   fprintf(dfile, "\n********** DATATYPE TABLE **********\n");
3173   for (dtype = (DTYPE)1; ((int)dtype) < stb.dt.stg_avail; dtype += dlen(DTY(dtype))) {
3174     dumpdtype(dtype);
3175   }
3176   fprintf(dfile, "\n");
3177 
3178 } /* dumpdtypes */
3179 
3180 void
dumpnewdtypes(int olddtavail)3181 dumpnewdtypes(int olddtavail)
3182 {
3183   DTYPE dtype;
3184   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
3185   fprintf(dfile, "\n********** DATATYPE TABLE **********\n");
3186   for (dtype = (DTYPE)olddtavail; ((int)dtype) < stb.dt.stg_avail; dtype += dlen(DTY(dtype))) {
3187     dumpdtype(dtype);
3188   }
3189   fprintf(dfile, "\n");
3190 } /* dumpnewdtypes */
3191 
3192 void
ddtypes(void)3193 ddtypes(void)
3194 {
3195   dumpdtypes();
3196 } /* ddtypes */
3197 
3198 static char prefix[1500];
3199 
3200 static char *
smsz(int m)3201 smsz(int m)
3202 {
3203   const char *msz = NULL;
3204   static char B[15];
3205   switch (m) {
3206   case MSZ_SBYTE:
3207     msz = "sb";
3208     break;
3209   case MSZ_SHWORD:
3210     msz = "sh";
3211     break;
3212   case MSZ_WORD:
3213     msz = "wd";
3214     break;
3215   case MSZ_SLWORD:
3216     msz = "sl";
3217     break;
3218   case MSZ_BYTE:
3219     msz = "bt";
3220     break;
3221   case MSZ_UHWORD:
3222     msz = "uh";
3223     break;
3224   case MSZ_PTR:
3225     msz = "pt";
3226     break;
3227   case MSZ_ULWORD:
3228     msz = "ul";
3229     break;
3230   case MSZ_F4:
3231     msz = "fl";
3232     break;
3233   case MSZ_F8:
3234     msz = "db";
3235     break;
3236 #ifdef MSZ_I8
3237   case MSZ_I8:
3238     msz = "i8";
3239     break;
3240 #endif
3241 #ifdef MSZ_F10
3242   case MSZ_F10:
3243     msz = "ep";
3244     break;
3245 #endif
3246   default:
3247     break;
3248   }
3249   if (msz ) {
3250     snprintf(B, 15, "%s", msz);
3251   } else {
3252     snprintf(B, 15, "%d", m);
3253   }
3254   return B;
3255 } /* smsz */
3256 
3257 char* scond(int);
3258 
3259 static void
putstc(ILI_OP opc,int opnum,int opnd)3260 putstc(ILI_OP opc, int opnum, int opnd)
3261 {
3262   switch (ilstckind(opc, opnum)) {
3263   case 1:
3264     putstring("cond", scond(opnd));
3265     break;
3266   case 2:
3267     putstring("msz", smsz(opnd));
3268     break;
3269   default:
3270     putint("stc", opnd);
3271     break;
3272   }
3273 } /* putstc */
3274 
3275 #define OT_UNARY 1
3276 #define OT_BINARY 2
3277 #define OT_LEAF 3
3278 
3279 static int
optype(int opc)3280 optype(int opc)
3281 {
3282   switch (opc) {
3283   case IL_INEG:
3284   case IL_UINEG:
3285   case IL_KNEG:
3286   case IL_UKNEG:
3287   case IL_SCMPLXNEG:
3288   case IL_DCMPLXNEG:
3289   case IL_FNEG:
3290   case IL_DNEG:
3291     return OT_UNARY;
3292 
3293   case IL_LD:
3294   case IL_LDKR:
3295   case IL_LDSP:
3296   case IL_LDDP:
3297   case IL_LDA:
3298   case IL_ICON:
3299   case IL_KCON:
3300   case IL_DCON:
3301   case IL_FCON:
3302   case IL_ACON:
3303     return OT_LEAF;
3304   }
3305   return OT_BINARY;
3306 } /* optype */
3307 
3308 static void _printili(int i);
3309 
3310 static void
pnme(int n,int ili)3311 pnme(int n, int ili)
3312 {
3313   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
3314   if (n < 0 || n >= nmeb.stg_avail) {
3315     fprintf(dfile, "nme:%d/%d", n, nmeb.stg_avail);
3316     return;
3317   }
3318   switch (NME_TYPE(n)) {
3319   case NT_VAR:
3320     appendstring1(printname(NME_SYM(n)));
3321     break;
3322   case NT_MEM:
3323     if (NME_NM(n)) {
3324       if (NME_TYPE(NME_NM(n)) == NT_IND)
3325         appendstring1("(");
3326       pnme(NME_NM(n), ili);
3327       if (NME_TYPE(NME_NM(n)) == NT_IND)
3328         appendstring1(")");
3329     } else {
3330       appendstring1("Unknown");
3331     }
3332     if (NME_SYM(n) == 0) {
3333       appendstring1(".real");
3334     } else if (NME_SYM(n) == 1) {
3335       appendstring1(".imag");
3336     } else {
3337       appendstring1(".");
3338       appendstring1(printname(NME_SYM(n)));
3339     }
3340     break;
3341   case NT_ARR:
3342     if (NME_TYPE(NME_NM(n)) == NT_IND)
3343       appendstring1("(");
3344     pnme(NME_NM(n), ili);
3345     if (NME_TYPE(NME_NM(n)) == NT_IND)
3346       appendstring1(")");
3347     if (NME_SYM(n) == NME_NULL) {
3348       appendstring1("[]");
3349     } else if (NME_SYM(n) == 0) {
3350       appendstring1("[");
3351       appendint1(NME_CNST(n));
3352       appendstring1("]");
3353     } else {
3354       appendstring1("[?]");
3355     }
3356     break;
3357   case NT_IND:
3358     appendstring1("*(");
3359     pnme(NME_NM(n), ili);
3360     if (NME_SYM(n) == NME_NULL) {
3361     } else if (NME_SYM(n) == 0) {
3362       if (NME_CNST(n)) {
3363         appendstring1("+");
3364         appendint1(NME_CNST(n));
3365       }
3366     } else {
3367       appendstring1("<");
3368       _printili(ili);
3369       appendstring1(">");
3370     }
3371     appendstring1(")");
3372     break;
3373   case NT_SAFE:
3374     appendstring1("safe(");
3375     pnme(NME_NM(n), ili);
3376     appendstring1(")");
3377     break;
3378   case NT_UNK:
3379     if (NME_SYM(n) == 0) {
3380       appendstring1("unknown");
3381     } else if (NME_SYM(n) == 1) {
3382       appendstring1("volatile");
3383     } else {
3384       appendstring1("unknown:");
3385       appendint1(NME_SYM(n));
3386     }
3387     break;
3388   default:
3389     appendstring1("nme(");
3390     appendint1(n);
3391     appendstring1(":");
3392     appendint1(NME_TYPE(n));
3393     appendstring1(")");
3394     break;
3395   }
3396 } /* pnme */
3397 
3398 static void
appendtarget(int sptr)3399 appendtarget(int sptr)
3400 {
3401   if (sptr > 0 && sptr < stb.stg_avail) {
3402     appendstring1("[bih");
3403     appendint1(ILIBLKG(sptr));
3404     appendstring1("]");
3405   }
3406 } /* appendtarget */
3407 
3408 static void
_put_device_type(int d)3409 _put_device_type(int d)
3410 {
3411   static const char *names[] = {"*",       "host",   "nvidia", "?",
3412                           "?", "opencl", NULL};
3413   int dd = 1, i, any = 0;
3414   if (!d)
3415     return;
3416   appendstring1(" device_type(");
3417   for (i = 0; names[i]; ++i) {
3418     if (d & dd) {
3419       if (any)
3420         appendstring1(",");
3421       appendstring1(names[i]);
3422       ++any;
3423     }
3424     dd <<= 1;
3425   }
3426   if (!any)
3427     appendhex1(d);
3428   appendstring1(")");
3429 } /* _put_device_type */
3430 
3431 static void
_printili(int i)3432 _printili(int i)
3433 {
3434   int n, k, j, noprs;
3435   ILI_OP opc;
3436   int o, typ;
3437   const char *opval;
3438   static const char *ccval[] = {"??",  "==",  "!=", "<",   ">=",  "<=", ">",
3439                           "!==", "!!=", "!<", "!>=", "!<=", "!>"};
3440   static const char *ccvalzero[] = {"??",   "==0",  "!=0",  "<0",   ">=0",
3441                               "<=0",  ">0",   "!==0", "!!=0", "!<0",
3442                               "!>=0", "!<=0", "!>0"};
3443 #define NONE 0
3444 #define UNOP 1
3445 #define postUNOP 2
3446 #define BINOP 3
3447 #define INTRINSIC 4
3448 #define MVREG 5
3449 #define DFREG 6
3450 #define PSCOMM 7
3451 #define ENC_N_OP 8
3452 
3453   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
3454   if (g_dout && (i <= 0 || i >= ilib.stg_size)) {
3455     fprintf(dfile, "ili %d out of %d", i, ilib.stg_size - 1);
3456     return;
3457   }
3458   opc = ILI_OPC(i);
3459   if (opc <= 0 || opc >= N_ILI) {
3460     appendstring1("illegalopc(");
3461     appendint1(opc);
3462     appendstring1(")");
3463     return;
3464   }
3465   noprs = ilis[opc].oprs;
3466   typ = NONE;
3467 
3468   switch (opc) {
3469   case IL_IADD:
3470   case IL_KADD:
3471   case IL_UKADD:
3472   case IL_FADD:
3473   case IL_DADD:
3474   case IL_UIADD:
3475   case IL_AADD:
3476     opval = "+";
3477     typ = BINOP;
3478     break;
3479   case IL_ISUB:
3480   case IL_KSUB:
3481   case IL_UKSUB:
3482   case IL_FSUB:
3483   case IL_DSUB:
3484   case IL_UISUB:
3485   case IL_ASUB:
3486     opval = "-";
3487     typ = BINOP;
3488     break;
3489   case IL_IMUL:
3490   case IL_KMUL:
3491   case IL_UKMUL:
3492   case IL_FMUL:
3493   case IL_DMUL:
3494   case IL_UIMUL:
3495     opval = "*";
3496     typ = BINOP;
3497     break;
3498   case IL_DDIV:
3499   case IL_KDIV:
3500   case IL_UKDIV:
3501   case IL_FDIV:
3502   case IL_IDIV:
3503     opval = "/";
3504     typ = BINOP;
3505     break;
3506   case IL_KAND:
3507   case IL_AND:
3508     opval = "&";
3509     typ = BINOP;
3510     break;
3511   case IL_KOR:
3512   case IL_OR:
3513     opval = "|";
3514     typ = BINOP;
3515     break;
3516   case IL_KXOR:
3517   case IL_XOR:
3518     opval = "^";
3519     typ = BINOP;
3520     break;
3521   case IL_KMOD:
3522   case IL_KUMOD:
3523   case IL_MOD:
3524   case IL_UIMOD:
3525     opval = "%";
3526     typ = BINOP;
3527     break;
3528   case IL_LSHIFT:
3529   case IL_ULSHIFT:
3530     opval = "<<";
3531     typ = BINOP;
3532     break;
3533   case IL_RSHIFT:
3534   case IL_URSHIFT:
3535     opval = ">>";
3536     typ = BINOP;
3537     break;
3538   case IL_ARSHIFT:
3539   case IL_KARSHIFT:
3540     opval = "a>>";
3541     typ = BINOP;
3542     break;
3543   case IL_KCMP:
3544   case IL_UKCMP:
3545   case IL_ICMP:
3546   case IL_FCMP:
3547   case IL_SCMPLXCMP:
3548   case IL_DCMPLXCMP:
3549   case IL_DCMP:
3550   case IL_ACMP:
3551   case IL_UICMP:
3552     opval = ccval[ILI_OPND(i, 3)];
3553     typ = BINOP;
3554     break;
3555 
3556   case IL_INEG:
3557   case IL_KNEG:
3558   case IL_UKNEG:
3559   case IL_DNEG:
3560   case IL_UINEG:
3561   case IL_FNEG:
3562   case IL_SCMPLXNEG:
3563   case IL_DCMPLXNEG:
3564     opval = "-";
3565     typ = UNOP;
3566     break;
3567   case IL_NOT:
3568   case IL_UNOT:
3569   case IL_KNOT:
3570   case IL_UKNOT:
3571     opval = "!";
3572     typ = UNOP;
3573     break;
3574   case IL_ICMPZ:
3575   case IL_KCMPZ:
3576   case IL_UKCMPZ:
3577   case IL_FCMPZ:
3578   case IL_DCMPZ:
3579   case IL_ACMPZ:
3580   case IL_UICMPZ:
3581     opval = ccvalzero[ILI_OPND(i, 2)];
3582     typ = postUNOP;
3583     break;
3584 
3585   case IL_FMAX:
3586   case IL_DMAX:
3587   case IL_KMAX:
3588   case IL_UKMAX:
3589   case IL_IMAX:
3590     n = 2;
3591     opval = "max";
3592     typ = INTRINSIC;
3593     break;
3594   case IL_FMIN:
3595   case IL_DMIN:
3596   case IL_KMIN:
3597   case IL_UKMIN:
3598   case IL_IMIN:
3599     n = 2;
3600     opval = "min";
3601     typ = INTRINSIC;
3602     break;
3603   case IL_DBLE:
3604     n = 1;
3605     opval = "dble";
3606     typ = INTRINSIC;
3607     break;
3608   case IL_SNGL:
3609     n = 1;
3610     opval = "sngl";
3611     typ = INTRINSIC;
3612     break;
3613 
3614   case IL_FIX:
3615   case IL_FIXK:
3616   case IL_FIXUK:
3617     n = 1;
3618     opval = "fix";
3619     typ = INTRINSIC;
3620     break;
3621   case IL_DFIXK:
3622   case IL_DFIXUK:
3623     n = 1;
3624     opval = "dfix";
3625     typ = INTRINSIC;
3626     break;
3627   case IL_UFIX:
3628     n = 1;
3629     opval = "fix";
3630     typ = INTRINSIC;
3631     break;
3632   case IL_DFIX:
3633   case IL_DFIXU:
3634     n = 1;
3635     opval = "dfix";
3636     typ = INTRINSIC;
3637     break;
3638   case IL_FLOAT:
3639   case IL_FLOATU:
3640     n = 1;
3641     opval = "float";
3642     typ = INTRINSIC;
3643     break;
3644   case IL_DFLOAT:
3645   case IL_DFLOATU:
3646     n = 1;
3647     opval = "dfloat";
3648     typ = INTRINSIC;
3649     break;
3650   case IL_DNEWT:
3651   case IL_FNEWT:
3652     n = 1;
3653     opval = "recip";
3654     typ = INTRINSIC;
3655     break;
3656   case IL_DABS:
3657     n = 1;
3658     opval = "abs";
3659     typ = INTRINSIC;
3660     break;
3661   case IL_FABS:
3662     n = 1;
3663     opval = "abs";
3664     typ = INTRINSIC;
3665     break;
3666   case IL_KABS:
3667     n = 1;
3668     opval = "abs";
3669     typ = INTRINSIC;
3670     break;
3671   case IL_IABS:
3672     n = 1;
3673     opval = "abs";
3674     typ = INTRINSIC;
3675     break;
3676   case IL_FSQRT:
3677     n = 1;
3678     opval = "sqrt";
3679     typ = INTRINSIC;
3680     break;
3681   case IL_DSQRT:
3682     n = 1;
3683     opval = "dsqrt";
3684     typ = INTRINSIC;
3685     break;
3686 
3687   case IL_KCJMP:
3688   case IL_UKCJMP:
3689   case IL_ICJMP:
3690   case IL_FCJMP:
3691   case IL_DCJMP:
3692   case IL_ACJMP:
3693   case IL_UICJMP:
3694     _printili(ILI_OPND(i, 1));
3695     appendstring1(" ");
3696     appendstring1(ccval[ILI_OPND(i, 3)]);
3697     appendstring1(" ");
3698     _printili(ILI_OPND(i, 2));
3699     appendstring1(" goto ");
3700     if (full) {
3701       appendint1(ILI_OPND(i, 4));
3702       appendstring1("=");
3703     }
3704     appendsym1(ILI_OPND(i, 4));
3705     appendtarget(ILI_OPND(i, 4));
3706     break;
3707   case IL_KCJMPZ:
3708   case IL_UKCJMPZ:
3709   case IL_ICJMPZ:
3710   case IL_FCJMPZ:
3711   case IL_DCJMPZ:
3712   case IL_ACJMPZ:
3713   case IL_UICJMPZ:
3714     _printili(ILI_OPND(i, 1));
3715     appendstring1(" ");
3716     appendstring1(ccval[ILI_OPND(i, 2)]);
3717     appendstring1(" 0 ");
3718     appendstring1(" goto ");
3719     if (full) {
3720       appendint1(ILI_OPND(i, 3));
3721       appendstring1("=");
3722     }
3723     appendsym1(ILI_OPND(i, 3));
3724     appendtarget(ILI_OPND(i, 3));
3725     break;
3726 
3727   case IL_JMP:
3728     appendstring1("goto ");
3729     if (full) {
3730       appendint1(ILI_OPND(i, 1));
3731       appendstring1("=");
3732     }
3733     appendsym1(ILI_OPND(i, 1));
3734     appendtarget(ILI_OPND(i, 1));
3735     break;
3736 
3737   case IL_DFRKR:
3738   case IL_DFRIR:
3739   case IL_DFRSP:
3740   case IL_DFRDP:
3741   case IL_DFRCS:
3742   case IL_DFRCD:
3743   case IL_DFRAR:
3744     _printili(ILI_OPND(i, 1));
3745     break;
3746 
3747   case IL_QJSR:
3748   case IL_JSR:
3749     appendstring1(printname(ILI_OPND(i, 1)));
3750     appendstring1("(");
3751     j = ILI_OPND(i, 2);
3752     k = 0;
3753     while (ILI_OPC(j) != 0) {
3754       if (k)
3755         appendstring1(", ");
3756       switch (ILI_OPC(j)) {
3757       case IL_DAKR:
3758       case IL_DAAR:
3759       case IL_DADP:
3760 #ifdef IL_DA128
3761       case IL_DA128:
3762 #endif
3763 #ifdef IL_DA256
3764       case IL_DA256:
3765 #endif
3766       case IL_DASP:
3767       case IL_DAIR:
3768         _printili(ILI_OPND(j, 1));
3769         j = ILI_OPND(j, 3);
3770         break;
3771       case IL_ARGKR:
3772       case IL_ARGIR:
3773       case IL_ARGSP:
3774       case IL_ARGDP:
3775       case IL_ARGAR:
3776         _printili(ILI_OPND(j, 1));
3777         j = ILI_OPND(j, 2);
3778         break;
3779 #ifdef IL_ARGRSRV
3780       case IL_ARGRSRV:
3781         appendstring1("rsrv(");
3782         appendint1(ILI_OPND(j, 1));
3783         appendstring1(")");
3784         j = ILI_OPND(j, 2);
3785         break;
3786 #endif
3787       default:
3788         goto done;
3789       }
3790       ++k;
3791     }
3792   done:
3793     appendstring1(")");
3794     break;
3795 
3796   case IL_MVKR:
3797     opval = "MVKR";
3798     appendstring1(opval);
3799     appendstring1("(");
3800     appendint1(KR_MSH(ILI_OPND(i, 2)));
3801     appendstring1(",");
3802     appendint1(KR_LSH(ILI_OPND(i, 2)));
3803     appendstring1(")");
3804     _printili(ILI_OPND(i, 1));
3805     break;
3806   case IL_MVIR:
3807     opval = "MVIR";
3808     typ = MVREG;
3809     break;
3810   case IL_MVSP:
3811     opval = "MVSP";
3812     typ = MVREG;
3813     break;
3814   case IL_MVDP:
3815     opval = "MVDP";
3816     typ = MVREG;
3817     break;
3818   case IL_MVAR:
3819     opval = "MVAR";
3820     typ = MVREG;
3821     break;
3822   case IL_KRDF:
3823     opval = "KRDF";
3824     appendstring1(opval);
3825     appendstring1("(");
3826     appendint1(KR_MSH(ILI_OPND(i, 1)));
3827     appendstring1(",");
3828     appendint1(KR_LSH(ILI_OPND(i, 1)));
3829     appendstring1(")");
3830     break;
3831   case IL_IRDF:
3832     opval = "IRDF";
3833     typ = DFREG;
3834     break;
3835   case IL_SPDF:
3836     opval = "SPDF";
3837     typ = DFREG;
3838     break;
3839   case IL_DPDF:
3840     opval = "DPDF";
3841     typ = DFREG;
3842     break;
3843   case IL_ARDF:
3844     opval = "ARDF";
3845     typ = DFREG;
3846     break;
3847   case IL_IAMV:
3848   case IL_AIMV:
3849   case IL_KAMV:
3850   case IL_AKMV:
3851     _printili(ILI_OPND(i, 1));
3852     break;
3853   case IL_KIMV:
3854     appendstring1("_K2I(");
3855     _printili(ILI_OPND(i, 1));
3856     appendstring1(")");
3857     break;
3858   case IL_IKMV:
3859     appendstring1("_I2K(");
3860     _printili(ILI_OPND(i, 1));
3861     appendstring1(")");
3862     break;
3863   case IL_UIKMV:
3864     appendstring1("_UI2K(");
3865     _printili(ILI_OPND(i, 1));
3866     appendstring1(")");
3867     break;
3868 
3869   case IL_CSE:
3870   case IL_CSEKR:
3871   case IL_CSEIR:
3872   case IL_CSESP:
3873   case IL_CSEDP:
3874   case IL_CSEAR:
3875   case IL_CSECS:
3876   case IL_CSECD:
3877 #ifdef LONG_DOUBLE_FLOAT128
3878   case IL_FLOAT128CSE:
3879 #endif
3880     appendstring1("#<");
3881     _printili(ILI_OPND(i, 1));
3882     appendstring1(">#");
3883     break;
3884   case IL_FREEKR:
3885     opval = "FREEKR";
3886     typ = PSCOMM;
3887     break;
3888   case IL_FREEDP:
3889     opval = "FREEDP";
3890     typ = PSCOMM;
3891     break;
3892   case IL_FREECS:
3893     opval = "FREECS";
3894     typ = PSCOMM;
3895     break;
3896   case IL_FREECD:
3897     opval = "FREECD";
3898     typ = PSCOMM;
3899     break;
3900   case IL_FREESP:
3901     opval = "FREESP";
3902     typ = PSCOMM;
3903     break;
3904   case IL_FREEAR:
3905     opval = "FREEAR";
3906     typ = PSCOMM;
3907     break;
3908   case IL_FREEIR:
3909     opval = "FREEIR";
3910     typ = PSCOMM;
3911     break;
3912 #ifdef LONG_DOUBLE_FLOAT128
3913   case IL_FLOAT128FREE:
3914     opval = "FLOAT128FREE";
3915     typ = PSCOMM;
3916     break;
3917 #endif
3918 
3919   case IL_KCON:
3920   case IL_ICON:
3921   case IL_FCON:
3922   case IL_DCON:
3923     appendstring1(printname(ILI_OPND(i, 1)));
3924     break;
3925 
3926   case IL_ACON:
3927     j = ILI_OPND(i, 1);
3928     appendstring1("&");
3929     if (ACONOFFG(j)) {
3930       appendstring1("(");
3931     }
3932     if (CONVAL1G(j)) {
3933       appendstring1(printname(CONVAL1G(j)));
3934       if (CONVAL1G(j) > NOSYM && CONVAL1G(j) < stb.stg_avail &&
3935           SCG(CONVAL1G(j)) == SC_PRIVATE)
3936         appendstring1("'");
3937     } else {
3938       appendint1(CONVAL1G(j));
3939     }
3940     if (ACONOFFG(j) > 0) {
3941       appendstring1("+");
3942       appendbigint(ACONOFFG(j));
3943       appendstring1(")");
3944     } else if (ACONOFFG(j) < 0) {
3945       appendstring1("-");
3946       appendbigint(-ACONOFFG(j));
3947       appendstring1(")");
3948     }
3949     break;
3950 
3951   case IL_LD:
3952   case IL_LDSP:
3953   case IL_LDDP:
3954   case IL_LDKR:
3955   case IL_LDA:
3956     _printnme(ILI_OPND(i, 2));
3957     if (DBGBIT(10, 4096)) {
3958       appendstring1("<*");
3959       _printili(ILI_OPND(i, 1));
3960       appendstring1("*>");
3961     }
3962     break;
3963 
3964   case IL_STKR:
3965   case IL_ST:
3966   case IL_STDP:
3967   case IL_STSP:
3968   case IL_SSTS_SCALAR:
3969   case IL_DSTS_SCALAR:
3970   case IL_STA:
3971     _printnme(ILI_OPND(i, 3));
3972     if (DBGBIT(10, 4096)) {
3973       appendstring1("<*");
3974       _printili(ILI_OPND(i, 2));
3975       appendstring1("*>");
3976     }
3977     appendstring1(" = ");
3978     _printili(ILI_OPND(i, 1));
3979     appendstring1(";");
3980     break;
3981 
3982   case IL_LABEL: {
3983     int label = ILI_OPND(i, 1);
3984     appendstring1("label ");
3985     appendsym1(label);
3986     if (BEGINSCOPEG(label)) {
3987       appendstring1(" beginscope(");
3988       appendsym1(ENCLFUNCG(label));
3989       appendstring1(")");
3990     }
3991     if (ENDSCOPEG(label)) {
3992       appendstring1(" endscope(");
3993       appendsym1(ENCLFUNCG(label));
3994       appendstring1(")");
3995     }
3996     break;
3997   }
3998 
3999   case IL_NULL:
4000     if (noprs == 1 && ILI_OPND(i, 1) == 0) {
4001       /* expected case, print nothing else */
4002       appendstring1("NULL");
4003       break;
4004     }
4005 /* fall through */
4006 
4007   default:
4008     appendstring1(ilis[opc].name);
4009     if (noprs) {
4010       int j;
4011       appendstring1("(");
4012       for (j = 1; j <= noprs; ++j) {
4013         if (j > 1)
4014           appendstring1(",");
4015         switch (IL_OPRFLAG(opc, j)) {
4016 #ifdef ILIO_NULL
4017         case ILIO_NULL:
4018           appendstring1("null=");
4019           appendint1(ILI_OPND(i, j));
4020           break;
4021 #endif
4022 #ifdef ILIO_SYM
4023         case ILIO_SYM:
4024           if (full) {
4025             appendint1(ILI_OPND(i, j));
4026             appendstring1("=");
4027           }
4028           appendsym1(ILI_OPND(i, j));
4029           break;
4030 #endif
4031 #ifdef ILIO_OFF
4032         case ILIO_OFF:
4033           appendstring1("off=");
4034           appendint1(ILI_OPND(i, j));
4035           break;
4036 #endif
4037 #ifdef ILIO_NME
4038         case ILIO_NME:
4039           appendstring1("nme=");
4040           if (full) {
4041             appendint1(ILI_OPND(i, j));
4042             appendstring1("=");
4043           }
4044           _printnme(ILI_OPND(i, j));
4045           break;
4046 #endif
4047 #ifdef ILIO_IR
4048         case ILIO_IR:
4049           appendstring1("ir=");
4050           appendint1(ILI_OPND(i, j));
4051           break;
4052 #endif
4053 #ifdef ILIO_SP
4054         case ILIO_SP:
4055           appendstring1("sp=");
4056           appendint1(ILI_OPND(i, j));
4057           break;
4058 #endif
4059 #ifdef ILIO_DR
4060         case ILIO_DR:
4061           appendstring1("dr=");
4062           appendint1(ILI_OPND(i, j));
4063           break;
4064 #endif
4065 #ifdef ILIO_AR
4066         case ILIO_AR:
4067           appendstring1("ar=");
4068           appendint1(ILI_OPND(i, j));
4069           break;
4070 #endif
4071 #ifdef ILIO_KR
4072         case ILIO_KR:
4073           appendstring1("kr=");
4074           appendint1(ILI_OPND(i, j));
4075           break;
4076 #endif
4077 #ifdef ILIO_XMM
4078         case ILIO_XMM:
4079           /*
4080              bits 0:23 of the operand represent the virtual register
4081              number, and the value of the top byte is 1 for 'ymm'
4082              register, otherwise for 'xmm' register.
4083           */
4084           if (ILI_OPND(i, j) >> 24 == 1)
4085             appendstring1("ymm=");
4086           else
4087             appendstring1("xmm=");
4088           appendint1(ILI_OPND(i, j) & 0xFFFFFF);
4089           break;
4090 #endif
4091 #ifdef ILIO_LNK
4092         case ILIO_LNK:
4093 #endif
4094 #ifdef ILIO_IRLNK
4095         case ILIO_IRLNK:
4096 #endif
4097 #ifdef ILIO_SPLNK
4098         case ILIO_SPLNK:
4099 #endif
4100 #ifdef ILIO_DPLNK
4101         case ILIO_DPLNK:
4102 #endif
4103 #ifdef ILIO_ARLNK
4104         case ILIO_ARLNK:
4105 #endif
4106 #ifdef ILIO_KRLNK
4107         case ILIO_KRLNK:
4108 #endif
4109 #ifdef ILIO_CSLNK
4110         case ILIO_CSLNK:
4111 #endif
4112 #ifdef ILIO_CDLNK
4113         case ILIO_CDLNK:
4114 #endif
4115 #ifdef ILIO_QPLNK
4116         case ILIO_QPLNK:
4117 #endif
4118 #ifdef ILIO_CQLNK
4119         case ILIO_CQLNK:
4120 #endif
4121 #ifdef ILIO_128LNK
4122         case ILIO_128LNK:
4123 #endif
4124 #ifdef ILIO_256LNK
4125         case ILIO_256LNK:
4126 #endif
4127 #ifdef ILIO_512LNK
4128         case ILIO_512LNK:
4129 #endif
4130 #ifdef ILIO_X87LNK
4131         case ILIO_X87LNK:
4132 #endif
4133 #ifdef ILIO_DOUBLEDOUBLELNK
4134         case ILIO_DOUBLEDOUBLELNK:
4135 #endif
4136           _printili(ILI_OPND(i, j));
4137           break;
4138         default:
4139           appendstring1("op=");
4140           appendint1(ILI_OPND(i, j));
4141           break;
4142         }
4143       }
4144       appendstring1(")");
4145     }
4146     break;
4147   }
4148 
4149   switch (typ) {
4150   case BINOP:
4151     o = optype(ILI_OPC(ILI_OPND(i, 1)));
4152     if (o != OT_UNARY && o != OT_LEAF) {
4153       appendstring1("(");
4154       _printili(ILI_OPND(i, 1));
4155       appendstring1(")");
4156     } else {
4157       _printili(ILI_OPND(i, 1));
4158     }
4159     appendstring1(opval);
4160     o = optype(ILI_OPC(ILI_OPND(i, 2)));
4161     if (o != OT_UNARY && o != OT_LEAF) {
4162       appendstring1("(");
4163       _printili(ILI_OPND(i, 2));
4164       appendstring1(")");
4165     } else {
4166       _printili(ILI_OPND(i, 2));
4167     }
4168     break;
4169   case UNOP:
4170     appendstring1(opval);
4171     o = optype(ILI_OPC(ILI_OPND(i, 1)));
4172     if (o != OT_UNARY && o != OT_LEAF) {
4173       appendstring1("(");
4174       _printili(ILI_OPND(i, 1));
4175       appendstring1(")");
4176     } else {
4177       _printili(ILI_OPND(i, 1));
4178     }
4179     break;
4180   case postUNOP:
4181     o = optype(ILI_OPC(ILI_OPND(i, 1)));
4182     if (o != OT_UNARY && o != OT_LEAF) {
4183       appendstring1("(");
4184       _printili(ILI_OPND(i, 1));
4185       appendstring1(")");
4186     } else {
4187       _printili(ILI_OPND(i, 1));
4188     }
4189     appendstring1(opval);
4190     break;
4191   case INTRINSIC:
4192     appendstring1(opval);
4193     appendstring1("(");
4194     for (j = 1; j <= n; ++j) {
4195       _printili(ILI_OPND(i, j));
4196       if (j != n)
4197         appendstring1(",");
4198     }
4199     appendstring1(")");
4200     break;
4201   case MVREG:
4202     appendstring1(opval);
4203     appendstring1(".");
4204     appendint1(ILI_OPND(i, 2));
4205     appendstring1("=");
4206     _printili(ILI_OPND(i, 1));
4207     break;
4208   case DFREG:
4209     appendstring1(opval);
4210     appendstring1("(");
4211     appendint1(ILI_OPND(i, 1));
4212     appendstring1(")");
4213     break;
4214   case PSCOMM:
4215     appendstring1(opval);
4216     appendstring1(" = ");
4217     _printili(ILI_OPND(i, 1));
4218     appendstring1(";");
4219     break;
4220   case ENC_N_OP:
4221     appendstring1(opval);
4222     appendstring1("#0x");
4223     appendhex1(ILI_OPND(i, n + 1));
4224     appendstring1("(");
4225     for (j = 1; j <= n; ++j) {
4226       _printili(ILI_OPND(i, j));
4227       if (j != n)
4228         appendstring1(",");
4229     }
4230     appendstring1(")");
4231     break;
4232   default:
4233     break;
4234   }
4235 } /* _printili */
4236 
4237 /*
4238  * call _printili with linelen = 0, so no prefix blanks are added
4239  */
4240 void
printili(int i)4241 printili(int i)
4242 {
4243   linelen = 0;
4244   _printili(i);
4245   linelen = 0;
4246 } /* printili */
4247 
4248 /**
4249  * call _printilt with linelen = 0, so no prefix blanks are added
4250  */
4251 void
printilt(int i)4252 printilt(int i)
4253 {
4254   linelen = 0;
4255   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4256   snprintf(BUF, BUFSIZE, "ilt:%-4d", i);
4257   putit();
4258   if (iltb.stg_base && i > 0 && i < iltb.stg_size && ILT_ILIP(i)) {
4259     snprintf(BUF, BUFSIZE, "lineno:%-4d ili:%-4d  ", ILT_LINENO(i),
4260              ILT_ILIP(i));
4261     putit();
4262     _printili(ILT_ILIP(i));
4263   }
4264   putline();
4265   linelen = 0;
4266 } /* printilt */
4267 
4268 void
putili(const char * name,int ilix)4269 putili(const char *name, int ilix)
4270 {
4271   if (ilix <= 0)
4272     return;
4273   if (full) {
4274     snprintf(BUF, BUFSIZE, "%s:%d=", name, ilix);
4275   } else {
4276     snprintf(BUF, BUFSIZE, "%s=", name);
4277   }
4278   putit();
4279   _printili(ilix);
4280 } /* putili */
4281 
4282 void
printblock(int block)4283 printblock(int block)
4284 {
4285   int ilt;
4286   if (bihb.stg_base == NULL) {
4287     fprintf(dfile, "bihb.stg_base not allocated\n");
4288     return;
4289   }
4290   db(block);
4291   for (ilt = BIH_ILTFIRST(block); ilt; ilt = ILT_NEXT(ilt)) {
4292     if (full) {
4293       snprintf(BUF, BUFSIZE, "ilt:%d", ilt);
4294       putit();
4295     }
4296     if (ilt >= 0 && ilt < iltb.stg_size) {
4297       putint("lineno", ILT_LINENO(ilt));
4298       putili("ili", ILT_ILIP(ilt));
4299       putline();
4300     }
4301   }
4302 } /* printblock */
4303 
4304 void
printblockline(int block)4305 printblockline(int block)
4306 {
4307   int ilt;
4308   if (bihb.stg_base == NULL) {
4309     fprintf(dfile, "bihb.stg_base not allocated\n");
4310     return;
4311   }
4312   db(block);
4313   for (ilt = BIH_ILTFIRST(block); ilt; ilt = ILT_NEXT(ilt)) {
4314     if (full) {
4315       snprintf(BUF, BUFSIZE, "ilt:%d", ilt);
4316       putit();
4317     }
4318     if (ilt >= 0 && ilt < iltb.stg_size) {
4319       putint("lineno", ILT_LINENO(ilt));
4320       putint("findex", ILT_FINDEX(ilt));
4321       putili("ili", ILT_ILIP(ilt));
4322       putline();
4323     }
4324   }
4325 } /* printblockline */
4326 
4327 void
printblocks(void)4328 printblocks(void)
4329 {
4330   int block;
4331   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4332   if (bihb.stg_base == NULL) {
4333     fprintf(dfile, "bihb.stg_base not allocated\n");
4334     return;
4335   }
4336   if (full) {
4337     fprintf(dfile, "func_count=%d, curr_func=%d=%s\n", gbl.func_count,
4338             GBL_CURRFUNC, GBL_CURRFUNC > 0 ? SYMNAME(GBL_CURRFUNC) : "");
4339   } else {
4340     fprintf(dfile, "func_count=%d, curr_func=%s\n", gbl.func_count,
4341             GBL_CURRFUNC > 0 ? SYMNAME(GBL_CURRFUNC) : "");
4342   }
4343 #ifdef CUDAG
4344   if (GBL_CURRFUNC > 0)
4345     putcuda("cuda", CUDAG(GBL_CURRFUNC));
4346   fprintf(dfile, "\n");
4347 #endif
4348   block = BIHNUMG(GBL_CURRFUNC);
4349   for (; block; block = BIH_NEXT(block)) {
4350     printblock(block);
4351     if (BIH_LAST(block))
4352       break;
4353     fprintf(dfile, "\n");
4354   }
4355 } /* printblocks */
4356 
4357 void
printblockt(int firstblock,int lastblock)4358 printblockt(int firstblock, int lastblock)
4359 {
4360   int block, limit = 1000, b;
4361   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4362   if (bihb.stg_base == NULL) {
4363     fprintf(dfile, "bihb.stg_base not allocated\n");
4364     return;
4365   }
4366   fprintf(dfile, "func_count=%d, curr_func=%d=%s, blocks=%d:%d\n",
4367           gbl.func_count, GBL_CURRFUNC,
4368           GBL_CURRFUNC > 0 ? SYMNAME(GBL_CURRFUNC) : "", firstblock, lastblock);
4369   block = BIHNUMG(GBL_CURRFUNC);
4370   for (; block; block = BIH_NEXT(block)) {
4371     if (block == firstblock)
4372       break;
4373   }
4374   if (block != firstblock) {
4375     fprintf(dfile, "block:%d not found\n", firstblock);
4376     for (b = 0, block = firstblock; block && b < limit;
4377          block = BIH_NEXT(block), ++b) {
4378       printblock(block);
4379       if (BIH_LAST(block) || block == lastblock)
4380         break;
4381       fprintf(dfile, "\n");
4382     }
4383     if (block != lastblock)
4384       fprintf(dfile, "block:%d not found\n", lastblock);
4385   } else {
4386     for (b = 0; block && b < limit; block = BIH_NEXT(block), ++b) {
4387       printblock(block);
4388       if (BIH_LAST(block) || block == lastblock)
4389         break;
4390       fprintf(dfile, "\n");
4391     }
4392     if (block != lastblock)
4393       fprintf(dfile, "block:%d not found\n", lastblock);
4394   }
4395 } /* printblockt */
4396 
4397 void
printblocktt(int firstblock,int lastblock)4398 printblocktt(int firstblock, int lastblock)
4399 {
4400   int block;
4401   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4402   if (bihb.stg_base == NULL) {
4403     fprintf(dfile, "bihb.stg_base not allocated\n");
4404     return;
4405   }
4406   fprintf(dfile, "func_count=%d, curr_func=%d=%s, blocks=%d:%d\n",
4407           gbl.func_count, GBL_CURRFUNC,
4408           GBL_CURRFUNC > 0 ? SYMNAME(GBL_CURRFUNC) : "", firstblock, lastblock);
4409   for (block = firstblock; block; block = BIH_NEXT(block)) {
4410     printblock(block);
4411     if (BIH_LAST(block) || block == lastblock)
4412       break;
4413     fprintf(dfile, "\n");
4414   }
4415   if (block != lastblock) {
4416     fprintf(dfile, "block:%d not found\n", lastblock);
4417   }
4418 } /* printblocktt */
4419 
4420 void
printblocksline(void)4421 printblocksline(void)
4422 {
4423   int block;
4424   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4425   if (bihb.stg_base == NULL) {
4426     fprintf(dfile, "bihb.stg_base not allocated\n");
4427     return;
4428   }
4429   fprintf(dfile, "func_count=%d, curr_func=%d=%s\n", gbl.func_count,
4430           GBL_CURRFUNC, GBL_CURRFUNC > 0 ? SYMNAME(GBL_CURRFUNC) : "");
4431   block = BIHNUMG(GBL_CURRFUNC);
4432   for (; block; block = BIH_NEXT(block)) {
4433     printblockline(block);
4434     if (BIH_LAST(block))
4435       break;
4436     fprintf(dfile, "\n");
4437   }
4438 } /* printblocksline */
4439 
4440 void
dili(int ilix)4441 dili(int ilix)
4442 {
4443   ILI_OP opc;
4444   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4445 
4446   if (full)
4447     putint("ili", ilix);
4448   if (ilix <= 0 || ilix >= ilib.stg_size) {
4449     putstring1("out of bounds");
4450     putline();
4451     return;
4452   }
4453 
4454   opc = ILI_OPC(ilix);
4455   if (opc <= 0 || opc >= N_ILI) {
4456     putint("illegalopc", opc);
4457   } else {
4458     int noprs, j;
4459     static const char *iltypes[] = {"(null)",   "(arth)", "(branch)", "(cons)",
4460                               "(define)", "(load)", "(move)",   "(other)",
4461                               "(proc)",   "(store)"};
4462     putstring("opc", IL_NAME(opc));
4463     putval1(IL_TYPE(opc), iltypes, SIZEOF(iltypes));
4464     noprs = IL_OPRS(opc);
4465     for (j = 1; j <= noprs; ++j) {
4466       int opnd;
4467       opnd = ILI_OPND(ilix, j);
4468       switch (IL_OPRFLAG(opc, j)) {
4469       case ILIO_SYM:
4470         putsym("sym", (SPTR)opnd);
4471         if (opc == IL_ACON) {
4472           putnsym("base", SymConval1((SPTR)opnd));
4473           putnzbigint("offset", ACONOFFG(opnd));
4474         }
4475         break;
4476       case ILIO_OFF:
4477         putsym("sym", (SPTR)opnd);
4478         break;
4479       case ILIO_NME:
4480         putnme("nme", opnd);
4481         break;
4482       case ILIO_STC:
4483         putstc(opc, j, opnd);
4484         break;
4485       case ILIO_LNK:
4486         if (full) {
4487           putint("lnk", opnd);
4488         } else {
4489           putstring1("lnk");
4490         }
4491         break;
4492       case ILIO_IRLNK:
4493         if (full) {
4494           putint("irlnk", opnd);
4495         } else {
4496           putstring1("irlnk");
4497         }
4498         break;
4499       case ILIO_KRLNK:
4500         if (full) {
4501           putint("krlnk", opnd);
4502         } else {
4503           putstring1("krlnk");
4504         }
4505         break;
4506       case ILIO_ARLNK:
4507         if (full) {
4508           putint("arlnk", opnd);
4509         } else {
4510           putstring1("arlnk");
4511         }
4512         break;
4513       case ILIO_SPLNK:
4514         if (full) {
4515           putint("splnk", opnd);
4516         } else {
4517           putstring1("splnk");
4518         }
4519         break;
4520       case ILIO_DPLNK:
4521         if (full) {
4522           putint("dplnk", opnd);
4523         } else {
4524           putstring1("dplnk");
4525         }
4526         break;
4527 #ifdef ILIO_CSLNK
4528       case ILIO_CSLNK:
4529         if (full) {
4530           putint("cslnk", opnd);
4531         } else {
4532           putstring1("cslnk");
4533         }
4534         break;
4535       case ILIO_QPLNK:
4536         if (full) {
4537           putint("qplnk", opnd);
4538         } else {
4539           putstring1("qplnk");
4540         }
4541         break;
4542       case ILIO_CDLNK:
4543         if (full) {
4544           putint("cdlnk", opnd);
4545         } else {
4546           putstring1("cdlnk");
4547         }
4548         break;
4549       case ILIO_CQLNK:
4550         if (full) {
4551           putint("cqlnk", opnd);
4552         } else {
4553           putstring1("cqlnk");
4554         }
4555         break;
4556       case ILIO_128LNK:
4557         if (full) {
4558           putint("128lnk", opnd);
4559         } else {
4560           putstring1("128lnk");
4561         }
4562         break;
4563       case ILIO_256LNK:
4564         if (full) {
4565           putint("256lnk", opnd);
4566         } else {
4567           putstring1("256lnk");
4568         }
4569         break;
4570       case ILIO_512LNK:
4571         if (full) {
4572           putint("512lnk", opnd);
4573         } else {
4574           putstring1("512lnk");
4575         }
4576         break;
4577 #ifdef LONG_DOUBLE_FLOAT128
4578       case ILIO_FLOAT128LNK:
4579         if (full) {
4580           putint("float128lnk", opnd);
4581         } else {
4582           putstring1("float128lnk");
4583         }
4584         break;
4585 #endif
4586 #endif /* ILIO_CSLNK */
4587 #ifdef ILIO_PPLNK
4588       case ILIO_PPLNK:
4589         if (full) {
4590           putint("pplnk", opnd);
4591         } else {
4592           putstring1("pplnk");
4593         }
4594         break;
4595 #endif
4596       case ILIO_IR:
4597         putint("ir", opnd);
4598         break;
4599 #ifdef ILIO_KR
4600       case ILIO_KR:
4601         putpint("kr", opnd);
4602         break;
4603 #endif
4604       case ILIO_AR:
4605         putint("ar", opnd);
4606         break;
4607       case ILIO_SP:
4608         putint("sp", opnd);
4609         break;
4610       case ILIO_DP:
4611         putint("dp", opnd);
4612         break;
4613       default:
4614         put2int("Unknown", IL_OPRFLAG(opc, j), opnd);
4615         break;
4616       }
4617     }
4618   }
4619   if (full) {
4620     putnzint("alt", ILI_ALT(ilix));
4621   } else {
4622     if (ILI_ALT(ilix)) {
4623       putstring1("alt");
4624     }
4625   }
4626   putnzint("count/rat/repl", ILI_COUNT(ilix));
4627   if (full)
4628     putnzint("hshlnk", ILI_HSHLNK(ilix));
4629   putnzint("visit", ILI_VISIT(ilix));
4630   if (full)
4631     putnzint("vlist", ILI_VLIST(ilix));
4632   putline();
4633 } /* dili */
4634 
4635 static void
dilitreex(int ilix,int l,int notlast)4636 dilitreex(int ilix, int l, int notlast)
4637 {
4638   ILI_OP opc;
4639   int noprs, j, jj, nlinks;
4640   int nshift = 0;
4641 
4642   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4643   fprintf(dfile, "%s", prefix);
4644   dili(ilix);
4645   if (ilix <= 0 || ilix >= ilib.stg_size)
4646     return;
4647   if (l) {
4648     if (notlast) {
4649       strcpy(prefix + l - 4, "|   ");
4650     } else {
4651       strcpy(prefix + l - 4, "    ");
4652     }
4653   }
4654   opc = ILI_OPC(ilix);
4655   if (opc >= 0 && opc < N_ILI) {
4656     noprs = IL_OPRS(opc);
4657   } else {
4658     noprs = 0;
4659   }
4660   nlinks = 0;
4661   for (j = 1; j <= noprs; ++j) {
4662     if (IL_ISLINK(opc, j)) {
4663       ++nlinks;
4664     }
4665   }
4666   if (ILI_ALT(ilix))
4667     ++nlinks;
4668   switch (opc) {
4669   case IL_CSEIR:
4670   case IL_CSESP:
4671   case IL_CSEDP:
4672   case IL_CSECS:
4673   case IL_CSECD:
4674   case IL_CSEAR:
4675   case IL_CSEKR:
4676   case IL_CSE:
4677 #ifdef LONG_DOUBLE_FLOAT128
4678   case IL_FLOAT128CSE:
4679 #endif
4680     /* don't recurse unless we're at the top level */
4681     if (l > 4)
4682       nlinks = 0;
4683     break;
4684   case IL_ACCCOPY:
4685   case IL_ACCCOPYIN:
4686   case IL_ACCCOPYOUT:
4687   case IL_ACCLOCAL:
4688   case IL_ACCCREATE:
4689   case IL_ACCDELETE:
4690   case IL_ACCPRESENT:
4691   case IL_ACCPCOPY:
4692   case IL_ACCPCOPYIN:
4693   case IL_ACCPCOPYOUT:
4694   case IL_ACCPCREATE:
4695   case IL_ACCPNOT:
4696   case IL_ACCTRIPLE:
4697     nshift = 1;
4698     break;
4699   default :
4700     break;
4701   }
4702   if (nlinks) {
4703     for (jj = 1; jj <= noprs; ++jj) {
4704       j = jj;
4705       if (nshift) {
4706         j += nshift;
4707         if (j > noprs)
4708           j -= noprs;
4709       }
4710       if (IL_ISLINK(opc, j)) {
4711         int opnd;
4712         opnd = ILI_OPND(ilix, j);
4713         if (ILI_OPC(opnd) != IL_NULL) {
4714           strcpy(prefix + l, "+-- ");
4715           dilitreex(opnd, l + 4, --nlinks);
4716         }
4717         prefix[l] = '\0';
4718       }
4719     }
4720     if (ILI_ALT(ilix) && ILI_ALT(ilix) != ilix &&
4721         ILI_OPC(ILI_ALT(ilix)) != IL_NULL) {
4722       int opnd;
4723       opnd = ILI_ALT(ilix);
4724       strcpy(prefix + l, "+-- ");
4725       dilitreex(opnd, l + 4, --nlinks);
4726       prefix[l] = '\0';
4727     }
4728   }
4729 } /* dilitreex */
4730 
4731 void
dilitre(int ilix)4732 dilitre(int ilix)
4733 {
4734   prefix[0] = ' ';
4735   prefix[1] = ' ';
4736   prefix[2] = ' ';
4737   prefix[3] = ' ';
4738   prefix[4] = '\0';
4739   dilitreex(ilix, 4, 0);
4740   prefix[0] = '\0';
4741 } /* dilitre */
4742 
4743 void
dilt(int ilt)4744 dilt(int ilt)
4745 {
4746   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4747   if (iltb.stg_base == NULL) {
4748     fprintf(dfile, "iltb.stg_base not allocated\n");
4749     return;
4750   }
4751   if (full) {
4752     putint("ilt", ilt);
4753   } else {
4754     putstring1("ilt:");
4755   }
4756   if (ilt <= 0 || ilt >= iltb.stg_size) {
4757     fprintf(dfile, "\nilt %d out of %d\n", ilt, iltb.stg_size - 1);
4758     return;
4759   }
4760   if (full) {
4761     putnzint("ilip", ILT_ILIP(ilt));
4762     putnzint("prev", ILT_PREV(ilt));
4763     putnzint("next", ILT_NEXT(ilt));
4764 #ifdef ILT_GUARD
4765     putnzint("guard", ILT_GUARD(ilt));
4766 #endif
4767   }
4768   putnzint("lineno", ILT_LINENO(ilt));
4769   putnzint("findex", ILT_FINDEX(ilt));
4770 #ifdef ILT_EXSDSCUNSAFE
4771   putbit("sdscunsafe", ILT_EXSDSCUNSAFE(ilt));
4772 #endif
4773   putbit("st", ILT_ST(ilt));
4774   putbit("br", ILT_BR(ilt));
4775   putbit("can_throw", ILT_CAN_THROW(ilt));
4776   putbit("dbgline", ILT_DBGLINE(ilt));
4777   putbit("delete", ILT_DELETE(ilt));
4778   putbit("ex", ILT_EX(ilt));
4779   putbit("free", ILT_FREE(ilt));
4780   putbit("ignore", ILT_IGNORE(ilt));
4781   putbit("split", ILT_SPLIT(ilt));
4782   putbit("cplx", ILT_CPLX(ilt));
4783   putbit("keep", ILT_KEEP(ilt));
4784   putbit("mcache", ILT_MCACHE(ilt));
4785   putbit("nodel", ILT_NODEL(ilt));
4786 #ifdef ILT_DELEBB
4787   putbit("delebb", ILT_DELEBB(ilt));
4788 #endif
4789 #ifdef ILT_EQASRT
4790   putbit("eqasrt", ILT_EQASRT(ilt));
4791 #endif
4792 #ifdef ILT_PREDC
4793   putbit("predc", ILT_PREDC(ilt));
4794 #endif
4795   putline();
4796 } /* dilt */
4797 
4798 void
dumpilt(int ilt)4799 dumpilt(int ilt)
4800 {
4801   dilt(ilt);
4802   if (ilt >= 0 && ilt < iltb.stg_size)
4803     dilitre(ILT_ILIP(ilt));
4804 } /* dumpilt */
4805 
4806 void
dumpilts()4807 dumpilts()
4808 {
4809   int bihx, iltx;
4810   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4811   if (bihb.stg_base == NULL) {
4812     fprintf(dfile, "bihb.stg_base not allocated\n");
4813     return;
4814   }
4815   bihx = BIHNUMG(gbl.currsub);
4816   for (; bihx; bihx = BIH_NEXT(bihx)) {
4817     db(bihx);
4818     for (iltx = BIH_ILTFIRST(bihx); iltx; iltx = ILT_NEXT(iltx)) {
4819       dilt(iltx);
4820     }
4821     if (BIH_LAST(bihx))
4822       break;
4823     fprintf(dfile, "\n");
4824   }
4825 } /* dumpilts */
4826 
4827 void
db(int block)4828 db(int block)
4829 {
4830   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4831   if (bihb.stg_base == NULL) {
4832     fprintf(dfile, "bihb.stg_base not allocated\n");
4833     return;
4834   }
4835   if (full) {
4836     putint("block", block);
4837   } else {
4838     putstring1("block:");
4839   }
4840   if (block <= 0 || block >= bihb.stg_size) {
4841     fprintf(dfile, "\nblock %d out of %d\n", block, bihb.stg_size - 1);
4842     return;
4843   }
4844   putnzint("lineno", BIH_LINENO(block));
4845   if (full)
4846     putnzint("iltfirst", BIH_ILTFIRST(block));
4847   if (full)
4848     putnzint("iltlast", BIH_ILTLAST(block));
4849   if (full)
4850     putnzint("prev", BIH_PREV(block));
4851   if (full)
4852     putnzint("next", BIH_NEXT(block));
4853   putnsym("label", BIH_LABEL(block));
4854   if (BIH_LABEL(block)) {
4855     putnzint("rfcnt", RFCNTG(BIH_LABEL(block)));
4856     putbit("vol", VOLG(BIH_LABEL(block)));
4857   }
4858   putnzint("assn", BIH_ASSN(block));
4859   putnzint("rgset", BIH_RGSET(block));
4860 #ifdef BIH_ASM
4861   putbit("asm", BIH_ASM(block));
4862 #endif
4863   putbit("rd", BIH_RD(block));
4864   putbit("ft", BIH_FT(block));
4865   putbit("en", BIH_EN(block));
4866   putbit("ex", BIH_EX(block));
4867 #ifdef BIH_EXSDSCUNSAFE
4868   putbit("sdscunsafe", BIH_EXSDSCUNSAFE(block));
4869 #endif
4870   putbit("last", BIH_LAST(block));
4871   putbit("xt", BIH_XT(block));
4872   putbit("pl", BIH_PL(block));
4873   putbit("ztrp", BIH_ZTRP(block));
4874   putbit("guardee", BIH_GUARDEE(block));
4875   putbit("guarder", BIH_GUARDER(block));
4876   putbit("smove", BIH_SMOVE(block));
4877   putbit("nobla", BIH_NOBLA(block));
4878   putbit("nomerge", BIH_NOMERGE(block));
4879   putbit("qjsr", BIH_QJSR(block));
4880   putbit("head", BIH_HEAD(block));
4881   putbit("tail", BIH_TAIL(block));
4882   putbit("innermost", BIH_INNERMOST(block));
4883   putbit("mexits", BIH_MEXITS(block));
4884   putbit("ozcr", BIH_OZCR(block));
4885   putbit("par", BIH_PAR(block));
4886   putbit("cs", BIH_CS(block));
4887   putbit("streg", BIH_STREG(block));
4888   putbit("vpar", BIH_VPAR(block));
4889   putbit("enlab", BIH_ENLAB(block));
4890   putbit("mark", BIH_MARK(block));
4891   putbit("mark2", BIH_MARK2(block));
4892   putbit("mark3", BIH_MARK3(block));
4893   putbit("parloop", BIH_PARLOOP(block));
4894   putbit("parsect", BIH_PARSECT(block));
4895   putbit("resid", BIH_RESID(block));
4896   putbit("ujres", BIH_UJRES(block));
4897   putbit("simd", BIH_SIMD(block));
4898   putbit("ldvol", BIH_LDVOL(block));
4899   putbit("stvol", BIH_STVOL(block));
4900   putbit("task", BIH_TASK(block));
4901   putbit("paraln", BIH_PARALN(block));
4902   putbit("invif", BIH_INVIF(block));
4903   putbit("noinvif", BIH_NOINVIF(block));
4904   putbit("combst", BIH_COMBST(block));
4905   putbit("deletable", BIH_DELETABLE(block));
4906   putbit("vcand", BIH_VCAND(block));
4907   putbit("accel", BIH_ACCEL(block));
4908   putbit("endaccel", BIH_ENDACCEL(block));
4909   putbit("accdata", BIH_ACCDATA(block));
4910   putbit("endaccdata", BIH_ENDACCDATA(block));
4911   putbit("kernel", BIH_KERNEL(block));
4912   putbit("endkernel", BIH_ENDKERNEL(block));
4913   putbit("midiom", BIH_MIDIOM(block));
4914   putbit("nodepchk", BIH_NODEPCHK(block));
4915   putbit("doconc", BIH_DOCONC(block));
4916   putline();
4917 #ifdef BIH_FINDEX
4918   if (BIH_FINDEX(block) || BIH_FTAG(block)) {
4919     putint("findex", BIH_FINDEX(block));
4920     putint("ftag", BIH_FTAG(block));
4921     /* The casting from double to int may cause an overflow in int.
4922      * Just take a short-cut here for the ease of debugging. Will need
4923      * to create a new function to accommodate the non-int types.
4924      */
4925     if (BIH_BLKCNT(block) != -1.0)
4926       putdouble("blkCnt", BIH_BLKCNT(block));
4927     if (BIH_FINDEX(block) > 0 && BIH_FINDEX(block) < fihb.stg_avail) {
4928       if (FIH_DIRNAME(BIH_FINDEX(block))) {
4929         putstring1(FIH_DIRNAME(BIH_FINDEX(block)));
4930         putstring1t("/");
4931         putstring1t(FIH_FILENAME(BIH_FINDEX(block)));
4932       } else {
4933         putstring1(FIH_FILENAME(BIH_FINDEX(block)));
4934       }
4935       if (FIH_FUNCNAME(BIH_FINDEX(block)) != NULL) {
4936         putstring1(FIH_FUNCNAME(BIH_FINDEX(block)));
4937       }
4938     } else if (BIH_FINDEX(block) < 0 || BIH_FINDEX(block) >= fihb.stg_avail) {
4939       puterr("bad findex value");
4940     }
4941     putline();
4942   }
4943 #endif
4944 } /* db */
4945 
4946 void
dumpblock(int block)4947 dumpblock(int block)
4948 {
4949   int ilt;
4950   if (bihb.stg_base == NULL) {
4951     fprintf(dfile, "bihb.stg_base not allocated\n");
4952     return;
4953   }
4954   db(block);
4955   for (ilt = BIH_ILTFIRST(block); ilt; ilt = ILT_NEXT(ilt)) {
4956     dilt(ilt);
4957     if (ilt >= 0 && ilt < iltb.stg_size)
4958       dilitre(ILT_ILIP(ilt));
4959   }
4960 } /* dumpblock */
4961 
4962 void
dumptblock(const char * title,int block)4963 dumptblock(const char *title, int block)
4964 {
4965   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4966   fprintf(dfile, "\n********** dump block %d %s **********\n", block, title);
4967   dumpblock(block);
4968 } /* dumptblock */
4969 
4970 void
dbih(void)4971 dbih(void)
4972 {
4973   int block;
4974   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4975   if (bihb.stg_base == NULL) {
4976     fprintf(dfile, "bihb.stg_base not allocated\n");
4977     return;
4978   }
4979   block = BIHNUMG(gbl.currsub);
4980   for (; block; block = BIH_NEXT(block)) {
4981     dumpblock(block);
4982     if (BIH_LAST(block))
4983       break;
4984     fprintf(dfile, "\n");
4985   }
4986 } /* dbih */
4987 
4988 void
dbihonly(void)4989 dbihonly(void)
4990 {
4991   int block;
4992   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
4993   if (bihb.stg_base == NULL) {
4994     fprintf(dfile, "bihb.stg_base not allocated\n");
4995     return;
4996   }
4997   block = BIHNUMG(gbl.currsub);
4998   for (; block; block = BIH_NEXT(block)) {
4999     db(block);
5000     if (BIH_LAST(block))
5001       break;
5002     fprintf(dfile, "\n");
5003   }
5004 } /* dbihonly */
5005 
5006 void
dumpblocksonly(void)5007 dumpblocksonly(void)
5008 {
5009   dbihonly();
5010 } /* dumpblocksonly */
5011 
5012 void
dumpblocks(const char * title)5013 dumpblocks(const char *title)
5014 {
5015   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5016   fprintf(dfile, "\n********** BLOCK INFORMATION HEADER TABLE **********\n");
5017   fprintf(dfile, "%s called\n", title);
5018   dbih();
5019   fprintf(dfile, "%s done\n**********\n\n", title);
5020 } /* dumpblocks */
5021 
5022 #ifdef FIH_FULLNAME
5023 void
dfih(int f)5024 dfih(int f)
5025 {
5026   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5027   if (fihb.stg_base == NULL) {
5028     fprintf(dfile, "fihb.stg_base not allocated\n");
5029     return;
5030   }
5031   if (full) {
5032     putint("fih", f);
5033   } else {
5034     putstring1("fih:");
5035   }
5036   if (f <= 0 || f >= fihb.stg_size) {
5037     fprintf(dfile, "\nfile %d out of %d\n", f, fihb.stg_size - 1);
5038     return;
5039   }
5040   putstring("fullname", FIH_FULLNAME(f));
5041   if (FIH_FUNCNAME(f) != NULL && FIH_FUNCNAME(f)[0] != '\0') {
5042     putstring("funcname", FIH_FUNCNAME(f));
5043   }
5044   putint("functag", FIH_FUNCTAG(f));
5045   putint("srcline", FIH_SRCLINE(f));
5046   putnzint("level", FIH_LEVEL(f));
5047   putnzint("parent", FIH_PARENT(f));
5048   putnzint("lineno", FIH_LINENO(f));
5049   putnzint("next", FIH_NEXT(f));
5050   putnzint("child", FIH_CHILD(f));
5051   putbit("included", FIH_INC(f));
5052   putbit("inlined", FIH_INL(f));
5053   putbit("ipainlined", FIH_IPAINL(f));
5054   putbit("ccff", FIH_FLAGS(f) & FIH_CCFF);
5055   putbit("ccffinfo", (FIH_CCFFINFO(f) != NULL));
5056   putline();
5057 } /* dfih */
5058 
5059 void
dumpfile(int f)5060 dumpfile(int f)
5061 {
5062   dfih(f);
5063 } /* dumpfile */
5064 
5065 void
dumpfiles(void)5066 dumpfiles(void)
5067 {
5068   int f;
5069   for (f = 1; f < fihb.stg_avail; ++f) {
5070     dfih(f);
5071   }
5072 } /* dumpfiles */
5073 #endif
5074 
5075 #ifdef NME_PTE
5076 void
putptelist(int pte)5077 putptelist(int pte)
5078 {
5079   for (; pte > 0; pte = (PTE_NEXT(pte) == pte ? -1 : PTE_NEXT(pte))) {
5080     switch (PTE_TYPE(pte)) {
5081     case PT_UNK:
5082       putstring1("unk");
5083       break;
5084     case PT_PSYM:
5085       putsym("psym", PTE_SPTR(pte));
5086       break;
5087     case PT_ISYM:
5088       putsym("isym", PTE_SPTR(pte));
5089       break;
5090     case PT_ANON:
5091       putint("anon", PTE_VAL(pte));
5092       break;
5093     case PT_GDYN:
5094       putint("gdyn", PTE_VAL(pte));
5095       break;
5096     case PT_LDYN:
5097       putint("ldyn", PTE_VAL(pte));
5098       break;
5099     case PT_NLOC:
5100       putstring1("nonlocal");
5101       break;
5102     default:
5103       put2int("???", PTE_TYPE(pte), PTE_VAL(pte));
5104       break;
5105     }
5106   }
5107 } /* putptelist */
5108 #endif
5109 
5110 static void
_printnme(int n)5111 _printnme(int n)
5112 {
5113   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5114   if (n < 0 || n >= nmeb.stg_avail) {
5115     putint("nme", n);
5116     return;
5117   }
5118   switch (NME_TYPE(n)) {
5119   case NT_VAR:
5120     appendstring1(printname(NME_SYM(n)));
5121     if (NME_SYM(n) > NOSYM && NME_SYM(n) < stb.stg_avail &&
5122         SCG(NME_SYM(n)) == SC_PRIVATE)
5123       appendstring1("'");
5124     break;
5125   case NT_MEM:
5126     if (NME_NM(n)) {
5127       _printnme(NME_NM(n));
5128     } else {
5129       appendstring1("Unknown");
5130     }
5131     if (NME_SYM(n) == 0) {
5132       appendstring1(".real");
5133     } else if (NME_SYM(n) == 1) {
5134       appendstring1(".imag");
5135     } else {
5136       appendstring1(".");
5137       appendstring1(printname(NME_SYM(n)));
5138     }
5139     break;
5140   case NT_ARR:
5141     if (NME_NM(n)) {
5142       _printnme(NME_NM(n));
5143     } else {
5144       appendstring1("Unknown");
5145     }
5146     if (NME_SYM(n) == 0) {
5147       appendstring1("[");
5148       appendint1(NME_CNST(n));
5149       appendstring1("]");
5150     } else if (NME_SUB(n) != 0) {
5151       appendstring1("[");
5152       _printili(NME_SUB(n));
5153       appendstring1("]");
5154     } else {
5155       appendstring1("[?]");
5156     }
5157     break;
5158   case NT_IND:
5159     appendstring1("*(");
5160     if (NME_NM(n)) {
5161       _printnme(NME_NM(n));
5162     } else {
5163       appendstring1("Unknown");
5164     }
5165     if (NME_SYM(n) == NME_NULL) {
5166     } else if (NME_SYM(n) == 0) {
5167       if (NME_CNST(n)) {
5168         appendstring1("+");
5169         appendint1(NME_CNST(n));
5170       }
5171     } else {
5172       appendstring1("+?");
5173     }
5174     appendstring1(")");
5175     if (NME_SUB(n) != 0) {
5176       appendstring1("[");
5177       _printili(NME_SUB(n));
5178       appendstring1("]");
5179     }
5180     break;
5181   case NT_UNK:
5182     if (NME_SYM(n) == 0) {
5183       appendstring1("unknown");
5184     } else if (NME_SYM(n) == 1) {
5185       appendstring1("volatile");
5186     } else {
5187       appendstring1("unknown:");
5188       appendint1(NME_SYM(n));
5189     }
5190     break;
5191   default:
5192     appendstring1("nme(");
5193     appendint1(n);
5194     appendstring1(":");
5195     appendint1(NME_TYPE(n));
5196     appendstring1(")");
5197     break;
5198   }
5199 } /* _printnme */
5200 
5201 void
pprintnme(int n)5202 pprintnme(int n)
5203 {
5204   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5205   putstring1("");
5206   _printnme(n);
5207 } /* pprintnme */
5208 
5209 void
printnme(int n)5210 printnme(int n)
5211 {
5212   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5213   linelen = 0;
5214   _printnme(n);
5215 } /* printnme */
5216 
5217 static const char *nmetypes[] = {"unknown ", "indirect", "variable",
5218                            "member  ", "element ", "safe    "};
5219 
5220 void
_dumpnme(int n,bool dumpdefsuses)5221 _dumpnme(int n, bool dumpdefsuses)
5222 {
5223   int store, pte;
5224   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5225   if (n <= 0 || n >= nmeb.stg_avail) {
5226     fprintf(dfile, "\nNME %d out of %d\n", n, nmeb.stg_avail - 1);
5227     return;
5228   }
5229   if (nmeb.stg_base == NULL) {
5230     fprintf(dfile, "nmeb.stg_base not allocated\n");
5231     return;
5232   }
5233   if (full) {
5234     putint("nme", n);
5235   } else {
5236     putstring1("nme");
5237   }
5238   putval1(NME_TYPE(n), nmetypes, SIZEOF(nmetypes));
5239   switch (NME_TYPE(n)) {
5240   case NT_VAR:
5241     putsym("var", NME_SYM(n));
5242     break;
5243   case NT_MEM:
5244     pprintnme(n);
5245     if (NME_SYM(n) == 0) {
5246       putstring1(".real");
5247     } else if (NME_SYM(n) == 1) {
5248       putstring1(".imag");
5249       break;
5250     } else {
5251       putsym("member", NME_SYM(n));
5252     }
5253     break;
5254   case NT_ARR:
5255   case NT_IND:
5256     pprintnme(n);
5257     if (NME_SYM(n) == NME_NULL) {
5258       putint("sym", -1);
5259     } else if (NME_SYM(n) == 0) {
5260     } else {
5261       if (NME_SYM(n) > 0 && NME_SYM(n) < stb.stg_avail) {
5262         putsym("sym", NME_SYM(n));
5263       } else {
5264         putnzint("sym", NME_SYM(n));
5265       }
5266     }
5267     break;
5268   case NT_UNK:
5269     pprintnme(n);
5270     break;
5271   default:
5272     if (NME_SYM(n) > 0 && NME_SYM(n) < stb.stg_avail) {
5273       putsym("sym", NME_SYM(n));
5274     } else {
5275       putnzint("sym", NME_SYM(n));
5276     }
5277     break;
5278   }
5279   putnzint("nm", NME_NM(n));
5280 #ifdef NME_BASE
5281   putnzint("base", NME_BASE(n));
5282 #endif
5283   putnzint("cnst", NME_CNST(n));
5284   putnzint("cnt", NME_CNT(n));
5285   if (full & 1)
5286     putnzint("hashlink", NME_HSHLNK(n));
5287   putnzint("inlarr", NME_INLARR(n));
5288   putnzint("rat/rfptr", NME_RAT(n));
5289   putnzint("stl", NME_STL(n));
5290   putnzint("sub", NME_SUB(n));
5291   putnzint("mask", NME_MASK(n));
5292 #ifdef NME_PTE
5293   pte = NME_PTE(n);
5294   if (dumpdefsuses && pte) {
5295     putline();
5296     putstring1("pointer targets:");
5297     putptelist(pte);
5298   }
5299 #endif
5300 } /* _dumpnme */
5301 
5302 void
dumpnnme(int n)5303 dumpnnme(int n)
5304 {
5305   linelen = 0;
5306   _dumpnme(n, false);
5307   putline();
5308 } /* dumpnme */
5309 
5310 void
dumpnme(int n)5311 dumpnme(int n)
5312 {
5313   linelen = 0;
5314   _dumpnme(n, true);
5315   putline();
5316 } /* dumpnme */
5317 
5318 void
dumpnmes(void)5319 dumpnmes(void)
5320 {
5321   int n;
5322   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5323   if (nmeb.stg_base == NULL) {
5324     fprintf(dfile, "nmeb.stg_base not allocated\n");
5325     return;
5326   }
5327   fprintf(dfile, "\n********** NME TABLE **********\n");
5328   for (n = 1; n < nmeb.stg_avail; ++n) {
5329     fprintf(dfile, "\n");
5330     dumpnme(n);
5331   }
5332   fprintf(dfile, "\n");
5333 } /* dumpnmes */
5334 
5335 #endif
5336 
5337 char *
printname(int sptr)5338 printname(int sptr)
5339 {
5340   extern void cprintf(char *s, const char *format, INT *val);
5341   static char b[200];
5342   double dd;
5343   union {
5344     float ff;
5345     ISZ_T ww;
5346   } xx;
5347 
5348   if (sptr <= 0 || sptr >= stb.stg_avail) {
5349     snprintf(b, 200, "symbol %d out of %d", sptr, stb.stg_avail - 1);
5350     return b;
5351   }
5352 
5353   if (STYPEG(sptr) == ST_CONST) {
5354     INT num[2], cons1, cons2;
5355     int pointee;
5356     char *bb, *ee;
5357     switch (DTY(DTYPEG(sptr))) {
5358     case TY_INT8:
5359     case TY_UINT8:
5360       num[0] = CONVAL1G(sptr);
5361       num[1] = CONVAL2G(sptr);
5362       ui64toax(num, b, 22, 0, 10);
5363       break;
5364     case TY_INT:
5365       snprintf(b, 200, "%10d", CONVAL2G(sptr));
5366       break;
5367 
5368     case TY_FLOAT:
5369       xx.ww = CONVAL2G(sptr);
5370       if ((xx.ww & 0x7f800000) == 0x7f800000) {
5371         /* Infinity or NaN */
5372         snprintf(b, 200, ("(float)(0x%8.8" ISZ_PF "x)"), xx.ww);
5373       } else {
5374         dd = xx.ff;
5375         snprintf(b, 200, "%.8ef", dd);
5376       }
5377       break;
5378 
5379     case TY_DBLE:
5380       num[0] = CONVAL1G(sptr);
5381       num[1] = CONVAL2G(sptr);
5382       if ((num[0] & 0x7ff00000) == 0x7ff00000) {
5383         /* Infinity or NaN */
5384         snprintf(b, 200, "(double)(0x%8.8x%8.8xLL)", num[0], num[1]);
5385       } else {
5386         cprintf(b, "%.17le", num);
5387       }
5388       break;
5389 
5390     case TY_CMPLX:
5391       xx.ww = CONVAL1G(sptr);
5392       if ((xx.ww & 0x7f800000) == 0x7f800000) {
5393         /* Infinity or NaN */
5394         int len;
5395         len = snprintf(b, 200, ("(0x%8.8" ISZ_PF "x, "), xx.ww);
5396         bb = b + len;
5397       } else {
5398         b[0] = '(';
5399         sprintf(&b[1], "%17.10e", xx.ff);
5400         b[18] = ',';
5401         b[19] = ' ';
5402         bb = &b[20];
5403       }
5404       xx.ww = CONVAL2G(sptr);
5405       if ((xx.ww & 0x7f800000) == 0x7f800000) {
5406         snprintf(bb, 200, ("(0x%8.8" ISZ_PF "x, "), xx.ww);
5407       } else {
5408         sprintf(bb, "%17.10e", xx.ff);
5409         bb += 17;
5410         *bb++ = ')';
5411         *bb = '\0';
5412       }
5413       break;
5414 
5415     case TY_DCMPLX:
5416       cons1 = CONVAL1G(sptr);
5417       cons2 = CONVAL2G(sptr);
5418       num[0] = CONVAL1G(cons1);
5419       num[1] = CONVAL2G(cons1);
5420       if ((num[0] & 0x7ff00000) == 0x7ff00000) {
5421         /* Infinity or NaN */
5422         int len;
5423         len = snprintf(b, 200, "(0x%8.8x%8.8xLL, ", num[0], num[1]);
5424         bb = b + len;
5425 
5426       } else {
5427         b[0] = '(';
5428         cprintf(&b[1], "%24.17le", num);
5429         b[25] = ',';
5430         b[26] = ' ';
5431         bb = &b[27];
5432       }
5433 
5434       num[0] = CONVAL1G(cons2);
5435       num[1] = CONVAL2G(cons2);
5436       if ((num[0] & 0x7ff00000) == 0x7ff00000) {
5437         /* Infinity or NaN */
5438         snprintf(bb, 200, "0x%8.8x%8.8xLL", num[0], num[1]);
5439       } else {
5440         cprintf(bb, "%24.17le", num);
5441         bb += 24;
5442         *bb++ = ')';
5443         *bb = '\0';
5444       }
5445 
5446       break;
5447 
5448     case TY_QUAD:
5449       num[0] = CONVAL1G(sptr);
5450       num[1] = CONVAL2G(sptr);
5451       cprintf(b, "%.17le", num);
5452       break;
5453 
5454     case TY_PTR:
5455       pointee = CONVAL1G(sptr);
5456       if (pointee > 0 && pointee < stb.stg_avail && STYPEG(pointee) != ST_CONST
5457           ) {
5458         if (ACONOFFG(sptr) == 0) {
5459           snprintf(b, 200, "*%s", SYMNAME(pointee));
5460         } else {
5461           snprintf(b, 200, "*%s+%" ISZ_PF "d", SYMNAME(pointee),
5462                    ACONOFFG(sptr));
5463         }
5464       } else {
5465         if (ACONOFFG(sptr) == 0) {
5466           snprintf(b, 200, "*(sym %d)", pointee);
5467         } else {
5468           snprintf(b, 200, "*(sym %d)+%" ISZ_PF "d", pointee, ACONOFFG(sptr));
5469         }
5470       }
5471       break;
5472 
5473     case TY_WORD:
5474       snprintf(b, 200, "%10" ISZ_PF "d", ACONOFFG(sptr));
5475       break;
5476 
5477     case TY_CHAR:
5478       return stb.n_base + CONVAL1G(sptr);
5479     case TY_BLOG:
5480     case TY_SLOG:
5481     case TY_LOG:
5482       snprintf(b, 200, "%10d", CONVAL2G(sptr));
5483       break;
5484     case TY_LOG8:
5485       num[0] = CONVAL1G(sptr);
5486       num[1] = CONVAL2G(sptr);
5487       ui64toax(num, b, 22, 0, 10);
5488       break;
5489 
5490     default:
5491       snprintf(b, 200, "unknown constant %d dty %d", sptr,
5492                DTY(DTYPEG(sptr)));
5493       break;
5494     }
5495     for (bb = b; *bb == ' '; ++bb)
5496       ;
5497     for (ee = bb; *ee; ++ee)
5498       ; /* go to end of string */
5499     for (; ee > bb && *(ee - 1) == ' '; --ee)
5500       *ee = '\0';
5501     return bb;
5502   }
5503   /* default case */
5504   if (strncmp(SYMNAME(sptr), "..inline", 8) == 0) {
5505     /* append symbol number to distinguish */
5506     snprintf(b, 200, "%s_%d", SYMNAME(sptr), sptr);
5507     return b;
5508   }
5509   return SYMNAME(sptr);
5510 } /* printname */
5511 
5512 #if DEBUG
5513 
5514 /*
5515  * dump the DVL structure
5516  */
5517 void
dumpdvl(int d)5518 dumpdvl(int d)
5519 {
5520   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5521   if (aux.dvl_base == NULL) {
5522     fprintf(dfile, "aux.dvl_base not allocated\n");
5523     return;
5524   }
5525   if (d < 0 || d >= aux.dvl_avl) {
5526     fprintf(dfile, "\ndvl %d out of %d\n", d, aux.dvl_avl - 1);
5527     return;
5528   }
5529   putint("dvl", d);
5530   putsym("sym", (SPTR) DVL_SPTR(d)); // ???
5531   putINT("conval", DVL_CONVAL(d));
5532   putline();
5533 } /* dumpdvl */
5534 
5535 void
dumpdvls()5536 dumpdvls()
5537 {
5538   int d;
5539   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5540   if (aux.dvl_base == NULL) {
5541     fprintf(dfile, "aux.dvl_base not allocated\n");
5542     return;
5543   }
5544   for (d = 0; d < aux.dvl_avl; ++d) {
5545     fprintf(dfile, "\n");
5546     dumpdvl(d);
5547   }
5548 } /* dumpdvls */
5549 
5550 /*
5551  * dump variables which are kept on the stack
5552  */
5553 void
stackvars()5554 stackvars()
5555 {
5556   int sptr;
5557   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5558   fprintf(dfile, "Local variables:\n");
5559   for (sptr = gbl.locals; sptr > NOSYM; sptr = SYMLKG(sptr)) {
5560     dsym(sptr);
5561   }
5562 } /* stackvars */
5563 
5564 /*
5565  * diagnose what stack locations are used
5566  */
5567 void
stackcheck()5568 stackcheck()
5569 {
5570   long maxstack, minstack, i, j, addr, size, totused, totfree;
5571   int sptr, lastclash;
5572   int *stack, *stackmem;
5573   dfile = gbl.dbgfil ? gbl.dbgfil : stderr;
5574   minstack = 0;
5575   maxstack = -1;
5576   for (sptr = gbl.locals; sptr > NOSYM; sptr = SYMLKG(sptr)) {
5577     size = size_of(DTYPEG(sptr));
5578     if (ADDRESSG(sptr) - size < minstack)
5579       minstack = ADDRESSG(sptr) - size;
5580     if (ADDRESSG(sptr) + size > maxstack)
5581       maxstack = ADDRESSG(sptr) + size;
5582   }
5583   fprintf(dfile, "Stack for subprogram %d:%s\n%8ld:%-8ld\n", gbl.func_count,
5584           SYMNAME(gbl.currsub), minstack, maxstack);
5585   stackmem = (int *)malloc((maxstack - minstack + 1) * sizeof(int));
5586   stack = stackmem - minstack; /* minstack is <= 0 */
5587   for (i = minstack; i <= maxstack; ++i)
5588     stack[i] = 0;
5589   for (sptr = gbl.locals; sptr > NOSYM; sptr = SYMLKG(sptr)) {
5590     addr = ADDRESSG(sptr);
5591     size = size_of(DTYPEG(sptr));
5592     lastclash = 0;
5593     for (i = addr; i < addr + size; ++i) {
5594       if (stack[i] != 0) {
5595         if (stack[i] != lastclash)
5596           fprintf(dfile, "sptr %d:%s and %d:%s clash at memory %ld\n", sptr,
5597                   SYMNAME(sptr), stack[i], SYMNAME(stack[i]), i);
5598         lastclash = stack[i];
5599       }
5600       stack[i] = sptr;
5601     }
5602   }
5603   sptr = -1;
5604   totfree = 0;
5605   totused = 0;
5606   for (i = minstack; i <= maxstack; ++i) {
5607     if (stack[i] == 0)
5608       ++totfree;
5609     else
5610       ++totused;
5611     if (stack[i] != sptr) {
5612       sptr = stack[i];
5613       for (j = i; j < maxstack && stack[j + 1] == sptr; ++j)
5614         ;
5615       if (sptr == 0) {
5616         fprintf(dfile, "%8ld:%-8ld           ---free (%ld)\n", i, j, j - i + 1);
5617       } else {
5618         size = size_of(DTYPEG(sptr));
5619         fprintf(dfile, "%8ld:%-8ld %8ld(%%rsp)  %5d:%s (%ld) ", i, j,
5620                 i + 8 - minstack, sptr, SYMNAME(sptr), size);
5621         putdtypex(DTYPEG(sptr), 1000);
5622         fprintf(dfile, "\n");
5623       }
5624     }
5625   }
5626   fprintf(dfile, "%8ld used\n%8ld free\n", totused, totfree);
5627   free(stackmem);
5628 } /* stackcheck */
5629 
5630 #endif /* DEBUG */
5631