]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/genconfig.c
c-common.c: Include <stdlib.h> and <string.h>/<strings.h>.
[thirdparty/gcc.git] / gcc / genconfig.c
CommitLineData
aabf90e8 1/* Generate from machine description:
aabf90e8 2 - some #define configuration flags.
ccd043a9 3 Copyright (C) 1987, 1991, 1997 Free Software Foundation, Inc.
aabf90e8
RK
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
a35311b0
RK
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
aabf90e8
RK
21
22
23#include <stdio.h>
0d64891c 24#include "hconfig.h"
aabf90e8
RK
25#include "rtl.h"
26#include "obstack.h"
27
ccd043a9
RL
28#ifdef HAVE_STDLIB_H
29#include <stdlib.h>
30#endif
31
aabf90e8
RK
32static struct obstack obstack;
33struct obstack *rtl_obstack = &obstack;
34
35#define obstack_chunk_alloc xmalloc
36#define obstack_chunk_free free
37
38extern void free ();
31d04616 39extern rtx read_rtx ();
aabf90e8
RK
40
41/* flags to determine output of machine description dependent #define's. */
7b7bceeb
RS
42static int max_recog_operands; /* Largest operand number seen. */
43static int max_dup_operands; /* Largest number of match_dup in any insn. */
aabf90e8
RK
44static int max_clobbers_per_insn;
45static int register_constraint_flag;
46static int have_cc0_flag;
674ba2d6 47static int have_cmove_flag;
aabf90e8
RK
48static int have_lo_sum_flag;
49
50/* Maximum number of insns seen in a split. */
51static int max_insns_per_split = 1;
52
53static int clobbers_seen_this_insn;
54static int dup_operands_seen_this_insn;
55
56char *xmalloc ();
57static void fatal ();
58void fancy_abort ();
59
60/* RECOG_P will be non-zero if this pattern was seen in a context where it will
674ba2d6
RK
61 be used to recognize, rather than just generate an insn.
62
63 NON_PC_SET_SRC will be non-zero if this pattern was seen in a SET_SRC
64 of a SET whose destination is not (pc). */
aabf90e8
RK
65
66static void
674ba2d6 67walk_insn_part (part, recog_p, non_pc_set_src)
aabf90e8 68 rtx part;
674ba2d6
RK
69 int recog_p;
70 int non_pc_set_src;
aabf90e8
RK
71{
72 register int i, j;
73 register RTX_CODE code;
74 register char *format_ptr;
75
76 if (part == 0)
77 return;
78
79 code = GET_CODE (part);
80 switch (code)
81 {
82 case CLOBBER:
83 clobbers_seen_this_insn++;
84 break;
85
86 case MATCH_OPERAND:
87 if (XINT (part, 0) > max_recog_operands)
88 max_recog_operands = XINT (part, 0);
89 if (XSTR (part, 2) && *XSTR (part, 2))
90 register_constraint_flag = 1;
91 return;
92
93 case MATCH_OP_DUP:
13ed0ef0 94 case MATCH_PAR_DUP:
aabf90e8
RK
95 ++dup_operands_seen_this_insn;
96 case MATCH_SCRATCH:
97 case MATCH_PARALLEL:
98 case MATCH_OPERATOR:
99 if (XINT (part, 0) > max_recog_operands)
100 max_recog_operands = XINT (part, 0);
101 /* Now scan the rtl's in the vector inside the MATCH_OPERATOR or
102 MATCH_PARALLEL. */
103 break;
104
105 case LABEL_REF:
106 if (GET_CODE (XEXP (part, 0)) == MATCH_OPERAND)
107 break;
108 return;
109
110 case MATCH_DUP:
111 ++dup_operands_seen_this_insn;
112 if (XINT (part, 0) > max_recog_operands)
113 max_recog_operands = XINT (part, 0);
114 return;
115
116 case CC0:
117 if (recog_p)
118 have_cc0_flag = 1;
119 return;
120
121 case LO_SUM:
122 if (recog_p)
123 have_lo_sum_flag = 1;
124 return;
125
674ba2d6
RK
126 case SET:
127 walk_insn_part (SET_DEST (part), 0, recog_p);
128 walk_insn_part (SET_SRC (part), recog_p,
129 GET_CODE (SET_DEST (part)) != PC);
130 return;
131
132 case IF_THEN_ELSE:
9e87cc89
RK
133 /* Only consider this machine as having a conditional move if the
134 two arms of the IF_THEN_ELSE are both MATCH_OPERAND. Otherwise,
135 we have some specific IF_THEN_ELSE construct (like the doz
136 instruction on the RS/6000) that can't be used in the general
137 context we want it for. */
138
139 if (recog_p && non_pc_set_src
140 && GET_CODE (XEXP (part, 1)) == MATCH_OPERAND
141 && GET_CODE (XEXP (part, 2)) == MATCH_OPERAND)
674ba2d6
RK
142 have_cmove_flag = 1;
143 break;
144
aabf90e8
RK
145 case REG: case CONST_INT: case SYMBOL_REF:
146 case PC:
147 return;
ccd043a9
RL
148
149 default:
150 break;
aabf90e8
RK
151 }
152
153 format_ptr = GET_RTX_FORMAT (GET_CODE (part));
154
155 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
156 switch (*format_ptr++)
157 {
158 case 'e':
159 case 'u':
674ba2d6 160 walk_insn_part (XEXP (part, i), recog_p, non_pc_set_src);
aabf90e8
RK
161 break;
162 case 'E':
163 if (XVEC (part, i) != NULL)
164 for (j = 0; j < XVECLEN (part, i); j++)
674ba2d6 165 walk_insn_part (XVECEXP (part, i, j), recog_p, non_pc_set_src);
aabf90e8
RK
166 break;
167 }
168}
169
170static void
171gen_insn (insn)
172 rtx insn;
173{
174 int i;
175
176 /* Walk the insn pattern to gather the #define's status. */
177 clobbers_seen_this_insn = 0;
178 dup_operands_seen_this_insn = 0;
179 if (XVEC (insn, 1) != 0)
180 for (i = 0; i < XVECLEN (insn, 1); i++)
674ba2d6 181 walk_insn_part (XVECEXP (insn, 1, i), 1, 0);
aabf90e8
RK
182
183 if (clobbers_seen_this_insn > max_clobbers_per_insn)
184 max_clobbers_per_insn = clobbers_seen_this_insn;
185 if (dup_operands_seen_this_insn > max_dup_operands)
186 max_dup_operands = dup_operands_seen_this_insn;
187}
188
189/* Similar but scan a define_expand. */
190
191static void
192gen_expand (insn)
193 rtx insn;
194{
195 int i;
196
197 /* Walk the insn pattern to gather the #define's status. */
198
199 /* Note that we don't bother recording the number of MATCH_DUPs
200 that occur in a gen_expand, because only reload cares about that. */
201 if (XVEC (insn, 1) != 0)
202 for (i = 0; i < XVECLEN (insn, 1); i++)
203 {
204 /* Compute the maximum SETs and CLOBBERS
205 in any one of the sub-insns;
206 don't sum across all of them. */
207 clobbers_seen_this_insn = 0;
208
674ba2d6 209 walk_insn_part (XVECEXP (insn, 1, i), 0, 0);
aabf90e8
RK
210
211 if (clobbers_seen_this_insn > max_clobbers_per_insn)
212 max_clobbers_per_insn = clobbers_seen_this_insn;
213 }
214}
215
216/* Similar but scan a define_split. */
217
218static void
219gen_split (split)
220 rtx split;
221{
222 int i;
223
224 /* Look through the patterns that are matched
225 to compute the maximum operand number. */
226 for (i = 0; i < XVECLEN (split, 0); i++)
674ba2d6 227 walk_insn_part (XVECEXP (split, 0, i), 1, 0);
aabf90e8
RK
228 /* Look at the number of insns this insn could split into. */
229 if (XVECLEN (split, 2) > max_insns_per_split)
230 max_insns_per_split = XVECLEN (split, 2);
231}
232
233static void
234gen_peephole (peep)
235 rtx peep;
236{
237 int i;
238
239 /* Look through the patterns that are matched
240 to compute the maximum operand number. */
241 for (i = 0; i < XVECLEN (peep, 0); i++)
674ba2d6 242 walk_insn_part (XVECEXP (peep, 0, i), 1, 0);
aabf90e8
RK
243}
244\f
245char *
246xmalloc (size)
247 unsigned size;
248{
249 register char *val = (char *) malloc (size);
250
251 if (val == 0)
252 fatal ("virtual memory exhausted");
253
254 return val;
255}
256
257char *
258xrealloc (ptr, size)
259 char *ptr;
260 unsigned size;
261{
262 char *result = (char *) realloc (ptr, size);
263 if (!result)
264 fatal ("virtual memory exhausted");
265 return result;
266}
267
268static void
269fatal (s, a1, a2)
270 char *s;
271{
272 fprintf (stderr, "genconfig: ");
273 fprintf (stderr, s, a1, a2);
274 fprintf (stderr, "\n");
275 exit (FATAL_EXIT_CODE);
276}
277
278/* More 'friendly' abort that prints the line and file.
279 config.h can #define abort fancy_abort if you like that sort of thing. */
280
281void
282fancy_abort ()
283{
284 fatal ("Internal gcc abort.");
285}
286\f
287int
288main (argc, argv)
289 int argc;
290 char **argv;
291{
292 rtx desc;
293 FILE *infile;
aabf90e8
RK
294 register int c;
295
296 obstack_init (rtl_obstack);
297
298 if (argc <= 1)
299 fatal ("No input file name.");
300
301 infile = fopen (argv[1], "r");
302 if (infile == 0)
303 {
304 perror (argv[1]);
305 exit (FATAL_EXIT_CODE);
306 }
307
308 init_rtl ();
309
310 printf ("/* Generated automatically by the program `genconfig'\n\
311from the machine description file `md'. */\n\n");
312
313 /* Allow at least 10 operands for the sake of asm constructs. */
7b7bceeb 314 max_recog_operands = 9; /* We will add 1 later. */
aabf90e8
RK
315 max_dup_operands = 1;
316
317 /* Read the machine description. */
318
319 while (1)
320 {
321 c = read_skip_spaces (infile);
322 if (c == EOF)
323 break;
324 ungetc (c, infile);
325
326 desc = read_rtx (infile);
327 if (GET_CODE (desc) == DEFINE_INSN)
328 gen_insn (desc);
329 if (GET_CODE (desc) == DEFINE_EXPAND)
330 gen_expand (desc);
331 if (GET_CODE (desc) == DEFINE_SPLIT)
332 gen_split (desc);
333 if (GET_CODE (desc) == DEFINE_PEEPHOLE)
334 gen_peephole (desc);
335 }
336
7b7bceeb 337 printf ("\n#define MAX_RECOG_OPERANDS %d\n", max_recog_operands + 1);
aabf90e8
RK
338
339 printf ("\n#define MAX_DUP_OPERANDS %d\n", max_dup_operands);
340
341 /* This is conditionally defined, in case the user writes code which emits
342 more splits than we can readily see (and knows s/he does it). */
343 printf ("#ifndef MAX_INSNS_PER_SPLIT\n#define MAX_INSNS_PER_SPLIT %d\n#endif\n",
344 max_insns_per_split);
345
346 if (register_constraint_flag)
347 printf ("#define REGISTER_CONSTRAINTS\n");
348
349 if (have_cc0_flag)
350 printf ("#define HAVE_cc0\n");
351
674ba2d6 352 if (have_cmove_flag)
1a395e69 353 printf ("#define HAVE_conditional_move\n");
674ba2d6 354
aabf90e8
RK
355 if (have_lo_sum_flag)
356 printf ("#define HAVE_lo_sum\n");
357
358 fflush (stdout);
359 exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
360 /* NOTREACHED */
361 return 0;
362}