]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/7c/list.c
1c,2c,7c,kc,vc: honor suppress condition for outstring() in swt.c
[plan9front.git] / sys / src / cmd / 7c / list.c
1 #define EXTERN
2 #include "gc.h"
3
4 void
5 listinit(void)
6 {
7
8         fmtinstall('A', Aconv);
9         fmtinstall('P', Pconv);
10         fmtinstall('S', Sconv);
11         fmtinstall('N', Nconv);
12         fmtinstall('B', Bconv);
13         fmtinstall('D', Dconv);
14 }
15
16 int
17 Bconv(Fmt *fp)
18 {
19         char str[STRINGSZ], ss[STRINGSZ], *s;
20         Bits bits;
21         int i;
22
23         memset(str, 0, sizeof str);
24         bits = va_arg(fp->args, Bits);
25         while(bany(&bits)) {
26                 i = bnum(bits);
27                 if(str[0])
28                         strncat(str, " ", sizeof str - 1);
29                 if(var[i].sym == S) {
30                         snprint(ss, sizeof ss, "$%lld", var[i].offset);
31                         s = ss;
32                 } else
33                         s = var[i].sym->name;
34                 strncat(str, s, sizeof str - 1);
35                 bits.b[i/32] &= ~(1L << (i%32));
36         }
37         return fmtstrcpy(fp, str);
38 }
39
40 int
41 Pconv(Fmt *fp)
42 {
43         char str[STRINGSZ];
44         Prog *p;
45         int a;
46
47         p = va_arg(fp->args, Prog*);
48         a = p->as;
49         if(a == ADATA)
50                 snprint(str, sizeof str, "      %A      %D/%d,%D", a, &p->from, p->reg, &p->to);
51         else
52         if(p->as == ATEXT)
53                 snprint(str, sizeof str, "      %A      %D,%d,%D", a, &p->from, p->reg, &p->to);
54         else
55         if(p->reg == NREG)
56                 snprint(str, sizeof str, "      %A      %D,%D", a, &p->from, &p->to);
57         else
58         if(p->from.type != D_FREG)
59                 snprint(str, sizeof str, "      %A      %D,R%d,%D", a, &p->from, p->reg, &p->to);
60         else
61                 snprint(str, sizeof str, "      %A      %D,F%d,%D", a, &p->from, p->reg, &p->to);
62         return fmtstrcpy(fp, str);
63 }
64
65 int
66 Aconv(Fmt *fp)
67 {
68         char *s;
69         int a;
70
71         a = va_arg(fp->args, int);
72         s = "???";
73         if(a >= AXXX && a < ALAST)
74                 s = anames[a];
75         return fmtstrcpy(fp, s);
76 }
77
78 int
79 Dconv(Fmt *fp)
80 {
81         char str[STRINGSZ];
82         Adr *a;
83
84         a = va_arg(fp->args, Adr*);
85         switch(a->type) {
86
87         default:
88                 snprint(str, sizeof str, "GOK-type(%d)", a->type);
89                 break;
90
91         case D_NONE:
92                 str[0] = 0;
93                 if(a->name != D_NONE || a->reg != NREG || a->sym != S)
94                         snprint(str, sizeof str, "%N(R%d)(NONE)", a, a->reg);
95                 break;
96
97         case D_CONST:
98                 if(a->reg != NREG)
99                         snprint(str, sizeof str, "$%N(R%d)", a, a->reg);
100                 else
101                         snprint(str, sizeof str, "$%N", a);
102                 break;
103
104         case D_OREG:
105                 if(a->reg != NREG)
106                         snprint(str, sizeof str, "%N(R%d)", a, a->reg);
107                 else
108                         snprint(str, sizeof str, "%N", a);
109                 break;
110
111         case D_REG:
112                 snprint(str, sizeof str, "R%d", a->reg);
113                 if(a->name != D_NONE || a->sym != S)
114                         snprint(str, sizeof str, "%N(R%d)(REG)", a, a->reg);
115                 break;
116
117         case D_FREG:
118                 snprint(str, sizeof str, "F%d", a->reg);
119                 if(a->name != D_NONE || a->sym != S)
120                         snprint(str, sizeof str, "%N(R%d)(REG)", a, a->reg);
121                 break;
122
123         case D_FCREG:
124                 snprint(str, sizeof str, "FPCR");
125                 if(a->reg != 0 || a->name != D_NONE || a->sym != S)
126                         snprint(str, sizeof str, "%N(FPCR%d)(REG)", a, a->reg);
127                 break;
128
129         case D_BRANCH:
130                 snprint(str, sizeof str, "%lld(PC)", a->offset-pc);
131                 break;
132
133         case D_FCONST:
134                 snprint(str, sizeof str, "$%.17e", a->dval);
135                 break;
136
137         case D_SCONST:
138                 snprint(str, sizeof str, "$\"%S\"", a->sval);
139                 break;
140         }
141         return fmtstrcpy(fp, str);
142 }
143
144 int
145 Sconv(Fmt *fp)
146 {
147         int i, c;
148         char str[STRINGSZ], *p, *a;
149
150         a = va_arg(fp->args, char*);
151         p = str;
152         for(i=0; i<NSNAME; i++) {
153                 c = a[i] & 0xff;
154                 if(c >= 'a' && c <= 'z' ||
155                    c >= 'A' && c <= 'Z' ||
156                    c >= '0' && c <= '9' ||
157                    c == ' ' || c == '%') {
158                         *p++ = c;
159                         continue;
160                 }
161                 *p++ = '\\';
162                 switch(c) {
163                 case 0:
164                         *p++ = 'z';
165                         continue;
166                 case '\\':
167                 case '"':
168                         *p++ = c;
169                         continue;
170                 case '\n':
171                         *p++ = 'n';
172                         continue;
173                 case '\t':
174                         *p++ = 't';
175                         continue;
176                 case '\r':
177                         *p++ = 'r';
178                         continue;
179                 case '\f':
180                         *p++ = 'f';
181                         continue;
182                 }
183                 *p++ = (c>>6) + '0';
184                 *p++ = ((c>>3) & 7) + '0';
185                 *p++ = (c & 7) + '0';
186         }
187         *p = 0;
188         return fmtstrcpy(fp, str);
189 }
190
191 int
192 Nconv(Fmt *fp)
193 {
194         char str[STRINGSZ];
195         Adr *a;
196         Sym *s;
197
198         a = va_arg(fp->args, Adr*);
199         s = a->sym;
200         if(s == S) {
201                 snprint(str, sizeof str, "%lld", a->offset);
202                 goto out;
203         }
204         switch(a->name) {
205         default:
206                 snprint(str, sizeof str, "GOK-name(%d)", a->name);
207                 break;
208
209         case D_NONE:
210                 snprint(str, sizeof str, "%lld", a->offset);
211                 break;
212
213         case D_EXTERN:
214                 snprint(str, sizeof str, "%s+%lld(SB)", s->name, a->offset);
215                 break;
216
217         case D_STATIC:
218                 snprint(str, sizeof str, "%s<>+%lld(SB)", s->name, a->offset);
219                 break;
220
221         case D_AUTO:
222                 snprint(str, sizeof str, "%s-%lld(SP)", s->name, -a->offset);
223                 break;
224
225         case D_PARAM:
226                 snprint(str, sizeof str, "%s+%lld(FP)", s->name, a->offset);
227                 break;
228         }
229 out:
230         return fmtstrcpy(fp, str);
231 }