1 /* Copyright 2001 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 extern
char writecode
;
37 char *loop
[] = {"","n","m","/*BAD*/"};
38 char *names
[] = {" ","[n]","[n][m]"};
39 char *pnames
[]= {"","*","**"};
52 %token
<i
> NUMBER UNIT
54 %type
<s
> attr_desc attr_id attr_type
61 printf
("#ifdef SYSROFF_SWAP_IN\n");
64 printf
("#ifdef SYSROFF_p\n");
69 printf
("#ifdef SYSROFF_SWAP_OUT\n");
72 printf
("#ifdef SYSROFF_PRINT\n");
73 printf
("#include <stdio.h>\n");
74 printf
("#include <stdlib.h>\n");
75 printf
("#include <ansidecl.h>\n");
106 printf
("\n\n\n#define IT_%s_CODE 0x%x\n", it
,code
);
107 printf
("struct IT_%s;\n", it
);
108 printf
("extern void sysroff_swap_%s_in PARAMS ((struct IT_%s *));\n",
110 printf
("extern void sysroff_swap_%s_out PARAMS ((FILE *, struct IT_%s *));\n",
112 printf
("extern void sysroff_print_%s_out PARAMS ((struct IT_%s *));\n",
114 printf
("struct IT_%s { \n", it
);
117 printf
("void sysroff_swap_%s_in(ptr)\n",$2);
118 printf
("struct IT_%s *ptr;\n", it
);
120 printf
("char raw[255];\n");
121 printf
("\tint idx = 0 ;\n");
122 printf
("\tint size;\n");
123 printf
("memset(raw,0,255);\n");
124 printf
("memset(ptr,0,sizeof(*ptr));\n");
125 printf
("size = fillup(raw);\n");
128 printf
("void sysroff_swap_%s_out(file,ptr)\n",$2);
129 printf
("FILE * file;\n");
130 printf
("struct IT_%s *ptr;\n", it
);
132 printf
("\tchar raw[255];\n");
133 printf
("\tint idx = 16 ;\n");
134 printf
("\tmemset (raw, 0, 255);\n");
135 printf
("\tcode = IT_%s_CODE;\n", it
);
138 printf
("void sysroff_swap_%s_out(abfd,ptr)\n",$2);
139 printf
("bfd * abfd;\n");
140 printf
("struct IT_%s *ptr;\n",it
);
142 printf
("int idx = 0 ;\n");
145 printf
("void sysroff_print_%s_out(ptr)\n",$2);
146 printf
("struct IT_%s *ptr;\n", it
);
148 printf
("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
164 printf
("\tchecksum(file,raw, idx, IT_%s_CODE);\n", it
);
178 it_field it_field_list
179 | cond_it_field it_field_list
180 | repeat_it_field it_field_list
184 repeat_it_field: '(' REPEAT NAME
191 printf
("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
193 printf
("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
200 printf
("\t{ int n; for (n = 0; n < %s; n++) {\n", $3);
203 printf
("\t{ int m; for (m = 0; m < %s[n]; m++) {\n", $3);
231 cond_it_field: '(' COND NAME
239 printf
("\tif (%s) {\n", $3);
258 '(' attr_desc
'(' attr_type attr_size
')' attr_id
266 char *p
= names
[rdepth
];
267 char *ptr
= pnames
[rdepth
];
274 printf
("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
276 names
[rdepth
], size
);
280 printf
("\twrite%s(ptr->%s%s,raw,&idx,%d,file);\n",
283 names
[rdepth
],size
/8);
292 printf
("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
302 printf
("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
314 printf
("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
320 printf
("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
328 printf
("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type
,size
/8,size%
8,id
,names
[rdepth
]);
332 printf
("\t/* repeat %s */\n", repeat
);
334 if
(type
[0] == 'I') {
335 printf
("\tint %s%s; \t/* %s */\n",ptr
,id
, desc
);
337 else if
(type
[0] =='C') {
338 printf
("\tchar %s*%s;\t /* %s */\n",ptr
,id
, desc
);
341 printf
("\tbarray %s%s;\t /* %s */\n",ptr
,id
, desc
);
345 printf
("tabout();\n");
346 printf
("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc
, id
);
349 printf
("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id
,p
);
350 else if
(type
[0] == 'C')
351 printf
("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id
,p
);
353 else if
(type
[0] == 'B')
355 printf
("\tpbarray(&ptr->%s%s);\n", id
,p
);
382 '(' NAME
')' { $$
= $2; }
387 |
'(' enum_list
')' ;
391 enum_list
'(' NAME NAME
')' {
395 printf
("#define %s %s\n", $3,$4);
398 printf
("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name
, names
[rdepth
],$4,$3);
409 -d write structure defintions for sysroff in host format
410 -i write functions to swap into sysroff format in
411 -o write functions to swap into sysroff format out
412 -c write code to print info in human form */
424 writecode
= av
[1][1];
425 if
(writecode
== 'd')
427 printf
("typedef struct { unsigned char *data; int len; } barray; \n");
428 printf
("typedef int INT;\n");
429 printf
("typedef char * CHARS;\n");
440 fprintf
(stderr
, "%s\n" , s
);