X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=binutils%2Fsysinfo.y;h=8e8897f79e25c95e9425b415d2bf200850135435;hb=39f34d7b64ee76e07b82a3e57800905d249d8005;hp=a7077480bc4a2ccfc793a12de59acb774907f3fe;hpb=01f0fe5e0450edf168c1f612feb93cf588e4e7ea;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/sysinfo.y b/binutils/sysinfo.y index a7077480bc..8e8897f79e 100644 --- a/binutils/sysinfo.y +++ b/binutils/sysinfo.y @@ -1,25 +1,27 @@ -/* Copyright 2001, 2003, 2005 Free Software Foundation, Inc. +/* Copyright (C) 2001-2019 Free Software Foundation, Inc. Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com). -This file is part of GNU binutils. + This file is part of GNU binutils. -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ %{ #include #include +#include static char writecode; static char *it; @@ -39,14 +41,14 @@ extern int yylex (void); %union { int i; char *s; -} +} %token COND %token REPEAT %token '(' ')' %token TYPE %token NAME %token NUMBER UNIT -%type attr_size +%type attr_size %type attr_desc attr_id attr_type %% @@ -55,10 +57,10 @@ top: { { case 'i': printf("#ifdef SYSROFF_SWAP_IN\n"); - break; + break; case 'p': printf("#ifdef SYSROFF_p\n"); - break; + break; case 'd': break; case 'g': @@ -71,7 +73,7 @@ top: { printf("#include \n"); break; } - } + } it_list { switch (writecode) { case 'i': @@ -79,7 +81,7 @@ it_list { case 'g': case 'c': printf("#endif\n"); - break; + break; case 'd': break; } @@ -93,53 +95,47 @@ it_list: it it_list ; it: - '(' NAME NUMBER + '(' NAME NUMBER { it = $2; code = $3; - switch (writecode) + switch (writecode) { case 'd': printf("\n\n\n#define IT_%s_CODE 0x%x\n", it,code); printf("struct IT_%s;\n", it); - printf("extern void sysroff_swap_%s_in PARAMS ((struct IT_%s *));\n", + printf("extern void sysroff_swap_%s_in (struct IT_%s *);\n", $2, it); - printf("extern void sysroff_swap_%s_out PARAMS ((FILE *, struct IT_%s *));\n", + printf("extern void sysroff_swap_%s_out (FILE *, struct IT_%s *);\n", $2, it); - printf("extern void sysroff_print_%s_out PARAMS ((struct IT_%s *));\n", + printf("extern void sysroff_print_%s_out (struct IT_%s *);\n", $2, it); printf("struct IT_%s { \n", it); break; case 'i': - printf("void sysroff_swap_%s_in(ptr)\n",$2); - printf("struct IT_%s *ptr;\n", it); + printf("void sysroff_swap_%s_in (struct IT_%s * ptr)\n",$2,it); printf("{\n"); - printf("unsigned char raw[255];\n"); - printf("\tint idx = 0 ;\n"); + printf("\tunsigned char raw[255];\n"); + printf("\tint idx = 0;\n"); printf("\tint size;\n"); - printf("memset(raw,0,255);\n"); - printf("memset(ptr,0,sizeof(*ptr));\n"); - printf("size = fillup(raw);\n"); + printf("\tmemset(raw,0,255);\n"); + printf("\tmemset(ptr,0,sizeof(*ptr));\n"); + printf("\tsize = fillup(raw);\n"); break; case 'g': - printf("void sysroff_swap_%s_out(file,ptr)\n",$2); - printf("FILE * file;\n"); - printf("struct IT_%s *ptr;\n", it); + printf("void sysroff_swap_%s_out (FILE * ffile, struct IT_%s * ptr)\n",$2,it); printf("{\n"); printf("\tunsigned char raw[255];\n"); - printf("\tint idx = 16 ;\n"); + printf("\tint idx = 16;\n"); printf("\tmemset (raw, 0, 255);\n"); printf("\tcode = IT_%s_CODE;\n", it); break; case 'o': - printf("void sysroff_swap_%s_out(abfd,ptr)\n",$2); - printf("bfd * abfd;\n"); - printf("struct IT_%s *ptr;\n",it); + printf("void sysroff_swap_%s_out (bfd * abfd, struct IT_%s * ptr)\n",$2, it); printf("{\n"); - printf("int idx = 0 ;\n"); + printf("\tint idx = 0;\n"); break; case 'c': - printf("void sysroff_print_%s_out(ptr)\n",$2); - printf("struct IT_%s *ptr;\n", it); + printf("void sysroff_print_%s_out (struct IT_%s *ptr)\n",$2,it); printf("{\n"); printf("itheader(\"%s\", IT_%s_CODE);\n",$2,$2); break; @@ -148,23 +144,24 @@ it: break; } - } - it_field_list + } + it_field_list ')' { switch (writecode) { - case 'd': + case 'd': printf("};\n"); break; case 'g': - printf("\tchecksum(file,raw, idx, IT_%s_CODE);\n", it); - + printf("\tchecksum(ffile,raw, idx, IT_%s_CODE);\n", it); + /* Fall through. */ case 'i': - case 'o': case 'c': printf("}\n"); } + + free (it); } ; @@ -172,7 +169,7 @@ it: it_field_list: it_field it_field_list - | cond_it_field it_field_list + | cond_it_field it_field_list | repeat_it_field it_field_list | ; @@ -180,24 +177,25 @@ it_field_list: repeat_it_field: '(' REPEAT NAME { rdepth++; - switch (writecode) + switch (writecode) { case 'c': if (rdepth==1) printf("\tprintf(\"repeat %%d\\n\", %s);\n",$3); if (rdepth==2) printf("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3); + /* Fall through. */ case 'i': case 'g': case 'o': - if (rdepth==1) + if (rdepth==1) { printf("\t{ int n; for (n = 0; n < %s; n++) {\n", $3); } if (rdepth == 2) { printf("\t{ int m; for (m = 0; m < %s[n]; m++) {\n", $3); - } + } break; } @@ -206,9 +204,11 @@ repeat_it_field: '(' REPEAT NAME repeat = $3; } - it_field_list ')' + it_field_list ')' { + free (repeat); + repeat = oldrepeat; oldrepeat =0; rdepth--; @@ -226,7 +226,7 @@ repeat_it_field: '(' REPEAT NAME cond_it_field: '(' COND NAME { - switch (writecode) + switch (writecode) { case 'i': case 'g': @@ -235,9 +235,11 @@ cond_it_field: '(' COND NAME printf("\tif (%s) {\n", $3); break; } + + free ($3); } - it_field_list ')' + it_field_list ')' { switch (writecode) { @@ -251,8 +253,8 @@ cond_it_field: '(' COND NAME ; it_field: - '(' attr_desc '(' attr_type attr_size ')' attr_id - {name = $7; } + '(' attr_desc '(' attr_type attr_size ')' attr_id + {name = $7; } enums ')' { char *desc = $2; @@ -261,32 +263,32 @@ it_field: char *id = $7; char *p = names[rdepth]; char *ptr = pnames[rdepth]; - switch (writecode) + switch (writecode) { case 'g': - if (size % 8) + if (size % 8) { - + printf("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n", id, names[rdepth], size); } else { - printf("\twrite%s(ptr->%s%s,raw,&idx,%d,file);\n", + printf("\twrite%s(ptr->%s%s,raw,&idx,%d,ffile);\n", type, id, names[rdepth],size/8); } - break; + break; case 'i': { if (rdepth >= 1) { - printf("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n", - id, + printf("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n", + id, id, type, repeat, @@ -295,8 +297,8 @@ char *ptr = pnames[rdepth]; if (rdepth == 2) { - printf("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n", - id, + printf("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n", + id, id, type, repeat, @@ -305,11 +307,11 @@ char *ptr = pnames[rdepth]; } - if (size % 8) + if (size % 8) { printf("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n", id, - names[rdepth], + names[rdepth], size); } else { @@ -324,7 +326,7 @@ char *ptr = pnames[rdepth]; printf("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type,size/8,size%8,id,names[rdepth]); break; case 'd': - if (repeat) + if (repeat) printf("\t/* repeat %s */\n", repeat); if (type[0] == 'I') { @@ -346,46 +348,49 @@ char *ptr = pnames[rdepth]; else if (type[0] == 'C') printf("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id,p); - else if (type[0] == 'B') + else if (type[0] == 'B') { printf("\tpbarray(&ptr->%s%s);\n", id,p); } else abort(); break; } + + free (desc); + free (id); } ; -attr_type: +attr_type: TYPE { $$ = $1; } | { $$ = "INT";} ; -attr_desc: - '(' NAME ')' +attr_desc: + '(' NAME ')' { $$ = $2; } ; attr_size: - NUMBER UNIT + NUMBER UNIT { $$ = $1 * $2; } ; attr_id: '(' NAME ')' { $$ = $2; } - | { $$ = "dummy";} - ; - -enums: + | { $$ = strdup ("dummy");} + ; + +enums: | '(' enum_list ')' ; enum_list: | - enum_list '(' NAME NAME ')' { - switch (writecode) + enum_list '(' NAME NAME ')' { + switch (writecode) { case 'd': printf("#define %s %s\n", $3,$4); @@ -393,6 +398,9 @@ enum_list: case 'c': printf("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name, names[rdepth],$4,$3); } + + free ($3); + free ($4); } ; @@ -409,7 +417,7 @@ enum_list: int yydebug; -int +int main (int ac, char **av) { yydebug=0;