Fix AArch64 in the same way as other targets updated in 8170f7693bc0a9442c0aa28019792...
[deliverable/binutils-gdb.git] / binutils / sysinfo.y
CommitLineData
2571583a 1/* Copyright (C) 2001-2017 Free Software Foundation, Inc.
8c2bc687
NC
2 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
3
32866df7 4 This file is part of GNU binutils.
8c2bc687 5
32866df7
NC
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
8c2bc687 10
32866df7
NC
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
8c2bc687 15
32866df7
NC
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
8c2bc687 20
252b5132
RH
21%{
22#include <stdio.h>
23#include <stdlib.h>
24
89b78896
BE
25static char writecode;
26static char *it;
27static int code;
28static char * repeat;
29static char *oldrepeat;
30static char *name;
31static int rdepth;
32static char *names[] = {" ","[n]","[n][m]"};
33static char *pnames[]= {"","*","**"};
dc3c06c2
AM
34
35static int yyerror (char *s);
36extern int yylex (void);
252b5132
RH
37%}
38
39
40%union {
41 int i;
42 char *s;
3aade688 43}
252b5132
RH
44%token COND
45%token REPEAT
46%token '(' ')'
47%token <s> TYPE
48%token <s> NAME
49%token <i> NUMBER UNIT
3aade688 50%type <i> attr_size
252b5132
RH
51%type <s> attr_desc attr_id attr_type
52%%
53
54top: {
55 switch (writecode)
56 {
57 case 'i':
58 printf("#ifdef SYSROFF_SWAP_IN\n");
3aade688 59 break;
252b5132
RH
60 case 'p':
61 printf("#ifdef SYSROFF_p\n");
3aade688 62 break;
252b5132
RH
63 case 'd':
64 break;
65 case 'g':
66 printf("#ifdef SYSROFF_SWAP_OUT\n");
67 break;
68 case 'c':
69 printf("#ifdef SYSROFF_PRINT\n");
70 printf("#include <stdio.h>\n");
71 printf("#include <stdlib.h>\n");
c32144ff 72 printf("#include <ansidecl.h>\n");
252b5132
RH
73 break;
74 }
3aade688 75 }
252b5132
RH
76it_list {
77 switch (writecode) {
78 case 'i':
79 case 'p':
80 case 'g':
81 case 'c':
82 printf("#endif\n");
3aade688 83 break;
252b5132
RH
84 case 'd':
85 break;
86 }
87}
88
89 ;
90
91
92it_list: it it_list
93 |
94 ;
95
96it:
3aade688 97 '(' NAME NUMBER
252b5132
RH
98 {
99 it = $2; code = $3;
3aade688 100 switch (writecode)
252b5132
RH
101 {
102 case 'd':
103 printf("\n\n\n#define IT_%s_CODE 0x%x\n", it,code);
c32144ff 104 printf("struct IT_%s;\n", it);
91d6fa6a 105 printf("extern void sysroff_swap_%s_in (struct IT_%s *);\n",
c32144ff 106 $2, it);
91d6fa6a 107 printf("extern void sysroff_swap_%s_out (FILE *, struct IT_%s *);\n",
c32144ff 108 $2, it);
91d6fa6a 109 printf("extern void sysroff_print_%s_out (struct IT_%s *);\n",
c32144ff 110 $2, it);
252b5132
RH
111 printf("struct IT_%s { \n", it);
112 break;
113 case 'i':
91d6fa6a 114 printf("void sysroff_swap_%s_in (struct IT_%s * ptr)\n",$2,it);
252b5132 115 printf("{\n");
91d6fa6a
NC
116 printf("\tunsigned char raw[255];\n");
117 printf("\tint idx = 0;\n");
252b5132 118 printf("\tint size;\n");
3aade688 119 printf("\tmemset(raw,0,255);\n");
91d6fa6a
NC
120 printf("\tmemset(ptr,0,sizeof(*ptr));\n");
121 printf("\tsize = fillup(raw);\n");
252b5132
RH
122 break;
123 case 'g':
91d6fa6a 124 printf("void sysroff_swap_%s_out (FILE * ffile, struct IT_%s * ptr)\n",$2,it);
252b5132 125 printf("{\n");
dc3c06c2 126 printf("\tunsigned char raw[255];\n");
91d6fa6a 127 printf("\tint idx = 16;\n");
252b5132
RH
128 printf("\tmemset (raw, 0, 255);\n");
129 printf("\tcode = IT_%s_CODE;\n", it);
130 break;
131 case 'o':
91d6fa6a 132 printf("void sysroff_swap_%s_out (bfd * abfd, struct IT_%s * ptr)\n",$2, it);
252b5132 133 printf("{\n");
91d6fa6a 134 printf("\tint idx = 0;\n");
252b5132
RH
135 break;
136 case 'c':
91d6fa6a 137 printf("void sysroff_print_%s_out (struct IT_%s *ptr)\n",$2,it);
252b5132
RH
138 printf("{\n");
139 printf("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
140 break;
141
142 case 't':
143 break;
144 }
145
3aade688
L
146 }
147 it_field_list
252b5132
RH
148')'
149{
150 switch (writecode) {
3aade688 151 case 'd':
252b5132
RH
152 printf("};\n");
153 break;
154 case 'g':
91d6fa6a 155 printf("\tchecksum(ffile,raw, idx, IT_%s_CODE);\n", it);
1a0670f3 156 /* Fall through. */
252b5132 157 case 'i':
252b5132
RH
158 case 'o':
159 case 'c':
160 printf("}\n");
161 }
162}
163;
164
165
166
167it_field_list:
168 it_field it_field_list
3aade688 169 | cond_it_field it_field_list
252b5132
RH
170 | repeat_it_field it_field_list
171 |
172 ;
173
174repeat_it_field: '(' REPEAT NAME
175 {
176 rdepth++;
3aade688 177 switch (writecode)
252b5132
RH
178 {
179 case 'c':
180 if (rdepth==1)
181 printf("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
182 if (rdepth==2)
183 printf("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
1a0670f3 184 /* Fall through. */
252b5132
RH
185 case 'i':
186 case 'g':
187 case 'o':
188
3aade688 189 if (rdepth==1)
252b5132
RH
190 {
191 printf("\t{ int n; for (n = 0; n < %s; n++) {\n", $3);
192 }
193 if (rdepth == 2) {
194 printf("\t{ int m; for (m = 0; m < %s[n]; m++) {\n", $3);
3aade688 195 }
252b5132
RH
196
197 break;
198 }
199
200 oldrepeat = repeat;
201 repeat = $3;
202 }
203
3aade688 204 it_field_list ')'
252b5132
RH
205
206 {
207 repeat = oldrepeat;
208 oldrepeat =0;
209 rdepth--;
210 switch (writecode)
211 {
212 case 'i':
213 case 'g':
214 case 'o':
215 case 'c':
216 printf("\t}}\n");
217 }
218 }
219 ;
220
221
222cond_it_field: '(' COND NAME
223 {
3aade688 224 switch (writecode)
252b5132
RH
225 {
226 case 'i':
227 case 'g':
228 case 'o':
229 case 'c':
230 printf("\tif (%s) {\n", $3);
231 break;
232 }
233 }
234
3aade688 235 it_field_list ')'
252b5132
RH
236 {
237 switch (writecode)
238 {
239 case 'i':
240 case 'g':
241 case 'o':
242 case 'c':
243 printf("\t}\n");
244 }
245 }
246 ;
247
248it_field:
3aade688
L
249 '(' attr_desc '(' attr_type attr_size ')' attr_id
250 {name = $7; }
252b5132
RH
251 enums ')'
252 {
253 char *desc = $2;
254 char *type = $4;
255 int size = $5;
256 char *id = $7;
257char *p = names[rdepth];
258char *ptr = pnames[rdepth];
3aade688 259 switch (writecode)
252b5132
RH
260 {
261 case 'g':
3aade688 262 if (size % 8)
252b5132 263 {
3aade688 264
252b5132
RH
265 printf("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
266 id,
267 names[rdepth], size);
268
269 }
270 else {
91d6fa6a 271 printf("\twrite%s(ptr->%s%s,raw,&idx,%d,ffile);\n",
252b5132
RH
272 type,
273 id,
274 names[rdepth],size/8);
275 }
3aade688 276 break;
252b5132
RH
277 case 'i':
278 {
279
280 if (rdepth >= 1)
281
282 {
3aade688
L
283 printf("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
284 id,
252b5132
RH
285 id,
286 type,
287 repeat,
288 id);
289 }
290
291 if (rdepth == 2)
292 {
3aade688
L
293 printf("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
294 id,
252b5132
RH
295 id,
296 type,
297 repeat,
298 id);
299 }
300
301 }
302
3aade688 303 if (size % 8)
252b5132
RH
304 {
305 printf("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
306 id,
3aade688 307 names[rdepth],
252b5132
RH
308 size);
309 }
310 else {
311 printf("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
312 id,
313 names[rdepth],
314 type,
315 size/8);
316 }
317 break;
318 case 'o':
319 printf("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type,size/8,size%8,id,names[rdepth]);
320 break;
321 case 'd':
3aade688 322 if (repeat)
252b5132
RH
323 printf("\t/* repeat %s */\n", repeat);
324
325 if (type[0] == 'I') {
326 printf("\tint %s%s; \t/* %s */\n",ptr,id, desc);
327 }
328 else if (type[0] =='C') {
329 printf("\tchar %s*%s;\t /* %s */\n",ptr,id, desc);
330 }
331 else {
332 printf("\tbarray %s%s;\t /* %s */\n",ptr,id, desc);
333 }
334 break;
335 case 'c':
336 printf("tabout();\n");
337 printf("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc, id);
338
339 if (type[0] == 'I')
340 printf("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id,p);
341 else if (type[0] == 'C')
342 printf("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id,p);
343
3aade688 344 else if (type[0] == 'B')
252b5132
RH
345 {
346 printf("\tpbarray(&ptr->%s%s);\n", id,p);
347 }
348 else abort();
349 break;
350 }
351 }
352
353 ;
354
355
3aade688 356attr_type:
252b5132
RH
357 TYPE { $$ = $1; }
358 | { $$ = "INT";}
359 ;
360
3aade688
L
361attr_desc:
362 '(' NAME ')'
252b5132
RH
363 { $$ = $2; }
364 ;
365
366attr_size:
3aade688 367 NUMBER UNIT
252b5132
RH
368 { $$ = $1 * $2; }
369 ;
370
371
372attr_id:
373 '(' NAME ')' { $$ = $2; }
374 | { $$ = "dummy";}
3aade688
L
375 ;
376
377enums:
252b5132
RH
378 | '(' enum_list ')' ;
379
380enum_list:
381 |
3aade688
L
382 enum_list '(' NAME NAME ')' {
383 switch (writecode)
252b5132
RH
384 {
385 case 'd':
386 printf("#define %s %s\n", $3,$4);
387 break;
388 case 'c':
389 printf("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name, names[rdepth],$4,$3);
390 }
391 }
392
393 ;
394
395
396
397%%
398/* four modes
399
50c2245b 400 -d write structure definitions for sysroff in host format
252b5132
RH
401 -i write functions to swap into sysroff format in
402 -o write functions to swap into sysroff format out
403 -c write code to print info in human form */
404
405int yydebug;
252b5132 406
3aade688 407int
2da42df6 408main (int ac, char **av)
252b5132
RH
409{
410 yydebug=0;
411 if (ac > 1)
412 writecode = av[1][1];
413if (writecode == 'd')
414 {
415 printf("typedef struct { unsigned char *data; int len; } barray; \n");
416 printf("typedef int INT;\n");
417 printf("typedef char * CHARS;\n");
418
419 }
420 yyparse();
421return 0;
422}
423
dc3c06c2 424static int
2da42df6 425yyerror (char *s)
252b5132
RH
426{
427 fprintf(stderr, "%s\n" , s);
428 return 0;
429}
This page took 0.705986 seconds and 4 git commands to generate.