1 /* Generate attribute information (insn-attr.h) from machine description.
2 Copyright (C) 1991 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@nyu.edu)
5 This file is part of GNU CC.
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)
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.
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. */
27 static struct obstack obstack;
28 struct obstack *rtl_obstack = &obstack;
30 #define obstack_chunk_alloc xmalloc
31 #define obstack_chunk_free free
35 extern rtx read_rtx ();
43 struct namelist *next;
52 if (*str >= 'a' && *str <= 'z')
53 printf ("%c", *str - 'a' + 'A');
64 printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0));
66 /* If numeric attribute, don't need to write an enum. */
67 if (*XSTR (attr, 1) == '\0')
68 printf ("extern int get_attr_%s ();\n", XSTR (attr, 0));
71 printf ("enum attr_%s {", XSTR (attr, 0));
72 write_upcase (XSTR (attr, 0));
75 for (p = XSTR (attr, 1); *p != '\0'; p++)
80 write_upcase (XSTR (attr, 0));
83 else if (*p >= 'a' && *p <= 'z')
84 printf ("%c", *p - 'a' + 'A');
90 printf ("extern enum attr_%s get_attr_%s ();\n\n",
91 XSTR (attr, 0), XSTR (attr, 0));
94 /* If `length' attribute, write additional function definitions and define
95 variables used by `insn_current_length'. */
96 if (! strcmp (XSTR (attr, 0), "length"))
98 printf ("extern void init_lengths ();\n");
99 printf ("extern void shorten_branches ();\n");
100 printf ("extern int insn_default_length ();\n");
101 printf ("extern int insn_variable_length_p ();\n");
102 printf ("extern int insn_current_length ();\n\n");
103 printf ("extern int *insn_addresses;\n");
104 printf ("extern int insn_current_address;\n\n");
109 write_units (num_units, min_ready_cost, max_ready_cost,
110 min_busy_delay, max_busy_delay)
112 printf ("#define INSN_SCHEDULING\n\n");
113 printf ("extern int result_ready_cost ();\n");
114 printf ("extern int function_units_used ();\n\n");
115 printf ("extern struct function_unit_desc\n");
117 printf (" char *name;\n");
118 printf (" int bitmask;\n");
119 printf (" int multiplicity;\n");
120 printf (" int simultaneity;\n");
121 printf (" int default_cost;\n");
122 printf (" int max_busy_cost;\n");
123 printf (" int (*ready_cost_function) ();\n");
124 printf (" int (*conflict_cost_function) ();\n");
125 printf ("} function_units[];\n\n");
126 printf ("#define FUNCTION_UNITS_SIZE %d\n", num_units);
127 printf ("#define MIN_READY_COST %d\n", min_ready_cost);
128 printf ("#define MAX_READY_COST %d\n", max_ready_cost);
129 printf ("#define MIN_BUSY_DELAY %d\n", min_busy_delay);
130 printf ("#define MAX_BUSY_DELAY %d\n\n", max_busy_delay);
137 register char *val = (char *) malloc (size);
140 fatal ("virtual memory exhausted");
149 char * result = (char *) realloc (ptr, size);
151 fatal ("virtual memory exhausted");
159 fprintf (stderr, "genattr: ");
160 fprintf (stderr, s, a1, a2);
161 fprintf (stderr, "\n");
162 exit (FATAL_EXIT_CODE);
165 /* More 'friendly' abort that prints the line and file.
166 config.h can #define abort fancy_abort if you like that sort of thing. */
171 fatal ("Internal gcc abort.");
183 int have_annul_true = 0;
184 int have_annul_false = 0;
187 int min_ready_cost = 100000, max_ready_cost = -1;
188 int min_busy_delay = 100000, max_busy_delay = -1;
189 struct namelist *units = 0;
192 obstack_init (rtl_obstack);
195 fatal ("No input file name.");
197 infile = fopen (argv[1], "r");
201 exit (FATAL_EXIT_CODE);
206 printf ("/* Generated automatically by the program `genattr'\n\
207 from the machine description file `md'. */\n\n");
209 /* For compatibility, define the attribute `alternative', which is just
210 a reference to the variable `which_alternative'. */
212 printf ("#define HAVE_ATTR_alternative\n");
213 printf ("#define get_attr_alternative(insn) which_alternative\n");
215 /* Read the machine description. */
219 c = read_skip_spaces (infile);
224 desc = read_rtx (infile);
225 if (GET_CODE (desc) == DEFINE_ATTR)
228 else if (GET_CODE (desc) == DEFINE_DELAY)
232 printf ("#define DELAY_SLOTS\n");
233 printf ("extern int num_delay_slots ();\n");
234 printf ("extern int eligible_for_delay ();\n\n");
238 for (i = 0; i < XVECLEN (desc, 1); i += 3)
240 if (XVECEXP (desc, 1, i + 1) && ! have_annul_true)
242 printf ("#define ANNUL_IFTRUE_SLOTS\n");
243 printf ("extern int eligible_for_annul_true ();\n");
247 if (XVECEXP (desc, 1, i + 2) && ! have_annul_false)
249 printf ("#define ANNUL_IFFALSE_SLOTS\n");
250 printf ("extern int eligible_for_annul_false ();\n");
251 have_annul_false = 1;
256 else if (GET_CODE (desc) == DEFINE_FUNCTION_UNIT)
258 struct namelist *unit;
259 char *name = XSTR (desc, 0);
260 int ready_cost = XINT (desc, 4);
261 int busy_delay = XINT (desc, 5);
264 if (min_ready_cost > ready_cost) min_ready_cost = ready_cost;
265 if (max_ready_cost < ready_cost) max_ready_cost = ready_cost;
266 if (min_busy_delay > busy_delay) min_busy_delay = busy_delay;
267 if (max_busy_delay < busy_delay) max_busy_delay = busy_delay;
269 /* If the optional conflict vector was specified, the busy delay
271 if (XVEC (desc, 6) != 0) min_busy_delay = 0;
273 for (unit = units; unit; unit = unit->next)
274 if (strcmp (unit->name, name) == 0)
278 int len = strlen (name) + 1;
279 unit = (struct namelist *) alloca (sizeof (struct namelist));
280 unit->name = (char *) alloca (len);
281 bcopy (name, unit->name, len);
290 write_units (num_units, min_ready_cost, max_ready_cost,
291 min_busy_delay, max_busy_delay);
294 exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);