Annotation of gcc/genflags.c, revision 1.1.1.1

1.1       root        1: /* Generate from machine description:
                      2: 
                      3:    - some flags HAVE_... saying which simple standard instructions are
                      4:    available for this machine.
                      5:    Copyright (C) 1987 Free Software Foundation, Inc.
                      6: 
                      7: This file is part of GNU CC.
                      8: 
                      9: GNU CC is distributed in the hope that it will be useful,
                     10: but WITHOUT ANY WARRANTY.  No author or distributor
                     11: accepts responsibility to anyone for the consequences of using it
                     12: or for whether it serves any particular purpose or works at all,
                     13: unless he says so in writing.  Refer to the GNU CC General Public
                     14: License for full details.
                     15: 
                     16: Everyone is granted permission to copy, modify and redistribute
                     17: GNU CC, but only under the conditions described in the
                     18: GNU CC General Public License.   A copy of this license is
                     19: supposed to have been given to you along with GNU CC so you
                     20: can know your rights and responsibilities.  It should be in a
                     21: file named COPYING.  Among other things, the copyright notice
                     22: and this notice must be preserved on all copies.  */
                     23: 
                     24: 
                     25: #include <stdio.h>
                     26: #include "rtl.h"
                     27: #include <obstack.h>
                     28: 
                     29: struct obstack obstack;
                     30: struct obstack *current_obstack = &obstack;
                     31: 
                     32: #define obstack_chunk_alloc xmalloc
                     33: #define obstack_chunk_free free
                     34: extern int xmalloc ();
                     35: extern void free ();
                     36: 
                     37: /* flags to determine output of machine description dependent #define's.  */
                     38: int max_recog_operands_flag;
                     39: int max_dup_operands_flag;
                     40: int max_sets_per_insn_flag;
                     41: int register_constraint_flag;
                     42: 
                     43: int sets_seen_this_insn;
                     44: int dup_operands_seen_this_insn;
                     45: 
                     46: void fatal ();
                     47: 
                     48: void
                     49: walk_insn_part (part)
                     50:      rtx part;
                     51: {
                     52:   register int i, j;
                     53:   register RTX_CODE code = GET_CODE (part);
                     54:   register char *format_ptr;
                     55: 
                     56:   switch (code)
                     57:     {
                     58:     case SET:
                     59:       sets_seen_this_insn++;
                     60:       break;
                     61: 
                     62:     case MATCH_OPERAND:
                     63:       if (XINT (part, 0) > max_recog_operands_flag)
                     64:        max_recog_operands_flag = XINT (part, 0);
                     65:       if (XSTR (part, 2) && *XSTR (part, 2))
                     66:        register_constraint_flag = 1;
                     67:       return;
                     68: 
                     69:     case MATCH_DUP:
                     70:       ++dup_operands_seen_this_insn;
                     71: 
                     72:     case REG: case CONST_INT: case SYMBOL_REF:
                     73:     case LABEL_REF: case PC: case CC0:
                     74:       return;
                     75:     }
                     76: 
                     77:   format_ptr = GET_RTX_FORMAT (GET_CODE (part));
                     78: 
                     79:   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
                     80:     switch (*format_ptr++)
                     81:       {
                     82:       case 'e':
                     83:        walk_insn_part (XEXP (part, i));
                     84:        break;
                     85:       case 'E':
                     86:        if (XVEC (part, i) != NULL)
                     87:          for (j = 0; j < XVECLEN (part, i); j++)
                     88:            walk_insn_part (XVECEXP (part, i, j));
                     89:        break;
                     90:       }
                     91: }
                     92: 
                     93: void
                     94: gen_insn (insn)
                     95:      rtx insn;
                     96: {
                     97:   int i;
                     98: 
                     99:   /* Walk the insn pattern to gather the #define's status.  */
                    100:   sets_seen_this_insn = 0;
                    101:   dup_operands_seen_this_insn = 0;
                    102:   for (i = 0; i < XVECLEN (insn, 1); i++) {
                    103:     walk_insn_part (XVECEXP (insn, 1, i));
                    104:   }
                    105:   if (sets_seen_this_insn > max_sets_per_insn_flag)
                    106:     max_sets_per_insn_flag = sets_seen_this_insn;
                    107:   if (dup_operands_seen_this_insn > max_dup_operands_flag)
                    108:     max_dup_operands_flag = dup_operands_seen_this_insn;
                    109: 
                    110:   /* Don't mention instructions whose names are the null string.
                    111:      They are in the machine description just to be recognized.  */
                    112:   if (strlen (XSTR (insn, 0)) == 0)
                    113:     return;
                    114: 
                    115:   printf ("#define HAVE_%s %s\n", XSTR (insn, 0),
                    116:          strlen (XSTR (insn, 2)) ? XSTR (insn, 2) : "1");
                    117:   printf ("extern rtx gen_%s ();\n", XSTR (insn, 0));
                    118: }
                    119: 
                    120: xmalloc (size)
                    121: {
                    122:   register int val = malloc (size);
                    123: 
                    124:   if (val == 0)
                    125:     abort ();
                    126: 
                    127:   return val;
                    128: }
                    129: 
                    130: int
                    131: xrealloc (ptr, size)
                    132:      char *ptr;
                    133:      int size;
                    134: {
                    135:   int result = realloc (ptr, size);
                    136:   if (!result)
                    137:     abort ();
                    138:   return result;
                    139: }
                    140: 
                    141: void
                    142: fatal (s, a1, a2)
                    143: {
                    144:   fprintf (stderr, "genflags: ");
                    145:   fprintf (stderr, s, a1, a2);
                    146:   fprintf (stderr, "\n");
                    147:   exit (1);
                    148: }
                    149: 
                    150: main (argc, argv)
                    151:      int argc;
                    152:      char **argv;
                    153: {
                    154:   rtx desc;
                    155:   FILE *infile;
                    156:   extern rtx read_rtx ();
                    157:   register int c;
                    158: 
                    159:   obstack_begin (current_obstack, 4060);
                    160: 
                    161:   if (argc <= 1)
                    162:     fatal ("No input file name.");
                    163: 
                    164:   infile = fopen (argv[1], "r");
                    165:   if (infile == 0)
                    166:     {
                    167:       perror (argv[1]);
                    168:       exit (1);
                    169:     }
                    170: 
                    171:   init_rtl ();
                    172: 
                    173:   printf ("/* Generated automatically by the program `genflags'\n\
                    174: from the machine description file `md'.  */\n\n");
                    175: 
                    176:   /* Read the machine description.  */
                    177: 
                    178:   while (1)
                    179:     {
                    180:       c = read_skip_spaces (infile);
                    181:       if (c == EOF)
                    182:        break;
                    183:       ungetc (c, infile);
                    184: 
                    185:       desc = read_rtx (infile);
                    186:       gen_insn (desc);
                    187:     }
                    188: 
                    189:   return 0;
                    190: }

unix.superglobalmegacorp.com

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