1 /* Copyright (C) 2001-2022 Free Software Foundation, Inc.
2 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
4 This file is part of GNU binutils.
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.
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.
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. */
26 static char writecode
;
30 static char *oldrepeat
;
33 static char *names
[] = {" ","[n]","[n][m]"};
34 static char *pnames
[]= {"","*","**"};
36 static void yyerror (const char *s
);
37 extern
int yylex (void);
50 %token
<i
> NUMBER UNIT
52 %type
<s
> attr_desc attr_id attr_type
59 printf
("#ifdef SYSROFF_SWAP_IN\n");
62 printf
("#ifdef SYSROFF_p\n");
67 printf
("#ifdef SYSROFF_SWAP_OUT\n");
70 printf
("#ifdef SYSROFF_PRINT\n");
71 printf
("#include <stdio.h>\n");
72 printf
("#include <stdlib.h>\n");
73 printf
("#include <ansidecl.h>\n");
104 printf
("\n\n\n#define IT_%s_CODE 0x%x\n", it
,code
);
105 printf
("struct IT_%s;\n", it
);
106 printf
("extern void sysroff_swap_%s_in (struct IT_%s *);\n",
108 printf
("extern void sysroff_swap_%s_out (FILE *, struct IT_%s *);\n",
110 printf
("extern void sysroff_print_%s_out (struct IT_%s *);\n",
112 printf
("struct IT_%s { \n", it
);
115 printf
("void sysroff_swap_%s_in (struct IT_%s * ptr)\n",$2,it
);
117 printf
("\tunsigned char raw[255];\n");
118 printf
("\tint idx = 0;\n");
119 printf
("\tint size;\n");
120 printf
("\tmemset(raw,0,255);\n");
121 printf
("\tmemset(ptr,0,sizeof(*ptr));\n");
122 printf
("\tsize = fillup(raw);\n");
125 printf
("void sysroff_swap_%s_out (FILE * ffile, struct IT_%s * ptr)\n",$2,it
);
127 printf
("\tunsigned char raw[255];\n");
128 printf
("\tint idx = 16;\n");
129 printf
("\tmemset (raw, 0, 255);\n");
130 printf
("\tcode = IT_%s_CODE;\n", it
);
133 printf
("void sysroff_swap_%s_out (bfd * abfd, struct IT_%s * ptr)\n",$2, it
);
135 printf
("\tint idx = 0;\n");
138 printf
("void sysroff_print_%s_out (struct IT_%s *ptr)\n",$2,it
);
140 printf
("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
156 printf
("\tchecksum(ffile,raw, idx, IT_%s_CODE);\n", it
);
171 it_field it_field_list
172 | cond_it_field it_field_list
173 | repeat_it_field it_field_list
177 repeat_it_field: '(' REPEAT NAME
184 printf
("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
186 printf
("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
194 printf
("\t{ int n; for (n = 0; n < %s; n++) {\n", $3);
197 printf
("\t{ int m; for (m = 0; m < %s[n]; m++) {\n", $3);
227 cond_it_field: '(' COND NAME
235 printf
("\tif (%s) {\n", $3);
256 '(' attr_desc
'(' attr_type attr_size
')' attr_id
264 char *p
= names
[rdepth
];
265 char *ptr
= pnames
[rdepth
];
272 printf
("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
274 names
[rdepth
], size
);
278 printf
("\twrite%s(ptr->%s%s,raw,&idx,%d,ffile);\n",
281 names
[rdepth
],size
/8);
290 printf
("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
300 printf
("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
312 printf
("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
318 printf
("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
326 printf
("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type
,size
/8,size%
8,id
,names
[rdepth
]);
330 printf
("\t/* repeat %s */\n", repeat
);
332 if
(type
[0] == 'I') {
333 printf
("\tint %s%s; \t/* %s */\n",ptr
,id
, desc
);
335 else if
(type
[0] =='C') {
336 printf
("\tchar %s*%s;\t /* %s */\n",ptr
,id
, desc
);
339 printf
("\tbarray %s%s;\t /* %s */\n",ptr
,id
, desc
);
343 printf
("tabout();\n");
344 printf
("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc
, id
);
347 printf
("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id
,p
);
348 else if
(type
[0] == 'C')
349 printf
("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id
,p
);
351 else if
(type
[0] == 'B')
353 printf
("\tpbarray(&ptr->%s%s);\n", id
,p
);
383 '(' NAME
')' { $$
= $2; }
384 |
{ $$
= strdup
("dummy");}
388 |
'(' enum_list
')' ;
392 enum_list
'(' NAME NAME
')' {
396 printf
("#define %s %s\n", $3,$4);
399 printf
("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name
, names
[rdepth
],$4,$3);
413 -d write structure definitions for sysroff in host format
414 -i write functions to swap into sysroff format in
415 -o write functions to swap into sysroff format out
416 -c write code to print info in human form */
421 main
(int ac
, char **av
)
425 writecode
= av
[1][1];
426 if
(writecode
== 'd')
428 printf
("typedef struct { unsigned char *data; int len; } barray; \n");
429 printf
("typedef int INT;\n");
430 printf
("typedef char * CHARS;\n");
438 yyerror (const char *s
)
440 fprintf
(stderr
, "%s\n" , s
);