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