Pristine Ack-5.5
[Ack-5.5.git] / util / ego / cs / cs_debug.c
1 /* $Id: cs_debug.c,v 1.8 1994/06/24 10:22:03 ceriel Exp $ */
2 /*
3  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4  * See the copyright notice in the ACK home directory, in the file "Copyright".
5  */
6 #include <stdio.h>
7 #include <em_spec.h>
8 #include "../share/types.h"
9 #include "../share/debug.h"
10 #include "../share/lset.h"
11 #include "cs.h"
12 #include "cs_aux.h"
13 #include "cs_avail.h"
14 #include "cs_entity.h"
15
16 #ifdef VERBOSE
17
18 extern char em_mnem[]; /* The mnemonics of the EM instructions. */
19
20 STATIC showinstr(lnp)
21         line_p lnp;
22 {
23         /* Makes the instruction in `lnp' human readable. Only lines that
24          * can occur in expressions that are going to be eliminated are
25          * properly handled.
26          */
27         if (INSTR(lnp) < sp_fmnem && INSTR(lnp) > sp_lmnem) {
28                 fprintf(stderr,"*** ?\n");
29                 return;
30         }
31
32         fprintf(stderr,"%s", &em_mnem[4 * (INSTR(lnp)-sp_fmnem)]);
33         switch (TYPE(lnp)) {
34                 case OPNO:
35                         break;
36                 case OPSHORT:
37                         fprintf(stderr," %d", SHORT(lnp));
38                         break;
39                 case OPOBJECT:
40                         fprintf(stderr," %d", OBJ(lnp)->o_id);
41                         break;
42                 case OPOFFSET:
43                         fprintf(stderr," %ld", OFFSET(lnp));
44                         break;
45                 default:
46                         fprintf(stderr," ?");
47                         break;
48         }
49         fprintf(stderr,"\n");
50 }
51
52 SHOWOCCUR(ocp)
53         occur_p ocp;
54 {
55         /* Shows all instructions in an occurrence. */
56
57         register line_p lnp, next;
58
59         if (verbose_flag) {
60                 for (lnp = ocp->oc_lfirst; lnp != (line_p) 0; lnp = next) {
61                         next = lnp == ocp->oc_llast ? (line_p) 0 : lnp->l_next;
62
63                         showinstr(lnp);
64                 }
65         }
66 }
67
68 #endif
69
70 #ifdef TRACE
71
72 SHOWAVAIL(avp)
73         avail_p avp;
74 {
75         /* Shows an available expression. */
76         showinstr(avp->av_found);
77         fprintf(stderr,"result %d,", avp->av_result);
78         fprintf(stderr,"occurred %d times\n", Lnrelems(avp->av_occurs) + 1);
79
80 }
81
82 OUTAVAILS()
83 {
84         register avail_p ravp;
85
86         fprintf(stderr,"AVAILABLE EXPRESSIONS\n");
87
88         for (ravp = avails; ravp != (avail_p) 0; ravp = ravp->av_before) {
89                 SHOWAVAIL(ravp);
90                 fprintf(stderr,"\n");
91         }
92 }
93
94 STATIC char *enkinds[] = {
95         "constant",
96         "local",
97         "external",
98         "indirect",
99         "offsetted",
100         "address of local",
101         "address of external",
102         "address of offsetted",
103         "address of local base",
104         "address of argument base",
105         "procedure",
106         "floating zero",
107         "array element",
108         "local base",
109         "heap pointer",
110         "ignore mask"
111 };
112
113 OUTENTITIES()
114 {
115         register Lindex i;
116
117         fprintf(stderr,"ENTITIES\n");
118         for (i = Lfirst(entities); i != (Lindex) 0; i = Lnext(i, entities)) {
119                 register entity_p rep = en_elem(i);
120
121                 fprintf(stderr,"%s,", enkinds[rep->en_kind]);
122                 fprintf(stderr,"size %ld,", rep->en_size);
123                 fprintf(stderr,"valno %d,", rep->en_vn);
124                 switch (rep->en_kind) {
125                         case ENCONST:
126                                 fprintf(stderr,"$%ld\n", rep->en_val);
127                                 break;
128                         case ENLOCAL:
129                         case ENALOCAL:
130                                 fprintf(stderr,"%ld(LB)\n", rep->en_loc);
131                                 break;
132                         case ENINDIR:
133                                 fprintf(stderr,"*%d\n", rep->en_ind);
134                                 break;
135                         case ENOFFSETTED:
136                         case ENAOFFSETTED:
137                                 fprintf(stderr,"%ld(%d)\n", rep->en_off, rep->en_base);
138                                 break;
139                         case ENALOCBASE:
140                         case ENAARGBASE:
141                                 fprintf(stderr,"%ld levels\n", rep->en_levels);
142                                 break;
143                         case ENARRELEM:
144                                 fprintf(stderr,"%d[%d], ",rep->en_arbase,rep->en_index);
145                                 fprintf(stderr,"rom at %d\n", rep->en_adesc);
146                                 break;
147                 }
148                 fprintf(stderr,"\n");
149         }
150 }
151
152 #endif /* TRACE */