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