OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [binutils-2.18.50/] [binutils/] [sysinfo.y] - Diff between revs 156 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 156 Rev 816
/* Copyright 2001, 2003, 2005, 2007 Free Software Foundation, Inc.
/* Copyright 2001, 2003, 2005, 2007 Free Software Foundation, Inc.
   Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
   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
   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
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */
   MA 02110-1301, USA.  */
%{
%{
#include 
#include 
#include 
#include 
static char writecode;
static char writecode;
static char *it;
static char *it;
static int code;
static int code;
static char * repeat;
static char * repeat;
static char *oldrepeat;
static char *oldrepeat;
static char *name;
static char *name;
static int rdepth;
static int rdepth;
static char *names[] = {" ","[n]","[n][m]"};
static char *names[] = {" ","[n]","[n][m]"};
static char *pnames[]= {"","*","**"};
static char *pnames[]= {"","*","**"};
static int yyerror (char *s);
static int yyerror (char *s);
extern int yylex (void);
extern int yylex (void);
%}
%}
%union {
%union {
 int i;
 int i;
 char *s;
 char *s;
}
}
%token COND
%token COND
%token REPEAT
%token REPEAT
%token '(' ')'
%token '(' ')'
%token  TYPE
%token  TYPE
%token  NAME
%token  NAME
%token  NUMBER UNIT
%token  NUMBER UNIT
%type  attr_size
%type  attr_size
%type  attr_desc attr_id attr_type
%type  attr_desc attr_id attr_type
%%
%%
top:  {
top:  {
  switch (writecode)
  switch (writecode)
    {
    {
    case 'i':
    case 'i':
      printf("#ifdef SYSROFF_SWAP_IN\n");
      printf("#ifdef SYSROFF_SWAP_IN\n");
      break;
      break;
    case 'p':
    case 'p':
      printf("#ifdef SYSROFF_p\n");
      printf("#ifdef SYSROFF_p\n");
      break;
      break;
    case 'd':
    case 'd':
      break;
      break;
    case 'g':
    case 'g':
      printf("#ifdef SYSROFF_SWAP_OUT\n");
      printf("#ifdef SYSROFF_SWAP_OUT\n");
      break;
      break;
    case 'c':
    case 'c':
      printf("#ifdef SYSROFF_PRINT\n");
      printf("#ifdef SYSROFF_PRINT\n");
      printf("#include \n");
      printf("#include \n");
      printf("#include \n");
      printf("#include \n");
      printf("#include \n");
      printf("#include \n");
      break;
      break;
    }
    }
 }
 }
it_list {
it_list {
  switch (writecode) {
  switch (writecode) {
  case 'i':
  case 'i':
  case 'p':
  case 'p':
  case 'g':
  case 'g':
  case 'c':
  case 'c':
    printf("#endif\n");
    printf("#endif\n");
    break;
    break;
  case 'd':
  case 'd':
    break;
    break;
  }
  }
}
}
  ;
  ;
it_list: it it_list
it_list: it it_list
  |
  |
  ;
  ;
it:
it:
        '(' NAME NUMBER
        '(' NAME NUMBER
      {
      {
        it = $2; code = $3;
        it = $2; code = $3;
        switch (writecode)
        switch (writecode)
          {
          {
          case 'd':
          case 'd':
            printf("\n\n\n#define IT_%s_CODE 0x%x\n", it,code);
            printf("\n\n\n#define IT_%s_CODE 0x%x\n", it,code);
            printf("struct IT_%s;\n", it);
            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 PARAMS ((struct IT_%s *));\n",
                   $2, it);
                   $2, it);
            printf("extern void sysroff_swap_%s_out PARAMS ((FILE *, struct IT_%s *));\n",
            printf("extern void sysroff_swap_%s_out PARAMS ((FILE *, struct IT_%s *));\n",
                   $2, it);
                   $2, it);
            printf("extern void sysroff_print_%s_out PARAMS ((struct IT_%s *));\n",
            printf("extern void sysroff_print_%s_out PARAMS ((struct IT_%s *));\n",
                   $2, it);
                   $2, it);
            printf("struct IT_%s { \n", it);
            printf("struct IT_%s { \n", it);
            break;
            break;
          case 'i':
          case 'i':
            printf("void sysroff_swap_%s_in(ptr)\n",$2);
            printf("void sysroff_swap_%s_in(ptr)\n",$2);
            printf("struct IT_%s *ptr;\n", it);
            printf("struct IT_%s *ptr;\n", it);
            printf("{\n");
            printf("{\n");
            printf("unsigned char raw[255];\n");
            printf("unsigned char raw[255];\n");
            printf("\tint idx = 0 ;\n");
            printf("\tint idx = 0 ;\n");
            printf("\tint size;\n");
            printf("\tint size;\n");
            printf("memset(raw,0,255);\n");
            printf("memset(raw,0,255);\n");
            printf("memset(ptr,0,sizeof(*ptr));\n");
            printf("memset(ptr,0,sizeof(*ptr));\n");
            printf("size = fillup(raw);\n");
            printf("size = fillup(raw);\n");
            break;
            break;
          case 'g':
          case 'g':
            printf("void sysroff_swap_%s_out(file,ptr)\n",$2);
            printf("void sysroff_swap_%s_out(file,ptr)\n",$2);
            printf("FILE * file;\n");
            printf("FILE * file;\n");
            printf("struct IT_%s *ptr;\n", it);
            printf("struct IT_%s *ptr;\n", it);
            printf("{\n");
            printf("{\n");
            printf("\tunsigned char raw[255];\n");
            printf("\tunsigned char raw[255];\n");
            printf("\tint idx = 16 ;\n");
            printf("\tint idx = 16 ;\n");
            printf("\tmemset (raw, 0, 255);\n");
            printf("\tmemset (raw, 0, 255);\n");
            printf("\tcode = IT_%s_CODE;\n", it);
            printf("\tcode = IT_%s_CODE;\n", it);
            break;
            break;
          case 'o':
          case 'o':
            printf("void sysroff_swap_%s_out(abfd,ptr)\n",$2);
            printf("void sysroff_swap_%s_out(abfd,ptr)\n",$2);
            printf("bfd * abfd;\n");
            printf("bfd * abfd;\n");
            printf("struct IT_%s *ptr;\n",it);
            printf("struct IT_%s *ptr;\n",it);
            printf("{\n");
            printf("{\n");
            printf("int idx = 0 ;\n");
            printf("int idx = 0 ;\n");
            break;
            break;
          case 'c':
          case 'c':
            printf("void sysroff_print_%s_out(ptr)\n",$2);
            printf("void sysroff_print_%s_out(ptr)\n",$2);
            printf("struct IT_%s *ptr;\n", it);
            printf("struct IT_%s *ptr;\n", it);
            printf("{\n");
            printf("{\n");
            printf("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
            printf("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
            break;
            break;
          case 't':
          case 't':
            break;
            break;
          }
          }
      }
      }
        it_field_list
        it_field_list
')'
')'
{
{
  switch (writecode) {
  switch (writecode) {
  case 'd':
  case 'd':
    printf("};\n");
    printf("};\n");
    break;
    break;
  case 'g':
  case 'g':
    printf("\tchecksum(file,raw, idx, IT_%s_CODE);\n", it);
    printf("\tchecksum(file,raw, idx, IT_%s_CODE);\n", it);
  case 'i':
  case 'i':
  case 'o':
  case 'o':
  case 'c':
  case 'c':
    printf("}\n");
    printf("}\n");
  }
  }
}
}
;
;
it_field_list:
it_field_list:
                it_field 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
        |       repeat_it_field it_field_list
        |
        |
        ;
        ;
repeat_it_field: '(' REPEAT NAME
repeat_it_field: '(' REPEAT NAME
        {
        {
          rdepth++;
          rdepth++;
          switch (writecode)
          switch (writecode)
            {
            {
            case 'c':
            case 'c':
              if (rdepth==1)
              if (rdepth==1)
              printf("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
              printf("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
              if (rdepth==2)
              if (rdepth==2)
              printf("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
              printf("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
            case 'i':
            case 'i':
            case 'g':
            case 'g':
            case 'o':
            case 'o':
              if (rdepth==1)
              if (rdepth==1)
                {
                {
              printf("\t{ int n; for (n = 0; n < %s; n++) {\n",    $3);
              printf("\t{ int n; for (n = 0; n < %s; n++) {\n",    $3);
            }
            }
              if (rdepth == 2) {
              if (rdepth == 2) {
              printf("\t{ int m; for (m = 0; m < %s[n]; m++) {\n",    $3);
              printf("\t{ int m; for (m = 0; m < %s[n]; m++) {\n",    $3);
            }
            }
              break;
              break;
            }
            }
          oldrepeat = repeat;
          oldrepeat = repeat;
         repeat = $3;
         repeat = $3;
        }
        }
         it_field_list ')'
         it_field_list ')'
        {
        {
          repeat = oldrepeat;
          repeat = oldrepeat;
          oldrepeat =0;
          oldrepeat =0;
          rdepth--;
          rdepth--;
          switch (writecode)
          switch (writecode)
            {
            {
            case 'i':
            case 'i':
            case 'g':
            case 'g':
            case 'o':
            case 'o':
            case 'c':
            case 'c':
          printf("\t}}\n");
          printf("\t}}\n");
        }
        }
        }
        }
       ;
       ;
cond_it_field: '(' COND NAME
cond_it_field: '(' COND NAME
        {
        {
          switch (writecode)
          switch (writecode)
            {
            {
            case 'i':
            case 'i':
            case 'g':
            case 'g':
            case 'o':
            case 'o':
            case 'c':
            case 'c':
              printf("\tif (%s) {\n", $3);
              printf("\tif (%s) {\n", $3);
              break;
              break;
            }
            }
        }
        }
         it_field_list ')'
         it_field_list ')'
        {
        {
          switch (writecode)
          switch (writecode)
            {
            {
            case 'i':
            case 'i':
            case 'g':
            case 'g':
            case 'o':
            case 'o':
            case 'c':
            case 'c':
          printf("\t}\n");
          printf("\t}\n");
        }
        }
        }
        }
       ;
       ;
it_field:
it_field:
        '(' attr_desc '(' attr_type attr_size ')' attr_id
        '(' attr_desc '(' attr_type attr_size ')' attr_id
        {name = $7; }
        {name = $7; }
        enums ')'
        enums ')'
        {
        {
          char *desc = $2;
          char *desc = $2;
          char *type = $4;
          char *type = $4;
          int size = $5;
          int size = $5;
          char *id = $7;
          char *id = $7;
char *p = names[rdepth];
char *p = names[rdepth];
char *ptr = pnames[rdepth];
char *ptr = pnames[rdepth];
          switch (writecode)
          switch (writecode)
            {
            {
            case 'g':
            case 'g':
              if (size % 8)
              if (size % 8)
                {
                {
                  printf("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
                  printf("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
                         id,
                         id,
                         names[rdepth], size);
                         names[rdepth], size);
                }
                }
              else {
              else {
                printf("\twrite%s(ptr->%s%s,raw,&idx,%d,file);\n",
                printf("\twrite%s(ptr->%s%s,raw,&idx,%d,file);\n",
                       type,
                       type,
                       id,
                       id,
                       names[rdepth],size/8);
                       names[rdepth],size/8);
                }
                }
              break;
              break;
            case 'i':
            case 'i':
              {
              {
                if (rdepth >= 1)
                if (rdepth >= 1)
                  {
                  {
                    printf("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
                    printf("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
                           id,
                           id,
                           id,
                           id,
                           type,
                           type,
                           repeat,
                           repeat,
                           id);
                           id);
                  }
                  }
                if (rdepth == 2)
                if (rdepth == 2)
                  {
                  {
                    printf("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
                    printf("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
                           id,
                           id,
                           id,
                           id,
                           type,
                           type,
                           repeat,
                           repeat,
                           id);
                           id);
                  }
                  }
              }
              }
              if (size % 8)
              if (size % 8)
                {
                {
                  printf("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
                  printf("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
                         id,
                         id,
                         names[rdepth],
                         names[rdepth],
                         size);
                         size);
                }
                }
              else {
              else {
                printf("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
                printf("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
                       id,
                       id,
                       names[rdepth],
                       names[rdepth],
                       type,
                       type,
                       size/8);
                       size/8);
                }
                }
              break;
              break;
            case 'o':
            case 'o':
              printf("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type,size/8,size%8,id,names[rdepth]);
              printf("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type,size/8,size%8,id,names[rdepth]);
              break;
              break;
            case 'd':
            case 'd':
              if (repeat)
              if (repeat)
                printf("\t/* repeat %s */\n", repeat);
                printf("\t/* repeat %s */\n", repeat);
                  if (type[0] == 'I') {
                  if (type[0] == 'I') {
                  printf("\tint %s%s; \t/* %s */\n",ptr,id, desc);
                  printf("\tint %s%s; \t/* %s */\n",ptr,id, desc);
                }
                }
                  else if (type[0] =='C') {
                  else if (type[0] =='C') {
                  printf("\tchar %s*%s;\t /* %s */\n",ptr,id, desc);
                  printf("\tchar %s*%s;\t /* %s */\n",ptr,id, desc);
                }
                }
              else {
              else {
                printf("\tbarray %s%s;\t /* %s */\n",ptr,id, desc);
                printf("\tbarray %s%s;\t /* %s */\n",ptr,id, desc);
              }
              }
                  break;
                  break;
                case 'c':
                case 'c':
              printf("tabout();\n");
              printf("tabout();\n");
                  printf("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc, id);
                  printf("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc, id);
                  if (type[0] == 'I')
                  if (type[0] == 'I')
                  printf("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id,p);
                  printf("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id,p);
                  else   if (type[0] == 'C')
                  else   if (type[0] == 'C')
                  printf("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id,p);
                  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);
                  printf("\tpbarray(&ptr->%s%s);\n", id,p);
                }
                }
              else abort();
              else abort();
                  break;
                  break;
                }
                }
        }
        }
        ;
        ;
attr_type:
attr_type:
         TYPE { $$ = $1; }
         TYPE { $$ = $1; }
        |  { $$ = "INT";}
        |  { $$ = "INT";}
        ;
        ;
attr_desc:
attr_desc:
        '(' NAME ')'
        '(' NAME ')'
        { $$ = $2; }
        { $$ = $2; }
        ;
        ;
attr_size:
attr_size:
         NUMBER UNIT
         NUMBER UNIT
        { $$ = $1 * $2; }
        { $$ = $1 * $2; }
        ;
        ;
attr_id:
attr_id:
                '(' NAME ')'    { $$ = $2; }
                '(' NAME ')'    { $$ = $2; }
        |       { $$ = "dummy";}
        |       { $$ = "dummy";}
        ;
        ;
enums:
enums:
        | '(' enum_list ')' ;
        | '(' enum_list ')' ;
enum_list:
enum_list:
        |
        |
        enum_list '(' NAME NAME ')' {
        enum_list '(' NAME NAME ')' {
          switch (writecode)
          switch (writecode)
            {
            {
            case 'd':
            case 'd':
              printf("#define %s %s\n", $3,$4);
              printf("#define %s %s\n", $3,$4);
              break;
              break;
            case 'c':
            case 'c':
                printf("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name, names[rdepth],$4,$3);
                printf("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name, names[rdepth],$4,$3);
            }
            }
        }
        }
        ;
        ;
%%
%%
/* four modes
/* four modes
   -d write structure definitions for sysroff in host format
   -d write structure definitions for sysroff in host format
   -i write functions to swap into sysroff format in
   -i write functions to swap into sysroff format in
   -o write functions to swap into sysroff format out
   -o write functions to swap into sysroff format out
   -c write code to print info in human form */
   -c write code to print info in human form */
int yydebug;
int yydebug;
int
int
main (int ac, char **av)
main (int ac, char **av)
{
{
  yydebug=0;
  yydebug=0;
  if (ac > 1)
  if (ac > 1)
    writecode = av[1][1];
    writecode = av[1][1];
if (writecode == 'd')
if (writecode == 'd')
  {
  {
    printf("typedef struct { unsigned char *data; int len; } barray; \n");
    printf("typedef struct { unsigned char *data; int len; } barray; \n");
    printf("typedef  int INT;\n");
    printf("typedef  int INT;\n");
    printf("typedef  char * CHARS;\n");
    printf("typedef  char * CHARS;\n");
  }
  }
  yyparse();
  yyparse();
return 0;
return 0;
}
}
static int
static int
yyerror (char *s)
yyerror (char *s)
{
{
  fprintf(stderr, "%s\n" , s);
  fprintf(stderr, "%s\n" , s);
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.