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");
105 printf
("\n\n\n#define IT_%s_CODE 0x%x\n", it
,code
);
106 printf
("struct IT_%s { \n", it
);
109 printf
("void sysroff_swap_%s_in(ptr)\n",$2);
110 printf
("struct IT_%s *ptr;\n", it
);
112 printf
("char raw[255];\n");
113 printf
("\tint idx = 0 ;\n");
114 printf
("\tint size;\n");
115 printf
("memset(raw,0,255);\n");
116 printf
("memset(ptr,0,sizeof(*ptr));\n");
117 printf
("size = fillup(raw);\n");
120 printf
("void sysroff_swap_%s_out(file,ptr)\n",$2);
121 printf
("FILE * file;\n");
122 printf
("struct IT_%s *ptr;\n", it
);
124 printf
("\tchar raw[255];\n");
125 printf
("\tint idx = 16 ;\n");
126 printf
("\tmemset (raw, 0, 255);\n");
127 printf
("\tcode = IT_%s_CODE;\n", it
);
130 printf
("void sysroff_swap_%s_out(abfd,ptr)\n",$2);
131 printf
("bfd * abfd;\n");
132 printf
("struct IT_%s *ptr;\n",it
);
134 printf
("int idx = 0 ;\n");
137 printf
("void sysroff_print_%s_out(ptr)\n",$2);
138 printf
("struct IT_%s *ptr;\n", it
);
140 printf
("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
156 printf
("\tchecksum(file,raw, idx, IT_%s_CODE);\n", it
);
170 it_field it_field_list
171 | cond_it_field it_field_list
172 | repeat_it_field it_field_list
176 repeat_it_field: '(' REPEAT NAME
183 printf
("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
185 printf
("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
192 printf
("\t{ int n; for (n = 0; n < %s; n++) {\n", $3);
195 printf
("\t{ int m; for (m = 0; m < %s[n]; m++) {\n", $3);
223 cond_it_field: '(' COND NAME
231 printf
("\tif (%s) {\n", $3);
250 '(' attr_desc
'(' attr_type attr_size
')' attr_id
258 char *p
= names
[rdepth
];
259 char *ptr
= pnames
[rdepth
];
266 printf
("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
268 names
[rdepth
], size
);
272 printf
("\twrite%s(ptr->%s%s,raw,&idx,%d,file);\n",
275 names
[rdepth
],size
/8);
284 printf
("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
294 printf
("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
306 printf
("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
312 printf
("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
320 printf
("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type
,size
/8,size%
8,id
,names
[rdepth
]);
324 printf
("\t/* repeat %s */\n", repeat
);
326 if
(type
[0] == 'I') {
327 printf
("\tint %s%s; \t/* %s */\n",ptr
,id
, desc
);
329 else if
(type
[0] =='C') {
330 printf
("\tchar %s*%s;\t /* %s */\n",ptr
,id
, desc
);
333 printf
("\tbarray %s%s;\t /* %s */\n",ptr
,id
, desc
);
337 printf
("tabout();\n");
338 printf
("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc
, id
);
341 printf
("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id
,p
);
342 else if
(type
[0] == 'C')
343 printf
("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id
,p
);
345 else if
(type
[0] == 'B')
347 printf
("\tpbarray(&ptr->%s%s);\n", id
,p
);
374 '(' NAME
')' { $$
= $2; }
379 |
'(' enum_list
')' ;
383 enum_list
'(' NAME NAME
')' {
387 printf
("#define %s %s\n", $3,$4);
390 printf
("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name
, names
[rdepth
],$4,$3);
401 -d write structure defintions for sysroff in host format
402 -i write functions to swap into sysroff format in
403 -o write functions to swap into sysroff format out
404 -c write code to print info in human form */
416 writecode
= av
[1][1];
417 if
(writecode
== 'd')
419 printf
("typedef struct { unsigned char *data; int len; } barray; \n");
420 printf
("typedef int INT;\n");
421 printf
("typedef char * CHARS;\n");
432 fprintf
(stderr
, "%s\n" , s
);