1 /* Copyright 2001, 2003, 2005 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 static char writecode
;
28 static char *oldrepeat
;
31 static char *names
[] = {" ","[n]","[n][m]"};
32 static char *pnames
[]= {"","*","**"};
34 static int yyerror (char *s
);
35 extern
int yylex (void);
48 %token
<i
> NUMBER UNIT
50 %type
<s
> attr_desc attr_id attr_type
57 printf
("#ifdef SYSROFF_SWAP_IN\n");
60 printf
("#ifdef SYSROFF_p\n");
65 printf
("#ifdef SYSROFF_SWAP_OUT\n");
68 printf
("#ifdef SYSROFF_PRINT\n");
69 printf
("#include <stdio.h>\n");
70 printf
("#include <stdlib.h>\n");
71 printf
("#include <ansidecl.h>\n");
102 printf
("\n\n\n#define IT_%s_CODE 0x%x\n", it
,code
);
103 printf
("struct IT_%s;\n", it
);
104 printf
("extern void sysroff_swap_%s_in PARAMS ((struct IT_%s *));\n",
106 printf
("extern void sysroff_swap_%s_out PARAMS ((FILE *, struct IT_%s *));\n",
108 printf
("extern void sysroff_print_%s_out PARAMS ((struct IT_%s *));\n",
110 printf
("struct IT_%s { \n", it
);
113 printf
("void sysroff_swap_%s_in(ptr)\n",$2);
114 printf
("struct IT_%s *ptr;\n", it
);
116 printf
("unsigned char raw[255];\n");
117 printf
("\tint idx = 0 ;\n");
118 printf
("\tint size;\n");
119 printf
("memset(raw,0,255);\n");
120 printf
("memset(ptr,0,sizeof(*ptr));\n");
121 printf
("size = fillup(raw);\n");
124 printf
("void sysroff_swap_%s_out(file,ptr)\n",$2);
125 printf
("FILE * file;\n");
126 printf
("struct IT_%s *ptr;\n", it
);
128 printf
("\tunsigned char raw[255];\n");
129 printf
("\tint idx = 16 ;\n");
130 printf
("\tmemset (raw, 0, 255);\n");
131 printf
("\tcode = IT_%s_CODE;\n", it
);
134 printf
("void sysroff_swap_%s_out(abfd,ptr)\n",$2);
135 printf
("bfd * abfd;\n");
136 printf
("struct IT_%s *ptr;\n",it
);
138 printf
("int idx = 0 ;\n");
141 printf
("void sysroff_print_%s_out(ptr)\n",$2);
142 printf
("struct IT_%s *ptr;\n", it
);
144 printf
("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
160 printf
("\tchecksum(file,raw, idx, IT_%s_CODE);\n", it
);
174 it_field it_field_list
175 | cond_it_field it_field_list
176 | repeat_it_field it_field_list
180 repeat_it_field: '(' REPEAT NAME
187 printf
("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
189 printf
("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
196 printf
("\t{ int n; for (n = 0; n < %s; n++) {\n", $3);
199 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);
254 '(' attr_desc
'(' attr_type attr_size
')' attr_id
262 char *p
= names
[rdepth
];
263 char *ptr
= pnames
[rdepth
];
270 printf
("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
272 names
[rdepth
], size
);
276 printf
("\twrite%s(ptr->%s%s,raw,&idx,%d,file);\n",
279 names
[rdepth
],size
/8);
288 printf
("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
298 printf
("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
310 printf
("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
316 printf
("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
324 printf
("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type
,size
/8,size%
8,id
,names
[rdepth
]);
328 printf
("\t/* repeat %s */\n", repeat
);
330 if
(type
[0] == 'I') {
331 printf
("\tint %s%s; \t/* %s */\n",ptr
,id
, desc
);
333 else if
(type
[0] =='C') {
334 printf
("\tchar %s*%s;\t /* %s */\n",ptr
,id
, desc
);
337 printf
("\tbarray %s%s;\t /* %s */\n",ptr
,id
, desc
);
341 printf
("tabout();\n");
342 printf
("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc
, id
);
345 printf
("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id
,p
);
346 else if
(type
[0] == 'C')
347 printf
("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id
,p
);
349 else if
(type
[0] == 'B')
351 printf
("\tpbarray(&ptr->%s%s);\n", id
,p
);
378 '(' NAME
')' { $$
= $2; }
383 |
'(' enum_list
')' ;
387 enum_list
'(' NAME NAME
')' {
391 printf
("#define %s %s\n", $3,$4);
394 printf
("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name
, names
[rdepth
],$4,$3);
405 -d write structure definitions for sysroff in host format
406 -i write functions to swap into sysroff format in
407 -o write functions to swap into sysroff format out
408 -c write code to print info in human form */
413 main
(int ac
, char **av
)
417 writecode
= av
[1][1];
418 if
(writecode
== 'd')
420 printf
("typedef struct { unsigned char *data; int len; } barray; \n");
421 printf
("typedef int INT;\n");
422 printf
("typedef char * CHARS;\n");
432 fprintf
(stderr
, "%s\n" , s
);