|
|
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 (); ! 35: ! 36: char *xmalloc (); ! 37: static void fatal (); ! 38: void fancy_abort (); ! 39: ! 40: static void ! 41: write_upcase (str) ! 42: char *str; ! 43: { ! 44: for (; *str; str++) ! 45: if (*str >= 'a' && *str <= 'z') ! 46: printf ("%c", *str - 'a' + 'A'); ! 47: else ! 48: printf ("%c", *str); ! 49: } ! 50: ! 51: static void ! 52: gen_attr (attr) ! 53: rtx attr; ! 54: { ! 55: char *p; ! 56: ! 57: printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0)); ! 58: ! 59: /* If numeric attribute, don't need to write an enum. */ ! 60: if (*XSTR (attr, 1) == '\0') ! 61: printf ("extern int get_attr_%s ();\n", XSTR (attr, 0)); ! 62: else ! 63: { ! 64: printf ("enum attr_%s {", XSTR (attr, 0)); ! 65: write_upcase (XSTR (attr, 0)); ! 66: printf ("_"); ! 67: ! 68: for (p = XSTR (attr, 1); *p != '\0'; p++) ! 69: { ! 70: if (*p == ',') ! 71: { ! 72: printf (", "); ! 73: write_upcase (XSTR (attr, 0)); ! 74: printf ("_"); ! 75: } ! 76: else if (*p >= 'a' && *p <= 'z') ! 77: printf ("%c", *p - 'a' + 'A'); ! 78: else ! 79: printf ("%c", *p); ! 80: } ! 81: ! 82: printf ("};\n"); ! 83: printf ("extern enum attr_%s get_attr_%s ();\n\n", ! 84: XSTR (attr, 0), XSTR (attr, 0)); ! 85: } ! 86: ! 87: /* If `length' attribute, write additional function definitions and define ! 88: variables used by `insn_current_length'. */ ! 89: if (! strcmp (XSTR (attr, 0), "length")) ! 90: { ! 91: printf ("extern void init_lengths ();\n"); ! 92: printf ("extern void shorten_branches ();\n"); ! 93: printf ("extern int insn_default_length ();\n"); ! 94: printf ("extern int insn_variable_length_p ();\n"); ! 95: printf ("extern int insn_current_length ();\n\n"); ! 96: printf ("extern int *insn_addresses;\n"); ! 97: printf ("extern int insn_current_address;\n\n"); ! 98: } ! 99: } ! 100: ! 101: static void ! 102: write_units () ! 103: { ! 104: printf ("#define INSN_SCHEDULING\n\n"); ! 105: printf ("extern int result_ready_cost ();\n"); ! 106: printf ("extern int function_units_used ();\n\n"); ! 107: printf ("extern struct function_unit_desc\n"); ! 108: printf ("{\n"); ! 109: printf (" char *name;\n"); ! 110: printf (" int bitmask;\n"); ! 111: printf (" int multiplicity;\n"); ! 112: printf (" int simultaneity;\n"); ! 113: printf (" int default_cost;\n"); ! 114: printf (" int (*ready_cost_function) ();\n"); ! 115: printf (" int (*conflict_cost_function) ();\n"); ! 116: printf ("} function_units[];\n\n"); ! 117: } ! 118: ! 119: char * ! 120: xmalloc (size) ! 121: unsigned size; ! 122: { ! 123: register char *val = (char *) malloc (size); ! 124: ! 125: if (val == 0) ! 126: fatal ("virtual memory exhausted"); ! 127: return val; ! 128: } ! 129: ! 130: char * ! 131: xrealloc (ptr, size) ! 132: char *ptr; ! 133: unsigned size; ! 134: { ! 135: char * result = (char *) realloc (ptr, size); ! 136: if (!result) ! 137: fatal ("virtual memory exhausted"); ! 138: return result; ! 139: } ! 140: ! 141: static void ! 142: fatal (s, a1, a2) ! 143: char *s; ! 144: { ! 145: fprintf (stderr, "genattr: "); ! 146: fprintf (stderr, s, a1, a2); ! 147: fprintf (stderr, "\n"); ! 148: exit (FATAL_EXIT_CODE); ! 149: } ! 150: ! 151: /* More 'friendly' abort that prints the line and file. ! 152: config.h can #define abort fancy_abort if you like that sort of thing. */ ! 153: ! 154: void ! 155: fancy_abort () ! 156: { ! 157: fatal ("Internal gcc abort."); ! 158: } ! 159: ! 160: int ! 161: main (argc, argv) ! 162: int argc; ! 163: char **argv; ! 164: { ! 165: rtx desc; ! 166: FILE *infile; ! 167: extern rtx read_rtx (); ! 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:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.