binutils-gdb/binutils/sysinfo.y

443 lines
8.2 KiB
Plaintext
Raw Normal View History

/* Copyright (C) 2001-2019 Free Software Foundation, Inc.
Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
2007-07-06 00:54:46 +08:00
This file is part of GNU binutils.
2007-07-06 00:54:46 +08:00
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.
2007-07-06 00:54:46 +08:00
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.
2007-07-06 00:54:46 +08:00
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. */
1999-05-03 15:29:11 +08:00
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
1999-05-03 15:29:11 +08:00
static char writecode;
static char *it;
static int code;
static char * repeat;
static char *oldrepeat;
static char *name;
static int rdepth;
static char *names[] = {" ","[n]","[n][m]"};
static char *pnames[]= {"","*","**"};
static int yyerror (char *s);
extern int yylex (void);
1999-05-03 15:29:11 +08:00
%}
%union {
int i;
char *s;
2015-08-12 19:42:37 +08:00
}
1999-05-03 15:29:11 +08:00
%token COND
%token REPEAT
%token '(' ')'
%token <s> TYPE
%token <s> NAME
%token <i> NUMBER UNIT
2015-08-12 19:42:37 +08:00
%type <i> attr_size
1999-05-03 15:29:11 +08:00
%type <s> attr_desc attr_id attr_type
%%
top: {
switch (writecode)
{
case 'i':
printf("#ifdef SYSROFF_SWAP_IN\n");
2015-08-12 19:42:37 +08:00
break;
1999-05-03 15:29:11 +08:00
case 'p':
printf("#ifdef SYSROFF_p\n");
2015-08-12 19:42:37 +08:00
break;
1999-05-03 15:29:11 +08:00
case 'd':
break;
case 'g':
printf("#ifdef SYSROFF_SWAP_OUT\n");
break;
case 'c':
printf("#ifdef SYSROFF_PRINT\n");
printf("#include <stdio.h>\n");
printf("#include <stdlib.h>\n");
printf("#include <ansidecl.h>\n");
1999-05-03 15:29:11 +08:00
break;
}
2015-08-12 19:42:37 +08:00
}
1999-05-03 15:29:11 +08:00
it_list {
switch (writecode) {
case 'i':
case 'p':
case 'g':
case 'c':
printf("#endif\n");
2015-08-12 19:42:37 +08:00
break;
1999-05-03 15:29:11 +08:00
case 'd':
break;
}
}
;
it_list: it it_list
|
;
it:
2015-08-12 19:42:37 +08:00
'(' NAME NUMBER
1999-05-03 15:29:11 +08:00
{
it = $2; code = $3;
2015-08-12 19:42:37 +08:00
switch (writecode)
1999-05-03 15:29:11 +08:00
{
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 (struct IT_%s *);\n",
$2, it);
printf("extern void sysroff_swap_%s_out (FILE *, struct IT_%s *);\n",
$2, it);
printf("extern void sysroff_print_%s_out (struct IT_%s *);\n",
$2, it);
1999-05-03 15:29:11 +08:00
printf("struct IT_%s { \n", it);
break;
case 'i':
printf("void sysroff_swap_%s_in (struct IT_%s * ptr)\n",$2,it);
1999-05-03 15:29:11 +08:00
printf("{\n");
printf("\tunsigned char raw[255];\n");
printf("\tint idx = 0;\n");
1999-05-03 15:29:11 +08:00
printf("\tint size;\n");
2015-08-12 19:42:37 +08:00
printf("\tmemset(raw,0,255);\n");
printf("\tmemset(ptr,0,sizeof(*ptr));\n");
printf("\tsize = fillup(raw);\n");
1999-05-03 15:29:11 +08:00
break;
case 'g':
printf("void sysroff_swap_%s_out (FILE * ffile, struct IT_%s * ptr)\n",$2,it);
1999-05-03 15:29:11 +08:00
printf("{\n");
printf("\tunsigned char raw[255];\n");
printf("\tint idx = 16;\n");
1999-05-03 15:29:11 +08:00
printf("\tmemset (raw, 0, 255);\n");
printf("\tcode = IT_%s_CODE;\n", it);
break;
case 'o':
printf("void sysroff_swap_%s_out (bfd * abfd, struct IT_%s * ptr)\n",$2, it);
1999-05-03 15:29:11 +08:00
printf("{\n");
printf("\tint idx = 0;\n");
1999-05-03 15:29:11 +08:00
break;
case 'c':
printf("void sysroff_print_%s_out (struct IT_%s *ptr)\n",$2,it);
1999-05-03 15:29:11 +08:00
printf("{\n");
printf("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
break;
case 't':
break;
}
2015-08-12 19:42:37 +08:00
}
it_field_list
1999-05-03 15:29:11 +08:00
')'
{
switch (writecode) {
2015-08-12 19:42:37 +08:00
case 'd':
1999-05-03 15:29:11 +08:00
printf("};\n");
break;
case 'g':
printf("\tchecksum(ffile,raw, idx, IT_%s_CODE);\n", it);
-Wimplicit-fallthrough warning fixes Comment changes. bfd/ * coff-h8300.c: Spell fall through comments consistently. * coffgen.c: Likewise. * elf32-hppa.c: Likewise. * elf32-ppc.c: Likewise. * elf32-score.c: Likewise. * elf32-score7.c: Likewise. * elf64-ppc.c: Likewise. * elfxx-aarch64.c: Likewise. * elfxx-mips.c: Likewise. * cpu-ns32k.c: Add missing fall through comments. * elf-m10300.c: Likewise. * elf32-arm.c: Likewise. * elf32-avr.c: Likewise. * elf32-bfin.c: Likewise. * elf32-frv.c: Likewise. * elf32-i386.c: Likewise. * elf32-microblaze.c: Likewise. * elf32-nds32.c: Likewise. * elf32-ppc.c: Likewise. * elf32-rl78.c: Likewise. * elf32-rx.c: Likewise. * elf32-s390.c: Likewise. * elf32-sh.c: Likewise. * elf32-tic6x.c: Likewise. * elf64-ia64-vms.c: Likewise. * elf64-ppc.c: Likewise. * elf64-s390.c: Likewise. * elf64-x86-64.c: Likewise. * elflink.c: Likewise. * elfnn-aarch64.c: Likewise. * elfnn-ia64.c: Likewise. * ieee.c: Likewise. * oasys.c: Likewise. * pdp11.c: Likewise. * srec.c: Likewise. * versados.c: Likewise. opcodes/ * aarch64-opc.c: Spell fall through comments consistently. * i386-dis.c: Likewise. * aarch64-dis.c: Add missing fall through comments. * aarch64-opc.c: Likewise. * arc-dis.c: Likewise. * arm-dis.c: Likewise. * i386-dis.c: Likewise. * m68k-dis.c: Likewise. * mep-asm.c: Likewise. * ns32k-dis.c: Likewise. * sh-dis.c: Likewise. * tic4x-dis.c: Likewise. * tic6x-dis.c: Likewise. * vax-dis.c: Likewise. binutils/ * dlltool.c: Spell fall through comments consistently. * objcopy.c: Likewise. * readelf.c: Likewise. * dwarf.c: Add missing fall through comments. * elfcomm.c: Likewise. * sysinfo.y: Likewise. * readelf.c: Likewise. Also remove extraneous comments. gas/ * app.c: Add missing fall through comments. * dw2gencfi.c: Likewise. * expr.c: Likewise. * config/tc-alpha.c: Likewise. * config/tc-arc.c: Likewise. * config/tc-arm.c: Likewise. * config/tc-cr16.c: Likewise. * config/tc-crx.c: Likewise. * config/tc-dlx.c: Likewise. * config/tc-h8300.c: Likewise. * config/tc-hppa.c: Likewise. * config/tc-i370.c: Likewise. * config/tc-i386.c: Likewise. * config/tc-i960.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-m68hc11.c: Likewise. * config/tc-m68k.c: Likewise. * config/tc-mep.c: Likewise. * config/tc-metag.c: Likewise. * config/tc-microblaze.c: Likewise. * config/tc-mips.c: Likewise. * config/tc-ns32k.c: Likewise. * config/tc-rx.c: Likewise. * config/tc-score.c: Likewise. * config/tc-score7.c: Likewise. * config/tc-sh.c: Likewise. * config/tc-tic4x.c: Likewise. * config/tc-vax.c: Likewise. * config/tc-xstormy16.c: Likewise. * config/tc-z80.c: Likewise. * config/tc-z8k.c: Likewise. * config/obj-elf.c: Likewise. * config/tc-i386.c: Likewise. * depend.c: Spell fall through comments consistently. * config/tc-arm.c: Likewise. * config/tc-d10v.c: Likewise. * config/tc-i960.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-m68k.c: Likewise. * config/tc-mcore.c: Likewise. * config/tc-mep.c: Likewise. * config/tc-ns32k.c: Likewise. * config/tc-visium.c: Likewise. * config/tc-xstormy16.c: Likewise. * config/tc-z8k.c: Likewise. gprof/ * gprof.c: Add missing fall through comments. ld/ * lexsup.c: Spell fall through comments consistently and add missing fall through comments.
2016-10-05 15:47:02 +08:00
/* Fall through. */
1999-05-03 15:29:11 +08:00
case 'i':
case 'o':
case 'c':
printf("}\n");
}
free (it);
1999-05-03 15:29:11 +08:00
}
;
it_field_list:
it_field it_field_list
2015-08-12 19:42:37 +08:00
| cond_it_field it_field_list
1999-05-03 15:29:11 +08:00
| repeat_it_field it_field_list
|
;
repeat_it_field: '(' REPEAT NAME
{
rdepth++;
2015-08-12 19:42:37 +08:00
switch (writecode)
1999-05-03 15:29:11 +08:00
{
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);
-Wimplicit-fallthrough warning fixes Comment changes. bfd/ * coff-h8300.c: Spell fall through comments consistently. * coffgen.c: Likewise. * elf32-hppa.c: Likewise. * elf32-ppc.c: Likewise. * elf32-score.c: Likewise. * elf32-score7.c: Likewise. * elf64-ppc.c: Likewise. * elfxx-aarch64.c: Likewise. * elfxx-mips.c: Likewise. * cpu-ns32k.c: Add missing fall through comments. * elf-m10300.c: Likewise. * elf32-arm.c: Likewise. * elf32-avr.c: Likewise. * elf32-bfin.c: Likewise. * elf32-frv.c: Likewise. * elf32-i386.c: Likewise. * elf32-microblaze.c: Likewise. * elf32-nds32.c: Likewise. * elf32-ppc.c: Likewise. * elf32-rl78.c: Likewise. * elf32-rx.c: Likewise. * elf32-s390.c: Likewise. * elf32-sh.c: Likewise. * elf32-tic6x.c: Likewise. * elf64-ia64-vms.c: Likewise. * elf64-ppc.c: Likewise. * elf64-s390.c: Likewise. * elf64-x86-64.c: Likewise. * elflink.c: Likewise. * elfnn-aarch64.c: Likewise. * elfnn-ia64.c: Likewise. * ieee.c: Likewise. * oasys.c: Likewise. * pdp11.c: Likewise. * srec.c: Likewise. * versados.c: Likewise. opcodes/ * aarch64-opc.c: Spell fall through comments consistently. * i386-dis.c: Likewise. * aarch64-dis.c: Add missing fall through comments. * aarch64-opc.c: Likewise. * arc-dis.c: Likewise. * arm-dis.c: Likewise. * i386-dis.c: Likewise. * m68k-dis.c: Likewise. * mep-asm.c: Likewise. * ns32k-dis.c: Likewise. * sh-dis.c: Likewise. * tic4x-dis.c: Likewise. * tic6x-dis.c: Likewise. * vax-dis.c: Likewise. binutils/ * dlltool.c: Spell fall through comments consistently. * objcopy.c: Likewise. * readelf.c: Likewise. * dwarf.c: Add missing fall through comments. * elfcomm.c: Likewise. * sysinfo.y: Likewise. * readelf.c: Likewise. Also remove extraneous comments. gas/ * app.c: Add missing fall through comments. * dw2gencfi.c: Likewise. * expr.c: Likewise. * config/tc-alpha.c: Likewise. * config/tc-arc.c: Likewise. * config/tc-arm.c: Likewise. * config/tc-cr16.c: Likewise. * config/tc-crx.c: Likewise. * config/tc-dlx.c: Likewise. * config/tc-h8300.c: Likewise. * config/tc-hppa.c: Likewise. * config/tc-i370.c: Likewise. * config/tc-i386.c: Likewise. * config/tc-i960.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-m68hc11.c: Likewise. * config/tc-m68k.c: Likewise. * config/tc-mep.c: Likewise. * config/tc-metag.c: Likewise. * config/tc-microblaze.c: Likewise. * config/tc-mips.c: Likewise. * config/tc-ns32k.c: Likewise. * config/tc-rx.c: Likewise. * config/tc-score.c: Likewise. * config/tc-score7.c: Likewise. * config/tc-sh.c: Likewise. * config/tc-tic4x.c: Likewise. * config/tc-vax.c: Likewise. * config/tc-xstormy16.c: Likewise. * config/tc-z80.c: Likewise. * config/tc-z8k.c: Likewise. * config/obj-elf.c: Likewise. * config/tc-i386.c: Likewise. * depend.c: Spell fall through comments consistently. * config/tc-arm.c: Likewise. * config/tc-d10v.c: Likewise. * config/tc-i960.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-m68k.c: Likewise. * config/tc-mcore.c: Likewise. * config/tc-mep.c: Likewise. * config/tc-ns32k.c: Likewise. * config/tc-visium.c: Likewise. * config/tc-xstormy16.c: Likewise. * config/tc-z8k.c: Likewise. gprof/ * gprof.c: Add missing fall through comments. ld/ * lexsup.c: Spell fall through comments consistently and add missing fall through comments.
2016-10-05 15:47:02 +08:00
/* Fall through. */
1999-05-03 15:29:11 +08:00
case 'i':
case 'g':
case 'o':
2015-08-12 19:42:37 +08:00
if (rdepth==1)
1999-05-03 15:29:11 +08:00
{
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);
2015-08-12 19:42:37 +08:00
}
1999-05-03 15:29:11 +08:00
break;
}
oldrepeat = repeat;
repeat = $3;
}
2015-08-12 19:42:37 +08:00
it_field_list ')'
1999-05-03 15:29:11 +08:00
{
free (repeat);
1999-05-03 15:29:11 +08:00
repeat = oldrepeat;
oldrepeat =0;
rdepth--;
switch (writecode)
{
case 'i':
case 'g':
case 'o':
case 'c':
printf("\t}}\n");
}
}
;
cond_it_field: '(' COND NAME
{
2015-08-12 19:42:37 +08:00
switch (writecode)
1999-05-03 15:29:11 +08:00
{
case 'i':
case 'g':
case 'o':
case 'c':
printf("\tif (%s) {\n", $3);
break;
}
free ($3);
1999-05-03 15:29:11 +08:00
}
2015-08-12 19:42:37 +08:00
it_field_list ')'
1999-05-03 15:29:11 +08:00
{
switch (writecode)
{
case 'i':
case 'g':
case 'o':
case 'c':
printf("\t}\n");
}
}
;
it_field:
2015-08-12 19:42:37 +08:00
'(' attr_desc '(' attr_type attr_size ')' attr_id
{name = $7; }
1999-05-03 15:29:11 +08:00
enums ')'
{
char *desc = $2;
char *type = $4;
int size = $5;
char *id = $7;
char *p = names[rdepth];
char *ptr = pnames[rdepth];
2015-08-12 19:42:37 +08:00
switch (writecode)
1999-05-03 15:29:11 +08:00
{
case 'g':
2015-08-12 19:42:37 +08:00
if (size % 8)
1999-05-03 15:29:11 +08:00
{
2015-08-12 19:42:37 +08:00
1999-05-03 15:29:11 +08:00
printf("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
id,
names[rdepth], size);
}
else {
printf("\twrite%s(ptr->%s%s,raw,&idx,%d,ffile);\n",
1999-05-03 15:29:11 +08:00
type,
id,
names[rdepth],size/8);
}
2015-08-12 19:42:37 +08:00
break;
1999-05-03 15:29:11 +08:00
case 'i':
{
if (rdepth >= 1)
{
2015-08-12 19:42:37 +08:00
printf("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
id,
1999-05-03 15:29:11 +08:00
id,
type,
repeat,
id);
}
if (rdepth == 2)
{
2015-08-12 19:42:37 +08:00
printf("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
id,
1999-05-03 15:29:11 +08:00
id,
type,
repeat,
id);
}
}
2015-08-12 19:42:37 +08:00
if (size % 8)
1999-05-03 15:29:11 +08:00
{
printf("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
id,
2015-08-12 19:42:37 +08:00
names[rdepth],
1999-05-03 15:29:11 +08:00
size);
}
else {
printf("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
id,
names[rdepth],
type,
size/8);
}
break;
case 'o':
printf("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type,size/8,size%8,id,names[rdepth]);
break;
case 'd':
2015-08-12 19:42:37 +08:00
if (repeat)
1999-05-03 15:29:11 +08:00
printf("\t/* repeat %s */\n", repeat);
if (type[0] == 'I') {
printf("\tint %s%s; \t/* %s */\n",ptr,id, desc);
}
else if (type[0] =='C') {
printf("\tchar %s*%s;\t /* %s */\n",ptr,id, desc);
}
else {
printf("\tbarray %s%s;\t /* %s */\n",ptr,id, desc);
}
break;
case 'c':
printf("tabout();\n");
printf("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc, id);
if (type[0] == 'I')
printf("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id,p);
else if (type[0] == 'C')
printf("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id,p);
2015-08-12 19:42:37 +08:00
else if (type[0] == 'B')
1999-05-03 15:29:11 +08:00
{
printf("\tpbarray(&ptr->%s%s);\n", id,p);
}
else abort();
break;
}
free (desc);
free (id);
1999-05-03 15:29:11 +08:00
}
;
2015-08-12 19:42:37 +08:00
attr_type:
1999-05-03 15:29:11 +08:00
TYPE { $$ = $1; }
| { $$ = "INT";}
;
2015-08-12 19:42:37 +08:00
attr_desc:
'(' NAME ')'
1999-05-03 15:29:11 +08:00
{ $$ = $2; }
;
attr_size:
2015-08-12 19:42:37 +08:00
NUMBER UNIT
1999-05-03 15:29:11 +08:00
{ $$ = $1 * $2; }
;
attr_id:
'(' NAME ')' { $$ = $2; }
| { $$ = strdup ("dummy");}
2015-08-12 19:42:37 +08:00
;
enums:
1999-05-03 15:29:11 +08:00
| '(' enum_list ')' ;
enum_list:
|
2015-08-12 19:42:37 +08:00
enum_list '(' NAME NAME ')' {
switch (writecode)
1999-05-03 15:29:11 +08:00
{
case 'd':
printf("#define %s %s\n", $3,$4);
break;
case 'c':
printf("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name, names[rdepth],$4,$3);
}
free ($3);
free ($4);
1999-05-03 15:29:11 +08:00
}
;
%%
/* four modes
-d write structure definitions for sysroff in host format
1999-05-03 15:29:11 +08:00
-i write functions to swap into sysroff format in
-o write functions to swap into sysroff format out
-c write code to print info in human form */
int yydebug;
2015-08-12 19:42:37 +08:00
int
main (int ac, char **av)
1999-05-03 15:29:11 +08:00
{
yydebug=0;
if (ac > 1)
writecode = av[1][1];
if (writecode == 'd')
{
printf("typedef struct { unsigned char *data; int len; } barray; \n");
printf("typedef int INT;\n");
printf("typedef char * CHARS;\n");
}
yyparse();
return 0;
}
static int
yyerror (char *s)
1999-05-03 15:29:11 +08:00
{
fprintf(stderr, "%s\n" , s);
return 0;
}