Annotation of gcc/genattr.c, revision 1.1.1.2

1.1       root        1: /* Generate attribute information (insn-attr.h) from machine description.
                      2:    Copyright (C) 1991 Free Software Foundation, Inc.
                      3:    Contributed by Richard Kenner ([email protected])
                      4: 
                      5: This file is part of GNU CC.
                      6: 
                      7: GNU CC is free software; you can redistribute it and/or modify
                      8: it under the terms of the GNU General Public License as published by
                      9: the Free Software Foundation; either version 2, or (at your option)
                     10: any later version.
                     11: 
                     12: GNU CC is distributed in the hope that it will be useful,
                     13: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: GNU General Public License for more details.
                     16: 
                     17: You should have received a copy of the GNU General Public License
                     18: along with GNU CC; see the file COPYING.  If not, write to
                     19: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
                     20: 
                     21: 
                     22: #include <stdio.h>
                     23: #include "config.h"
                     24: #include "rtl.h"
                     25: #include "obstack.h"
                     26: 
                     27: static struct obstack obstack;
                     28: struct obstack *rtl_obstack = &obstack;
                     29: 
                     30: #define obstack_chunk_alloc xmalloc
                     31: #define obstack_chunk_free free
                     32: 
                     33: extern void free ();
                     34: extern int atoi ();
1.1.1.2 ! root       35: extern rtx read_rtx ();
1.1       root       36: 
                     37: char *xmalloc ();
                     38: static void fatal ();
                     39: void fancy_abort ();
                     40: 
                     41: static void
                     42: write_upcase (str)
                     43:     char *str;
                     44: {
                     45:   for (; *str; str++)
                     46:     if (*str >= 'a' && *str <= 'z')
                     47:       printf ("%c", *str - 'a' + 'A');
                     48:     else
                     49:       printf ("%c", *str);
                     50: }
                     51: 
                     52: static void
                     53: gen_attr (attr)
                     54:      rtx attr;
                     55: {
                     56:   char *p;
                     57: 
                     58:   printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0));
                     59: 
                     60:   /* If numeric attribute, don't need to write an enum.  */
                     61:   if (*XSTR (attr, 1) == '\0')
                     62:     printf ("extern int get_attr_%s ();\n", XSTR (attr, 0));
                     63:   else
                     64:     {
                     65:       printf ("enum attr_%s {", XSTR (attr, 0));
                     66:       write_upcase (XSTR (attr, 0));
                     67:       printf ("_");
                     68: 
                     69:       for (p = XSTR (attr, 1); *p != '\0'; p++)
                     70:        {
                     71:          if (*p == ',')
                     72:            {
                     73:              printf (", ");
                     74:              write_upcase (XSTR (attr, 0));
                     75:              printf ("_");
                     76:            }
                     77:          else if (*p >= 'a' && *p <= 'z')
                     78:            printf ("%c", *p - 'a' + 'A');
                     79:          else
                     80:            printf ("%c", *p);
                     81:        }
                     82: 
                     83:       printf ("};\n");
                     84:       printf ("extern enum attr_%s get_attr_%s ();\n\n",
                     85:              XSTR (attr, 0), XSTR (attr, 0));
                     86:     }
                     87: 
                     88:   /* If `length' attribute, write additional function definitions and define
                     89:      variables used by `insn_current_length'.  */
                     90:   if (! strcmp (XSTR (attr, 0), "length"))
                     91:     {
                     92:       printf ("extern void init_lengths ();\n");
                     93:       printf ("extern void shorten_branches ();\n");
                     94:       printf ("extern int insn_default_length ();\n");
                     95:       printf ("extern int insn_variable_length_p ();\n");
                     96:       printf ("extern int insn_current_length ();\n\n");
                     97:       printf ("extern int *insn_addresses;\n");
                     98:       printf ("extern int insn_current_address;\n\n");
                     99:     }
                    100: }
                    101: 
                    102: static void
                    103: write_units ()
                    104: {
                    105:   printf ("#define INSN_SCHEDULING\n\n");
                    106:   printf ("extern int result_ready_cost ();\n");
                    107:   printf ("extern int function_units_used ();\n\n");
                    108:   printf ("extern struct function_unit_desc\n");
                    109:   printf ("{\n");
                    110:   printf ("  char *name;\n");
                    111:   printf ("  int bitmask;\n");
                    112:   printf ("  int multiplicity;\n");
                    113:   printf ("  int simultaneity;\n");
                    114:   printf ("  int default_cost;\n");
                    115:   printf ("  int (*ready_cost_function) ();\n");
                    116:   printf ("  int (*conflict_cost_function) ();\n");
                    117:   printf ("} function_units[];\n\n");
                    118: }
                    119: 
                    120: char *
                    121: xmalloc (size)
                    122:      unsigned size;
                    123: {
                    124:   register char *val = (char *) malloc (size);
                    125: 
                    126:   if (val == 0)
                    127:     fatal ("virtual memory exhausted");
                    128:   return val;
                    129: }
                    130: 
                    131: char *
                    132: xrealloc (ptr, size)
                    133:      char *ptr;
                    134:      unsigned size;
                    135: {
                    136:   char * result = (char *) realloc (ptr, size);
                    137:   if (!result)
                    138:     fatal ("virtual memory exhausted");
                    139:   return result;
                    140: }
                    141: 
                    142: static void
                    143: fatal (s, a1, a2)
                    144:      char *s;
                    145: {
                    146:   fprintf (stderr, "genattr: ");
                    147:   fprintf (stderr, s, a1, a2);
                    148:   fprintf (stderr, "\n");
                    149:   exit (FATAL_EXIT_CODE);
                    150: }
                    151: 
                    152: /* More 'friendly' abort that prints the line and file.
                    153:    config.h can #define abort fancy_abort if you like that sort of thing.  */
                    154: 
                    155: void
                    156: fancy_abort ()
                    157: {
                    158:   fatal ("Internal gcc abort.");
                    159: }
                    160: 
                    161: int
                    162: main (argc, argv)
                    163:      int argc;
                    164:      char **argv;
                    165: {
                    166:   rtx desc;
                    167:   FILE *infile;
                    168:   register int c;
                    169:   int have_delay = 0;
                    170:   int have_annul_true = 0;
                    171:   int have_annul_false = 0;
                    172:   int have_units = 0;
                    173:   int i;
                    174: 
                    175:   obstack_init (rtl_obstack);
                    176: 
                    177:   if (argc <= 1)
                    178:     fatal ("No input file name.");
                    179: 
                    180:   infile = fopen (argv[1], "r");
                    181:   if (infile == 0)
                    182:     {
                    183:       perror (argv[1]);
                    184:       exit (FATAL_EXIT_CODE);
                    185:     }
                    186: 
                    187:   init_rtl ();
                    188: 
                    189:   printf ("/* Generated automatically by the program `genattr'\n\
                    190: from the machine description file `md'.  */\n\n");
                    191: 
                    192:   /* For compatibility, define the attribute `alternative', which is just
                    193:      a reference to the variable `which_alternative'.  */
                    194: 
                    195:   printf ("#define HAVE_ATTR_alternative\n");
                    196:   printf ("#define get_attr_alternative(insn) which_alternative\n");
                    197:      
                    198:   /* Read the machine description.  */
                    199: 
                    200:   while (1)
                    201:     {
                    202:       c = read_skip_spaces (infile);
                    203:       if (c == EOF)
                    204:        break;
                    205:       ungetc (c, infile);
                    206: 
                    207:       desc = read_rtx (infile);
                    208:       if (GET_CODE (desc) == DEFINE_ATTR)
                    209:        gen_attr (desc);
                    210: 
                    211:       else if (GET_CODE (desc) == DEFINE_DELAY)
                    212:         {
                    213:          if (! have_delay)
                    214:            {
                    215:              printf ("#define DELAY_SLOTS\n");
                    216:              printf ("extern int num_delay_slots ();\n");
                    217:              printf ("extern int eligible_for_delay ();\n\n");
                    218:              have_delay = 1;
                    219:            }
                    220: 
                    221:          for (i = 0; i < XVECLEN (desc, 1); i += 3)
                    222:            {
                    223:              if (XVECEXP (desc, 1, i + 1) && ! have_annul_true)
                    224:                {
                    225:                  printf ("#define ANNUL_IFTRUE_SLOTS\n");
                    226:                  printf ("extern int eligible_for_annul_true ();\n");
                    227:                  have_annul_true = 1;
                    228:                }
                    229: 
                    230:              if (XVECEXP (desc, 1, i + 2) && ! have_annul_false)
                    231:                {
                    232:                  printf ("#define ANNUL_IFFALSE_SLOTS\n");
                    233:                  printf ("extern int eligible_for_annul_false ();\n");
                    234:                  have_annul_false = 1;
                    235:                }
                    236:            }
                    237:         }
                    238: 
                    239:       else if (GET_CODE (desc) == DEFINE_FUNCTION_UNIT && ! have_units)
                    240:        {
                    241:          have_units = 1;
                    242:          write_units ();
                    243:        }
                    244:     }
                    245: 
                    246:   fflush (stdout);
                    247:   exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
                    248:   /* NOTREACHED */
                    249:   return 0;
                    250: }
                    251: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.