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 ();
46 if (*str >= 'a' && *str <= 'z')
47 printf ("%c", *str - 'a' + 'A');
58 printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0));
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));
65 printf ("enum attr_%s {", XSTR (attr, 0));
66 write_upcase (XSTR (attr, 0));
69 for (p = XSTR (attr, 1); *p != '\0'; p++)
74 write_upcase (XSTR (attr, 0));
77 else if (*p >= 'a' && *p <= 'z')
78 printf ("%c", *p - 'a' + 'A');
84 printf ("extern enum attr_%s get_attr_%s ();\n\n",
85 XSTR (attr, 0), XSTR (attr, 0));
88 /* If `length' attribute, write additional function definitions and define
89 variables used by `insn_current_length'. */
90 if (! strcmp (XSTR (attr, 0), "length"))
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");
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");
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");
124 register char *val = (char *) malloc (size);
127 fatal ("virtual memory exhausted");
136 char * result = (char *) realloc (ptr, size);
138 fatal ("virtual memory exhausted");
146 fprintf (stderr, "genattr: ");
147 fprintf (stderr, s, a1, a2);
148 fprintf (stderr, "\n");
149 exit (FATAL_EXIT_CODE);
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. */
158 fatal ("Internal gcc abort.");
170 int have_annul_true = 0;
171 int have_annul_false = 0;
175 obstack_init (rtl_obstack);
178 fatal ("No input file name.");
180 infile = fopen (argv[1], "r");
184 exit (FATAL_EXIT_CODE);
189 printf ("/* Generated automatically by the program `genattr'\n\
190 from the machine description file `md'. */\n\n");
192 /* For compatibility, define the attribute `alternative', which is just
193 a reference to the variable `which_alternative'. */
195 printf ("#define HAVE_ATTR_alternative\n");
196 printf ("#define get_attr_alternative(insn) which_alternative\n");
198 /* Read the machine description. */
202 c = read_skip_spaces (infile);
207 desc = read_rtx (infile);
208 if (GET_CODE (desc) == DEFINE_ATTR)
211 else if (GET_CODE (desc) == DEFINE_DELAY)
215 printf ("#define DELAY_SLOTS\n");
216 printf ("extern int num_delay_slots ();\n");
217 printf ("extern int eligible_for_delay ();\n\n");
221 for (i = 0; i < XVECLEN (desc, 1); i += 3)
223 if (XVECEXP (desc, 1, i + 1) && ! have_annul_true)
225 printf ("#define ANNUL_IFTRUE_SLOTS\n");
226 printf ("extern int eligible_for_annul_true ();\n");
230 if (XVECEXP (desc, 1, i + 2) && ! have_annul_false)
232 printf ("#define ANNUL_IFFALSE_SLOTS\n");
233 printf ("extern int eligible_for_annul_false ();\n");
234 have_annul_false = 1;
239 else if (GET_CODE (desc) == DEFINE_FUNCTION_UNIT && ! have_units)
247 exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);