1 /* Generate code from to output assembler insns as recognized from rtl.
2 Copyright (C) 1987, 1988, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2002,
3 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2012
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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_d', which is indexed by insn code number,
29 a. `name' is the name for that pattern. Nameless patterns are
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
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
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
57 b. `constraint' is the constraint for this operand.
59 c. `address_p' indicates that the operand appears within ADDRESS
62 d. `mode' is the machine mode that that operand is supposed to have.
64 e. `strict_low', is nonzero for operands contained in a STRICT_LOW_PART.
66 f. `eliminable', is nonzero for operands that are matched normally by
67 MATCH_OPERAND; it is zero for operands that should not be changed during
68 register elimination such as MATCH_OPERATORs.
70 g. `allows_mem', is true for operands that accept MEM rtxes.
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
79 [(set (match_operand:DF 0 "general_operand" "")
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. */
90 #include "coretypes.h"
95 #include "gensupport.h"
97 /* No instruction can have more operands than this. Sorry for this
98 arbitrary limit, but what machine will have an instruction with
99 this many operands? */
101 #define MAX_MAX_OPERANDS 40
103 static int n_occurrences (int, const char *);
104 static const char *strip_whitespace (const char *);
106 /* insns in the machine description are assigned sequential code numbers
107 that are used by insn-recog.c (produced by genrecog) to communicate
108 to insn-output.c (produced by this program). */
110 static int next_code_number;
112 /* This counts all definitions in the md file,
113 for the sake of error messages. */
115 static int next_index_number;
117 /* This counts all operands used in the md file. The first is null. */
119 static int next_operand_number = 1;
121 /* Record in this chain all information about the operands we will output. */
125 struct operand_data *next;
127 const char *predicate;
128 const char *constraint;
129 enum machine_mode mode;
130 unsigned char n_alternatives;
137 /* Begin with a null operand at index 0. */
139 static struct operand_data null_operand =
141 0, 0, "", "", VOIDmode, 0, 0, 0, 0, 0
144 static struct operand_data *odata = &null_operand;
145 static struct operand_data **odata_end = &null_operand.next;
147 /* Must match the constants in recog.h. */
149 #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */
150 #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */
151 #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */
152 #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */
154 /* Record in this chain all information that we will output,
155 associated with the code number of the insn. */
161 const char *template_code;
164 const char *filename;
166 int n_generator_args; /* Number of arguments passed to generator */
167 int n_operands; /* Number of operands this insn recognizes */
168 int n_dups; /* Number times match_dup appears in pattern */
169 int n_alternatives; /* Number of alternatives in each constraint */
170 int operand_number; /* Operand index in the big array. */
171 int output_format; /* INSN_OUTPUT_FORMAT_*. */
172 struct operand_data operand[MAX_MAX_OPERANDS];
175 /* A dummy insn, for CODE_FOR_nothing. */
176 static struct data nothing;
178 /* This variable points to the first link in the insn chain. */
179 static struct data *idata = ¬hing;
181 /* This variable points to the end of the insn chain. This is where
182 everything relevant from the machien description is appended to. */
183 static struct data **idata_end = ¬hing.next;
186 static void output_prologue (void);
187 static void output_operand_data (void);
188 static void output_insn_data (void);
189 static void output_get_insn_name (void);
190 static void scan_operands (struct data *, rtx, int, int);
191 static int compare_operands (struct operand_data *,
192 struct operand_data *);
193 static void place_operands (struct data *);
194 static void process_template (struct data *, const char *);
195 static void validate_insn_alternatives (struct data *);
196 static void validate_insn_operands (struct data *);
197 static void gen_insn (rtx, int);
198 static void gen_peephole (rtx, int);
199 static void gen_expand (rtx, int);
200 static void gen_split (rtx, int);
202 #ifdef USE_MD_CONSTRAINTS
204 struct constraint_data
206 struct constraint_data *next_this_letter;
208 unsigned int namelen;
212 /* This is a complete list (unlike the one in genpreds.c) of constraint
213 letters and modifiers with machine-independent meaning. The only
214 omission is digits, as these are handled specially. */
215 static const char indep_constraints[] = ",=+%*?!#&<>EFVXgimnoprs";
217 static struct constraint_data *
218 constraints_by_letter_table[1 << CHAR_BIT];
220 static int mdep_constraint_len (const char *, int, int);
221 static void note_constraint (rtx, int);
223 #else /* !USE_MD_CONSTRAINTS */
225 static void check_constraint_len (void);
226 static int constraint_len (const char *, int);
228 #endif /* !USE_MD_CONSTRAINTS */
232 output_prologue (void)
234 printf ("/* Generated automatically by the program `genoutput'\n\
235 from the machine description file `md'. */\n\n");
237 printf ("#include \"config.h\"\n");
238 printf ("#include \"system.h\"\n");
239 printf ("#include \"coretypes.h\"\n");
240 printf ("#include \"tm.h\"\n");
241 printf ("#include \"flags.h\"\n");
242 printf ("#include \"ggc.h\"\n");
243 printf ("#include \"rtl.h\"\n");
244 printf ("#include \"expr.h\"\n");
245 printf ("#include \"insn-codes.h\"\n");
246 printf ("#include \"tm_p.h\"\n");
247 printf ("#include \"function.h\"\n");
248 printf ("#include \"regs.h\"\n");
249 printf ("#include \"hard-reg-set.h\"\n");
250 printf ("#include \"insn-config.h\"\n\n");
251 printf ("#include \"conditions.h\"\n");
252 printf ("#include \"insn-attr.h\"\n\n");
253 printf ("#include \"recog.h\"\n\n");
254 printf ("#include \"diagnostic-core.h\"\n");
255 printf ("#include \"output.h\"\n");
256 printf ("#include \"target.h\"\n");
257 printf ("#include \"tm-constrs.h\"\n");
261 output_operand_data (void)
263 struct operand_data *d;
265 printf ("\nstatic const struct insn_operand_data operand_data[] = \n{\n");
267 for (d = odata; d; d = d->next)
269 struct pred_data *pred;
274 d->predicate && d->predicate[0] ? d->predicate : "0");
276 printf (" \"%s\",\n", d->constraint ? d->constraint : "");
278 printf (" %smode,\n", GET_MODE_NAME (d->mode));
280 printf (" %d,\n", d->strict_low);
282 printf (" %d,\n", d->constraint == NULL ? 1 : 0);
284 printf (" %d,\n", d->eliminable);
288 pred = lookup_predicate (d->predicate);
289 printf (" %d\n", pred && pred->codes[MEM]);
297 output_insn_data (void)
301 int next_name_offset;
302 const char * last_name = 0;
303 const char * next_name = 0;
306 for (n = idata, next_name_offset = 1; n; n = n->next, next_name_offset++)
313 printf ("#if GCC_VERSION >= 2007\n__extension__\n#endif\n");
314 printf ("\nconst struct insn_data_d insn_data[] = \n{\n");
316 for (d = idata; d; d = d->next)
318 printf (" /* %s:%d */\n", d->filename, d->lineno);
323 printf (" \"%s\",\n", d->name);
327 for (n = d->next, next_name_offset = 1; n;
328 n = n->next, next_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);
345 printf (" \"%s+%d\",\n", last_name, name_offset);
348 switch (d->output_format)
350 case INSN_OUTPUT_FORMAT_NONE:
351 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
352 printf (" { 0 },\n");
354 printf (" { 0, 0, 0 },\n");
357 case INSN_OUTPUT_FORMAT_SINGLE:
359 const char *p = d->template_code;
362 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
363 printf (" { .single =\n");
370 if (IS_VSPACE (*p) && prev != '\\')
372 /* Preserve two consecutive \n's or \r's, but treat \r\n
373 as a single newline. */
374 if (*p == '\n' && prev != '\r')
383 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
386 printf (" 0, 0 },\n");
390 case INSN_OUTPUT_FORMAT_MULTI:
391 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
392 printf (" { .multi = output_%d },\n", d->code_number);
394 printf (" { 0, output_%d, 0 },\n", d->code_number);
397 case INSN_OUTPUT_FORMAT_FUNCTION:
398 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
399 printf (" { .function = output_%d },\n", d->code_number);
401 printf (" { 0, 0, output_%d },\n", d->code_number);
408 if (d->name && d->name[0] != '*')
409 printf (" (insn_gen_fn) gen_%s,\n", d->name);
413 printf (" &operand_data[%d],\n", d->operand_number);
414 printf (" %d,\n", d->n_generator_args);
415 printf (" %d,\n", d->n_operands);
416 printf (" %d,\n", d->n_dups);
417 printf (" %d,\n", d->n_alternatives);
418 printf (" %d\n", d->output_format);
426 output_get_insn_name (void)
428 printf ("const char *\n");
429 printf ("get_insn_name (int code)\n");
431 printf (" if (code == NOOP_MOVE_INSN_CODE)\n");
432 printf (" return \"NOOP_MOVE\";\n");
434 printf (" return insn_data[code].name;\n");
439 /* Stores the operand data into `d->operand[i]'.
441 THIS_ADDRESS_P is nonzero if the containing rtx was an ADDRESS.
442 THIS_STRICT_LOW is nonzero if the containing rtx was a STRICT_LOW_PART. */
445 scan_operands (struct data *d, rtx part, int this_address_p,
449 const char *format_ptr;
455 switch (GET_CODE (part))
458 opno = XINT (part, 0);
459 if (opno >= MAX_MAX_OPERANDS)
461 error_with_line (d->lineno, "maximum number of operands exceeded");
464 if (d->operand[opno].seen)
465 error_with_line (d->lineno, "repeated operand number %d\n", opno);
467 d->operand[opno].seen = 1;
468 d->operand[opno].mode = GET_MODE (part);
469 d->operand[opno].strict_low = this_strict_low;
470 d->operand[opno].predicate = XSTR (part, 1);
471 d->operand[opno].constraint = strip_whitespace (XSTR (part, 2));
472 d->operand[opno].n_alternatives
473 = n_occurrences (',', d->operand[opno].constraint) + 1;
474 d->operand[opno].address_p = this_address_p;
475 d->operand[opno].eliminable = 1;
479 opno = XINT (part, 0);
480 if (opno >= MAX_MAX_OPERANDS)
482 error_with_line (d->lineno, "maximum number of operands exceeded");
485 if (d->operand[opno].seen)
486 error_with_line (d->lineno, "repeated operand number %d\n", opno);
488 d->operand[opno].seen = 1;
489 d->operand[opno].mode = GET_MODE (part);
490 d->operand[opno].strict_low = 0;
491 d->operand[opno].predicate = "scratch_operand";
492 d->operand[opno].constraint = strip_whitespace (XSTR (part, 1));
493 d->operand[opno].n_alternatives
494 = n_occurrences (',', d->operand[opno].constraint) + 1;
495 d->operand[opno].address_p = 0;
496 d->operand[opno].eliminable = 0;
501 opno = XINT (part, 0);
502 if (opno >= MAX_MAX_OPERANDS)
504 error_with_line (d->lineno, "maximum number of operands exceeded");
507 if (d->operand[opno].seen)
508 error_with_line (d->lineno, "repeated operand number %d\n", opno);
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);
521 case STRICT_LOW_PART:
522 scan_operands (d, XEXP (part, 0), 0, 1);
529 format_ptr = GET_RTX_FORMAT (GET_CODE (part));
531 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
532 switch (*format_ptr++)
536 scan_operands (d, XEXP (part, i), 0, 0);
539 if (XVEC (part, i) != NULL)
540 for (j = 0; j < XVECLEN (part, i); j++)
541 scan_operands (d, XVECEXP (part, i, j), 0, 0);
546 /* Compare two operands for content equality. */
549 compare_operands (struct operand_data *d0, struct operand_data *d1)
559 if (strcmp (p0, p1) != 0)
568 if (strcmp (p0, p1) != 0)
571 if (d0->mode != d1->mode)
574 if (d0->strict_low != d1->strict_low)
577 if (d0->eliminable != d1->eliminable)
583 /* Scan the list of operands we've already committed to output and either
584 find a subsequence that is the same, or allocate a new one at the end. */
587 place_operands (struct data *d)
589 struct operand_data *od, *od2;
592 if (d->n_operands == 0)
594 d->operand_number = 0;
598 /* Brute force substring search. */
599 for (od = odata, i = 0; od; od = od->next, i = 0)
600 if (compare_operands (od, &d->operand[0]))
606 if (i == d->n_operands)
610 if (! compare_operands (od2, &d->operand[i]))
612 ++i, od2 = od2->next;
616 /* Either partial match at the end of the list, or no match. In either
617 case, we tack on what operands are remaining to the end of the list. */
619 d->operand_number = next_operand_number - i;
620 for (; i < d->n_operands; ++i)
622 od2 = &d->operand[i];
624 odata_end = &od2->next;
625 od2->index = next_operand_number++;
631 d->operand_number = od->index;
636 /* Process an assembler template from a define_insn or a define_peephole.
637 It is either the assembler code template, a list of assembler code
638 templates, or C code to generate the assembler code template. */
641 process_template (struct data *d, const char *template_code)
646 /* Templates starting with * contain straight code to be run. */
647 if (template_code[0] == '*')
649 d->template_code = 0;
650 d->output_format = INSN_OUTPUT_FORMAT_FUNCTION;
652 puts ("\nstatic const char *");
653 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, rtx insn ATTRIBUTE_UNUSED)\n",
656 print_md_ptr_loc (template_code);
657 puts (template_code + 1);
661 /* If the assembler code template starts with a @ it is a newline-separated
662 list of assembler code templates, one for each alternative. */
663 else if (template_code[0] == '@')
665 d->template_code = 0;
666 d->output_format = INSN_OUTPUT_FORMAT_MULTI;
668 printf ("\nstatic const char * const output_%d[] = {\n", d->code_number);
670 for (i = 0, cp = &template_code[1]; *cp; )
674 while (ISSPACE (*cp))
679 for (ep = sp = cp; !IS_VSPACE (*ep) && *ep != '\0'; ++ep)
684 message_with_line (d->lineno,
685 "trailing whitespace in output template");
697 message_with_line (d->lineno,
698 "'@' is redundant for output template with single alternative");
699 if (i != d->n_alternatives)
700 error_with_line (d->lineno,
701 "wrong number of alternatives in the output template");
707 d->template_code = template_code;
708 d->output_format = INSN_OUTPUT_FORMAT_SINGLE;
712 /* Check insn D for consistency in number of constraint alternatives. */
715 validate_insn_alternatives (struct data *d)
719 /* Make sure all the operands have the same number of alternatives
720 in their constraints. Let N be that number. */
721 for (start = 0; start < d->n_operands; start++)
722 if (d->operand[start].n_alternatives > 0)
727 int which_alternative = 0;
728 int alternative_count_unsure = 0;
730 for (p = d->operand[start].constraint; (c = *p); p += len)
732 #ifdef USE_MD_CONSTRAINTS
733 if (ISSPACE (c) || strchr (indep_constraints, c))
735 else if (ISDIGIT (c))
740 while (ISDIGIT (*q));
744 len = mdep_constraint_len (p, d->lineno, start);
746 len = CONSTRAINT_LEN (c, p);
748 if (len < 1 || (len > 1 && strchr (",#*+=&%!0123456789", c)))
750 error_with_line (d->lineno,
751 "invalid length %d for char '%c' in"
752 " alternative %d of operand %d",
753 len, c, which_alternative, start);
764 for (i = 1; i < len; i++)
767 error_with_line (d->lineno,
768 "NUL in alternative %d of operand %d",
769 which_alternative, start);
770 alternative_count_unsure = 1;
773 else if (strchr (",#*", p[i]))
775 error_with_line (d->lineno,
776 "'%c' in alternative %d of operand %d",
777 p[i], which_alternative, start);
778 alternative_count_unsure = 1;
781 if (!alternative_count_unsure)
784 n = d->operand[start].n_alternatives;
785 else if (n != d->operand[start].n_alternatives)
786 error_with_line (d->lineno,
787 "wrong number of alternatives in operand %d",
792 /* Record the insn's overall number of alternatives. */
793 d->n_alternatives = n;
796 /* Verify that there are no gaps in operand numbers for INSNs. */
799 validate_insn_operands (struct data *d)
803 for (i = 0; i < d->n_operands; ++i)
804 if (d->operand[i].seen == 0)
805 error_with_line (d->lineno, "missing operand %d", i);
809 validate_optab_operands (struct data *d)
811 if (!d->name || d->name[0] == '\0' || d->name[0] == '*')
814 /* Miscellaneous tests. */
815 if (strncmp (d->name, "cstore", 6) == 0
816 && d->name[strlen (d->name) - 1] == '4'
817 && d->operand[0].mode == VOIDmode)
819 message_with_line (d->lineno, "missing mode for operand 0 of cstore");
824 /* Look at a define_insn just read. Assign its code number. Record
825 on idata the template and the number of arguments. If the insn has
826 a hairy output action, output a function for now. */
829 gen_insn (rtx insn, int lineno)
831 struct pattern_stats stats;
832 struct data *d = XNEW (struct data);
835 d->code_number = next_code_number;
836 d->index_number = next_index_number;
837 d->filename = read_md_filename;
839 if (XSTR (insn, 0)[0])
840 d->name = XSTR (insn, 0);
844 /* Build up the list in the same order as the insns are seen
845 in the machine description. */
848 idata_end = &d->next;
850 memset (d->operand, 0, sizeof (d->operand));
852 for (i = 0; i < XVECLEN (insn, 1); i++)
853 scan_operands (d, XVECEXP (insn, 1, i), 0, 0);
855 get_pattern_stats (&stats, XVEC (insn, 1));
856 d->n_generator_args = stats.num_generator_args;
857 d->n_operands = stats.num_insn_operands;
858 d->n_dups = stats.num_dups;
860 #ifndef USE_MD_CONSTRAINTS
861 check_constraint_len ();
863 validate_insn_operands (d);
864 validate_insn_alternatives (d);
865 validate_optab_operands (d);
867 process_template (d, XTMPL (insn, 3));
870 /* Look at a define_peephole just read. Assign its code number.
871 Record on idata the template and the number of arguments.
872 If the insn has a hairy output action, output it now. */
875 gen_peephole (rtx peep, int lineno)
877 struct pattern_stats stats;
878 struct data *d = XNEW (struct data);
881 d->code_number = next_code_number;
882 d->index_number = next_index_number;
883 d->filename = read_md_filename;
887 /* Build up the list in the same order as the insns are seen
888 in the machine description. */
891 idata_end = &d->next;
893 memset (d->operand, 0, sizeof (d->operand));
895 /* Get the number of operands by scanning all the patterns of the
896 peephole optimizer. But ignore all the rest of the information
898 for (i = 0; i < XVECLEN (peep, 0); i++)
899 scan_operands (d, XVECEXP (peep, 0, i), 0, 0);
901 get_pattern_stats (&stats, XVEC (peep, 0));
902 d->n_generator_args = 0;
903 d->n_operands = stats.num_insn_operands;
906 validate_insn_alternatives (d);
908 process_template (d, XTMPL (peep, 2));
911 /* Process a define_expand just read. Assign its code number,
912 only for the purposes of `insn_gen_function'. */
915 gen_expand (rtx insn, int lineno)
917 struct pattern_stats stats;
918 struct data *d = XNEW (struct data);
921 d->code_number = next_code_number;
922 d->index_number = next_index_number;
923 d->filename = read_md_filename;
925 if (XSTR (insn, 0)[0])
926 d->name = XSTR (insn, 0);
930 /* Build up the list in the same order as the insns are seen
931 in the machine description. */
934 idata_end = &d->next;
936 memset (d->operand, 0, sizeof (d->operand));
938 /* Scan the operands to get the specified predicates and modes,
939 since expand_binop needs to know them. */
942 for (i = 0; i < XVECLEN (insn, 1); i++)
943 scan_operands (d, XVECEXP (insn, 1, i), 0, 0);
945 get_pattern_stats (&stats, XVEC (insn, 1));
946 d->n_generator_args = stats.num_generator_args;
947 d->n_operands = stats.num_insn_operands;
948 d->n_dups = stats.num_dups;
949 d->template_code = 0;
950 d->output_format = INSN_OUTPUT_FORMAT_NONE;
952 validate_insn_alternatives (d);
953 validate_optab_operands (d);
957 /* Process a define_split just read. Assign its code number,
958 only for reasons of consistency and to simplify genrecog. */
961 gen_split (rtx split, int lineno)
963 struct pattern_stats stats;
964 struct data *d = XNEW (struct data);
967 d->code_number = next_code_number;
968 d->index_number = next_index_number;
969 d->filename = read_md_filename;
973 /* Build up the list in the same order as the insns are seen
974 in the machine description. */
977 idata_end = &d->next;
979 memset (d->operand, 0, sizeof (d->operand));
981 /* Get the number of operands by scanning all the patterns of the
982 split patterns. But ignore all the rest of the information thus
984 for (i = 0; i < XVECLEN (split, 0); i++)
985 scan_operands (d, XVECEXP (split, 0, i), 0, 0);
987 get_pattern_stats (&stats, XVEC (split, 0));
988 d->n_generator_args = 0;
989 d->n_operands = stats.num_insn_operands;
991 d->n_alternatives = 0;
992 d->template_code = 0;
993 d->output_format = INSN_OUTPUT_FORMAT_NONE;
999 init_insn_for_nothing (void)
1001 memset (¬hing, 0, sizeof (nothing));
1002 nothing.name = "*placeholder_for_nothing";
1003 nothing.filename = "<internal>";
1006 extern int main (int, char **);
1009 main (int argc, char **argv)
1013 progname = "genoutput";
1015 init_insn_for_nothing ();
1017 if (!init_rtx_reader_args (argc, argv))
1018 return (FATAL_EXIT_CODE);
1021 next_index_number = 0;
1023 /* Read the machine description. */
1029 desc = read_md_rtx (&line_no, &next_code_number);
1033 switch (GET_CODE (desc))
1036 gen_insn (desc, line_no);
1039 case DEFINE_PEEPHOLE:
1040 gen_peephole (desc, line_no);
1044 gen_expand (desc, line_no);
1048 case DEFINE_PEEPHOLE2:
1049 gen_split (desc, line_no);
1052 #ifdef USE_MD_CONSTRAINTS
1053 case DEFINE_CONSTRAINT:
1054 case DEFINE_REGISTER_CONSTRAINT:
1055 case DEFINE_ADDRESS_CONSTRAINT:
1056 case DEFINE_MEMORY_CONSTRAINT:
1057 note_constraint (desc, line_no);
1064 next_index_number++;
1068 output_operand_data ();
1069 output_insn_data ();
1070 output_get_insn_name ();
1073 return (ferror (stdout) != 0 || have_error
1074 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
1077 /* Return the number of occurrences of character C in string S or
1078 -1 if S is the null string. */
1081 n_occurrences (int c, const char *s)
1085 if (s == 0 || *s == '\0')
1094 /* Remove whitespace in `s' by moving up characters until the end.
1095 Return a new string. */
1098 strip_whitespace (const char *s)
1106 p = q = XNEWVEC (char, strlen (s) + 1);
1107 while ((ch = *s++) != '\0')
1115 #ifdef USE_MD_CONSTRAINTS
1117 /* Record just enough information about a constraint to allow checking
1118 of operand constraint strings above, in validate_insn_alternatives.
1119 Does not validate most properties of the constraint itself; does
1120 enforce no duplicate names, no overlap with MI constraints, and no
1121 prefixes. EXP is the define_*constraint form, LINENO the line number
1122 reported by the reader. */
1124 note_constraint (rtx exp, int lineno)
1126 const char *name = XSTR (exp, 0);
1127 unsigned int namelen = strlen (name);
1128 struct constraint_data **iter, **slot, *new_cdata;
1130 /* The 'm' constraint is special here since that constraint letter
1131 can be overridden by the back end by defining the
1132 TARGET_MEM_CONSTRAINT macro. */
1133 if (strchr (indep_constraints, name[0]) && name[0] != 'm')
1135 if (name[1] == '\0')
1136 error_with_line (lineno, "constraint letter '%s' cannot be "
1137 "redefined by the machine description", name);
1139 error_with_line (lineno, "constraint name '%s' cannot be defined by "
1140 "the machine description, as it begins with '%c'",
1145 slot = &constraints_by_letter_table[(unsigned int)name[0]];
1146 for (iter = slot; *iter; iter = &(*iter)->next_this_letter)
1148 /* This causes slot to end up pointing to the
1149 next_this_letter field of the last constraint with a name
1150 of equal or greater length than the new constraint; hence
1151 the new constraint will be inserted after all previous
1152 constraints with names of the same length. */
1153 if ((*iter)->namelen >= namelen)
1156 if (!strcmp ((*iter)->name, name))
1158 error_with_line (lineno, "redefinition of constraint '%s'", name);
1159 message_with_line ((*iter)->lineno, "previous definition is here");
1162 else if (!strncmp ((*iter)->name, name, (*iter)->namelen))
1164 error_with_line (lineno, "defining constraint '%s' here", name);
1165 message_with_line ((*iter)->lineno, "renders constraint '%s' "
1166 "(defined here) a prefix", (*iter)->name);
1169 else if (!strncmp ((*iter)->name, name, namelen))
1171 error_with_line (lineno, "constraint '%s' is a prefix", name);
1172 message_with_line ((*iter)->lineno, "of constraint '%s' "
1173 "(defined here)", (*iter)->name);
1177 new_cdata = XNEWVAR (struct constraint_data, sizeof (struct constraint_data) + namelen);
1178 strcpy ((char *)new_cdata + offsetof(struct constraint_data, name), name);
1179 new_cdata->namelen = namelen;
1180 new_cdata->lineno = lineno;
1181 new_cdata->next_this_letter = *slot;
1185 /* Return the length of the constraint name beginning at position S
1186 of an operand constraint string, or issue an error message if there
1187 is no such constraint. Does not expect to be called for generic
1190 mdep_constraint_len (const char *s, int lineno, int opno)
1192 struct constraint_data *p;
1194 p = constraints_by_letter_table[(unsigned int)s[0]];
1197 for (; p; p = p->next_this_letter)
1198 if (!strncmp (s, p->name, p->namelen))
1201 error_with_line (lineno,
1202 "error: undefined machine-specific constraint "
1203 "at this point: \"%s\"", s);
1204 message_with_line (lineno, "note: in operand %d", opno);
1205 return 1; /* safe */
1209 /* Verify that DEFAULT_CONSTRAINT_LEN is used properly and not
1210 tampered with. This isn't bullet-proof, but it should catch
1211 most genuine mistakes. */
1213 check_constraint_len (void)
1218 for (p = ",#*+=&%!1234567890"; *p; p++)
1219 for (d = -9; d < 9; d++)
1220 gcc_assert (constraint_len (p, d) == d);
1224 constraint_len (const char *p, int genoutput_default_constraint_len)
1226 /* Check that we still match defaults.h . First we do a generation-time
1227 check that fails if the value is not the expected one... */
1228 gcc_assert (DEFAULT_CONSTRAINT_LEN (*p, p) == 1);
1229 /* And now a compile-time check that should give a diagnostic if the
1230 definition doesn't exactly match. */
1231 #define DEFAULT_CONSTRAINT_LEN(C,STR) 1
1232 /* Now re-define DEFAULT_CONSTRAINT_LEN so that we can verify it is
1234 #undef DEFAULT_CONSTRAINT_LEN
1235 #define DEFAULT_CONSTRAINT_LEN(C,STR) \
1236 ((C) != *p || STR != p ? -1 : genoutput_default_constraint_len)
1237 return CONSTRAINT_LEN (*p, p);
1238 /* And set it back. */
1239 #undef DEFAULT_CONSTRAINT_LEN
1240 #define DEFAULT_CONSTRAINT_LEN(C,STR) 1