OSDN Git Service

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