genpreds.c (write_constraint_satisfied_p_1): Replace with...
[platform/upstream/gcc.git] / gcc / genpreds.c
1 /* Generate from machine description:
2    - prototype declarations for operand predicates (tm-preds.h)
3    - function definitions of operand predicates, if defined new-style
4      (insn-preds.c)
5    Copyright (C) 2001-2014 Free Software Foundation, Inc.
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22
23 #include "bconfig.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "errors.h"
29 #include "obstack.h"
30 #include "read-md.h"
31 #include "gensupport.h"
32
33 /* Given a predicate expression EXP, from form NAME at line LINENO,
34    verify that it does not contain any RTL constructs which are not
35    valid in predicate definitions.  Returns true if EXP is
36    INvalid; issues error messages, caller need not.  */
37 static bool
38 validate_exp (rtx exp, const char *name, int lineno)
39 {
40   if (exp == 0)
41     {
42       message_with_line (lineno, "%s: must give a predicate expression", name);
43       return true;
44     }
45
46   switch (GET_CODE (exp))
47     {
48       /* Ternary, binary, unary expressions: recurse into subexpressions.  */
49     case IF_THEN_ELSE:
50       if (validate_exp (XEXP (exp, 2), name, lineno))
51         return true;
52       /* else fall through */
53     case AND:
54     case IOR:
55       if (validate_exp (XEXP (exp, 1), name, lineno))
56         return true;
57       /* else fall through */
58     case NOT:
59       return validate_exp (XEXP (exp, 0), name, lineno);
60
61       /* MATCH_CODE might have a syntax error in its path expression.  */
62     case MATCH_CODE:
63       {
64         const char *p;
65         for (p = XSTR (exp, 1); *p; p++)
66           {
67             if (!ISDIGIT (*p) && !ISLOWER (*p))
68               {
69                 error_with_line (lineno, "%s: invalid character in path "
70                                  "string '%s'", name, XSTR (exp, 1));
71                 return true;
72               }
73           }
74       }
75       /* fall through */
76
77       /* These need no special checking.  */
78     case MATCH_OPERAND:
79     case MATCH_TEST:
80       return false;
81
82     default:
83       error_with_line (lineno,
84                        "%s: cannot use '%s' in a predicate expression",
85                        name, GET_RTX_NAME (GET_CODE (exp)));
86       return true;
87     }
88 }
89
90 /* Predicates are defined with (define_predicate) or
91    (define_special_predicate) expressions in the machine description.  */
92 static void
93 process_define_predicate (rtx defn, int lineno)
94 {
95   validate_exp (XEXP (defn, 1), XSTR (defn, 0), lineno);
96 }
97
98 /* Given a predicate, if it has an embedded C block, write the block
99    out as a static inline subroutine, and augment the RTL test with a
100    match_test that calls that subroutine.  For instance,
101
102        (define_predicate "basereg_operand"
103          (match_operand 0 "register_operand")
104        {
105          if (GET_CODE (op) == SUBREG)
106            op = SUBREG_REG (op);
107          return REG_POINTER (op);
108        })
109
110    becomes
111
112        static inline int basereg_operand_1(rtx op, enum machine_mode mode)
113        {
114          if (GET_CODE (op) == SUBREG)
115            op = SUBREG_REG (op);
116          return REG_POINTER (op);
117        }
118
119        (define_predicate "basereg_operand"
120          (and (match_operand 0 "register_operand")
121               (match_test "basereg_operand_1 (op, mode)")))
122
123    The only wart is that there's no way to insist on a { } string in
124    an RTL template, so we have to handle "" strings.  */
125
126
127 static void
128 write_predicate_subfunction (struct pred_data *p)
129 {
130   const char *match_test_str;
131   rtx match_test_exp, and_exp;
132
133   if (p->c_block[0] == '\0')
134     return;
135
136   /* Construct the function-call expression.  */
137   obstack_grow (rtl_obstack, p->name, strlen (p->name));
138   obstack_grow (rtl_obstack, "_1 (op, mode)",
139                 sizeof "_1 (op, mode)");
140   match_test_str = XOBFINISH (rtl_obstack, const char *);
141
142   /* Add the function-call expression to the complete expression to be
143      evaluated.  */
144   match_test_exp = rtx_alloc (MATCH_TEST);
145   XSTR (match_test_exp, 0) = match_test_str;
146
147   and_exp = rtx_alloc (AND);
148   XEXP (and_exp, 0) = p->exp;
149   XEXP (and_exp, 1) = match_test_exp;
150
151   p->exp = and_exp;
152
153   printf ("static inline int\n"
154           "%s_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)\n",
155           p->name);
156   print_md_ptr_loc (p->c_block);
157   if (p->c_block[0] == '{')
158     fputs (p->c_block, stdout);
159   else
160     printf ("{\n  %s\n}", p->c_block);
161   fputs ("\n\n", stdout);
162 }
163
164 /* Given a predicate expression EXP, from form NAME, determine whether
165    it refers to the variable given as VAR.  */
166 static bool
167 needs_variable (rtx exp, const char *var)
168 {
169   switch (GET_CODE (exp))
170     {
171       /* Ternary, binary, unary expressions need a variable if
172          any of their subexpressions do.  */
173     case IF_THEN_ELSE:
174       if (needs_variable (XEXP (exp, 2), var))
175         return true;
176       /* else fall through */
177     case AND:
178     case IOR:
179       if (needs_variable (XEXP (exp, 1), var))
180         return true;
181       /* else fall through */
182     case NOT:
183       return needs_variable (XEXP (exp, 0), var);
184
185       /* MATCH_CODE uses "op", but nothing else.  */
186     case MATCH_CODE:
187       return !strcmp (var, "op");
188
189       /* MATCH_OPERAND uses "op" and may use "mode".  */
190     case MATCH_OPERAND:
191       if (!strcmp (var, "op"))
192         return true;
193       if (!strcmp (var, "mode") && GET_MODE (exp) == VOIDmode)
194         return true;
195       return false;
196
197       /* MATCH_TEST uses var if XSTR (exp, 0) =~ /\b${var}\b/o; */
198     case MATCH_TEST:
199       {
200         const char *p = XSTR (exp, 0);
201         const char *q = strstr (p, var);
202         if (!q)
203           return false;
204         if (q != p && (ISALNUM (q[-1]) || q[-1] == '_'))
205           return false;
206         q += strlen (var);
207         if (ISALNUM (q[0]) || q[0] == '_')
208           return false;
209       }
210       return true;
211
212     default:
213       gcc_unreachable ();
214     }
215 }
216
217 /* Given an RTL expression EXP, find all subexpressions which we may
218    assume to perform mode tests.  Normal MATCH_OPERAND does;
219    MATCH_CODE does if it applies to the whole expression and accepts
220    CONST_INT or CONST_DOUBLE; and we have to assume that MATCH_TEST
221    does not.  These combine in almost-boolean fashion - the only
222    exception is that (not X) must be assumed not to perform a mode
223    test, whether or not X does.
224
225    The mark is the RTL /v flag, which is true for subexpressions which
226    do *not* perform mode tests.
227 */
228 #define NO_MODE_TEST(EXP) RTX_FLAG (EXP, volatil)
229 static void
230 mark_mode_tests (rtx exp)
231 {
232   switch (GET_CODE (exp))
233     {
234     case MATCH_OPERAND:
235       {
236         struct pred_data *p = lookup_predicate (XSTR (exp, 1));
237         if (!p)
238           error ("reference to undefined predicate '%s'", XSTR (exp, 1));
239         else if (p->special || GET_MODE (exp) != VOIDmode)
240           NO_MODE_TEST (exp) = 1;
241       }
242       break;
243
244     case MATCH_CODE:
245       if (XSTR (exp, 1)[0] != '\0'
246           || (!strstr (XSTR (exp, 0), "const_int")
247               && !strstr (XSTR (exp, 0), "const_double")))
248         NO_MODE_TEST (exp) = 1;
249       break;
250
251     case MATCH_TEST:
252     case NOT:
253       NO_MODE_TEST (exp) = 1;
254       break;
255
256     case AND:
257       mark_mode_tests (XEXP (exp, 0));
258       mark_mode_tests (XEXP (exp, 1));
259
260       NO_MODE_TEST (exp) = (NO_MODE_TEST (XEXP (exp, 0))
261                             && NO_MODE_TEST (XEXP (exp, 1)));
262       break;
263
264     case IOR:
265       mark_mode_tests (XEXP (exp, 0));
266       mark_mode_tests (XEXP (exp, 1));
267
268       NO_MODE_TEST (exp) = (NO_MODE_TEST (XEXP (exp, 0))
269                             || NO_MODE_TEST (XEXP (exp, 1)));
270       break;
271
272     case IF_THEN_ELSE:
273       /* A ? B : C does a mode test if (one of A and B) does a mode
274          test, and C does too.  */
275       mark_mode_tests (XEXP (exp, 0));
276       mark_mode_tests (XEXP (exp, 1));
277       mark_mode_tests (XEXP (exp, 2));
278
279       NO_MODE_TEST (exp) = ((NO_MODE_TEST (XEXP (exp, 0))
280                              && NO_MODE_TEST (XEXP (exp, 1)))
281                             || NO_MODE_TEST (XEXP (exp, 2)));
282       break;
283
284     default:
285       gcc_unreachable ();
286     }
287 }
288
289 /* Determine whether the expression EXP is a MATCH_CODE that should
290    be written as a switch statement.  */
291 static bool
292 generate_switch_p (rtx exp)
293 {
294   return GET_CODE (exp) == MATCH_CODE
295          && strchr (XSTR (exp, 0), ',');
296 }
297
298 /* Given a predicate, work out where in its RTL expression to add
299    tests for proper modes.  Special predicates do not get any such
300    tests.  We try to avoid adding tests when we don't have to; in
301    particular, other normal predicates can be counted on to do it for
302    us.  */
303
304 static void
305 add_mode_tests (struct pred_data *p)
306 {
307   rtx match_test_exp, and_exp;
308   rtx *pos;
309
310   /* Don't touch special predicates.  */
311   if (p->special)
312     return;
313
314   mark_mode_tests (p->exp);
315
316   /* If the whole expression already tests the mode, we're done.  */
317   if (!NO_MODE_TEST (p->exp))
318     return;
319
320   match_test_exp = rtx_alloc (MATCH_TEST);
321   XSTR (match_test_exp, 0) = "mode == VOIDmode || GET_MODE (op) == mode";
322   and_exp = rtx_alloc (AND);
323   XEXP (and_exp, 1) = match_test_exp;
324
325   /* It is always correct to rewrite p->exp as
326
327         (and (...) (match_test "mode == VOIDmode || GET_MODE (op) == mode"))
328
329      but there are a couple forms where we can do better.  If the
330      top-level pattern is an IOR, and one of the two branches does test
331      the mode, we can wrap just the branch that doesn't.  Likewise, if
332      we have an IF_THEN_ELSE, and one side of it tests the mode, we can
333      wrap just the side that doesn't.  And, of course, we can repeat this
334      descent as many times as it works.  */
335
336   pos = &p->exp;
337   for (;;)
338     {
339       rtx subexp = *pos;
340
341       switch (GET_CODE (subexp))
342         {
343         case AND:
344           /* The switch code generation in write_predicate_stmts prefers
345              rtx code tests to be at the top of the expression tree.  So
346              push this AND down into the second operand of an existing
347              AND expression.  */
348           if (generate_switch_p (XEXP (subexp, 0)))
349             pos = &XEXP (subexp, 1);
350           goto break_loop;
351
352         case IOR:
353           {
354             int test0 = NO_MODE_TEST (XEXP (subexp, 0));
355             int test1 = NO_MODE_TEST (XEXP (subexp, 1));
356
357             gcc_assert (test0 || test1);
358
359             if (test0 && test1)
360               goto break_loop;
361             pos = test0 ? &XEXP (subexp, 0) : &XEXP (subexp, 1);
362           }
363           break;
364
365         case IF_THEN_ELSE:
366           {
367             int test0 = NO_MODE_TEST (XEXP (subexp, 0));
368             int test1 = NO_MODE_TEST (XEXP (subexp, 1));
369             int test2 = NO_MODE_TEST (XEXP (subexp, 2));
370
371             gcc_assert ((test0 && test1) || test2);
372
373             if (test0 && test1 && test2)
374               goto break_loop;
375             if (test0 && test1)
376               /* Must put it on the dependent clause, not the
377                  controlling expression, or we change the meaning of
378                  the test.  */
379               pos = &XEXP (subexp, 1);
380             else
381               pos = &XEXP (subexp, 2);
382           }
383           break;
384
385         default:
386           goto break_loop;
387         }
388     }
389  break_loop:
390   XEXP (and_exp, 0) = *pos;
391   *pos = and_exp;
392 }
393
394 /* PATH is a string describing a path from the root of an RTL
395    expression to an inner subexpression to be tested.  Output
396    code which computes the subexpression from the variable
397    holding the root of the expression.  */
398 static void
399 write_extract_subexp (const char *path)
400 {
401   int len = strlen (path);
402   int i;
403
404   /* We first write out the operations (XEXP or XVECEXP) in reverse
405      order, then write "op", then the indices in forward order.  */
406   for (i = len - 1; i >= 0; i--)
407     {
408       if (ISLOWER (path[i]))
409         fputs ("XVECEXP (", stdout);
410       else if (ISDIGIT (path[i]))
411         fputs ("XEXP (", stdout);
412       else
413         gcc_unreachable ();
414     }
415
416   fputs ("op", stdout);
417
418   for (i = 0; i < len; i++)
419     {
420       if (ISLOWER (path[i]))
421         printf (", 0, %d)", path[i] - 'a');
422       else if (ISDIGIT (path[i]))
423         printf (", %d)", path[i] - '0');
424       else
425         gcc_unreachable ();
426     }
427 }
428
429 /* CODES is a list of RTX codes.  Write out an expression which
430    determines whether the operand has one of those codes.  */
431 static void
432 write_match_code (const char *path, const char *codes)
433 {
434   const char *code;
435
436   while ((code = scan_comma_elt (&codes)) != 0)
437     {
438       fputs ("GET_CODE (", stdout);
439       write_extract_subexp (path);
440       fputs (") == ", stdout);
441       while (code < codes)
442         {
443           putchar (TOUPPER (*code));
444           code++;
445         }
446
447       if (*codes == ',')
448         fputs (" || ", stdout);
449     }
450 }
451
452 /* EXP is an RTL (sub)expression for a predicate.  Recursively
453    descend the expression and write out an equivalent C expression.  */
454 static void
455 write_predicate_expr (rtx exp)
456 {
457   switch (GET_CODE (exp))
458     {
459     case AND:
460       putchar ('(');
461       write_predicate_expr (XEXP (exp, 0));
462       fputs (") && (", stdout);
463       write_predicate_expr (XEXP (exp, 1));
464       putchar (')');
465       break;
466
467     case IOR:
468       putchar ('(');
469       write_predicate_expr (XEXP (exp, 0));
470       fputs (") || (", stdout);
471       write_predicate_expr (XEXP (exp, 1));
472       putchar (')');
473       break;
474
475     case NOT:
476       fputs ("!(", stdout);
477       write_predicate_expr (XEXP (exp, 0));
478       putchar (')');
479       break;
480
481     case IF_THEN_ELSE:
482       putchar ('(');
483       write_predicate_expr (XEXP (exp, 0));
484       fputs (") ? (", stdout);
485       write_predicate_expr (XEXP (exp, 1));
486       fputs (") : (", stdout);
487       write_predicate_expr (XEXP (exp, 2));
488       putchar (')');
489       break;
490
491     case MATCH_OPERAND:
492       if (GET_MODE (exp) == VOIDmode)
493         printf ("%s (op, mode)", XSTR (exp, 1));
494       else
495         printf ("%s (op, %smode)", XSTR (exp, 1), mode_name[GET_MODE (exp)]);
496       break;
497
498     case MATCH_CODE:
499       write_match_code (XSTR (exp, 1), XSTR (exp, 0));
500       break;
501
502     case MATCH_TEST:
503       print_c_condition (XSTR (exp, 0));
504       break;
505
506     default:
507       gcc_unreachable ();
508     }
509 }
510
511 /* Write the MATCH_CODE expression EXP as a switch statement.  */
512
513 static void
514 write_match_code_switch (rtx exp)
515 {
516   const char *codes = XSTR (exp, 0);
517   const char *path = XSTR (exp, 1);
518   const char *code;
519
520   fputs ("  switch (GET_CODE (", stdout);
521   write_extract_subexp (path);
522   fputs ("))\n    {\n", stdout);
523
524   while ((code = scan_comma_elt (&codes)) != 0)
525     {
526       fputs ("    case ", stdout);
527       while (code < codes)
528         {
529           putchar (TOUPPER (*code));
530           code++;
531         }
532       fputs (":\n", stdout);
533     }
534 }
535
536 /* Given a predicate expression EXP, write out a sequence of stmts
537    to evaluate it.  This is similar to write_predicate_expr but can
538    generate efficient switch statements.  */
539
540 static void
541 write_predicate_stmts (rtx exp)
542 {
543   switch (GET_CODE (exp))
544     {
545     case MATCH_CODE:
546       if (generate_switch_p (exp))
547         {
548           write_match_code_switch (exp);
549           puts ("      return true;\n"
550                 "    default:\n"
551                 "      break;\n"
552                 "    }\n"
553                 "  return false;");
554           return;
555         }
556       break;
557
558     case AND:
559       if (generate_switch_p (XEXP (exp, 0)))
560         {
561           write_match_code_switch (XEXP (exp, 0));
562           puts ("      break;\n"
563                 "    default:\n"
564                 "      return false;\n"
565                 "    }");
566           exp = XEXP (exp, 1);
567         }
568       break;
569
570     case IOR:
571       if (generate_switch_p (XEXP (exp, 0)))
572         {
573           write_match_code_switch (XEXP (exp, 0));
574           puts ("      return true;\n"
575                 "    default:\n"
576                 "      break;\n"
577                 "    }");
578           exp = XEXP (exp, 1);
579         }
580       break;
581
582     case NOT:
583       if (generate_switch_p (XEXP (exp, 0)))
584         {
585           write_match_code_switch (XEXP (exp, 0));
586           puts ("      return false;\n"
587                 "    default:\n"
588                 "      break;\n"
589                 "    }\n"
590                 "  return true;");
591           return;
592         }
593       break;
594
595     default:
596       break;
597     }
598
599   fputs ("  return ",stdout);
600   write_predicate_expr (exp);
601   fputs (";\n", stdout);
602 }
603
604 /* Given a predicate, write out a complete C function to compute it.  */
605 static void
606 write_one_predicate_function (struct pred_data *p)
607 {
608   if (!p->exp)
609     return;
610
611   write_predicate_subfunction (p);
612   add_mode_tests (p);
613
614   /* A normal predicate can legitimately not look at enum machine_mode
615      if it accepts only CONST_INTs and/or CONST_WIDE_INT and/or CONST_DOUBLEs.  */
616   printf ("int\n%s (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)\n{\n",
617           p->name);
618   write_predicate_stmts (p->exp);
619   fputs ("}\n\n", stdout);
620 }
621 \f
622 /* Constraints fall into two categories: register constraints
623    (define_register_constraint), and others (define_constraint,
624    define_memory_constraint, define_address_constraint).  We
625    work out automatically which of the various old-style macros
626    they correspond to, and produce appropriate code.  They all
627    go in the same hash table so we can verify that there are no
628    duplicate names.  */
629
630 /* All data from one constraint definition.  */
631 struct constraint_data
632 {
633   struct constraint_data *next_this_letter;
634   struct constraint_data *next_textual;
635   const char *name;
636   const char *c_name;    /* same as .name unless mangling is necessary */
637   size_t namelen;
638   const char *regclass;  /* for register constraints */
639   rtx exp;               /* for other constraints */
640   unsigned int lineno;   /* line of definition */
641   unsigned int is_register  : 1;
642   unsigned int is_const_int : 1;
643   unsigned int is_const_dbl : 1;
644   unsigned int is_extra     : 1;
645   unsigned int is_memory    : 1;
646   unsigned int is_address   : 1;
647 };
648
649 /* Overview of all constraints beginning with a given letter.  */
650
651 static struct constraint_data *
652 constraints_by_letter_table[1<<CHAR_BIT];
653
654 /* For looking up all the constraints in the order that they appeared
655    in the machine description.  */
656 static struct constraint_data *first_constraint;
657 static struct constraint_data **last_constraint_ptr = &first_constraint;
658
659 #define FOR_ALL_CONSTRAINTS(iter_) \
660   for (iter_ = first_constraint; iter_; iter_ = iter_->next_textual)
661
662 /* These letters, and all names beginning with them, are reserved for
663    generic constraints.
664    The 'm' constraint is not mentioned here since that constraint
665    letter can be overridden by the back end by defining the
666    TARGET_MEM_CONSTRAINT macro.  */
667 static const char generic_constraint_letters[] = "EFVXginoprs";
668
669 /* Machine-independent code expects that constraints with these
670    (initial) letters will allow only (a subset of all) CONST_INTs.  */
671
672 static const char const_int_constraints[] = "IJKLMNOP";
673
674 /* Machine-independent code expects that constraints with these
675    (initial) letters will allow only (a subset of all) CONST_DOUBLEs.  */
676
677 static const char const_dbl_constraints[] = "GH";
678
679 /* Summary data used to decide whether to output various functions and
680    macro definitions.  */
681 static unsigned int constraint_max_namelen;
682 static bool have_register_constraints;
683 static bool have_memory_constraints;
684 static bool have_address_constraints;
685 static bool have_extra_constraints;
686 static bool have_const_int_constraints;
687 static bool have_const_dbl_constraints;
688 static unsigned int num_constraints;
689
690 static const constraint_data **enum_order;
691 static unsigned int register_start, register_end;
692 static unsigned int satisfied_start;
693 static unsigned int memory_start, memory_end;
694 static unsigned int address_start, address_end;
695
696 /* Convert NAME, which contains angle brackets and/or underscores, to
697    a string that can be used as part of a C identifier.  The string
698    comes from the rtl_obstack.  */
699 static const char *
700 mangle (const char *name)
701 {
702   for (; *name; name++)
703     switch (*name)
704       {
705       case '_': obstack_grow (rtl_obstack, "__", 2); break;
706       case '<': obstack_grow (rtl_obstack, "_l", 2); break;
707       case '>': obstack_grow (rtl_obstack, "_g", 2); break;
708       default: obstack_1grow (rtl_obstack, *name); break;
709       }
710
711   obstack_1grow (rtl_obstack, '\0');
712   return XOBFINISH (rtl_obstack, const char *);
713 }
714
715 /* Add one constraint, of any sort, to the tables.  NAME is its name;
716    REGCLASS is the register class, if any; EXP is the expression to
717    test, if any;  IS_MEMORY and IS_ADDRESS indicate memory and address
718    constraints, respectively; LINENO is the line number from the MD reader.
719    Not all combinations of arguments are valid; most importantly, REGCLASS
720    is mutually exclusive with EXP, and IS_MEMORY/IS_ADDRESS are only
721    meaningful for constraints with EXP.
722
723    This function enforces all syntactic and semantic rules about what
724    constraints can be defined.  */
725
726 static void
727 add_constraint (const char *name, const char *regclass,
728                 rtx exp, bool is_memory, bool is_address,
729                 int lineno)
730 {
731   struct constraint_data *c, **iter, **slot;
732   const char *p;
733   bool need_mangled_name = false;
734   bool is_const_int;
735   bool is_const_dbl;
736   size_t namelen;
737
738   if (exp && validate_exp (exp, name, lineno))
739     return;
740
741   if (!ISALPHA (name[0]) && name[0] != '_')
742     {
743       if (name[1] == '\0')
744         error_with_line (lineno, "constraint name '%s' is not "
745                          "a letter or underscore", name);
746       else
747         error_with_line (lineno, "constraint name '%s' does not begin "
748                          "with a letter or underscore", name);
749       return;
750     }
751   for (p = name; *p; p++)
752     if (!ISALNUM (*p))
753       {
754         if (*p == '<' || *p == '>' || *p == '_')
755           need_mangled_name = true;
756         else
757           {
758             error_with_line (lineno,
759                              "constraint name '%s' must be composed of "
760                              "letters, digits, underscores, and "
761                              "angle brackets", name);
762             return;
763           }
764       }
765
766   if (strchr (generic_constraint_letters, name[0]))
767     {
768       if (name[1] == '\0')
769         error_with_line (lineno, "constraint letter '%s' cannot be "
770                          "redefined by the machine description", name);
771       else
772         error_with_line (lineno, "constraint name '%s' cannot be defined by "
773                          "the machine description, as it begins with '%c'",
774                          name, name[0]);
775       return;
776     }
777
778
779   namelen = strlen (name);
780   slot = &constraints_by_letter_table[(unsigned int)name[0]];
781   for (iter = slot; *iter; iter = &(*iter)->next_this_letter)
782     {
783       /* This causes slot to end up pointing to the
784          next_this_letter field of the last constraint with a name
785          of equal or greater length than the new constraint; hence
786          the new constraint will be inserted after all previous
787          constraints with names of the same length.  */
788       if ((*iter)->namelen >= namelen)
789         slot = iter;
790
791       if (!strcmp ((*iter)->name, name))
792         {
793           error_with_line (lineno, "redefinition of constraint '%s'", name);
794           message_with_line ((*iter)->lineno, "previous definition is here");
795           return;
796         }
797       else if (!strncmp ((*iter)->name, name, (*iter)->namelen))
798         {
799           error_with_line (lineno, "defining constraint '%s' here", name);
800           message_with_line ((*iter)->lineno, "renders constraint '%s' "
801                              "(defined here) a prefix", (*iter)->name);
802           return;
803         }
804       else if (!strncmp ((*iter)->name, name, namelen))
805         {
806           error_with_line (lineno, "constraint '%s' is a prefix", name);
807           message_with_line ((*iter)->lineno, "of constraint '%s' "
808                              "(defined here)", (*iter)->name);
809           return;
810         }
811     }
812
813   is_const_int = strchr (const_int_constraints, name[0]) != 0;
814   is_const_dbl = strchr (const_dbl_constraints, name[0]) != 0;
815
816   if (is_const_int || is_const_dbl)
817     {
818       enum rtx_code appropriate_code
819         = is_const_int ? CONST_INT : CONST_DOUBLE;
820
821       /* Consider relaxing this requirement in the future.  */
822       if (regclass
823           || GET_CODE (exp) != AND
824           || GET_CODE (XEXP (exp, 0)) != MATCH_CODE
825           || strcmp (XSTR (XEXP (exp, 0), 0),
826                      GET_RTX_NAME (appropriate_code)))
827         {
828           if (name[1] == '\0')
829             error_with_line (lineno, "constraint letter '%c' is reserved "
830                              "for %s constraints",
831                              name[0], GET_RTX_NAME (appropriate_code));
832           else
833             error_with_line (lineno, "constraint names beginning with '%c' "
834                              "(%s) are reserved for %s constraints",
835                              name[0], name, GET_RTX_NAME (appropriate_code));
836           return;
837         }
838
839       if (is_memory)
840         {
841           if (name[1] == '\0')
842             error_with_line (lineno, "constraint letter '%c' cannot be a "
843                              "memory constraint", name[0]);
844           else
845             error_with_line (lineno, "constraint name '%s' begins with '%c', "
846                              "and therefore cannot be a memory constraint",
847                              name, name[0]);
848           return;
849         }
850       else if (is_address)
851         {
852           if (name[1] == '\0')
853             error_with_line (lineno, "constraint letter '%c' cannot be a "
854                              "memory constraint", name[0]);
855           else
856             error_with_line (lineno, "constraint name '%s' begins with '%c', "
857                              "and therefore cannot be a memory constraint",
858                              name, name[0]);
859           return;
860         }
861     }
862
863
864   c = XOBNEW (rtl_obstack, struct constraint_data);
865   c->name = name;
866   c->c_name = need_mangled_name ? mangle (name) : name;
867   c->lineno = lineno;
868   c->namelen = namelen;
869   c->regclass = regclass;
870   c->exp = exp;
871   c->is_register = regclass != 0;
872   c->is_const_int = is_const_int;
873   c->is_const_dbl = is_const_dbl;
874   c->is_extra = !(regclass || is_const_int || is_const_dbl);
875   c->is_memory = is_memory;
876   c->is_address = is_address;
877
878   c->next_this_letter = *slot;
879   *slot = c;
880
881   /* Insert this constraint in the list of all constraints in textual
882      order.  */
883   c->next_textual = 0;
884   *last_constraint_ptr = c;
885   last_constraint_ptr = &c->next_textual;
886
887   constraint_max_namelen = MAX (constraint_max_namelen, strlen (name));
888   have_register_constraints |= c->is_register;
889   have_const_int_constraints |= c->is_const_int;
890   have_const_dbl_constraints |= c->is_const_dbl;
891   have_extra_constraints |= c->is_extra;
892   have_memory_constraints |= c->is_memory;
893   have_address_constraints |= c->is_address;
894   num_constraints += 1;
895 }
896
897 /* Process a DEFINE_CONSTRAINT, DEFINE_MEMORY_CONSTRAINT, or
898    DEFINE_ADDRESS_CONSTRAINT expression, C.  */
899 static void
900 process_define_constraint (rtx c, int lineno)
901 {
902   add_constraint (XSTR (c, 0), 0, XEXP (c, 2),
903                   GET_CODE (c) == DEFINE_MEMORY_CONSTRAINT,
904                   GET_CODE (c) == DEFINE_ADDRESS_CONSTRAINT,
905                   lineno);
906 }
907
908 /* Process a DEFINE_REGISTER_CONSTRAINT expression, C.  */
909 static void
910 process_define_register_constraint (rtx c, int lineno)
911 {
912   add_constraint (XSTR (c, 0), XSTR (c, 1), 0, false, false, lineno);
913 }
914
915 /* Put the constraints into enum order.  We want to keep constraints
916    of the same type together so that query functions can be simple
917    range checks.  */
918 static void
919 choose_enum_order (void)
920 {
921   struct constraint_data *c;
922
923   enum_order = XNEWVEC (const constraint_data *, num_constraints);
924   unsigned int next = 0;
925
926   register_start = next;
927   FOR_ALL_CONSTRAINTS (c)
928     if (c->is_register)
929       enum_order[next++] = c;
930   register_end = next;
931
932   satisfied_start = next;
933
934   memory_start = next;
935   FOR_ALL_CONSTRAINTS (c)
936     if (c->is_memory)
937       enum_order[next++] = c;
938   memory_end = next;
939
940   address_start = next;
941   FOR_ALL_CONSTRAINTS (c)
942     if (c->is_address)
943       enum_order[next++] = c;
944   address_end = next;
945
946   FOR_ALL_CONSTRAINTS (c)
947     if (!c->is_register && !c->is_memory && !c->is_address)
948       enum_order[next++] = c;
949   gcc_assert (next == num_constraints);
950 }
951
952 /* Write out an enumeration with one entry per machine-specific
953    constraint.  */
954 static void
955 write_enum_constraint_num (void)
956 {
957   fputs ("#define CONSTRAINT_NUM_DEFINED_P 1\n", stdout);
958   fputs ("enum constraint_num\n"
959          "{\n"
960          "  CONSTRAINT__UNKNOWN = 0", stdout);
961   for (unsigned int i = 0; i < num_constraints; ++i)
962     printf (",\n  CONSTRAINT_%s", enum_order[i]->c_name);
963   puts (",\n  CONSTRAINT__LIMIT\n};\n");
964 }
965
966 /* Write out a function which looks at a string and determines what
967    constraint name, if any, it begins with.  */
968 static void
969 write_lookup_constraint_1 (void)
970 {
971   unsigned int i;
972   puts ("enum constraint_num\n"
973         "lookup_constraint_1 (const char *str)\n"
974         "{\n"
975         "  switch (str[0])\n"
976         "    {");
977
978   for (i = 0; i < ARRAY_SIZE (constraints_by_letter_table); i++)
979     {
980       struct constraint_data *c = constraints_by_letter_table[i];
981       if (!c)
982         continue;
983
984       printf ("    case '%c':\n", i);
985       if (c->namelen == 1)
986         printf ("      return CONSTRAINT_%s;\n", c->c_name);
987       else
988         {
989           do
990             {
991               printf ("      if (!strncmp (str + 1, \"%s\", %lu))\n"
992                       "        return CONSTRAINT_%s;\n",
993                       c->name + 1, (unsigned long int) c->namelen - 1,
994                       c->c_name);
995               c = c->next_this_letter;
996             }
997           while (c);
998           puts ("      break;");
999         }
1000     }
1001
1002   puts ("    default: break;\n"
1003         "    }\n"
1004         "  return CONSTRAINT__UNKNOWN;\n"
1005         "}\n");
1006 }
1007
1008 /* Write out an array that maps single-letter characters to their
1009    constraints (if that fits in a character) or 255 if lookup_constraint_1
1010    must be called.  */
1011 static void
1012 write_lookup_constraint_array (void)
1013 {
1014   unsigned int i;
1015   printf ("const unsigned char lookup_constraint_array[] = {\n  ");
1016   for (i = 0; i < ARRAY_SIZE (constraints_by_letter_table); i++)
1017     {
1018       if (i != 0)
1019         printf (",\n  ");
1020       struct constraint_data *c = constraints_by_letter_table[i];
1021       if (!c)
1022         printf ("CONSTRAINT__UNKNOWN");
1023       else if (c->namelen == 1)
1024         printf ("MIN ((int) CONSTRAINT_%s, (int) UCHAR_MAX)", c->c_name);
1025       else
1026         printf ("UCHAR_MAX");
1027     }
1028   printf ("\n};\n\n");
1029 }
1030
1031 /* Write out a function which looks at a string and determines what
1032    the constraint name length is.  */
1033 static void
1034 write_insn_constraint_len (void)
1035 {
1036   unsigned int i;
1037
1038   puts ("static inline size_t\n"
1039         "insn_constraint_len (char fc, const char *str ATTRIBUTE_UNUSED)\n"
1040         "{\n"
1041         "  switch (fc)\n"
1042         "    {");
1043
1044   for (i = 0; i < ARRAY_SIZE (constraints_by_letter_table); i++)
1045     {
1046       struct constraint_data *c = constraints_by_letter_table[i];
1047
1048       if (!c
1049           || c->namelen == 1)
1050         continue;
1051
1052       /* Constraints with multiple characters should have the same
1053          length.  */
1054       {
1055         struct constraint_data *c2 = c->next_this_letter;
1056         size_t len = c->namelen;
1057         while (c2)
1058           {
1059             if (c2->namelen != len)
1060               error ("Multi-letter constraints with first letter '%c' "
1061                      "should have same length", i);
1062             c2 = c2->next_this_letter;
1063           }
1064       }
1065
1066       printf ("    case '%c': return %lu;\n",
1067               i, (unsigned long int) c->namelen);
1068     }
1069
1070   puts ("    default: break;\n"
1071         "    }\n"
1072         "  return 1;\n"
1073         "}\n");
1074 }
1075
1076 /* Write out the function which computes the register class corresponding
1077    to a register constraint.  */
1078 static void
1079 write_reg_class_for_constraint_1 (void)
1080 {
1081   struct constraint_data *c;
1082
1083   puts ("enum reg_class\n"
1084         "reg_class_for_constraint_1 (enum constraint_num c)\n"
1085         "{\n"
1086         "  switch (c)\n"
1087         "    {");
1088
1089   FOR_ALL_CONSTRAINTS (c)
1090     if (c->is_register)
1091       printf ("    case CONSTRAINT_%s: return %s;\n", c->c_name, c->regclass);
1092
1093   puts ("    default: break;\n"
1094         "    }\n"
1095         "  return NO_REGS;\n"
1096         "}\n");
1097 }
1098
1099 /* Write out the functions which compute whether a given value matches
1100    a given non-register constraint.  */
1101 static void
1102 write_tm_constrs_h (void)
1103 {
1104   struct constraint_data *c;
1105
1106   printf ("\
1107 /* Generated automatically by the program '%s'\n\
1108    from the machine description file '%s'.  */\n\n", progname, in_fname);
1109
1110   puts ("\
1111 #ifndef GCC_TM_CONSTRS_H\n\
1112 #define GCC_TM_CONSTRS_H\n");
1113
1114   FOR_ALL_CONSTRAINTS (c)
1115     if (!c->is_register)
1116       {
1117         bool needs_ival = needs_variable (c->exp, "ival");
1118         bool needs_hval = needs_variable (c->exp, "hval");
1119         bool needs_lval = needs_variable (c->exp, "lval");
1120         bool needs_rval = needs_variable (c->exp, "rval");
1121         bool needs_mode = (needs_variable (c->exp, "mode")
1122                            || needs_hval || needs_lval || needs_rval);
1123         bool needs_op = (needs_variable (c->exp, "op")
1124                          || needs_ival || needs_mode);
1125
1126         printf ("static inline bool\n"
1127                 "satisfies_constraint_%s (rtx %s)\n"
1128                 "{\n", c->c_name,
1129                 needs_op ? "op" : "ARG_UNUSED (op)");
1130         if (needs_mode)
1131           puts ("  enum machine_mode mode = GET_MODE (op);");
1132         if (needs_ival)
1133           puts ("  HOST_WIDE_INT ival = 0;");
1134         if (needs_hval)
1135           puts ("  HOST_WIDE_INT hval = 0;");
1136         if (needs_lval)
1137           puts ("  unsigned HOST_WIDE_INT lval = 0;");
1138         if (needs_rval)
1139           puts ("  const REAL_VALUE_TYPE *rval = 0;");
1140
1141         if (needs_ival)
1142           puts ("  if (CONST_INT_P (op))\n"
1143                 "    ival = INTVAL (op);");
1144 #if TARGET_SUPPORTS_WIDE_INT
1145         if (needs_lval || needs_hval)
1146           error ("you can't use lval or hval");
1147 #else
1148         if (needs_hval)
1149           puts ("  if (GET_CODE (op) == CONST_DOUBLE && mode == VOIDmode)"
1150                 "    hval = CONST_DOUBLE_HIGH (op);");
1151         if (needs_lval)
1152           puts ("  if (GET_CODE (op) == CONST_DOUBLE && mode == VOIDmode)"
1153                 "    lval = CONST_DOUBLE_LOW (op);");
1154 #endif
1155         if (needs_rval)
1156           puts ("  if (GET_CODE (op) == CONST_DOUBLE && mode != VOIDmode)"
1157                 "    rval = CONST_DOUBLE_REAL_VALUE (op);");
1158
1159         write_predicate_stmts (c->exp);
1160         fputs ("}\n", stdout);
1161       }
1162   puts ("#endif /* tm-constrs.h */");
1163 }
1164
1165 /* Write out the wrapper function, constraint_satisfied_p, that maps
1166    a CONSTRAINT_xxx constant to one of the predicate functions generated
1167    above.  */
1168 static void
1169 write_constraint_satisfied_p_array (void)
1170 {
1171   if (satisfied_start == num_constraints)
1172     return;
1173
1174   printf ("bool (*constraint_satisfied_p_array[]) (rtx) = {\n  ");
1175   for (unsigned int i = satisfied_start; i < num_constraints; ++i)
1176     {
1177       if (i != satisfied_start)
1178         printf (",\n  ");
1179       printf ("satisfies_constraint_%s", enum_order[i]->c_name);
1180     }
1181   printf ("\n};\n\n");
1182 }
1183
1184 /* Write out the function which computes whether a given value matches
1185    a given CONST_INT constraint.  This doesn't just forward to
1186    constraint_satisfied_p because caller passes the INTVAL, not the RTX.  */
1187 static void
1188 write_insn_const_int_ok_for_constraint (void)
1189 {
1190   struct constraint_data *c;
1191
1192   puts ("bool\n"
1193         "insn_const_int_ok_for_constraint (HOST_WIDE_INT ival, "
1194                                           "enum constraint_num c)\n"
1195         "{\n"
1196         "  switch (c)\n"
1197         "    {");
1198
1199   FOR_ALL_CONSTRAINTS (c)
1200     if (c->is_const_int)
1201       {
1202         printf ("    case CONSTRAINT_%s:\n      return ", c->c_name);
1203         /* c->exp is guaranteed to be (and (match_code "const_int") (...));
1204            we know at this point that we have a const_int, so we need not
1205            bother with that part of the test.  */
1206         write_predicate_expr (XEXP (c->exp, 1));
1207         fputs (";\n\n", stdout);
1208       }
1209
1210   puts ("    default: break;\n"
1211         "    }\n"
1212         "  return false;\n"
1213         "}\n");
1214 }
1215 \f
1216 /* Write a definition for a function NAME that returns true if a given
1217    constraint_num is in the range [START, END).  */
1218 static void
1219 write_range_function (const char *name, unsigned int start, unsigned int end)
1220 {
1221   printf ("static inline bool\n");
1222   if (start != end)
1223     printf ("%s (enum constraint_num c)\n"
1224             "{\n"
1225             "  return c >= CONSTRAINT_%s && c <= CONSTRAINT_%s;\n"
1226             "}\n\n",
1227             name, enum_order[start]->c_name, enum_order[end - 1]->c_name);
1228   else
1229     printf ("%s (enum constraint_num)\n"
1230             "{\n"
1231             "  return false;\n"
1232             "}\n\n", name);
1233 }
1234
1235 /* Write tm-preds.h.  Unfortunately, it is impossible to forward-declare
1236    an enumeration in portable C, so we have to condition all these
1237    prototypes on HAVE_MACHINE_MODES.  */
1238 static void
1239 write_tm_preds_h (void)
1240 {
1241   struct pred_data *p;
1242
1243   printf ("\
1244 /* Generated automatically by the program '%s'\n\
1245    from the machine description file '%s'.  */\n\n", progname, in_fname);
1246
1247   puts ("\
1248 #ifndef GCC_TM_PREDS_H\n\
1249 #define GCC_TM_PREDS_H\n\
1250 \n\
1251 #ifdef HAVE_MACHINE_MODES");
1252
1253   FOR_ALL_PREDICATES (p)
1254     printf ("extern int %s (rtx, enum machine_mode);\n", p->name);
1255
1256   puts ("#endif /* HAVE_MACHINE_MODES */\n");
1257
1258   if (constraint_max_namelen > 0)
1259     {
1260       write_enum_constraint_num ();
1261       puts ("extern enum constraint_num lookup_constraint_1 (const char *);\n"
1262             "extern const unsigned char lookup_constraint_array[];\n"
1263             "\n"
1264             "/* Return the constraint at the beginning of P, or"
1265             " CONSTRAINT__UNKNOWN if it\n"
1266             "   isn't recognized.  */\n"
1267             "\n"
1268             "static inline enum constraint_num\n"
1269             "lookup_constraint (const char *p)\n"
1270             "{\n"
1271             "  unsigned int index = lookup_constraint_array"
1272             "[(unsigned char) *p];\n"
1273             "  return (index == UCHAR_MAX\n"
1274             "          ? lookup_constraint_1 (p)\n"
1275             "          : (enum constraint_num) index);\n"
1276             "}\n");
1277       if (satisfied_start == num_constraints)
1278         puts ("/* Return true if X satisfies constraint C.  */\n"
1279               "\n"
1280               "static inline bool\n"
1281               "constraint_satisfied_p (rtx, enum constraint_num)\n"
1282               "{\n"
1283               "  return false;\n"
1284               "}\n");
1285       else
1286         printf ("extern bool (*constraint_satisfied_p_array[]) (rtx);\n"
1287                 "\n"
1288                 "/* Return true if X satisfies constraint C.  */\n"
1289                 "\n"
1290                 "static inline bool\n"
1291                 "constraint_satisfied_p (rtx x, enum constraint_num c)\n"
1292                 "{\n"
1293                 "  int i = (int) c - (int) CONSTRAINT_%s;\n"
1294                 "  return i >= 0 && constraint_satisfied_p_array[i] (x);\n"
1295                 "}\n"
1296                 "\n",
1297                 enum_order[satisfied_start]->name);
1298
1299       write_range_function ("insn_extra_register_constraint",
1300                             register_start, register_end);
1301       write_range_function ("insn_extra_memory_constraint",
1302                             memory_start, memory_end);
1303       write_range_function ("insn_extra_address_constraint",
1304                             address_start, address_end);
1305
1306       if (constraint_max_namelen > 1)
1307         {
1308           write_insn_constraint_len ();
1309           puts ("#define CONSTRAINT_LEN(c_,s_) "
1310                 "insn_constraint_len (c_,s_)\n");
1311         }
1312       else
1313         puts ("#define CONSTRAINT_LEN(c_,s_) 1\n");
1314       if (have_register_constraints)
1315         puts ("extern enum reg_class reg_class_for_constraint_1 "
1316               "(enum constraint_num);\n"
1317               "\n"
1318               "static inline enum reg_class\n"
1319               "reg_class_for_constraint (enum constraint_num c)\n"
1320               "{\n"
1321               "  if (insn_extra_register_constraint (c))\n"
1322               "    return reg_class_for_constraint_1 (c);\n"
1323               "  return NO_REGS;\n"
1324               "}\n"
1325               "\n"
1326               "#define REG_CLASS_FROM_CONSTRAINT(c_,s_) \\\n"
1327               "    reg_class_for_constraint (lookup_constraint (s_))\n"
1328               "#define REG_CLASS_FOR_CONSTRAINT(x_) \\\n"
1329               "    reg_class_for_constraint (x_)\n");
1330       else
1331         puts ("static inline enum reg_class\n"
1332               "reg_class_for_constraint (enum constraint_num)\n"
1333               "{\n"
1334               "  return NO_REGS;\n"
1335               "}\n\n"
1336               "#define REG_CLASS_FROM_CONSTRAINT(c_,s_) NO_REGS\n"
1337               "#define REG_CLASS_FOR_CONSTRAINT(x_) \\\n"
1338               "    NO_REGS\n");
1339       if (have_const_int_constraints)
1340         puts ("extern bool insn_const_int_ok_for_constraint "
1341               "(HOST_WIDE_INT, enum constraint_num);\n"
1342               "#define CONST_OK_FOR_CONSTRAINT_P(v_,c_,s_) \\\n"
1343               "    insn_const_int_ok_for_constraint (v_, "
1344               "lookup_constraint (s_))\n");
1345       if (have_const_dbl_constraints)
1346         puts ("#define CONST_DOUBLE_OK_FOR_CONSTRAINT_P(v_,c_,s_) \\\n"
1347               "    constraint_satisfied_p (v_, lookup_constraint (s_))\n");
1348       else
1349         puts ("#define CONST_DOUBLE_OK_FOR_CONSTRAINT_P(v_,c_,s_) 0\n");
1350       if (have_extra_constraints)
1351         puts ("#define EXTRA_CONSTRAINT_STR(v_,c_,s_) \\\n"
1352               "    constraint_satisfied_p (v_, lookup_constraint (s_))\n");
1353       if (have_memory_constraints)
1354         puts ("#define EXTRA_MEMORY_CONSTRAINT(c_,s_) "
1355               "insn_extra_memory_constraint (lookup_constraint (s_))\n");
1356       else
1357         puts ("#define EXTRA_MEMORY_CONSTRAINT(c_,s_) false\n");
1358       if (have_address_constraints)
1359         puts ("#define EXTRA_ADDRESS_CONSTRAINT(c_,s_) "
1360               "insn_extra_address_constraint (lookup_constraint (s_))\n");
1361       else
1362         puts ("#define EXTRA_ADDRESS_CONSTRAINT(c_,s_) false\n");
1363     }
1364
1365   puts ("#endif /* tm-preds.h */");
1366 }
1367
1368 /* Write insn-preds.c.
1369    N.B. the list of headers to include was copied from genrecog; it
1370    may not be ideal.
1371
1372    FUTURE: Write #line markers referring back to the machine
1373    description.  (Can't practically do this now since we don't know
1374    the line number of the C block - just the line number of the enclosing
1375    expression.)  */
1376 static void
1377 write_insn_preds_c (void)
1378 {
1379   struct pred_data *p;
1380
1381   printf ("\
1382 /* Generated automatically by the program '%s'\n\
1383    from the machine description file '%s'.  */\n\n", progname, in_fname);
1384
1385   puts ("\
1386 #include \"config.h\"\n\
1387 #include \"system.h\"\n\
1388 #include \"coretypes.h\"\n\
1389 #include \"tm.h\"\n\
1390 #include \"rtl.h\"\n\
1391 #include \"tree.h\"\n\
1392 #include \"varasm.h\"\n\
1393 #include \"stor-layout.h\"\n\
1394 #include \"calls.h\"\n\
1395 #include \"tm_p.h\"\n\
1396 #include \"function.h\"\n\
1397 #include \"insn-config.h\"\n\
1398 #include \"recog.h\"\n\
1399 #include \"output.h\"\n\
1400 #include \"flags.h\"\n\
1401 #include \"hard-reg-set.h\"\n\
1402 #include \"resource.h\"\n\
1403 #include \"diagnostic-core.h\"\n\
1404 #include \"reload.h\"\n\
1405 #include \"regs.h\"\n\
1406 #include \"tm-constrs.h\"\n");
1407
1408   FOR_ALL_PREDICATES (p)
1409     write_one_predicate_function (p);
1410
1411   if (constraint_max_namelen > 0)
1412     {
1413       write_lookup_constraint_1 ();
1414       write_lookup_constraint_array ();
1415       if (have_register_constraints)
1416         write_reg_class_for_constraint_1 ();
1417       write_constraint_satisfied_p_array ();
1418
1419       if (have_const_int_constraints)
1420         write_insn_const_int_ok_for_constraint ();
1421     }
1422 }
1423
1424 /* Argument parsing.  */
1425 static bool gen_header;
1426 static bool gen_constrs;
1427
1428 static bool
1429 parse_option (const char *opt)
1430 {
1431   if (!strcmp (opt, "-h"))
1432     {
1433       gen_header = true;
1434       return 1;
1435     }
1436   else if (!strcmp (opt, "-c"))
1437     {
1438       gen_constrs = true;
1439       return 1;
1440     }
1441   else
1442     return 0;
1443 }
1444
1445 /* Master control.  */
1446 int
1447 main (int argc, char **argv)
1448 {
1449   rtx defn;
1450   int pattern_lineno, next_insn_code = 0;
1451
1452   progname = argv[0];
1453   if (argc <= 1)
1454     fatal ("no input file name");
1455   if (!init_rtx_reader_args_cb (argc, argv, parse_option))
1456     return FATAL_EXIT_CODE;
1457
1458   while ((defn = read_md_rtx (&pattern_lineno, &next_insn_code)) != 0)
1459     switch (GET_CODE (defn))
1460       {
1461       case DEFINE_PREDICATE:
1462       case DEFINE_SPECIAL_PREDICATE:
1463         process_define_predicate (defn, pattern_lineno);
1464         break;
1465
1466       case DEFINE_CONSTRAINT:
1467       case DEFINE_MEMORY_CONSTRAINT:
1468       case DEFINE_ADDRESS_CONSTRAINT:
1469         process_define_constraint (defn, pattern_lineno);
1470         break;
1471
1472       case DEFINE_REGISTER_CONSTRAINT:
1473         process_define_register_constraint (defn, pattern_lineno);
1474         break;
1475
1476       default:
1477         break;
1478       }
1479
1480   choose_enum_order ();
1481
1482   if (gen_header)
1483     write_tm_preds_h ();
1484   else if (gen_constrs)
1485     write_tm_constrs_h ();
1486   else
1487     write_insn_preds_c ();
1488
1489   if (have_error || ferror (stdout) || fflush (stdout) || fclose (stdout))
1490     return FATAL_EXIT_CODE;
1491
1492   return SUCCESS_EXIT_CODE;
1493 }