Call fatal_insn_not_found instead of abort
[official-gcc.git] / gcc / genconfig.c
blobb01a24bfc289a4dd170265101bb1b037625c895c
1 /* Generate from machine description:
2 - some #define configuration flags.
3 Copyright (C) 1987, 1991, 1997, 1998 Free Software Foundation, Inc.
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)
10 any later version.
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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "hconfig.h"
24 #ifdef __STDC__
25 #include <stdarg.h>
26 #else
27 #include <varargs.h>
28 #endif
29 #include "system.h"
30 #include "rtl.h"
31 #include "obstack.h"
33 static struct obstack obstack;
34 struct obstack *rtl_obstack = &obstack;
36 #define obstack_chunk_alloc xmalloc
37 #define obstack_chunk_free free
39 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
40 char **insn_name_ptr = 0;
42 /* flags to determine output of machine description dependent #define's. */
43 static int max_recog_operands; /* Largest operand number seen. */
44 static int max_dup_operands; /* Largest number of match_dup in any insn. */
45 static int max_clobbers_per_insn;
46 static int register_constraint_flag;
47 static int have_cc0_flag;
48 static int have_cmove_flag;
49 static int have_lo_sum_flag;
51 /* Maximum number of insns seen in a split. */
52 static int max_insns_per_split = 1;
54 static int clobbers_seen_this_insn;
55 static int dup_operands_seen_this_insn;
57 char *xmalloc PROTO((unsigned));
58 static void fatal PVPROTO ((char *, ...)) ATTRIBUTE_PRINTF_1;
59 void fancy_abort PROTO((void));
61 static void walk_insn_part PROTO((rtx, int, int));
62 static void gen_insn PROTO((rtx));
63 static void gen_expand PROTO((rtx));
64 static void gen_split PROTO((rtx));
65 static void gen_peephole PROTO((rtx));
67 /* RECOG_P will be non-zero if this pattern was seen in a context where it will
68 be used to recognize, rather than just generate an insn.
70 NON_PC_SET_SRC will be non-zero if this pattern was seen in a SET_SRC
71 of a SET whose destination is not (pc). */
73 static void
74 walk_insn_part (part, recog_p, non_pc_set_src)
75 rtx part;
76 int recog_p;
77 int non_pc_set_src;
79 register int i, j;
80 register RTX_CODE code;
81 register char *format_ptr;
83 if (part == 0)
84 return;
86 code = GET_CODE (part);
87 switch (code)
89 case CLOBBER:
90 clobbers_seen_this_insn++;
91 break;
93 case MATCH_OPERAND:
94 if (XINT (part, 0) > max_recog_operands)
95 max_recog_operands = XINT (part, 0);
96 if (XSTR (part, 2) && *XSTR (part, 2))
97 register_constraint_flag = 1;
98 return;
100 case MATCH_OP_DUP:
101 case MATCH_PAR_DUP:
102 ++dup_operands_seen_this_insn;
103 case MATCH_SCRATCH:
104 case MATCH_PARALLEL:
105 case MATCH_OPERATOR:
106 if (XINT (part, 0) > max_recog_operands)
107 max_recog_operands = XINT (part, 0);
108 /* Now scan the rtl's in the vector inside the MATCH_OPERATOR or
109 MATCH_PARALLEL. */
110 break;
112 case LABEL_REF:
113 if (GET_CODE (XEXP (part, 0)) == MATCH_OPERAND)
114 break;
115 return;
117 case MATCH_DUP:
118 ++dup_operands_seen_this_insn;
119 if (XINT (part, 0) > max_recog_operands)
120 max_recog_operands = XINT (part, 0);
121 return;
123 case CC0:
124 if (recog_p)
125 have_cc0_flag = 1;
126 return;
128 case LO_SUM:
129 if (recog_p)
130 have_lo_sum_flag = 1;
131 return;
133 case SET:
134 walk_insn_part (SET_DEST (part), 0, recog_p);
135 walk_insn_part (SET_SRC (part), recog_p,
136 GET_CODE (SET_DEST (part)) != PC);
137 return;
139 case IF_THEN_ELSE:
140 /* Only consider this machine as having a conditional move if the
141 two arms of the IF_THEN_ELSE are both MATCH_OPERAND. Otherwise,
142 we have some specific IF_THEN_ELSE construct (like the doz
143 instruction on the RS/6000) that can't be used in the general
144 context we want it for. */
146 if (recog_p && non_pc_set_src
147 && GET_CODE (XEXP (part, 1)) == MATCH_OPERAND
148 && GET_CODE (XEXP (part, 2)) == MATCH_OPERAND)
149 have_cmove_flag = 1;
150 break;
152 case REG: case CONST_INT: case SYMBOL_REF:
153 case PC:
154 return;
156 default:
157 break;
160 format_ptr = GET_RTX_FORMAT (GET_CODE (part));
162 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
163 switch (*format_ptr++)
165 case 'e':
166 case 'u':
167 walk_insn_part (XEXP (part, i), recog_p, non_pc_set_src);
168 break;
169 case 'E':
170 if (XVEC (part, i) != NULL)
171 for (j = 0; j < XVECLEN (part, i); j++)
172 walk_insn_part (XVECEXP (part, i, j), recog_p, non_pc_set_src);
173 break;
177 static void
178 gen_insn (insn)
179 rtx insn;
181 int i;
183 /* Walk the insn pattern to gather the #define's status. */
184 clobbers_seen_this_insn = 0;
185 dup_operands_seen_this_insn = 0;
186 if (XVEC (insn, 1) != 0)
187 for (i = 0; i < XVECLEN (insn, 1); i++)
188 walk_insn_part (XVECEXP (insn, 1, i), 1, 0);
190 if (clobbers_seen_this_insn > max_clobbers_per_insn)
191 max_clobbers_per_insn = clobbers_seen_this_insn;
192 if (dup_operands_seen_this_insn > max_dup_operands)
193 max_dup_operands = dup_operands_seen_this_insn;
196 /* Similar but scan a define_expand. */
198 static void
199 gen_expand (insn)
200 rtx insn;
202 int i;
204 /* Walk the insn pattern to gather the #define's status. */
206 /* Note that we don't bother recording the number of MATCH_DUPs
207 that occur in a gen_expand, because only reload cares about that. */
208 if (XVEC (insn, 1) != 0)
209 for (i = 0; i < XVECLEN (insn, 1); i++)
211 /* Compute the maximum SETs and CLOBBERS
212 in any one of the sub-insns;
213 don't sum across all of them. */
214 clobbers_seen_this_insn = 0;
216 walk_insn_part (XVECEXP (insn, 1, i), 0, 0);
218 if (clobbers_seen_this_insn > max_clobbers_per_insn)
219 max_clobbers_per_insn = clobbers_seen_this_insn;
223 /* Similar but scan a define_split. */
225 static void
226 gen_split (split)
227 rtx split;
229 int i;
231 /* Look through the patterns that are matched
232 to compute the maximum operand number. */
233 for (i = 0; i < XVECLEN (split, 0); i++)
234 walk_insn_part (XVECEXP (split, 0, i), 1, 0);
235 /* Look at the number of insns this insn could split into. */
236 if (XVECLEN (split, 2) > max_insns_per_split)
237 max_insns_per_split = XVECLEN (split, 2);
240 static void
241 gen_peephole (peep)
242 rtx peep;
244 int i;
246 /* Look through the patterns that are matched
247 to compute the maximum operand number. */
248 for (i = 0; i < XVECLEN (peep, 0); i++)
249 walk_insn_part (XVECEXP (peep, 0, i), 1, 0);
252 char *
253 xmalloc (size)
254 unsigned size;
256 register char *val = (char *) malloc (size);
258 if (val == 0)
259 fatal ("virtual memory exhausted");
261 return val;
264 char *
265 xrealloc (ptr, size)
266 char *ptr;
267 unsigned size;
269 char *result = (char *) realloc (ptr, size);
270 if (!result)
271 fatal ("virtual memory exhausted");
272 return result;
275 static void
276 fatal VPROTO ((char *format, ...))
278 #ifndef __STDC__
279 char *format;
280 #endif
281 va_list ap;
283 VA_START (ap, format);
285 #ifndef __STDC__
286 format = va_arg (ap, char *);
287 #endif
289 fprintf (stderr, "genconfig: ");
290 vfprintf (stderr, format, ap);
291 va_end (ap);
292 fprintf (stderr, "\n");
293 exit (FATAL_EXIT_CODE);
296 /* More 'friendly' abort that prints the line and file.
297 config.h can #define abort fancy_abort if you like that sort of thing. */
299 void
300 fancy_abort ()
302 fatal ("Internal gcc abort.");
306 main (argc, argv)
307 int argc;
308 char **argv;
310 rtx desc;
311 FILE *infile;
312 register int c;
314 obstack_init (rtl_obstack);
316 if (argc <= 1)
317 fatal ("No input file name.");
319 infile = fopen (argv[1], "r");
320 if (infile == 0)
322 perror (argv[1]);
323 exit (FATAL_EXIT_CODE);
326 init_rtl ();
328 printf ("/* Generated automatically by the program `genconfig'\n\
329 from the machine description file `md'. */\n\n");
331 /* Allow at least 10 operands for the sake of asm constructs. */
332 max_recog_operands = 9; /* We will add 1 later. */
333 max_dup_operands = 1;
335 /* Read the machine description. */
337 while (1)
339 c = read_skip_spaces (infile);
340 if (c == EOF)
341 break;
342 ungetc (c, infile);
344 desc = read_rtx (infile);
345 if (GET_CODE (desc) == DEFINE_INSN)
346 gen_insn (desc);
347 if (GET_CODE (desc) == DEFINE_EXPAND)
348 gen_expand (desc);
349 if (GET_CODE (desc) == DEFINE_SPLIT)
350 gen_split (desc);
351 if (GET_CODE (desc) == DEFINE_PEEPHOLE)
352 gen_peephole (desc);
355 printf ("\n#define MAX_RECOG_OPERANDS %d\n", max_recog_operands + 1);
357 printf ("\n#define MAX_DUP_OPERANDS %d\n", max_dup_operands);
359 /* This is conditionally defined, in case the user writes code which emits
360 more splits than we can readily see (and knows s/he does it). */
361 printf ("#ifndef MAX_INSNS_PER_SPLIT\n#define MAX_INSNS_PER_SPLIT %d\n#endif\n",
362 max_insns_per_split);
364 if (register_constraint_flag)
365 printf ("#define REGISTER_CONSTRAINTS\n");
367 if (have_cc0_flag)
368 printf ("#define HAVE_cc0\n");
370 if (have_cmove_flag)
371 printf ("#define HAVE_conditional_move\n");
373 if (have_lo_sum_flag)
374 printf ("#define HAVE_lo_sum\n");
376 fflush (stdout);
377 exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
378 /* NOTREACHED */
379 return 0;