* toplev.c (lang_independent_f_options): Remove
[official-gcc.git] / gcc / genoutput.c
blob34624306e62a37240afeac23a96f2bd54e5c6ba8
1 /* Generate code from to output assembler insns as recognized from rtl.
2 Copyright (C) 1987, 1988, 1992, 1994, 1995, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This program reads the machine description for the compiler target machine
24 and produces a file containing these things:
26 1. An array of `struct insn_data', which is indexed by insn code number,
27 which contains:
29 a. `name' is the name for that pattern. Nameless patterns are
30 given a name.
32 b. `output' hold either the output template, an array of output
33 templates, or an output function.
35 c. `genfun' is the function to generate a body for that pattern,
36 given operands as arguments.
38 d. `n_operands' is the number of distinct operands in the pattern
39 for that insn,
41 e. `n_dups' is the number of match_dup's that appear in the insn's
42 pattern. This says how many elements of `recog_data.dup_loc' are
43 significant after an insn has been recognized.
45 f. `n_alternatives' is the number of alternatives in the constraints
46 of each pattern.
48 g. `output_format' tells what type of thing `output' is.
50 h. `operand' is the base of an array of operand data for the insn.
52 2. An array of `struct insn_operand data', used by `operand' above.
54 a. `predicate', an int-valued function, is the match_operand predicate
55 for this operand.
57 b. `constraint' is the constraint for this operand. This exists
58 only if register constraints appear in match_operand rtx's.
60 c. `address_p' indicates that the operand appears within ADDRESS
61 rtx's. This exists only if there are *no* register constraints
62 in the match_operand rtx's.
64 d. `mode' is the machine mode that that operand is supposed to have.
66 e. `strict_low', is nonzero for operands contained in a STRICT_LOW_PART.
68 f. `eliminable', is nonzero for operands that are matched normally by
69 MATCH_OPERAND; it is zero for operands that should not be changed during
70 register elimination such as MATCH_OPERATORs.
72 The code number of an insn is simply its position in the machine
73 description; code numbers are assigned sequentially to entries in
74 the description, starting with code number 0.
76 Thus, the following entry in the machine description
78 (define_insn "clrdf"
79 [(set (match_operand:DF 0 "general_operand" "")
80 (const_int 0))]
82 "clrd %0")
84 assuming it is the 25th entry present, would cause
85 insn_data[24].template to be "clrd %0", and
86 insn_data[24].n_operands to be 1. */
88 #include "hconfig.h"
89 #include "system.h"
90 #include "rtl.h"
91 #include "errors.h"
92 #include "gensupport.h"
94 /* No instruction can have more operands than this. Sorry for this
95 arbitrary limit, but what machine will have an instruction with
96 this many operands? */
98 #define MAX_MAX_OPERANDS 40
100 static int n_occurrences PARAMS ((int, const char *));
101 static const char *strip_whitespace PARAMS ((const char *));
103 /* insns in the machine description are assigned sequential code numbers
104 that are used by insn-recog.c (produced by genrecog) to communicate
105 to insn-output.c (produced by this program). */
107 static int next_code_number;
109 /* This counts all definitions in the md file,
110 for the sake of error messages. */
112 static int next_index_number;
114 /* This counts all operands used in the md file. The first is null. */
116 static int next_operand_number = 1;
118 /* Record in this chain all information about the operands we will output. */
120 struct operand_data
122 struct operand_data *next;
123 int index;
124 const char *predicate;
125 const char *constraint;
126 enum machine_mode mode;
127 unsigned char n_alternatives;
128 char address_p;
129 char strict_low;
130 char eliminable;
131 char seen;
134 /* Begin with a null operand at index 0. */
136 static struct operand_data null_operand =
138 0, 0, "", "", VOIDmode, 0, 0, 0, 0, 0
141 static struct operand_data *odata = &null_operand;
142 static struct operand_data **odata_end = &null_operand.next;
144 /* Must match the constants in recog.h. */
146 #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */
147 #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */
148 #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */
149 #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */
151 /* Record in this chain all information that we will output,
152 associated with the code number of the insn. */
154 struct data
156 struct data *next;
157 const char *name;
158 const char *template;
159 int code_number;
160 int index_number;
161 int lineno;
162 int n_operands; /* Number of operands this insn recognizes */
163 int n_dups; /* Number times match_dup appears in pattern */
164 int n_alternatives; /* Number of alternatives in each constraint */
165 int operand_number; /* Operand index in the big array. */
166 int output_format; /* INSN_OUTPUT_FORMAT_*. */
167 struct operand_data operand[MAX_MAX_OPERANDS];
170 /* This variable points to the first link in the insn chain. */
172 static struct data *idata, **idata_end = &idata;
174 static void output_prologue PARAMS ((void));
175 static void output_predicate_decls PARAMS ((void));
176 static void output_operand_data PARAMS ((void));
177 static void output_insn_data PARAMS ((void));
178 static void output_get_insn_name PARAMS ((void));
179 static void scan_operands PARAMS ((struct data *, rtx, int, int));
180 static int compare_operands PARAMS ((struct operand_data *,
181 struct operand_data *));
182 static void place_operands PARAMS ((struct data *));
183 static void process_template PARAMS ((struct data *, const char *));
184 static void validate_insn_alternatives PARAMS ((struct data *));
185 static void validate_insn_operands PARAMS ((struct data *));
186 static void gen_insn PARAMS ((rtx, int));
187 static void gen_peephole PARAMS ((rtx, int));
188 static void gen_expand PARAMS ((rtx, int));
189 static void gen_split PARAMS ((rtx, int));
191 const char *
192 get_insn_name (index)
193 int index;
195 static char buf[100];
197 struct data *i, *last_named = NULL;
198 for (i = idata; i ; i = i->next)
200 if (i->index_number == index)
201 return i->name;
202 if (i->name)
203 last_named = i;
206 if (last_named)
207 sprintf(buf, "%s+%d", last_named->name, index - last_named->index_number);
208 else
209 sprintf(buf, "insn %d", index);
211 return buf;
214 static void
215 output_prologue ()
217 printf ("/* Generated automatically by the program `genoutput'\n\
218 from the machine description file `md'. */\n\n");
220 printf ("#include \"config.h\"\n");
221 printf ("#include \"system.h\"\n");
222 printf ("#include \"flags.h\"\n");
223 printf ("#include \"ggc.h\"\n");
224 printf ("#include \"rtl.h\"\n");
225 printf ("#include \"tm_p.h\"\n");
226 printf ("#include \"function.h\"\n");
227 printf ("#include \"regs.h\"\n");
228 printf ("#include \"hard-reg-set.h\"\n");
229 printf ("#include \"real.h\"\n");
230 printf ("#include \"insn-config.h\"\n\n");
231 printf ("#include \"conditions.h\"\n");
232 printf ("#include \"insn-attr.h\"\n\n");
233 printf ("#include \"recog.h\"\n\n");
234 printf ("#include \"toplev.h\"\n");
235 printf ("#include \"output.h\"\n");
239 /* We need to define all predicates used. Keep a list of those we
240 have defined so far. There normally aren't very many predicates
241 used, so a linked list should be fast enough. */
243 static void
244 output_predicate_decls ()
246 struct predicate { const char *name; struct predicate *next; } *predicates = 0;
247 register struct operand_data *d;
248 struct predicate *p;
250 for (d = odata; d; d = d->next)
251 if (d->predicate && d->predicate[0])
253 for (p = predicates; p; p = p->next)
254 if (strcmp (p->name, d->predicate) == 0)
255 break;
257 if (p == 0)
259 printf ("extern int %s PARAMS ((rtx, enum machine_mode));\n",
260 d->predicate);
261 p = (struct predicate *) alloca (sizeof (struct predicate));
262 p->name = d->predicate;
263 p->next = predicates;
264 predicates = p;
268 printf ("\n\n");
271 static void
272 output_operand_data ()
274 register struct operand_data *d;
276 printf ("\nstatic const struct insn_operand_data operand_data[] = \n{\n");
278 for (d = odata; d; d = d->next)
280 printf (" {\n");
282 printf (" %s,\n",
283 d->predicate && d->predicate[0] ? d->predicate : "0");
285 printf (" \"%s\",\n", d->constraint ? d->constraint : "");
287 printf (" %smode,\n", GET_MODE_NAME (d->mode));
289 printf (" %d,\n", d->strict_low);
291 printf (" %d\n", d->eliminable);
293 printf(" },\n");
295 printf("};\n\n\n");
298 static void
299 output_insn_data ()
301 register struct data *d;
302 int name_offset = 0;
303 int next_name_offset;
304 const char * last_name = 0;
305 const char * next_name = 0;
306 register struct data *n;
308 for (n = idata, next_name_offset = 1; n; n = n->next, next_name_offset++)
309 if (n->name)
311 next_name = n->name;
312 break;
315 printf ("\nconst struct insn_data insn_data[] = \n{\n");
317 for (d = idata; d; d = d->next)
319 printf (" {\n");
321 if (d->name)
323 printf (" \"%s\",\n", d->name);
324 name_offset = 0;
325 last_name = d->name;
326 next_name = 0;
327 for (n = d->next, next_name_offset = 1; n;
328 n = n->next, next_name_offset++)
330 if (n->name)
332 next_name = n->name;
333 break;
337 else
339 name_offset++;
340 if (next_name && (last_name == 0
341 || name_offset > next_name_offset / 2))
342 printf (" \"%s-%d\",\n", next_name,
343 next_name_offset - name_offset);
344 else
345 printf (" \"%s+%d\",\n", last_name, name_offset);
348 switch (d->output_format)
350 case INSN_OUTPUT_FORMAT_NONE:
351 printf (" 0,\n");
352 break;
353 case INSN_OUTPUT_FORMAT_SINGLE:
355 const char *p = d->template;
356 char prev = 0;
358 printf (" \"");
359 while (*p)
361 if (*p == '\n' && prev != '\\')
362 printf ("\\n\\\n");
363 else
364 putchar (*p);
365 prev = *p;
366 ++p;
368 printf ("\",\n");
370 break;
371 case INSN_OUTPUT_FORMAT_MULTI:
372 case INSN_OUTPUT_FORMAT_FUNCTION:
373 printf (" (const PTR) output_%d,\n", d->code_number);
374 break;
375 default:
376 abort ();
379 if (d->name && d->name[0] != '*')
380 printf (" (insn_gen_fn) gen_%s,\n", d->name);
381 else
382 printf (" 0,\n");
384 printf (" &operand_data[%d],\n", d->operand_number);
385 printf (" %d,\n", d->n_operands);
386 printf (" %d,\n", d->n_dups);
387 printf (" %d,\n", d->n_alternatives);
388 printf (" %d\n", d->output_format);
390 printf(" },\n");
392 printf ("};\n\n\n");
395 static void
396 output_get_insn_name ()
398 printf ("const char *\n");
399 printf ("get_insn_name (code)\n");
400 printf (" int code;\n");
401 printf ("{\n");
402 printf (" return insn_data[code].name;\n");
403 printf ("}\n");
407 /* Stores in max_opno the largest operand number present in `part', if
408 that is larger than the previous value of max_opno, and the rest of
409 the operand data into `d->operand[i]'.
411 THIS_ADDRESS_P is nonzero if the containing rtx was an ADDRESS.
412 THIS_STRICT_LOW is nonzero if the containing rtx was a STRICT_LOW_PART. */
414 static int max_opno;
415 static int num_dups;
417 static void
418 scan_operands (d, part, this_address_p, this_strict_low)
419 struct data *d;
420 rtx part;
421 int this_address_p;
422 int this_strict_low;
424 register int i, j;
425 register const char *format_ptr;
426 int opno;
428 if (part == 0)
429 return;
431 switch (GET_CODE (part))
433 case MATCH_OPERAND:
434 opno = XINT (part, 0);
435 if (opno > max_opno)
436 max_opno = opno;
437 if (max_opno >= MAX_MAX_OPERANDS)
439 message_with_line (d->lineno,
440 "maximum number of operands exceeded");
441 have_error = 1;
442 return;
444 if (d->operand[opno].seen)
446 message_with_line (d->lineno,
447 "repeated operand number %d\n", opno);
448 have_error = 1;
451 d->operand[opno].seen = 1;
452 d->operand[opno].mode = GET_MODE (part);
453 d->operand[opno].strict_low = this_strict_low;
454 d->operand[opno].predicate = XSTR (part, 1);
455 d->operand[opno].constraint = strip_whitespace (XSTR (part, 2));
456 d->operand[opno].n_alternatives
457 = n_occurrences (',', d->operand[opno].constraint) + 1;
458 d->operand[opno].address_p = this_address_p;
459 d->operand[opno].eliminable = 1;
460 return;
462 case MATCH_SCRATCH:
463 opno = XINT (part, 0);
464 if (opno > max_opno)
465 max_opno = opno;
466 if (max_opno >= MAX_MAX_OPERANDS)
468 message_with_line (d->lineno,
469 "maximum number of operands exceeded");
470 have_error = 1;
471 return;
473 if (d->operand[opno].seen)
475 message_with_line (d->lineno,
476 "repeated operand number %d\n", opno);
477 have_error = 1;
480 d->operand[opno].seen = 1;
481 d->operand[opno].mode = GET_MODE (part);
482 d->operand[opno].strict_low = 0;
483 d->operand[opno].predicate = "scratch_operand";
484 d->operand[opno].constraint = strip_whitespace (XSTR (part, 1));
485 d->operand[opno].n_alternatives
486 = n_occurrences (',', d->operand[opno].constraint) + 1;
487 d->operand[opno].address_p = 0;
488 d->operand[opno].eliminable = 0;
489 return;
491 case MATCH_OPERATOR:
492 case MATCH_PARALLEL:
493 opno = XINT (part, 0);
494 if (opno > max_opno)
495 max_opno = opno;
496 if (max_opno >= MAX_MAX_OPERANDS)
498 message_with_line (d->lineno,
499 "maximum number of operands exceeded");
500 have_error = 1;
501 return;
503 if (d->operand[opno].seen)
505 message_with_line (d->lineno,
506 "repeated operand number %d\n", opno);
507 have_error = 1;
510 d->operand[opno].seen = 1;
511 d->operand[opno].mode = GET_MODE (part);
512 d->operand[opno].strict_low = 0;
513 d->operand[opno].predicate = XSTR (part, 1);
514 d->operand[opno].constraint = 0;
515 d->operand[opno].address_p = 0;
516 d->operand[opno].eliminable = 0;
517 for (i = 0; i < XVECLEN (part, 2); i++)
518 scan_operands (d, XVECEXP (part, 2, i), 0, 0);
519 return;
521 case MATCH_DUP:
522 case MATCH_OP_DUP:
523 case MATCH_PAR_DUP:
524 ++num_dups;
525 return;
527 case ADDRESS:
528 scan_operands (d, XEXP (part, 0), 1, 0);
529 return;
531 case STRICT_LOW_PART:
532 scan_operands (d, XEXP (part, 0), 0, 1);
533 return;
535 default:
536 break;
539 format_ptr = GET_RTX_FORMAT (GET_CODE (part));
541 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
542 switch (*format_ptr++)
544 case 'e':
545 case 'u':
546 scan_operands (d, XEXP (part, i), 0, 0);
547 break;
548 case 'E':
549 if (XVEC (part, i) != NULL)
550 for (j = 0; j < XVECLEN (part, i); j++)
551 scan_operands (d, XVECEXP (part, i, j), 0, 0);
552 break;
556 /* Compare two operands for content equality. */
558 static int
559 compare_operands (d0, d1)
560 struct operand_data *d0, *d1;
562 const char *p0, *p1;
564 p0 = d0->predicate;
565 if (!p0)
566 p0 = "";
567 p1 = d1->predicate;
568 if (!p1)
569 p1 = "";
570 if (strcmp (p0, p1) != 0)
571 return 0;
573 p0 = d0->constraint;
574 if (!p0)
575 p0 = "";
576 p1 = d1->constraint;
577 if (!p1)
578 p1 = "";
579 if (strcmp (p0, p1) != 0)
580 return 0;
582 if (d0->mode != d1->mode)
583 return 0;
585 if (d0->strict_low != d1->strict_low)
586 return 0;
588 if (d0->eliminable != d1->eliminable)
589 return 0;
591 return 1;
594 /* Scan the list of operands we've already committed to output and either
595 find a subsequence that is the same, or allocate a new one at the end. */
597 static void
598 place_operands (d)
599 struct data *d;
601 struct operand_data *od, *od2;
602 int i;
604 if (d->n_operands == 0)
606 d->operand_number = 0;
607 return;
610 /* Brute force substring search. */
611 for (od = odata, i = 0; od; od = od->next, i = 0)
612 if (compare_operands (od, &d->operand[0]))
614 od2 = od->next;
615 i = 1;
616 while (1)
618 if (i == d->n_operands)
619 goto full_match;
620 if (od2 == NULL)
621 goto partial_match;
622 if (! compare_operands (od2, &d->operand[i]))
623 break;
624 ++i, od2 = od2->next;
628 /* Either partial match at the end of the list, or no match. In either
629 case, we tack on what operands are remaining to the end of the list. */
630 partial_match:
631 d->operand_number = next_operand_number - i;
632 for (; i < d->n_operands; ++i)
634 od2 = &d->operand[i];
635 *odata_end = od2;
636 odata_end = &od2->next;
637 od2->index = next_operand_number++;
639 *odata_end = NULL;
640 return;
642 full_match:
643 d->operand_number = od->index;
644 return;
648 /* Process an assembler template from a define_insn or a define_peephole.
649 It is either the assembler code template, a list of assembler code
650 templates, or C code to generate the assembler code template. */
652 static void
653 process_template (d, template)
654 struct data *d;
655 const char *template;
657 register const char *cp;
658 register int i;
660 /* Templates starting with * contain straight code to be run. */
661 if (template[0] == '*')
663 d->template = 0;
664 d->output_format = INSN_OUTPUT_FORMAT_FUNCTION;
666 printf ("\nstatic const char *output_%d PARAMS ((rtx *, rtx));\n",
667 d->code_number);
668 puts ("\nstatic const char *");
669 printf ("output_%d (operands, insn)\n", d->code_number);
670 puts (" rtx *operands ATTRIBUTE_UNUSED;");
671 puts (" rtx insn ATTRIBUTE_UNUSED;");
672 puts ("{");
674 puts (template + 1);
675 puts ("}");
678 /* If the assembler code template starts with a @ it is a newline-separated
679 list of assembler code templates, one for each alternative. */
680 else if (template[0] == '@')
682 d->template = 0;
683 d->output_format = INSN_OUTPUT_FORMAT_MULTI;
685 printf ("\nstatic const char * const output_%d[] = {\n", d->code_number);
687 for (i = 0, cp = &template[1]; *cp; )
689 while (*cp == '\n' || *cp == ' ' || *cp== '\t')
690 cp++;
692 printf (" \"");
693 while (*cp != '\n' && *cp != '\0')
695 putchar (*cp);
696 cp++;
699 printf ("\",\n");
700 i++;
702 if (i == 1)
703 message_with_line (d->lineno,
704 "'@' is redundant for output template with single alternative");
705 if (i != d->n_alternatives)
707 message_with_line (d->lineno,
708 "Wrong number of alternatives in the output template");
709 have_error = 1;
712 printf ("};\n");
714 else
716 d->template = template;
717 d->output_format = INSN_OUTPUT_FORMAT_SINGLE;
721 /* Check insn D for consistency in number of constraint alternatives. */
723 static void
724 validate_insn_alternatives (d)
725 struct data *d;
727 register int n = 0, start;
729 /* Make sure all the operands have the same number of alternatives
730 in their constraints. Let N be that number. */
731 for (start = 0; start < d->n_operands; start++)
732 if (d->operand[start].n_alternatives > 0)
734 if (n == 0)
735 n = d->operand[start].n_alternatives;
736 else if (n != d->operand[start].n_alternatives)
738 message_with_line (d->lineno,
739 "wrong number of alternatives in operand %d",
740 start);
741 have_error = 1;
745 /* Record the insn's overall number of alternatives. */
746 d->n_alternatives = n;
749 /* Verify that there are no gaps in operand numbers for INSNs. */
751 static void
752 validate_insn_operands (d)
753 struct data *d;
755 int i;
757 for (i = 0; i < d->n_operands; ++i)
758 if (d->operand[i].seen == 0)
760 message_with_line (d->lineno, "missing operand %d", i);
761 have_error = 1;
765 /* Look at a define_insn just read. Assign its code number. Record
766 on idata the template and the number of arguments. If the insn has
767 a hairy output action, output a function for now. */
769 static void
770 gen_insn (insn, lineno)
771 rtx insn;
772 int lineno;
774 register struct data *d = (struct data *) xmalloc (sizeof (struct data));
775 register int i;
777 d->code_number = next_code_number;
778 d->index_number = next_index_number;
779 d->lineno = lineno;
780 if (XSTR (insn, 0)[0])
781 d->name = XSTR (insn, 0);
782 else
783 d->name = 0;
785 /* Build up the list in the same order as the insns are seen
786 in the machine description. */
787 d->next = 0;
788 *idata_end = d;
789 idata_end = &d->next;
791 max_opno = -1;
792 num_dups = 0;
793 memset (d->operand, 0, sizeof (d->operand));
795 for (i = 0; i < XVECLEN (insn, 1); i++)
796 scan_operands (d, XVECEXP (insn, 1, i), 0, 0);
798 d->n_operands = max_opno + 1;
799 d->n_dups = num_dups;
801 validate_insn_operands (d);
802 validate_insn_alternatives (d);
803 place_operands (d);
804 process_template (d, XSTR (insn, 3));
807 /* Look at a define_peephole just read. Assign its code number.
808 Record on idata the template and the number of arguments.
809 If the insn has a hairy output action, output it now. */
811 static void
812 gen_peephole (peep, lineno)
813 rtx peep;
814 int lineno;
816 register struct data *d = (struct data *) xmalloc (sizeof (struct data));
817 register int i;
819 d->code_number = next_code_number;
820 d->index_number = next_index_number;
821 d->lineno = lineno;
822 d->name = 0;
824 /* Build up the list in the same order as the insns are seen
825 in the machine description. */
826 d->next = 0;
827 *idata_end = d;
828 idata_end = &d->next;
830 max_opno = -1;
831 num_dups = 0;
832 memset (d->operand, 0, sizeof (d->operand));
834 /* Get the number of operands by scanning all the patterns of the
835 peephole optimizer. But ignore all the rest of the information
836 thus obtained. */
837 for (i = 0; i < XVECLEN (peep, 0); i++)
838 scan_operands (d, XVECEXP (peep, 0, i), 0, 0);
840 d->n_operands = max_opno + 1;
841 d->n_dups = 0;
843 validate_insn_alternatives (d);
844 place_operands (d);
845 process_template (d, XSTR (peep, 2));
848 /* Process a define_expand just read. Assign its code number,
849 only for the purposes of `insn_gen_function'. */
851 static void
852 gen_expand (insn, lineno)
853 rtx insn;
854 int lineno;
856 register struct data *d = (struct data *) xmalloc (sizeof (struct data));
857 register int i;
859 d->code_number = next_code_number;
860 d->index_number = next_index_number;
861 d->lineno = lineno;
862 if (XSTR (insn, 0)[0])
863 d->name = XSTR (insn, 0);
864 else
865 d->name = 0;
867 /* Build up the list in the same order as the insns are seen
868 in the machine description. */
869 d->next = 0;
870 *idata_end = d;
871 idata_end = &d->next;
873 max_opno = -1;
874 num_dups = 0;
875 memset (d->operand, 0, sizeof (d->operand));
877 /* Scan the operands to get the specified predicates and modes,
878 since expand_binop needs to know them. */
880 if (XVEC (insn, 1))
881 for (i = 0; i < XVECLEN (insn, 1); i++)
882 scan_operands (d, XVECEXP (insn, 1, i), 0, 0);
884 d->n_operands = max_opno + 1;
885 d->n_dups = num_dups;
886 d->template = 0;
887 d->output_format = INSN_OUTPUT_FORMAT_NONE;
889 validate_insn_alternatives (d);
890 place_operands (d);
893 /* Process a define_split just read. Assign its code number,
894 only for reasons of consistency and to simplify genrecog. */
896 static void
897 gen_split (split, lineno)
898 rtx split;
899 int lineno;
901 register struct data *d = (struct data *) xmalloc (sizeof (struct data));
902 register int i;
904 d->code_number = next_code_number;
905 d->index_number = next_index_number;
906 d->lineno = lineno;
907 d->name = 0;
909 /* Build up the list in the same order as the insns are seen
910 in the machine description. */
911 d->next = 0;
912 *idata_end = d;
913 idata_end = &d->next;
915 max_opno = -1;
916 num_dups = 0;
917 memset (d->operand, 0, sizeof (d->operand));
919 /* Get the number of operands by scanning all the patterns of the
920 split patterns. But ignore all the rest of the information thus
921 obtained. */
922 for (i = 0; i < XVECLEN (split, 0); i++)
923 scan_operands (d, XVECEXP (split, 0, i), 0, 0);
925 d->n_operands = max_opno + 1;
926 d->n_dups = 0;
927 d->n_alternatives = 0;
928 d->template = 0;
929 d->output_format = INSN_OUTPUT_FORMAT_NONE;
931 place_operands (d);
934 extern int main PARAMS ((int, char **));
937 main (argc, argv)
938 int argc;
939 char **argv;
941 rtx desc;
943 progname = "genoutput";
945 if (argc <= 1)
946 fatal ("No input file name.");
948 if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
949 return (FATAL_EXIT_CODE);
951 output_prologue ();
952 next_code_number = 0;
953 next_index_number = 0;
955 /* Read the machine description. */
957 while (1)
959 int line_no;
961 desc = read_md_rtx (&line_no, &next_code_number);
962 if (desc == NULL)
963 break;
965 if (GET_CODE (desc) == DEFINE_INSN)
966 gen_insn (desc, line_no);
967 if (GET_CODE (desc) == DEFINE_PEEPHOLE)
968 gen_peephole (desc, line_no);
969 if (GET_CODE (desc) == DEFINE_EXPAND)
970 gen_expand (desc, line_no);
971 if (GET_CODE (desc) == DEFINE_SPLIT
972 || GET_CODE (desc) == DEFINE_PEEPHOLE2)
973 gen_split (desc, line_no);
974 next_index_number++;
977 printf("\n\n");
978 output_predicate_decls ();
979 output_operand_data ();
980 output_insn_data ();
981 output_get_insn_name ();
983 fflush (stdout);
984 return (ferror (stdout) != 0 || have_error
985 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
988 /* Return the number of occurrences of character C in string S or
989 -1 if S is the null string. */
991 static int
992 n_occurrences (c, s)
993 int c;
994 const char *s;
996 int n = 0;
998 if (s == 0 || *s == '\0')
999 return -1;
1001 while (*s)
1002 n += (*s++ == c);
1004 return n;
1007 /* Remove whitespace in `s' by moving up characters until the end.
1008 Return a new string. */
1010 static const char *
1011 strip_whitespace (s)
1012 const char *s;
1014 char *p, *q;
1015 char ch;
1017 if (s == 0)
1018 return 0;
1020 p = q = xmalloc (strlen (s) + 1);
1021 while ((ch = *s++) != '\0')
1022 if (! ISSPACE (ch))
1023 *p++ = ch;
1025 *p = '\0';
1026 return q;