]>
Commit | Line | Data |
---|---|---|
65963943 | 1 | /* Generate code from machine description to emit insns as rtl. |
55485756 | 2 | Copyright (C) 1987, 1988, 1991 Free Software Foundation, Inc. |
65963943 RK |
3 | |
4 | This file is part of GNU CC. | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | ||
21 | #include <stdio.h> | |
22 | #include "config.h" | |
23 | #include "rtl.h" | |
24 | #include "obstack.h" | |
25 | ||
26 | static struct obstack obstack; | |
27 | struct obstack *rtl_obstack = &obstack; | |
28 | ||
29 | #define obstack_chunk_alloc xmalloc | |
30 | #define obstack_chunk_free free | |
31 | ||
32 | extern void free (); | |
33 | ||
34 | char *xmalloc (); | |
35 | static void fatal (); | |
36 | void fancy_abort (); | |
37 | ||
38 | static int max_opno; | |
39 | static int max_dup_opno; | |
40 | static int register_constraints; | |
41 | static int insn_code_number; | |
42 | static int insn_index_number; | |
43 | ||
44 | /* Data structure for recording the patterns of insns that have CLOBBERs. | |
45 | We use this to output a function that adds these CLOBBERs to a | |
46 | previously-allocated PARALLEL expression. */ | |
47 | ||
48 | struct clobber_pat | |
49 | { | |
e5f6a288 | 50 | struct clobber_ent *insns; |
65963943 RK |
51 | rtx pattern; |
52 | int first_clobber; | |
53 | struct clobber_pat *next; | |
54 | } *clobber_list; | |
55 | ||
e5f6a288 RK |
56 | /* Records one insn that uses the clobber list. */ |
57 | ||
58 | struct clobber_ent | |
59 | { | |
60 | int code_number; /* Counts only insns. */ | |
61 | struct clobber_ent *next; | |
62 | }; | |
63 | ||
65963943 RK |
64 | static void |
65 | max_operand_1 (x) | |
66 | rtx x; | |
67 | { | |
68 | register RTX_CODE code; | |
69 | register int i; | |
70 | register int len; | |
71 | register char *fmt; | |
72 | ||
73 | if (x == 0) | |
74 | return; | |
75 | ||
76 | code = GET_CODE (x); | |
77 | ||
78 | if (code == MATCH_OPERAND && XSTR (x, 2) != 0 && *XSTR (x, 2) != '\0') | |
79 | register_constraints = 1; | |
80 | if (code == MATCH_SCRATCH && XSTR (x, 1) != 0 && *XSTR (x, 1) != '\0') | |
81 | register_constraints = 1; | |
82 | if (code == MATCH_OPERAND || code == MATCH_OPERATOR | |
83 | || code == MATCH_PARALLEL) | |
84 | max_opno = MAX (max_opno, XINT (x, 0)); | |
85 | if (code == MATCH_DUP || code == MATCH_OP_DUP) | |
86 | max_dup_opno = MAX (max_dup_opno, XINT (x, 0)); | |
87 | ||
88 | fmt = GET_RTX_FORMAT (code); | |
89 | len = GET_RTX_LENGTH (code); | |
90 | for (i = 0; i < len; i++) | |
91 | { | |
92 | if (fmt[i] == 'e' || fmt[i] == 'u') | |
93 | max_operand_1 (XEXP (x, i)); | |
94 | else if (fmt[i] == 'E') | |
95 | { | |
96 | int j; | |
97 | for (j = 0; j < XVECLEN (x, i); j++) | |
98 | max_operand_1 (XVECEXP (x, i, j)); | |
99 | } | |
100 | } | |
101 | } | |
102 | ||
103 | static int | |
104 | max_operand_vec (insn, arg) | |
105 | rtx insn; | |
106 | int arg; | |
107 | { | |
108 | register int len = XVECLEN (insn, arg); | |
109 | register int i; | |
110 | ||
111 | max_opno = -1; | |
112 | max_dup_opno = -1; | |
113 | ||
114 | for (i = 0; i < len; i++) | |
115 | max_operand_1 (XVECEXP (insn, arg, i)); | |
116 | ||
117 | return max_opno + 1; | |
118 | } | |
119 | \f | |
120 | static void | |
121 | print_code (code) | |
122 | RTX_CODE code; | |
123 | { | |
124 | register char *p1; | |
125 | for (p1 = GET_RTX_NAME (code); *p1; p1++) | |
126 | { | |
127 | if (*p1 >= 'a' && *p1 <= 'z') | |
128 | putchar (*p1 + 'A' - 'a'); | |
129 | else | |
130 | putchar (*p1); | |
131 | } | |
132 | } | |
133 | ||
134 | /* Print a C expression to construct an RTX just like X, | |
135 | substituting any operand references appearing within. */ | |
136 | ||
137 | static void | |
138 | gen_exp (x) | |
139 | rtx x; | |
140 | { | |
141 | register RTX_CODE code; | |
142 | register int i; | |
143 | register int len; | |
144 | register char *fmt; | |
145 | ||
146 | if (x == 0) | |
147 | { | |
148 | printf ("0"); | |
149 | return; | |
150 | } | |
151 | ||
152 | code = GET_CODE (x); | |
153 | ||
154 | switch (code) | |
155 | { | |
156 | case MATCH_OPERAND: | |
157 | case MATCH_DUP: | |
158 | printf ("operand%d", XINT (x, 0)); | |
159 | return; | |
160 | ||
161 | case MATCH_OP_DUP: | |
162 | printf ("gen_rtx (GET_CODE (operand%d), GET_MODE (operand%d)", | |
163 | XINT (x, 0), XINT (x, 0)); | |
164 | for (i = 0; i < XVECLEN (x, 1); i++) | |
165 | { | |
166 | printf (",\n\t\t"); | |
167 | gen_exp (XVECEXP (x, 1, i)); | |
168 | } | |
169 | printf (")"); | |
170 | return; | |
171 | ||
172 | case MATCH_OPERATOR: | |
173 | printf ("gen_rtx (GET_CODE (operand%d)", XINT (x, 0)); | |
174 | printf (", %smode", GET_MODE_NAME (GET_MODE (x))); | |
175 | for (i = 0; i < XVECLEN (x, 2); i++) | |
176 | { | |
177 | printf (",\n\t\t"); | |
178 | gen_exp (XVECEXP (x, 2, i)); | |
179 | } | |
180 | printf (")"); | |
181 | return; | |
182 | ||
183 | case MATCH_PARALLEL: | |
184 | printf ("operand%d", XINT (x, 0)); | |
185 | return; | |
186 | ||
187 | case MATCH_SCRATCH: | |
188 | printf ("gen_rtx (SCRATCH, %smode, 0)", GET_MODE_NAME (GET_MODE (x))); | |
189 | return; | |
190 | ||
191 | case ADDRESS: | |
192 | fatal ("ADDRESS expression code used in named instruction pattern"); | |
193 | ||
194 | case PC: | |
195 | printf ("pc_rtx"); | |
196 | return; | |
197 | ||
198 | case CC0: | |
199 | printf ("cc0_rtx"); | |
200 | return; | |
201 | ||
202 | case CONST_INT: | |
203 | if (INTVAL (x) == 0) | |
204 | { | |
205 | printf ("const0_rtx"); | |
206 | return; | |
207 | } | |
208 | if (INTVAL (x) == 1) | |
209 | { | |
210 | printf ("const1_rtx"); | |
211 | return; | |
212 | } | |
213 | if (INTVAL (x) == -1) | |
214 | { | |
215 | printf ("constm1_rtx"); | |
216 | return; | |
217 | } | |
218 | if (INTVAL (x) == STORE_FLAG_VALUE) | |
219 | { | |
220 | printf ("const_true_rtx"); | |
221 | return; | |
222 | } | |
223 | } | |
224 | ||
225 | printf ("gen_rtx ("); | |
226 | print_code (code); | |
227 | printf (", %smode", GET_MODE_NAME (GET_MODE (x))); | |
228 | ||
229 | fmt = GET_RTX_FORMAT (code); | |
230 | len = GET_RTX_LENGTH (code); | |
231 | for (i = 0; i < len; i++) | |
232 | { | |
233 | if (fmt[i] == '0') | |
234 | break; | |
235 | printf (", "); | |
236 | if (fmt[i] == 'e' || fmt[i] == 'u') | |
237 | gen_exp (XEXP (x, i)); | |
238 | else if (fmt[i] == 'i') | |
239 | printf ("%u", (unsigned) XINT (x, i)); | |
240 | else if (fmt[i] == 's') | |
241 | printf ("\"%s\"", XSTR (x, i)); | |
242 | else if (fmt[i] == 'E') | |
243 | { | |
244 | int j; | |
245 | printf ("gen_rtvec (%d", XVECLEN (x, i)); | |
246 | for (j = 0; j < XVECLEN (x, i); j++) | |
247 | { | |
248 | printf (",\n\t\t"); | |
249 | gen_exp (XVECEXP (x, i, j)); | |
250 | } | |
251 | printf (")"); | |
252 | } | |
253 | else | |
254 | abort (); | |
255 | } | |
256 | printf (")"); | |
257 | } | |
258 | \f | |
259 | /* Generate the `gen_...' function for a DEFINE_INSN. */ | |
260 | ||
261 | static void | |
262 | gen_insn (insn) | |
263 | rtx insn; | |
264 | { | |
265 | int operands; | |
266 | register int i; | |
267 | ||
268 | /* See if the pattern for this insn ends with a group of CLOBBERs of (hard) | |
269 | registers or MATCH_SCRATCHes. If so, store away the information for | |
270 | later. */ | |
271 | ||
272 | if (XVEC (insn, 1)) | |
273 | { | |
274 | for (i = XVECLEN (insn, 1) - 1; i > 0; i--) | |
275 | if (GET_CODE (XVECEXP (insn, 1, i)) != CLOBBER | |
276 | || (GET_CODE (XEXP (XVECEXP (insn, 1, i), 0)) != REG | |
277 | && GET_CODE (XEXP (XVECEXP (insn, 1, i), 0)) != MATCH_SCRATCH)) | |
278 | break; | |
279 | ||
280 | if (i != XVECLEN (insn, 1) - 1) | |
281 | { | |
e5f6a288 RK |
282 | register struct clobber_pat *p; |
283 | register struct clobber_ent *link | |
284 | = (struct clobber_ent *) xmalloc (sizeof (struct clobber_ent)); | |
285 | register int j; | |
286 | ||
287 | link->code_number = insn_code_number; | |
288 | ||
289 | /* See if any previous CLOBBER_LIST entry is the same as this | |
290 | one. */ | |
291 | ||
292 | for (p = clobber_list; p; p = p->next) | |
293 | { | |
294 | if (p->first_clobber != i + 1 | |
295 | || XVECLEN (p->pattern, 1) != XVECLEN (insn, 1)) | |
296 | continue; | |
297 | ||
298 | for (j = i + 1; j < XVECLEN (insn, 1); j++) | |
299 | { | |
300 | rtx old = XEXP (XVECEXP (p->pattern, 1, j), 0); | |
301 | rtx new = XEXP (XVECEXP (insn, 1, j), 0); | |
302 | ||
303 | /* OLD and NEW are the same if both are to be a SCRATCH | |
304 | or if both are registers of the same mode and number. */ | |
305 | if (! ((GET_CODE (old) == MATCH_SCRATCH | |
306 | && GET_CODE (new) == MATCH_SCRATCH) | |
307 | || (GET_CODE (old) == REG && GET_CODE (new) == REG | |
308 | && GET_MODE (old) == GET_MODE (new) | |
309 | && REGNO (old) == REGNO (new)))) | |
310 | break; | |
311 | } | |
312 | ||
313 | if (j == XVECLEN (insn, 1)) | |
314 | break; | |
315 | } | |
316 | ||
317 | if (p == 0) | |
318 | { | |
319 | p = (struct clobber_pat *) xmalloc (sizeof (struct clobber_pat)); | |
65963943 | 320 | |
e5f6a288 RK |
321 | p->insns = 0; |
322 | p->pattern = insn; | |
323 | p->first_clobber = i + 1; | |
324 | p->next = clobber_list; | |
325 | clobber_list = p; | |
326 | } | |
327 | ||
328 | link->next = p->insns; | |
329 | p->insns = link; | |
65963943 RK |
330 | } |
331 | } | |
332 | ||
333 | /* Don't mention instructions whose names are the null string. | |
334 | They are in the machine description just to be recognized. */ | |
335 | if (strlen (XSTR (insn, 0)) == 0) | |
336 | return; | |
337 | ||
338 | /* Find out how many operands this function has, | |
339 | and also whether any of them have register constraints. */ | |
340 | register_constraints = 0; | |
341 | operands = max_operand_vec (insn, 1); | |
342 | if (max_dup_opno >= operands) | |
343 | fatal ("match_dup operand number has no match_operand"); | |
344 | ||
345 | /* Output the function name and argument declarations. */ | |
346 | printf ("rtx\ngen_%s (", XSTR (insn, 0)); | |
347 | for (i = 0; i < operands; i++) | |
348 | printf (i ? ", operand%d" : "operand%d", i); | |
349 | printf (")\n"); | |
350 | for (i = 0; i < operands; i++) | |
351 | printf (" rtx operand%d;\n", i); | |
352 | printf ("{\n"); | |
353 | ||
354 | /* Output code to construct and return the rtl for the instruction body */ | |
355 | ||
356 | if (XVECLEN (insn, 1) == 1) | |
357 | { | |
358 | printf (" return "); | |
359 | gen_exp (XVECEXP (insn, 1, 0)); | |
360 | printf (";\n}\n\n"); | |
361 | } | |
362 | else | |
363 | { | |
364 | printf (" return gen_rtx (PARALLEL, VOIDmode, gen_rtvec (%d", XVECLEN (insn, 1)); | |
365 | for (i = 0; i < XVECLEN (insn, 1); i++) | |
366 | { | |
367 | printf (",\n\t\t"); | |
368 | gen_exp (XVECEXP (insn, 1, i)); | |
369 | } | |
370 | printf ("));\n}\n\n"); | |
371 | } | |
372 | } | |
373 | \f | |
374 | /* Generate the `gen_...' function for a DEFINE_EXPAND. */ | |
375 | ||
376 | static void | |
377 | gen_expand (expand) | |
378 | rtx expand; | |
379 | { | |
380 | int operands; | |
381 | register int i; | |
382 | ||
383 | if (strlen (XSTR (expand, 0)) == 0) | |
384 | fatal ("define_expand lacks a name"); | |
385 | if (XVEC (expand, 1) == 0) | |
386 | fatal ("define_expand for %s lacks a pattern", XSTR (expand, 0)); | |
387 | ||
388 | /* Find out how many operands this function has, | |
389 | and also whether any of them have register constraints. */ | |
390 | register_constraints = 0; | |
391 | ||
392 | operands = max_operand_vec (expand, 1); | |
393 | ||
394 | /* Output the function name and argument declarations. */ | |
395 | printf ("rtx\ngen_%s (", XSTR (expand, 0)); | |
396 | for (i = 0; i < operands; i++) | |
397 | printf (i ? ", operand%d" : "operand%d", i); | |
398 | printf (")\n"); | |
399 | for (i = 0; i < operands; i++) | |
400 | printf (" rtx operand%d;\n", i); | |
401 | printf ("{\n"); | |
402 | ||
403 | /* If we don't have any C code to write, only one insn is being written, | |
404 | and no MATCH_DUPs are present, we can just return the desired insn | |
405 | like we do for a DEFINE_INSN. This saves memory. */ | |
406 | if ((XSTR (expand, 3) == 0 || *XSTR (expand, 3) == '\0') | |
407 | && operands > max_dup_opno | |
408 | && XVECLEN (expand, 1) == 1) | |
409 | { | |
410 | printf (" return "); | |
411 | gen_exp (XVECEXP (expand, 1, 0)); | |
412 | printf (";\n}\n\n"); | |
413 | return; | |
414 | } | |
415 | ||
416 | /* For each operand referred to only with MATCH_DUPs, | |
417 | make a local variable. */ | |
418 | for (i = operands; i <= max_dup_opno; i++) | |
419 | printf (" rtx operand%d;\n", i); | |
420 | if (operands > 0 || max_dup_opno >= 0) | |
421 | printf (" rtx operands[%d];\n", MAX (operands, max_dup_opno + 1)); | |
422 | printf (" rtx _val = 0;\n"); | |
423 | printf (" start_sequence ();\n"); | |
424 | ||
425 | /* The fourth operand of DEFINE_EXPAND is some code to be executed | |
426 | before the actual construction. | |
427 | This code expects to refer to `operands' | |
428 | just as the output-code in a DEFINE_INSN does, | |
429 | but here `operands' is an automatic array. | |
430 | So copy the operand values there before executing it. */ | |
431 | if (XSTR (expand, 3) && *XSTR (expand, 3)) | |
432 | { | |
433 | /* Output code to copy the arguments into `operands'. */ | |
434 | for (i = 0; i < operands; i++) | |
435 | printf (" operands[%d] = operand%d;\n", i, i); | |
436 | ||
437 | /* Output the special code to be executed before the sequence | |
438 | is generated. */ | |
439 | printf ("%s\n", XSTR (expand, 3)); | |
440 | ||
441 | /* Output code to copy the arguments back out of `operands' | |
442 | (unless we aren't going to use them at all). */ | |
443 | if (XVEC (expand, 1) != 0) | |
444 | { | |
445 | for (i = 0; i < operands; i++) | |
446 | printf (" operand%d = operands[%d];\n", i, i); | |
447 | for (; i <= max_dup_opno; i++) | |
448 | printf (" operand%d = operands[%d];\n", i, i); | |
449 | } | |
450 | } | |
451 | ||
452 | /* Output code to construct the rtl for the instruction bodies. | |
453 | Use emit_insn to add them to the sequence being accumulated. | |
454 | But don't do this if the user's code has set `no_more' nonzero. */ | |
455 | ||
456 | for (i = 0; i < XVECLEN (expand, 1); i++) | |
457 | { | |
458 | rtx next = XVECEXP (expand, 1, i); | |
459 | if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC) | |
460 | || (GET_CODE (next) == PARALLEL | |
461 | && GET_CODE (XVECEXP (next, 0, 0)) == SET | |
462 | && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC) | |
463 | || GET_CODE (next) == RETURN) | |
464 | printf (" emit_jump_insn ("); | |
465 | else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL) | |
466 | || GET_CODE (next) == CALL | |
467 | || (GET_CODE (next) == PARALLEL | |
468 | && GET_CODE (XVECEXP (next, 0, 0)) == SET | |
469 | && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL) | |
470 | || (GET_CODE (next) == PARALLEL | |
471 | && GET_CODE (XVECEXP (next, 0, 0)) == CALL)) | |
472 | printf (" emit_call_insn ("); | |
473 | else if (GET_CODE (next) == CODE_LABEL) | |
474 | printf (" emit_label ("); | |
475 | else if (GET_CODE (next) == MATCH_OPERAND | |
476 | || GET_CODE (next) == MATCH_OPERATOR | |
477 | || GET_CODE (next) == MATCH_PARALLEL | |
478 | || GET_CODE (next) == MATCH_OP_DUP | |
479 | || GET_CODE (next) == MATCH_DUP | |
480 | || GET_CODE (next) == PARALLEL) | |
481 | printf (" emit ("); | |
482 | else | |
483 | printf (" emit_insn ("); | |
484 | gen_exp (next); | |
485 | printf (");\n"); | |
486 | if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC | |
487 | && GET_CODE (SET_SRC (next)) == LABEL_REF) | |
488 | printf (" emit_barrier ();"); | |
489 | } | |
490 | ||
491 | /* Call `gen_sequence' to make a SEQUENCE out of all the | |
492 | insns emitted within this gen_... function. */ | |
493 | ||
494 | printf (" _done:\n"); | |
495 | printf (" _val = gen_sequence ();\n"); | |
496 | printf (" _fail:\n"); | |
497 | printf (" end_sequence ();\n"); | |
498 | printf (" return _val;\n}\n\n"); | |
499 | } | |
500 | ||
501 | /* Like gen_expand, but generates a SEQUENCE. */ | |
502 | static void | |
503 | gen_split (split) | |
504 | rtx split; | |
505 | { | |
506 | register int i; | |
507 | int operands; | |
508 | ||
509 | if (XVEC (split, 0) == 0) | |
3462dc45 | 510 | fatal ("define_split (definition %d) lacks a pattern", insn_index_number); |
65963943 | 511 | else if (XVEC (split, 2) == 0) |
3462dc45 RK |
512 | fatal ("define_split (definition %d) lacks a replacement pattern", |
513 | insn_index_number); | |
65963943 RK |
514 | |
515 | /* Find out how many operands this function has. */ | |
516 | ||
517 | max_operand_vec (split, 2); | |
518 | operands = MAX (max_opno, max_dup_opno) + 1; | |
519 | ||
520 | /* Output the function name and argument declarations. */ | |
521 | printf ("rtx\ngen_split_%d (operands)\n rtx *operands;\n", | |
522 | insn_code_number); | |
523 | printf ("{\n"); | |
524 | ||
525 | /* Declare all local variables. */ | |
526 | for (i = 0; i < operands; i++) | |
527 | printf (" rtx operand%d;\n", i); | |
528 | printf (" rtx _val;\n"); | |
529 | printf (" start_sequence ();\n"); | |
530 | ||
531 | /* The fourth operand of DEFINE_SPLIT is some code to be executed | |
532 | before the actual construction. */ | |
533 | ||
534 | if (XSTR (split, 3)) | |
535 | printf ("%s\n", XSTR (split, 3)); | |
536 | ||
537 | /* Output code to copy the arguments back out of `operands' */ | |
538 | for (i = 0; i < operands; i++) | |
539 | printf (" operand%d = operands[%d];\n", i, i); | |
540 | ||
541 | /* Output code to construct the rtl for the instruction bodies. | |
542 | Use emit_insn to add them to the sequence being accumulated. | |
543 | But don't do this if the user's code has set `no_more' nonzero. */ | |
544 | ||
545 | for (i = 0; i < XVECLEN (split, 2); i++) | |
546 | { | |
547 | rtx next = XVECEXP (split, 2, i); | |
548 | if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC) | |
549 | || (GET_CODE (next) == PARALLEL | |
550 | && GET_CODE (XVECEXP (next, 0, 0)) == SET | |
551 | && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC) | |
552 | || GET_CODE (next) == RETURN) | |
553 | printf (" emit_jump_insn ("); | |
554 | else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL) | |
555 | || GET_CODE (next) == CALL | |
556 | || (GET_CODE (next) == PARALLEL | |
557 | && GET_CODE (XVECEXP (next, 0, 0)) == SET | |
558 | && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL) | |
559 | || (GET_CODE (next) == PARALLEL | |
560 | && GET_CODE (XVECEXP (next, 0, 0)) == CALL)) | |
561 | printf (" emit_call_insn ("); | |
562 | else if (GET_CODE (next) == CODE_LABEL) | |
563 | printf (" emit_label ("); | |
564 | else if (GET_CODE (next) == MATCH_OPERAND | |
565 | || GET_CODE (next) == MATCH_OPERATOR | |
566 | || GET_CODE (next) == MATCH_PARALLEL | |
567 | || GET_CODE (next) == MATCH_OP_DUP | |
568 | || GET_CODE (next) == MATCH_DUP | |
569 | || GET_CODE (next) == PARALLEL) | |
570 | printf (" emit ("); | |
571 | else | |
572 | printf (" emit_insn ("); | |
573 | gen_exp (next); | |
574 | printf (");\n"); | |
575 | if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC | |
576 | && GET_CODE (SET_SRC (next)) == LABEL_REF) | |
577 | printf (" emit_barrier ();"); | |
578 | } | |
579 | ||
580 | /* Call `gen_sequence' to make a SEQUENCE out of all the | |
581 | insns emitted within this gen_... function. */ | |
582 | ||
583 | printf (" _done:\n"); | |
584 | printf (" _val = gen_sequence ();\n"); | |
585 | printf (" _fail:\n"); | |
586 | printf (" end_sequence ();\n"); | |
587 | printf (" return _val;\n}\n\n"); | |
588 | } | |
589 | \f | |
590 | /* Write a function, `add_clobbers', that is given a PARALLEL of sufficient | |
591 | size for the insn and an INSN_CODE, and inserts the required CLOBBERs at | |
592 | the end of the vector. */ | |
593 | ||
594 | static void | |
595 | output_add_clobbers () | |
596 | { | |
597 | struct clobber_pat *clobber; | |
e5f6a288 | 598 | struct clobber_ent *ent; |
65963943 RK |
599 | int i; |
600 | ||
601 | printf ("\n\nvoid\nadd_clobbers (pattern, insn_code_number)\n"); | |
602 | printf (" rtx pattern;\n int insn_code_number;\n"); | |
603 | printf ("{\n"); | |
604 | printf (" int i;\n\n"); | |
605 | printf (" switch (insn_code_number)\n"); | |
606 | printf (" {\n"); | |
607 | ||
608 | for (clobber = clobber_list; clobber; clobber = clobber->next) | |
609 | { | |
e5f6a288 RK |
610 | for (ent = clobber->insns; ent; ent = ent->next) |
611 | printf (" case %d:\n", ent->code_number); | |
65963943 RK |
612 | |
613 | for (i = clobber->first_clobber; i < XVECLEN (clobber->pattern, 1); i++) | |
614 | { | |
615 | printf (" XVECEXP (pattern, 0, %d) = ", i); | |
616 | gen_exp (XVECEXP (clobber->pattern, 1, i)); | |
617 | printf (";\n"); | |
618 | } | |
619 | ||
e5f6a288 | 620 | printf (" break;\n\n"); |
65963943 RK |
621 | } |
622 | ||
623 | printf (" default:\n"); | |
624 | printf (" abort ();\n"); | |
625 | printf (" }\n"); | |
626 | printf ("}\n"); | |
627 | } | |
628 | \f | |
629 | /* Write a function, init_mov_optab, that is called to set up entries | |
630 | in mov_optab for EXTRA_CC_MODES. */ | |
631 | ||
632 | static void | |
633 | output_init_mov_optab () | |
634 | { | |
635 | #ifdef EXTRA_CC_NAMES | |
636 | static char *cc_names[] = { EXTRA_CC_NAMES }; | |
637 | char *p; | |
638 | int i; | |
639 | ||
640 | printf ("\nvoid\ninit_mov_optab ()\n{\n"); | |
641 | ||
642 | for (i = 0; i < sizeof cc_names / sizeof cc_names[0]; i++) | |
643 | { | |
644 | printf ("#ifdef HAVE_mov"); | |
645 | for (p = cc_names[i]; *p; p++) | |
646 | printf ("%c", *p >= 'A' && *p <= 'Z' ? *p - 'A' + 'a' : *p); | |
647 | printf ("\n"); | |
648 | printf (" if (HAVE_mov"); | |
649 | for (p = cc_names[i]; *p; p++) | |
650 | printf ("%c", *p >= 'A' && *p <= 'Z' ? *p - 'A' + 'a' : *p); | |
651 | printf (")\n"); | |
652 | printf (" mov_optab->handlers[(int) %smode].insn_code = CODE_FOR_mov", | |
653 | cc_names[i]); | |
654 | for (p = cc_names[i]; *p; p++) | |
655 | printf ("%c", *p >= 'A' && *p <= 'Z' ? *p - 'A' + 'a' : *p); | |
656 | printf (";\n#endif\n"); | |
657 | } | |
658 | ||
659 | printf ("}\n"); | |
660 | #endif | |
661 | } | |
662 | \f | |
663 | char * | |
664 | xmalloc (size) | |
665 | unsigned size; | |
666 | { | |
667 | register char *val = (char *) malloc (size); | |
668 | ||
669 | if (val == 0) | |
670 | fatal ("virtual memory exhausted"); | |
671 | ||
672 | return val; | |
673 | } | |
674 | ||
675 | char * | |
676 | xrealloc (ptr, size) | |
677 | char *ptr; | |
678 | unsigned size; | |
679 | { | |
680 | char *result = (char *) realloc (ptr, size); | |
681 | if (!result) | |
682 | fatal ("virtual memory exhausted"); | |
683 | return result; | |
684 | } | |
685 | ||
686 | static void | |
687 | fatal (s, a1, a2) | |
688 | char *s; | |
689 | { | |
690 | fprintf (stderr, "genemit: "); | |
691 | fprintf (stderr, s, a1, a2); | |
692 | fprintf (stderr, "\n"); | |
693 | exit (FATAL_EXIT_CODE); | |
694 | } | |
695 | ||
696 | /* More 'friendly' abort that prints the line and file. | |
697 | config.h can #define abort fancy_abort if you like that sort of thing. */ | |
698 | ||
699 | void | |
700 | fancy_abort () | |
701 | { | |
702 | fatal ("Internal gcc abort."); | |
703 | } | |
704 | \f | |
705 | int | |
706 | main (argc, argv) | |
707 | int argc; | |
708 | char **argv; | |
709 | { | |
710 | rtx desc; | |
711 | FILE *infile; | |
712 | extern rtx read_rtx (); | |
713 | register int c; | |
714 | ||
715 | obstack_init (rtl_obstack); | |
716 | ||
717 | if (argc <= 1) | |
718 | fatal ("No input file name."); | |
719 | ||
720 | infile = fopen (argv[1], "r"); | |
721 | if (infile == 0) | |
722 | { | |
723 | perror (argv[1]); | |
724 | exit (FATAL_EXIT_CODE); | |
725 | } | |
726 | ||
727 | init_rtl (); | |
728 | ||
729 | /* Assign sequential codes to all entries in the machine description | |
730 | in parallel with the tables in insn-output.c. */ | |
731 | ||
732 | insn_code_number = 0; | |
733 | insn_index_number = 0; | |
734 | ||
735 | printf ("/* Generated automatically by the program `genemit'\n\ | |
736 | from the machine description file `md'. */\n\n"); | |
737 | ||
738 | printf ("#include \"config.h\"\n"); | |
739 | printf ("#include \"rtl.h\"\n"); | |
740 | printf ("#include \"expr.h\"\n"); | |
741 | printf ("#include \"real.h\"\n"); | |
742 | printf ("#include \"output.h\"\n"); | |
743 | printf ("#include \"insn-config.h\"\n\n"); | |
744 | printf ("#include \"insn-flags.h\"\n\n"); | |
745 | printf ("#include \"insn-codes.h\"\n\n"); | |
746 | printf ("extern char *insn_operand_constraint[][MAX_RECOG_OPERANDS];\n\n"); | |
747 | printf ("extern rtx recog_operand[];\n"); | |
748 | printf ("#define operands emit_operand\n\n"); | |
749 | printf ("#define FAIL goto _fail\n\n"); | |
750 | printf ("#define DONE goto _done\n\n"); | |
751 | ||
752 | /* Read the machine description. */ | |
753 | ||
754 | while (1) | |
755 | { | |
756 | c = read_skip_spaces (infile); | |
757 | if (c == EOF) | |
758 | break; | |
759 | ungetc (c, infile); | |
760 | ||
761 | desc = read_rtx (infile); | |
762 | if (GET_CODE (desc) == DEFINE_INSN) | |
763 | { | |
764 | gen_insn (desc); | |
765 | ++insn_code_number; | |
766 | } | |
767 | if (GET_CODE (desc) == DEFINE_EXPAND) | |
768 | { | |
769 | gen_expand (desc); | |
770 | ++insn_code_number; | |
771 | } | |
772 | if (GET_CODE (desc) == DEFINE_SPLIT) | |
773 | { | |
774 | gen_split (desc); | |
775 | ++insn_code_number; | |
776 | } | |
777 | if (GET_CODE (desc) == DEFINE_PEEPHOLE) | |
778 | { | |
779 | ++insn_code_number; | |
780 | } | |
781 | ++insn_index_number; | |
782 | } | |
783 | ||
784 | /* Write out the routine to add CLOBBERs to a pattern. */ | |
785 | output_add_clobbers (); | |
786 | ||
787 | /* Write the routine to initialize mov_optab for the EXTRA_CC_MODES. */ | |
788 | output_init_mov_optab (); | |
789 | ||
790 | fflush (stdout); | |
791 | exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); | |
792 | /* NOTREACHED */ | |
793 | return 0; | |
794 | } |