This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / binutils / sysinfo.y
1 %{
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 extern char *word;
6 extern char writecode;
7 extern int number;
8 extern int unit;
9 char nice_name[1000];
10 char *it;
11 int sofar;
12 int width;
13 int code;
14 char * repeat;
15 char *oldrepeat;
16 char *name;
17 int rdepth;
18 char *loop [] = {"","n","m","/*BAD*/"};
19 char *names[] = {" ","[n]","[n][m]"};
20 char *pnames[]= {"","*","**"};
21 %}
22
23
24 %union {
25 int i;
26 char *s;
27 }
28 %token COND
29 %token REPEAT
30 %token '(' ')'
31 %token <s> TYPE
32 %token <s> NAME
33 %token <i> NUMBER UNIT
34 %type <i> attr_size
35 %type <s> attr_desc attr_id attr_type
36 %%
37
38 top: {
39 switch (writecode)
40 {
41 case 'i':
42 printf("#ifdef SYSROFF_SWAP_IN\n");
43 break;
44 case 'p':
45 printf("#ifdef SYSROFF_p\n");
46 break;
47 case 'd':
48 break;
49 case 'g':
50 printf("#ifdef SYSROFF_SWAP_OUT\n");
51 break;
52 case 'c':
53 printf("#ifdef SYSROFF_PRINT\n");
54 printf("#include <stdio.h>\n");
55 printf("#include <stdlib.h>\n");
56 break;
57 }
58 }
59 it_list {
60 switch (writecode) {
61 case 'i':
62 case 'p':
63 case 'g':
64 case 'c':
65 printf("#endif\n");
66 break;
67 case 'd':
68 break;
69 }
70 }
71
72 ;
73
74
75 it_list: it it_list
76 |
77 ;
78
79 it:
80 '(' NAME NUMBER
81 {
82 it = $2; code = $3;
83 switch (writecode)
84 {
85 case 'd':
86 printf("\n\n\n#define IT_%s_CODE 0x%x\n", it,code);
87 printf("struct IT_%s { \n", it);
88 break;
89 case 'i':
90 printf("void sysroff_swap_%s_in(ptr)\n",$2);
91 printf("struct IT_%s *ptr;\n", it);
92 printf("{\n");
93 printf("char raw[255];\n");
94 printf("\tint idx = 0 ;\n");
95 printf("\tint size;\n");
96 printf("memset(raw,0,255);\n");
97 printf("memset(ptr,0,sizeof(*ptr));\n");
98 printf("size = fillup(raw);\n");
99 break;
100 case 'g':
101 printf("void sysroff_swap_%s_out(file,ptr)\n",$2);
102 printf("FILE * file;\n");
103 printf("struct IT_%s *ptr;\n", it);
104 printf("{\n");
105 printf("\tchar raw[255];\n");
106 printf("\tint idx = 16 ;\n");
107 printf("\tmemset (raw, 0, 255);\n");
108 printf("\tcode = IT_%s_CODE;\n", it);
109 break;
110 case 'o':
111 printf("void sysroff_swap_%s_out(abfd,ptr)\n",$2);
112 printf("bfd * abfd;\n");
113 printf("struct IT_%s *ptr;\n",it);
114 printf("{\n");
115 printf("int idx = 0 ;\n");
116 break;
117 case 'c':
118 printf("void sysroff_print_%s_out(ptr)\n",$2);
119 printf("struct IT_%s *ptr;\n", it);
120 printf("{\n");
121 printf("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
122 break;
123
124 case 't':
125 break;
126 }
127
128 }
129 it_field_list
130 ')'
131 {
132 switch (writecode) {
133 case 'd':
134 printf("};\n");
135 break;
136 case 'g':
137 printf("\tchecksum(file,raw, idx, IT_%s_CODE);\n", it);
138
139 case 'i':
140
141 case 'o':
142 case 'c':
143 printf("}\n");
144 }
145 }
146 ;
147
148
149
150 it_field_list:
151 it_field it_field_list
152 | cond_it_field it_field_list
153 | repeat_it_field it_field_list
154 |
155 ;
156
157 repeat_it_field: '(' REPEAT NAME
158 {
159 rdepth++;
160 switch (writecode)
161 {
162 case 'c':
163 if (rdepth==1)
164 printf("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
165 if (rdepth==2)
166 printf("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
167 case 'i':
168 case 'g':
169 case 'o':
170
171 if (rdepth==1)
172 {
173 printf("\t{ int n; for (n = 0; n < %s; n++) {\n", $3);
174 }
175 if (rdepth == 2) {
176 printf("\t{ int m; for (m = 0; m < %s[n]; m++) {\n", $3);
177 }
178
179 break;
180 }
181
182 oldrepeat = repeat;
183 repeat = $3;
184 }
185
186 it_field_list ')'
187
188 {
189 repeat = oldrepeat;
190 oldrepeat =0;
191 rdepth--;
192 switch (writecode)
193 {
194 case 'i':
195 case 'g':
196 case 'o':
197 case 'c':
198 printf("\t}}\n");
199 }
200 }
201 ;
202
203
204 cond_it_field: '(' COND NAME
205 {
206 switch (writecode)
207 {
208 case 'i':
209 case 'g':
210 case 'o':
211 case 'c':
212 printf("\tif (%s) {\n", $3);
213 break;
214 }
215 }
216
217 it_field_list ')'
218 {
219 switch (writecode)
220 {
221 case 'i':
222 case 'g':
223 case 'o':
224 case 'c':
225 printf("\t}\n");
226 }
227 }
228 ;
229
230 it_field:
231 '(' attr_desc '(' attr_type attr_size ')' attr_id
232 {name = $7; }
233 enums ')'
234 {
235 char *desc = $2;
236 char *type = $4;
237 int size = $5;
238 char *id = $7;
239 char *p = names[rdepth];
240 char *ptr = pnames[rdepth];
241 switch (writecode)
242 {
243 case 'g':
244 if (size % 8)
245 {
246
247 printf("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
248 id,
249 names[rdepth], size);
250
251 }
252 else {
253 printf("\twrite%s(ptr->%s%s,raw,&idx,%d,file);\n",
254 type,
255 id,
256 names[rdepth],size/8);
257 }
258 break;
259 case 'i':
260 {
261
262 if (rdepth >= 1)
263
264 {
265 printf("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
266 id,
267 id,
268 type,
269 repeat,
270 id);
271 }
272
273 if (rdepth == 2)
274 {
275 printf("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
276 id,
277 id,
278 type,
279 repeat,
280 id);
281 }
282
283 }
284
285 if (size % 8)
286 {
287 printf("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
288 id,
289 names[rdepth],
290 size);
291 }
292 else {
293 printf("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
294 id,
295 names[rdepth],
296 type,
297 size/8);
298 }
299 break;
300 case 'o':
301 printf("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type,size/8,size%8,id,names[rdepth]);
302 break;
303 case 'd':
304 if (repeat)
305 printf("\t/* repeat %s */\n", repeat);
306
307 if (type[0] == 'I') {
308 printf("\tint %s%s; \t/* %s */\n",ptr,id, desc);
309 }
310 else if (type[0] =='C') {
311 printf("\tchar %s*%s;\t /* %s */\n",ptr,id, desc);
312 }
313 else {
314 printf("\tbarray %s%s;\t /* %s */\n",ptr,id, desc);
315 }
316 break;
317 case 'c':
318 printf("tabout();\n");
319 printf("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc, id);
320
321 if (type[0] == 'I')
322 printf("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id,p);
323 else if (type[0] == 'C')
324 printf("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id,p);
325
326 else if (type[0] == 'B')
327 {
328 printf("\tpbarray(&ptr->%s%s);\n", id,p);
329 }
330 else abort();
331 break;
332 }
333 }
334
335 ;
336
337
338 attr_type:
339 TYPE { $$ = $1; }
340 | { $$ = "INT";}
341 ;
342
343 attr_desc:
344 '(' NAME ')'
345 { $$ = $2; }
346 ;
347
348 attr_size:
349 NUMBER UNIT
350 { $$ = $1 * $2; }
351 ;
352
353
354 attr_id:
355 '(' NAME ')' { $$ = $2; }
356 | { $$ = "dummy";}
357 ;
358
359 enums:
360 | '(' enum_list ')' ;
361
362 enum_list:
363 |
364 enum_list '(' NAME NAME ')' {
365 switch (writecode)
366 {
367 case 'd':
368 printf("#define %s %s\n", $3,$4);
369 break;
370 case 'c':
371 printf("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name, names[rdepth],$4,$3);
372 }
373 }
374
375 ;
376
377
378
379 %%
380 /* four modes
381
382 -d write structure defintions for sysroff in host format
383 -i write functions to swap into sysroff format in
384 -o write functions to swap into sysroff format out
385 -c write code to print info in human form */
386
387 int yydebug;
388 char writecode;
389
390 int
391 main(ac,av)
392 int ac;
393 char **av;
394 {
395 yydebug=0;
396 if (ac > 1)
397 writecode = av[1][1];
398 if (writecode == 'd')
399 {
400 printf("typedef struct { unsigned char *data; int len; } barray; \n");
401 printf("typedef int INT;\n");
402 printf("typedef char * CHARS;\n");
403
404 }
405 yyparse();
406 return 0;
407 }
408
409 int
410 yyerror(s)
411 char *s;
412 {
413 fprintf(stderr, "%s\n" , s);
414 return 0;
415 }
This page took 0.038658 seconds and 5 git commands to generate.