|
|
1.1 root 1: /* Generate from machine description:
2:
3: - some #define configuration flags.
4: Copyright (C) 1987 Free Software Foundation, Inc.
5:
6: This file is part of GNU CC.
7:
8: GNU CC is distributed in the hope that it will be useful,
9: but WITHOUT ANY WARRANTY. No author or distributor
10: accepts responsibility to anyone for the consequences of using it
11: or for whether it serves any particular purpose or works at all,
12: unless he says so in writing. Refer to the GNU CC General Public
13: License for full details.
14:
15: Everyone is granted permission to copy, modify and redistribute
16: GNU CC, but only under the conditions described in the
17: GNU CC General Public License. A copy of this license is
18: supposed to have been given to you along with GNU CC so you
19: can know your rights and responsibilities. It should be in a
20: file named COPYING. Among other things, the copyright notice
21: and this notice must be preserved on all copies. */
22:
23:
24: #include <stdio.h>
25: #include "config.h"
26: #include "rtl.h"
27: #include "obstack.h"
28:
29: struct obstack obstack;
30: struct obstack *rtl_obstack = &obstack;
31:
32: #define obstack_chunk_alloc xmalloc
33: #define obstack_chunk_free free
34: extern int xmalloc ();
35: extern void free ();
36:
37: /* flags to determine output of machine description dependent #define's. */
38: int max_recog_operands_flag;
39: int max_dup_operands_flag;
40: int max_sets_per_insn_flag;
41: int max_clobbers_per_insn_flag;
42: int register_constraint_flag;
43:
44: int sets_seen_this_insn;
45: int clobbers_seen_this_insn;
46: int dup_operands_seen_this_insn;
47:
48: void fatal ();
49:
50: void
51: walk_insn_part (part)
52: rtx part;
53: {
54: register int i, j;
55: register RTX_CODE code;
56: register char *format_ptr;
57:
58: if (part == 0)
59: return;
60:
61: code = GET_CODE (part);
62: switch (code)
63: {
64: case SET:
65: sets_seen_this_insn++;
66: break;
67:
68: case CLOBBER:
69: clobbers_seen_this_insn++;
70: break;
71:
72: case MATCH_OPERAND:
73: if (XINT (part, 0) > max_recog_operands_flag)
74: max_recog_operands_flag = XINT (part, 0);
75: if (XSTR (part, 2) && *XSTR (part, 2))
76: register_constraint_flag = 1;
77: return;
78:
79: case LABEL_REF:
80: if (GET_CODE (XEXP (part, 0)) == MATCH_OPERAND)
81: break;
82: return;
83:
84: case MATCH_DUP:
85: ++dup_operands_seen_this_insn;
86: if (XINT (part, 0) > max_recog_operands_flag)
87: max_recog_operands_flag = XINT (part, 0);
88:
89: case REG: case CONST_INT: case SYMBOL_REF:
90: case PC: case CC0:
91: return;
92: }
93:
94: format_ptr = GET_RTX_FORMAT (GET_CODE (part));
95:
96: for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
97: switch (*format_ptr++)
98: {
99: case 'e':
100: case 'u':
101: walk_insn_part (XEXP (part, i));
102: break;
103: case 'E':
104: if (XVEC (part, i) != NULL)
105: for (j = 0; j < XVECLEN (part, i); j++)
106: walk_insn_part (XVECEXP (part, i, j));
107: break;
108: }
109: }
110:
111: void
112: gen_insn (insn)
113: rtx insn;
114: {
115: int i;
116:
117: /* Walk the insn pattern to gather the #define's status. */
118: sets_seen_this_insn = 0;
119: clobbers_seen_this_insn = 0;
120: dup_operands_seen_this_insn = 0;
121: if (XVEC (insn, 1) != 0)
122: for (i = 0; i < XVECLEN (insn, 1); i++)
123: walk_insn_part (XVECEXP (insn, 1, i));
124:
125: if (sets_seen_this_insn > max_sets_per_insn_flag)
126: max_sets_per_insn_flag = sets_seen_this_insn;
127: if (clobbers_seen_this_insn > max_clobbers_per_insn_flag)
128: max_clobbers_per_insn_flag = clobbers_seen_this_insn;
129: if (dup_operands_seen_this_insn > max_dup_operands_flag)
130: max_dup_operands_flag = dup_operands_seen_this_insn;
131: }
132:
133: /* Similar but scan a define_expand. */
134:
135: void
136: gen_expand (insn)
137: rtx insn;
138: {
139: int i;
140:
141: /* Walk the insn pattern to gather the #define's status. */
142:
143: /* Note that we don't bother recording the number of MATCH_DUPs
144: that occur in a gen_expand, because only reload cares about that. */
145: if (XVEC (insn, 1) != 0)
146: for (i = 0; i < XVECLEN (insn, 1); i++)
147: {
148: /* Compute the maximum SETs and CLOBBERS
149: in any one of the sub-insns;
150: don't sum across all of them. */
151: sets_seen_this_insn = 0;
152: clobbers_seen_this_insn = 0;
153:
154: walk_insn_part (XVECEXP (insn, 1, i));
155:
156: if (sets_seen_this_insn > max_sets_per_insn_flag)
157: max_sets_per_insn_flag = sets_seen_this_insn;
158: if (clobbers_seen_this_insn > max_clobbers_per_insn_flag)
159: max_clobbers_per_insn_flag = clobbers_seen_this_insn;
160: }
161: }
162:
163: void
164: gen_peephole (peep)
165: rtx peep;
166: {
167: int i;
168:
169: /* Look through the patterns that are matched
170: to compute the maximum operand number. */
171: for (i = 0; i < XVECLEN (peep, 0); i++)
172: walk_insn_part (XVECEXP (peep, 0, i));
173: }
174:
175: int
176: xmalloc (size)
177: {
178: register int val = malloc (size);
179:
180: if (val == 0)
181: fatal ("virtual memory exhausted");
182:
183: return val;
184: }
185:
186: int
187: xrealloc (ptr, size)
188: char *ptr;
189: int size;
190: {
191: int result = realloc (ptr, size);
192: if (!result)
193: fatal ("virtual memory exhausted");
194: return result;
195: }
196:
197: void
198: fatal (s, a1, a2)
199: {
200: fprintf (stderr, "genconfig: ");
201: fprintf (stderr, s, a1, a2);
202: fprintf (stderr, "\n");
203: exit (FATAL_EXIT_CODE);
204: }
205:
206: int
207: main (argc, argv)
208: int argc;
209: char **argv;
210: {
211: rtx desc;
212: FILE *infile;
213: extern rtx read_rtx ();
214: register int c;
215:
216: obstack_init (rtl_obstack);
217:
218: if (argc <= 1)
219: fatal ("No input file name.");
220:
221: infile = fopen (argv[1], "r");
222: if (infile == 0)
223: {
224: perror (argv[1]);
225: exit (FATAL_EXIT_CODE);
226: }
227:
228: init_rtl ();
229:
230: printf ("/* Generated automatically by the program `genconfig'\n\
231: from the machine description file `md'. */\n\n");
232:
233: /* Read the machine description. */
234:
235: while (1)
236: {
237: c = read_skip_spaces (infile);
238: if (c == EOF)
239: break;
240: ungetc (c, infile);
241:
242: desc = read_rtx (infile);
243: if (GET_CODE (desc) == DEFINE_INSN)
244: gen_insn (desc);
245: if (GET_CODE (desc) == DEFINE_EXPAND)
246: gen_expand (desc);
247: if (GET_CODE (desc) == DEFINE_PEEPHOLE)
248: gen_peephole (desc);
249: }
250:
251: printf ("\n#define MAX_RECOG_OPERANDS %d\n", max_recog_operands_flag + 1);
252:
253: if (max_dup_operands_flag == 0)
254: max_dup_operands_flag = 1;
255: printf ("\n#define MAX_DUP_OPERANDS %d\n", max_dup_operands_flag);
256:
257: printf ("#define MAX_SETS_PER_INSN %d\n", max_sets_per_insn_flag);
258:
259: printf ("#define MAX_CLOBBERS_PER_INSN %d\n", max_clobbers_per_insn_flag);
260:
261: if (register_constraint_flag)
262: printf ("#define REGISTER_CONSTRAINTS\n");
263:
264: fflush (stdout);
265: exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
266: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.