OSDN Git Service

*** empty log message ***
[pf3gnuchains/gcc-fork.git] / gcc / genemit.c
1 /* Generate code from machine description to emit insns as rtl.
2    Copyright (C) 1987, 1988, 1991 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, 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 {
50   struct clobber_ent *insns;
51   rtx pattern;
52   int first_clobber;
53   struct clobber_pat *next;
54 } *clobber_list;
55
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
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         {
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                      of the same mode, 
305                      or if both are registers of the same mode and number.  */
306                   if (! (GET_MODE (old) == GET_MODE (new)
307                          && ((GET_CODE (old) == MATCH_SCRATCH
308                               && GET_CODE (new) == MATCH_SCRATCH)
309                              || (GET_CODE (old) == REG && GET_CODE (new) == REG
310                                  && REGNO (old) == REGNO (new)))))
311                     break;
312                 }
313       
314               if (j == XVECLEN (insn, 1))
315                 break;
316             }
317
318           if (p == 0)
319             {
320               p = (struct clobber_pat *) xmalloc (sizeof (struct clobber_pat));
321           
322               p->insns = 0;
323               p->pattern = insn;
324               p->first_clobber = i + 1;
325               p->next = clobber_list;
326               clobber_list = p;
327             }
328
329           link->next = p->insns;
330           p->insns = link;
331         }
332     }
333
334   /* Don't mention instructions whose names are the null string.
335      They are in the machine description just to be recognized.  */
336   if (strlen (XSTR (insn, 0)) == 0)
337     return;
338
339   /* Find out how many operands this function has,
340      and also whether any of them have register constraints.  */
341   register_constraints = 0;
342   operands = max_operand_vec (insn, 1);
343   if (max_dup_opno >= operands)
344     fatal ("match_dup operand number has no match_operand");
345
346   /* Output the function name and argument declarations.  */
347   printf ("rtx\ngen_%s (", XSTR (insn, 0));
348   for (i = 0; i < operands; i++)
349     printf (i ? ", operand%d" : "operand%d", i);
350   printf (")\n");
351   for (i = 0; i < operands; i++)
352     printf ("     rtx operand%d;\n", i);
353   printf ("{\n");
354
355   /* Output code to construct and return the rtl for the instruction body */
356
357   if (XVECLEN (insn, 1) == 1)
358     {
359       printf ("  return ");
360       gen_exp (XVECEXP (insn, 1, 0));
361       printf (";\n}\n\n");
362     }
363   else
364     {
365       printf ("  return gen_rtx (PARALLEL, VOIDmode, gen_rtvec (%d", XVECLEN (insn, 1));
366       for (i = 0; i < XVECLEN (insn, 1); i++)
367         {
368           printf (",\n\t\t");
369           gen_exp (XVECEXP (insn, 1, i));
370         }
371       printf ("));\n}\n\n");
372     }
373 }
374 \f
375 /* Generate the `gen_...' function for a DEFINE_EXPAND.  */
376
377 static void
378 gen_expand (expand)
379      rtx expand;
380 {
381   int operands;
382   register int i;
383
384   if (strlen (XSTR (expand, 0)) == 0)
385     fatal ("define_expand lacks a name");
386   if (XVEC (expand, 1) == 0)
387     fatal ("define_expand for %s lacks a pattern", XSTR (expand, 0));
388
389   /* Find out how many operands this function has,
390      and also whether any of them have register constraints.  */
391   register_constraints = 0;
392
393   operands = max_operand_vec (expand, 1);
394
395   /* Output the function name and argument declarations.  */
396   printf ("rtx\ngen_%s (", XSTR (expand, 0));
397   for (i = 0; i < operands; i++)
398     printf (i ? ", operand%d" : "operand%d", i);
399   printf (")\n");
400   for (i = 0; i < operands; i++)
401     printf ("     rtx operand%d;\n", i);
402   printf ("{\n");
403
404   /* If we don't have any C code to write, only one insn is being written,
405      and no MATCH_DUPs are present, we can just return the desired insn
406      like we do for a DEFINE_INSN.  This saves memory.  */
407   if ((XSTR (expand, 3) == 0 || *XSTR (expand, 3) == '\0')
408       && operands > max_dup_opno
409       && XVECLEN (expand, 1) == 1)
410     {
411       printf ("  return ");
412       gen_exp (XVECEXP (expand, 1, 0));
413       printf (";\n}\n\n");
414       return;
415     }
416
417   /* For each operand referred to only with MATCH_DUPs,
418      make a local variable.  */
419   for (i = operands; i <= max_dup_opno; i++)
420     printf ("  rtx operand%d;\n", i);
421   if (operands > 0 || max_dup_opno >= 0)
422     printf ("  rtx operands[%d];\n", MAX (operands, max_dup_opno + 1));
423   printf ("  rtx _val = 0;\n");
424   printf ("  start_sequence ();\n");
425
426   /* The fourth operand of DEFINE_EXPAND is some code to be executed
427      before the actual construction.
428      This code expects to refer to `operands'
429      just as the output-code in a DEFINE_INSN does,
430      but here `operands' is an automatic array.
431      So copy the operand values there before executing it.  */
432   if (XSTR (expand, 3) && *XSTR (expand, 3))
433     {
434       /* Output code to copy the arguments into `operands'.  */
435       for (i = 0; i < operands; i++)
436         printf ("  operands[%d] = operand%d;\n", i, i);
437
438       /* Output the special code to be executed before the sequence
439          is generated.  */
440       printf ("%s\n", XSTR (expand, 3));
441
442       /* Output code to copy the arguments back out of `operands'
443          (unless we aren't going to use them at all).  */
444       if (XVEC (expand, 1) != 0)
445         {
446           for (i = 0; i < operands; i++)
447             printf ("  operand%d = operands[%d];\n", i, i);
448           for (; i <= max_dup_opno; i++)
449             printf ("  operand%d = operands[%d];\n", i, i);
450         }
451     }
452
453   /* Output code to construct the rtl for the instruction bodies.
454      Use emit_insn to add them to the sequence being accumulated.
455      But don't do this if the user's code has set `no_more' nonzero.  */
456
457   for (i = 0; i < XVECLEN (expand, 1); i++)
458     {
459       rtx next = XVECEXP (expand, 1, i);
460       if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC)
461           || (GET_CODE (next) == PARALLEL
462               && GET_CODE (XVECEXP (next, 0, 0)) == SET
463               && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC)
464           || GET_CODE (next) == RETURN)
465         printf ("  emit_jump_insn (");
466       else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL)
467                || GET_CODE (next) == CALL
468                || (GET_CODE (next) == PARALLEL
469                    && GET_CODE (XVECEXP (next, 0, 0)) == SET
470                    && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL)
471                || (GET_CODE (next) == PARALLEL
472                    && GET_CODE (XVECEXP (next, 0, 0)) == CALL))
473         printf ("  emit_call_insn (");
474       else if (GET_CODE (next) == CODE_LABEL)
475         printf ("  emit_label (");
476       else if (GET_CODE (next) == MATCH_OPERAND
477                || GET_CODE (next) == MATCH_OPERATOR
478                || GET_CODE (next) == MATCH_PARALLEL
479                || GET_CODE (next) == MATCH_OP_DUP
480                || GET_CODE (next) == MATCH_DUP
481                || GET_CODE (next) == PARALLEL)
482         printf ("  emit (");
483       else
484         printf ("  emit_insn (");
485       gen_exp (next);
486       printf (");\n");
487       if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC
488           && GET_CODE (SET_SRC (next)) == LABEL_REF)
489         printf ("  emit_barrier ();");
490     }
491
492   /* Call `gen_sequence' to make a SEQUENCE out of all the
493      insns emitted within this gen_... function.  */
494
495   printf (" _done:\n");
496   printf ("  _val = gen_sequence ();\n");
497   printf (" _fail:\n");
498   printf ("  end_sequence ();\n");
499   printf ("  return _val;\n}\n\n");
500 }
501
502 /* Like gen_expand, but generates a SEQUENCE.  */
503 static void
504 gen_split (split)
505      rtx split;
506 {
507   register int i;
508   int operands;
509
510   if (XVEC (split, 0) == 0)
511     fatal ("define_split (definition %d) lacks a pattern", insn_index_number);
512   else if (XVEC (split, 2) == 0)
513     fatal ("define_split (definition %d) lacks a replacement pattern",
514            insn_index_number);
515
516   /* Find out how many operands this function has.  */
517
518   max_operand_vec (split, 2);
519   operands = MAX (max_opno, max_dup_opno) + 1;
520
521   /* Output the function name and argument declarations.  */
522   printf ("rtx\ngen_split_%d (operands)\n     rtx *operands;\n",
523           insn_code_number);
524   printf ("{\n");
525
526   /* Declare all local variables.  */
527   for (i = 0; i < operands; i++)
528     printf ("  rtx operand%d;\n", i);
529   printf ("  rtx _val;\n");
530   printf ("  start_sequence ();\n");
531
532   /* The fourth operand of DEFINE_SPLIT is some code to be executed
533      before the actual construction.  */
534
535   if (XSTR (split, 3))
536     printf ("%s\n", XSTR (split, 3));
537
538   /* Output code to copy the arguments back out of `operands'  */
539   for (i = 0; i < operands; i++)
540     printf ("  operand%d = operands[%d];\n", i, i);
541
542   /* Output code to construct the rtl for the instruction bodies.
543      Use emit_insn to add them to the sequence being accumulated.
544      But don't do this if the user's code has set `no_more' nonzero.  */
545
546   for (i = 0; i < XVECLEN (split, 2); i++)
547     {
548       rtx next = XVECEXP (split, 2, i);
549       if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC)
550           || (GET_CODE (next) == PARALLEL
551               && GET_CODE (XVECEXP (next, 0, 0)) == SET
552               && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC)
553           || GET_CODE (next) == RETURN)
554         printf ("  emit_jump_insn (");
555       else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL)
556                || GET_CODE (next) == CALL
557                || (GET_CODE (next) == PARALLEL
558                    && GET_CODE (XVECEXP (next, 0, 0)) == SET
559                    && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL)
560                || (GET_CODE (next) == PARALLEL
561                    && GET_CODE (XVECEXP (next, 0, 0)) == CALL))
562         printf ("  emit_call_insn (");
563       else if (GET_CODE (next) == CODE_LABEL)
564         printf ("  emit_label (");
565       else if (GET_CODE (next) == MATCH_OPERAND
566                || GET_CODE (next) == MATCH_OPERATOR
567                || GET_CODE (next) == MATCH_PARALLEL
568                || GET_CODE (next) == MATCH_OP_DUP
569                || GET_CODE (next) == MATCH_DUP
570                || GET_CODE (next) == PARALLEL)
571         printf ("  emit (");
572       else
573         printf ("  emit_insn (");
574       gen_exp (next);
575       printf (");\n");
576       if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC
577           && GET_CODE (SET_SRC (next)) == LABEL_REF)
578         printf ("  emit_barrier ();");
579     }
580
581   /* Call `gen_sequence' to make a SEQUENCE out of all the
582      insns emitted within this gen_... function.  */
583
584   printf (" _done:\n");
585   printf ("  _val = gen_sequence ();\n");
586   printf (" _fail:\n");
587   printf ("  end_sequence ();\n");
588   printf ("  return _val;\n}\n\n");
589 }
590 \f
591 /* Write a function, `add_clobbers', that is given a PARALLEL of sufficient
592    size for the insn and an INSN_CODE, and inserts the required CLOBBERs at
593    the end of the vector.  */
594
595 static void
596 output_add_clobbers ()
597 {
598   struct clobber_pat *clobber;
599   struct clobber_ent *ent;
600   int i;
601
602   printf ("\n\nvoid\nadd_clobbers (pattern, insn_code_number)\n");
603   printf ("     rtx pattern;\n     int insn_code_number;\n");
604   printf ("{\n");
605   printf ("  int i;\n\n");
606   printf ("  switch (insn_code_number)\n");
607   printf ("    {\n");
608
609   for (clobber = clobber_list; clobber; clobber = clobber->next)
610     {
611       for (ent = clobber->insns; ent; ent = ent->next)
612         printf ("    case %d:\n", ent->code_number);
613
614       for (i = clobber->first_clobber; i < XVECLEN (clobber->pattern, 1); i++)
615         {
616           printf ("      XVECEXP (pattern, 0, %d) = ", i);
617           gen_exp (XVECEXP (clobber->pattern, 1, i));
618           printf (";\n");
619         }
620
621       printf ("      break;\n\n");
622     }
623
624   printf ("    default:\n");
625   printf ("      abort ();\n");
626   printf ("    }\n");
627   printf ("}\n");
628 }
629 \f
630 /* Write a function, init_mov_optab, that is called to set up entries
631    in mov_optab for EXTRA_CC_MODES.  */
632
633 static void
634 output_init_mov_optab ()
635 {
636 #ifdef EXTRA_CC_NAMES
637   static char *cc_names[] = { EXTRA_CC_NAMES };
638   char *p;
639   int i;
640
641   printf ("\nvoid\ninit_mov_optab ()\n{\n");
642
643   for (i = 0; i < sizeof cc_names / sizeof cc_names[0]; i++)
644     {
645       printf ("#ifdef HAVE_mov");
646       for (p = cc_names[i]; *p; p++)
647         printf ("%c", *p >= 'A' && *p <= 'Z' ? *p - 'A' + 'a' : *p);
648       printf ("\n");
649       printf ("  if (HAVE_mov");
650       for (p = cc_names[i]; *p; p++)
651         printf ("%c", *p >= 'A' && *p <= 'Z' ? *p - 'A' + 'a' : *p);
652       printf (")\n");
653       printf ("    mov_optab->handlers[(int) %smode].insn_code = CODE_FOR_mov",
654               cc_names[i]);
655       for (p = cc_names[i]; *p; p++)
656         printf ("%c", *p >= 'A' && *p <= 'Z' ? *p - 'A' + 'a' : *p);
657       printf (";\n#endif\n");
658     }
659
660   printf ("}\n");
661 #endif
662 }
663 \f
664 char *
665 xmalloc (size)
666      unsigned size;
667 {
668   register char *val = (char *) malloc (size);
669
670   if (val == 0)
671     fatal ("virtual memory exhausted");
672
673   return val;
674 }
675
676 char *
677 xrealloc (ptr, size)
678      char *ptr;
679      unsigned size;
680 {
681   char *result = (char *) realloc (ptr, size);
682   if (!result)
683     fatal ("virtual memory exhausted");
684   return result;
685 }
686
687 static void
688 fatal (s, a1, a2)
689      char *s;
690 {
691   fprintf (stderr, "genemit: ");
692   fprintf (stderr, s, a1, a2);
693   fprintf (stderr, "\n");
694   exit (FATAL_EXIT_CODE);
695 }
696
697 /* More 'friendly' abort that prints the line and file.
698    config.h can #define abort fancy_abort if you like that sort of thing.  */
699
700 void
701 fancy_abort ()
702 {
703   fatal ("Internal gcc abort.");
704 }
705 \f
706 int
707 main (argc, argv)
708      int argc;
709      char **argv;
710 {
711   rtx desc;
712   FILE *infile;
713   extern rtx read_rtx ();
714   register int c;
715
716   obstack_init (rtl_obstack);
717
718   if (argc <= 1)
719     fatal ("No input file name.");
720
721   infile = fopen (argv[1], "r");
722   if (infile == 0)
723     {
724       perror (argv[1]);
725       exit (FATAL_EXIT_CODE);
726     }
727
728   init_rtl ();
729
730   /* Assign sequential codes to all entries in the machine description
731      in parallel with the tables in insn-output.c.  */
732
733   insn_code_number = 0;
734   insn_index_number = 0;
735
736   printf ("/* Generated automatically by the program `genemit'\n\
737 from the machine description file `md'.  */\n\n");
738
739   printf ("#include \"config.h\"\n");
740   printf ("#include \"rtl.h\"\n");
741   printf ("#include \"expr.h\"\n");
742   printf ("#include \"real.h\"\n");
743   printf ("#include \"output.h\"\n");
744   printf ("#include \"insn-config.h\"\n\n");
745   printf ("#include \"insn-flags.h\"\n\n");
746   printf ("#include \"insn-codes.h\"\n\n");
747   printf ("extern char *insn_operand_constraint[][MAX_RECOG_OPERANDS];\n\n");
748   printf ("extern rtx recog_operand[];\n");
749   printf ("#define operands emit_operand\n\n");
750   printf ("#define FAIL goto _fail\n\n");
751   printf ("#define DONE goto _done\n\n");
752
753   /* Read the machine description.  */
754
755   while (1)
756     {
757       c = read_skip_spaces (infile);
758       if (c == EOF)
759         break;
760       ungetc (c, infile);
761
762       desc = read_rtx (infile);
763       if (GET_CODE (desc) == DEFINE_INSN)
764         {
765           gen_insn (desc);
766           ++insn_code_number;
767         }
768       if (GET_CODE (desc) == DEFINE_EXPAND)
769         {
770           gen_expand (desc);
771           ++insn_code_number;
772         }
773       if (GET_CODE (desc) == DEFINE_SPLIT)
774         {
775           gen_split (desc);
776           ++insn_code_number;
777         }
778       if (GET_CODE (desc) == DEFINE_PEEPHOLE)
779         {
780           ++insn_code_number;
781         }
782       ++insn_index_number;
783     }
784
785   /* Write out the routine to add CLOBBERs to a pattern.  */
786   output_add_clobbers ();
787
788   /* Write the routine to initialize mov_optab for the EXTRA_CC_MODES.  */
789   output_init_mov_optab ();
790
791   fflush (stdout);
792   exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
793   /* NOTREACHED */
794   return 0;
795 }