* g++.dg/cpp/ucn-1.C: Fix typo.
[official-gcc.git] / gcc / genpreds.c
blobeac2180e246f9b1d6d4544e91786af34d01abbd2
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-2015 Free Software Foundation, Inc.
7 This file is part of GCC.
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.
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.
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/>. */
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"
33 static char general_mem[] = { TARGET_MEM_CONSTRAINT, 0 };
35 /* Given a predicate expression EXP, from form NAME at location LOC,
36 verify that it does not contain any RTL constructs which are not
37 valid in predicate definitions. Returns true if EXP is
38 INvalid; issues error messages, caller need not. */
39 static bool
40 validate_exp (rtx exp, const char *name, file_location loc)
42 if (exp == 0)
44 message_at (loc, "%s: must give a predicate expression", name);
45 return true;
48 switch (GET_CODE (exp))
50 /* Ternary, binary, unary expressions: recurse into subexpressions. */
51 case IF_THEN_ELSE:
52 if (validate_exp (XEXP (exp, 2), name, loc))
53 return true;
54 /* else fall through */
55 case AND:
56 case IOR:
57 if (validate_exp (XEXP (exp, 1), name, loc))
58 return true;
59 /* else fall through */
60 case NOT:
61 return validate_exp (XEXP (exp, 0), name, loc);
63 /* MATCH_CODE might have a syntax error in its path expression. */
64 case MATCH_CODE:
66 const char *p;
67 for (p = XSTR (exp, 1); *p; p++)
69 if (!ISDIGIT (*p) && !ISLOWER (*p))
71 error_at (loc, "%s: invalid character in path "
72 "string '%s'", name, XSTR (exp, 1));
73 return true;
77 /* fall through */
79 /* These need no special checking. */
80 case MATCH_OPERAND:
81 case MATCH_TEST:
82 return false;
84 default:
85 error_at (loc, "%s: cannot use '%s' in a predicate expression",
86 name, GET_RTX_NAME (GET_CODE (exp)));
87 return true;
91 /* Predicates are defined with (define_predicate) or
92 (define_special_predicate) expressions in the machine description. */
93 static void
94 process_define_predicate (md_rtx_info *info)
96 validate_exp (XEXP (info->def, 1), XSTR (info->def, 0), info->loc);
99 /* Given a predicate, if it has an embedded C block, write the block
100 out as a static inline subroutine, and augment the RTL test with a
101 match_test that calls that subroutine. For instance,
103 (define_predicate "basereg_operand"
104 (match_operand 0 "register_operand")
106 if (GET_CODE (op) == SUBREG)
107 op = SUBREG_REG (op);
108 return REG_POINTER (op);
111 becomes
113 static inline int basereg_operand_1(rtx op, machine_mode mode)
115 if (GET_CODE (op) == SUBREG)
116 op = SUBREG_REG (op);
117 return REG_POINTER (op);
120 (define_predicate "basereg_operand"
121 (and (match_operand 0 "register_operand")
122 (match_test "basereg_operand_1 (op, mode)")))
124 The only wart is that there's no way to insist on a { } string in
125 an RTL template, so we have to handle "" strings. */
128 static void
129 write_predicate_subfunction (struct pred_data *p)
131 const char *match_test_str;
132 rtx match_test_exp, and_exp;
134 if (p->c_block[0] == '\0')
135 return;
137 /* Construct the function-call expression. */
138 obstack_grow (rtl_obstack, p->name, strlen (p->name));
139 obstack_grow (rtl_obstack, "_1 (op, mode)",
140 sizeof "_1 (op, mode)");
141 match_test_str = XOBFINISH (rtl_obstack, const char *);
143 /* Add the function-call expression to the complete expression to be
144 evaluated. */
145 match_test_exp = rtx_alloc (MATCH_TEST);
146 XSTR (match_test_exp, 0) = match_test_str;
148 and_exp = rtx_alloc (AND);
149 XEXP (and_exp, 0) = p->exp;
150 XEXP (and_exp, 1) = match_test_exp;
152 p->exp = and_exp;
154 printf ("static inline int\n"
155 "%s_1 (rtx op, machine_mode mode ATTRIBUTE_UNUSED)\n",
156 p->name);
157 print_md_ptr_loc (p->c_block);
158 if (p->c_block[0] == '{')
159 fputs (p->c_block, stdout);
160 else
161 printf ("{\n %s\n}", p->c_block);
162 fputs ("\n\n", stdout);
165 /* Given a predicate expression EXP, from form NAME, determine whether
166 it refers to the variable given as VAR. */
167 static bool
168 needs_variable (rtx exp, const char *var)
170 switch (GET_CODE (exp))
172 /* Ternary, binary, unary expressions need a variable if
173 any of their subexpressions do. */
174 case IF_THEN_ELSE:
175 if (needs_variable (XEXP (exp, 2), var))
176 return true;
177 /* else fall through */
178 case AND:
179 case IOR:
180 if (needs_variable (XEXP (exp, 1), var))
181 return true;
182 /* else fall through */
183 case NOT:
184 return needs_variable (XEXP (exp, 0), var);
186 /* MATCH_CODE uses "op", but nothing else. */
187 case MATCH_CODE:
188 return !strcmp (var, "op");
190 /* MATCH_OPERAND uses "op" and may use "mode". */
191 case MATCH_OPERAND:
192 if (!strcmp (var, "op"))
193 return true;
194 if (!strcmp (var, "mode") && GET_MODE (exp) == VOIDmode)
195 return true;
196 return false;
198 /* MATCH_TEST uses var if XSTR (exp, 0) =~ /\b${var}\b/o; */
199 case MATCH_TEST:
201 const char *p = XSTR (exp, 0);
202 const char *q = strstr (p, var);
203 if (!q)
204 return false;
205 if (q != p && (ISALNUM (q[-1]) || q[-1] == '_'))
206 return false;
207 q += strlen (var);
208 if (ISALNUM (q[0]) || q[0] == '_')
209 return false;
211 return true;
213 default:
214 gcc_unreachable ();
218 /* Given an RTL expression EXP, find all subexpressions which we may
219 assume to perform mode tests. Normal MATCH_OPERAND does;
220 MATCH_CODE doesn't as such (although certain codes always have
221 VOIDmode); and we have to assume that MATCH_TEST does not.
222 These combine in almost-boolean fashion - the only exception is
223 that (not X) must be assumed not to perform a mode test, whether
224 or not X does.
226 The mark is the RTL /v flag, which is true for subexpressions which
227 do *not* perform mode tests.
229 #define NO_MODE_TEST(EXP) RTX_FLAG (EXP, volatil)
230 static void
231 mark_mode_tests (rtx exp)
233 switch (GET_CODE (exp))
235 case MATCH_OPERAND:
237 struct pred_data *p = lookup_predicate (XSTR (exp, 1));
238 if (!p)
239 error ("reference to undefined predicate '%s'", XSTR (exp, 1));
240 else if (p->special || GET_MODE (exp) != VOIDmode)
241 NO_MODE_TEST (exp) = 1;
243 break;
245 case MATCH_CODE:
246 NO_MODE_TEST (exp) = 1;
247 break;
249 case MATCH_TEST:
250 case NOT:
251 NO_MODE_TEST (exp) = 1;
252 break;
254 case AND:
255 mark_mode_tests (XEXP (exp, 0));
256 mark_mode_tests (XEXP (exp, 1));
258 NO_MODE_TEST (exp) = (NO_MODE_TEST (XEXP (exp, 0))
259 && NO_MODE_TEST (XEXP (exp, 1)));
260 break;
262 case IOR:
263 mark_mode_tests (XEXP (exp, 0));
264 mark_mode_tests (XEXP (exp, 1));
266 NO_MODE_TEST (exp) = (NO_MODE_TEST (XEXP (exp, 0))
267 || NO_MODE_TEST (XEXP (exp, 1)));
268 break;
270 case IF_THEN_ELSE:
271 /* A ? B : C does a mode test if (one of A and B) does a mode
272 test, and C does too. */
273 mark_mode_tests (XEXP (exp, 0));
274 mark_mode_tests (XEXP (exp, 1));
275 mark_mode_tests (XEXP (exp, 2));
277 NO_MODE_TEST (exp) = ((NO_MODE_TEST (XEXP (exp, 0))
278 && NO_MODE_TEST (XEXP (exp, 1)))
279 || NO_MODE_TEST (XEXP (exp, 2)));
280 break;
282 default:
283 gcc_unreachable ();
287 /* Determine whether the expression EXP is a MATCH_CODE that should
288 be written as a switch statement. */
289 static bool
290 generate_switch_p (rtx exp)
292 return GET_CODE (exp) == MATCH_CODE
293 && strchr (XSTR (exp, 0), ',');
296 /* Given a predicate, work out where in its RTL expression to add
297 tests for proper modes. Special predicates do not get any such
298 tests. We try to avoid adding tests when we don't have to; in
299 particular, other normal predicates can be counted on to do it for
300 us. */
302 static void
303 add_mode_tests (struct pred_data *p)
305 rtx match_test_exp, and_exp;
306 rtx *pos;
308 /* Don't touch special predicates. */
309 if (p->special)
310 return;
312 /* Check whether the predicate accepts const scalar ints (which always
313 have a stored mode of VOIDmode, but logically have a real mode)
314 and whether it matches anything besides const scalar ints. */
315 bool matches_const_scalar_int_p = false;
316 bool matches_other_p = false;
317 for (int i = 0; i < NUM_RTX_CODE; ++i)
318 if (p->codes[i])
319 switch (i)
321 case CONST_INT:
322 case CONST_WIDE_INT:
323 matches_const_scalar_int_p = true;
324 break;
326 case CONST_DOUBLE:
327 if (!TARGET_SUPPORTS_WIDE_INT)
328 matches_const_scalar_int_p = true;
329 matches_other_p = true;
330 break;
332 default:
333 matches_other_p = true;
334 break;
337 /* There's no need for a mode check if the predicate only accepts
338 constant integers. The code checks in the predicate are enough
339 to establish that the mode is VOIDmode.
341 Note that the predicate itself should check whether a scalar
342 integer is in range of the given mode. */
343 if (!matches_other_p)
344 return;
346 mark_mode_tests (p->exp);
348 /* If the whole expression already tests the mode, we're done. */
349 if (!NO_MODE_TEST (p->exp))
350 return;
352 match_test_exp = rtx_alloc (MATCH_TEST);
353 if (matches_const_scalar_int_p)
354 XSTR (match_test_exp, 0) = ("mode == VOIDmode || GET_MODE (op) == mode"
355 " || GET_MODE (op) == VOIDmode");
356 else
357 XSTR (match_test_exp, 0) = "mode == VOIDmode || GET_MODE (op) == mode";
358 and_exp = rtx_alloc (AND);
359 XEXP (and_exp, 1) = match_test_exp;
361 /* It is always correct to rewrite p->exp as
363 (and (...) (match_test "mode == VOIDmode || GET_MODE (op) == mode"))
365 but there are a couple forms where we can do better. If the
366 top-level pattern is an IOR, and one of the two branches does test
367 the mode, we can wrap just the branch that doesn't. Likewise, if
368 we have an IF_THEN_ELSE, and one side of it tests the mode, we can
369 wrap just the side that doesn't. And, of course, we can repeat this
370 descent as many times as it works. */
372 pos = &p->exp;
373 for (;;)
375 rtx subexp = *pos;
377 switch (GET_CODE (subexp))
379 case AND:
380 /* The switch code generation in write_predicate_stmts prefers
381 rtx code tests to be at the top of the expression tree. So
382 push this AND down into the second operand of an existing
383 AND expression. */
384 if (generate_switch_p (XEXP (subexp, 0)))
385 pos = &XEXP (subexp, 1);
386 goto break_loop;
388 case IOR:
390 int test0 = NO_MODE_TEST (XEXP (subexp, 0));
391 int test1 = NO_MODE_TEST (XEXP (subexp, 1));
393 gcc_assert (test0 || test1);
395 if (test0 && test1)
396 goto break_loop;
397 pos = test0 ? &XEXP (subexp, 0) : &XEXP (subexp, 1);
399 break;
401 case IF_THEN_ELSE:
403 int test0 = NO_MODE_TEST (XEXP (subexp, 0));
404 int test1 = NO_MODE_TEST (XEXP (subexp, 1));
405 int test2 = NO_MODE_TEST (XEXP (subexp, 2));
407 gcc_assert ((test0 && test1) || test2);
409 if (test0 && test1 && test2)
410 goto break_loop;
411 if (test0 && test1)
412 /* Must put it on the dependent clause, not the
413 controlling expression, or we change the meaning of
414 the test. */
415 pos = &XEXP (subexp, 1);
416 else
417 pos = &XEXP (subexp, 2);
419 break;
421 default:
422 goto break_loop;
425 break_loop:
426 XEXP (and_exp, 0) = *pos;
427 *pos = and_exp;
430 /* PATH is a string describing a path from the root of an RTL
431 expression to an inner subexpression to be tested. Output
432 code which computes the subexpression from the variable
433 holding the root of the expression. */
434 static void
435 write_extract_subexp (const char *path)
437 int len = strlen (path);
438 int i;
440 /* We first write out the operations (XEXP or XVECEXP) in reverse
441 order, then write "op", then the indices in forward order. */
442 for (i = len - 1; i >= 0; i--)
444 if (ISLOWER (path[i]))
445 fputs ("XVECEXP (", stdout);
446 else if (ISDIGIT (path[i]))
447 fputs ("XEXP (", stdout);
448 else
449 gcc_unreachable ();
452 fputs ("op", stdout);
454 for (i = 0; i < len; i++)
456 if (ISLOWER (path[i]))
457 printf (", 0, %d)", path[i] - 'a');
458 else if (ISDIGIT (path[i]))
459 printf (", %d)", path[i] - '0');
460 else
461 gcc_unreachable ();
465 /* CODES is a list of RTX codes. Write out an expression which
466 determines whether the operand has one of those codes. */
467 static void
468 write_match_code (const char *path, const char *codes)
470 const char *code;
472 while ((code = scan_comma_elt (&codes)) != 0)
474 fputs ("GET_CODE (", stdout);
475 write_extract_subexp (path);
476 fputs (") == ", stdout);
477 while (code < codes)
479 putchar (TOUPPER (*code));
480 code++;
483 if (*codes == ',')
484 fputs (" || ", stdout);
488 /* EXP is an RTL (sub)expression for a predicate. Recursively
489 descend the expression and write out an equivalent C expression. */
490 static void
491 write_predicate_expr (rtx exp)
493 switch (GET_CODE (exp))
495 case AND:
496 putchar ('(');
497 write_predicate_expr (XEXP (exp, 0));
498 fputs (") && (", stdout);
499 write_predicate_expr (XEXP (exp, 1));
500 putchar (')');
501 break;
503 case IOR:
504 putchar ('(');
505 write_predicate_expr (XEXP (exp, 0));
506 fputs (") || (", stdout);
507 write_predicate_expr (XEXP (exp, 1));
508 putchar (')');
509 break;
511 case NOT:
512 fputs ("!(", stdout);
513 write_predicate_expr (XEXP (exp, 0));
514 putchar (')');
515 break;
517 case IF_THEN_ELSE:
518 putchar ('(');
519 write_predicate_expr (XEXP (exp, 0));
520 fputs (") ? (", stdout);
521 write_predicate_expr (XEXP (exp, 1));
522 fputs (") : (", stdout);
523 write_predicate_expr (XEXP (exp, 2));
524 putchar (')');
525 break;
527 case MATCH_OPERAND:
528 if (GET_MODE (exp) == VOIDmode)
529 printf ("%s (op, mode)", XSTR (exp, 1));
530 else
531 printf ("%s (op, %smode)", XSTR (exp, 1), mode_name[GET_MODE (exp)]);
532 break;
534 case MATCH_CODE:
535 write_match_code (XSTR (exp, 1), XSTR (exp, 0));
536 break;
538 case MATCH_TEST:
539 print_c_condition (XSTR (exp, 0));
540 break;
542 default:
543 gcc_unreachable ();
547 /* Write the MATCH_CODE expression EXP as a switch statement. */
549 static void
550 write_match_code_switch (rtx exp)
552 const char *codes = XSTR (exp, 0);
553 const char *path = XSTR (exp, 1);
554 const char *code;
556 fputs (" switch (GET_CODE (", stdout);
557 write_extract_subexp (path);
558 fputs ("))\n {\n", stdout);
560 while ((code = scan_comma_elt (&codes)) != 0)
562 fputs (" case ", stdout);
563 while (code < codes)
565 putchar (TOUPPER (*code));
566 code++;
568 fputs (":\n", stdout);
572 /* Given a predicate expression EXP, write out a sequence of stmts
573 to evaluate it. This is similar to write_predicate_expr but can
574 generate efficient switch statements. */
576 static void
577 write_predicate_stmts (rtx exp)
579 switch (GET_CODE (exp))
581 case MATCH_CODE:
582 if (generate_switch_p (exp))
584 write_match_code_switch (exp);
585 puts (" return true;\n"
586 " default:\n"
587 " break;\n"
588 " }\n"
589 " return false;");
590 return;
592 break;
594 case AND:
595 if (generate_switch_p (XEXP (exp, 0)))
597 write_match_code_switch (XEXP (exp, 0));
598 puts (" break;\n"
599 " default:\n"
600 " return false;\n"
601 " }");
602 exp = XEXP (exp, 1);
604 break;
606 case IOR:
607 if (generate_switch_p (XEXP (exp, 0)))
609 write_match_code_switch (XEXP (exp, 0));
610 puts (" return true;\n"
611 " default:\n"
612 " break;\n"
613 " }");
614 exp = XEXP (exp, 1);
616 break;
618 case NOT:
619 if (generate_switch_p (XEXP (exp, 0)))
621 write_match_code_switch (XEXP (exp, 0));
622 puts (" return false;\n"
623 " default:\n"
624 " break;\n"
625 " }\n"
626 " return true;");
627 return;
629 break;
631 default:
632 break;
635 fputs (" return ",stdout);
636 write_predicate_expr (exp);
637 fputs (";\n", stdout);
640 /* Given a predicate, write out a complete C function to compute it. */
641 static void
642 write_one_predicate_function (struct pred_data *p)
644 if (!p->exp)
645 return;
647 write_predicate_subfunction (p);
648 add_mode_tests (p);
650 /* A normal predicate can legitimately not look at machine_mode
651 if it accepts only CONST_INTs and/or CONST_WIDE_INT and/or CONST_DOUBLEs. */
652 printf ("int\n%s (rtx op, machine_mode mode ATTRIBUTE_UNUSED)\n{\n",
653 p->name);
654 write_predicate_stmts (p->exp);
655 fputs ("}\n\n", stdout);
658 /* Constraints fall into two categories: register constraints
659 (define_register_constraint), and others (define_constraint,
660 define_memory_constraint, define_address_constraint). We
661 work out automatically which of the various old-style macros
662 they correspond to, and produce appropriate code. They all
663 go in the same hash table so we can verify that there are no
664 duplicate names. */
666 /* All data from one constraint definition. */
667 struct constraint_data
669 struct constraint_data *next_this_letter;
670 struct constraint_data *next_textual;
671 const char *name;
672 const char *c_name; /* same as .name unless mangling is necessary */
673 file_location loc; /* location of definition */
674 size_t namelen;
675 const char *regclass; /* for register constraints */
676 rtx exp; /* for other constraints */
677 unsigned int is_register : 1;
678 unsigned int is_const_int : 1;
679 unsigned int is_const_dbl : 1;
680 unsigned int is_extra : 1;
681 unsigned int is_memory : 1;
682 unsigned int is_address : 1;
683 unsigned int maybe_allows_reg : 1;
684 unsigned int maybe_allows_mem : 1;
687 /* Overview of all constraints beginning with a given letter. */
689 static struct constraint_data *
690 constraints_by_letter_table[1<<CHAR_BIT];
692 /* For looking up all the constraints in the order that they appeared
693 in the machine description. */
694 static struct constraint_data *first_constraint;
695 static struct constraint_data **last_constraint_ptr = &first_constraint;
697 #define FOR_ALL_CONSTRAINTS(iter_) \
698 for (iter_ = first_constraint; iter_; iter_ = iter_->next_textual)
700 /* Contraint letters that have a special meaning and that cannot be used
701 in define*_constraints. */
702 static const char generic_constraint_letters[] = "g";
704 /* Machine-independent code expects that constraints with these
705 (initial) letters will allow only (a subset of all) CONST_INTs. */
707 static const char const_int_constraints[] = "IJKLMNOP";
709 /* Machine-independent code expects that constraints with these
710 (initial) letters will allow only (a subset of all) CONST_DOUBLEs. */
712 static const char const_dbl_constraints[] = "GH";
714 /* Summary data used to decide whether to output various functions and
715 macro definitions. */
716 static unsigned int constraint_max_namelen;
717 static bool have_register_constraints;
718 static bool have_memory_constraints;
719 static bool have_address_constraints;
720 static bool have_extra_constraints;
721 static bool have_const_int_constraints;
722 static unsigned int num_constraints;
724 static const constraint_data **enum_order;
725 static unsigned int register_start, register_end;
726 static unsigned int satisfied_start;
727 static unsigned int const_int_start, const_int_end;
728 static unsigned int memory_start, memory_end;
729 static unsigned int address_start, address_end;
730 static unsigned int maybe_allows_none_start, maybe_allows_none_end;
731 static unsigned int maybe_allows_reg_start, maybe_allows_reg_end;
732 static unsigned int maybe_allows_mem_start, maybe_allows_mem_end;
734 /* Convert NAME, which contains angle brackets and/or underscores, to
735 a string that can be used as part of a C identifier. The string
736 comes from the rtl_obstack. */
737 static const char *
738 mangle (const char *name)
740 for (; *name; name++)
741 switch (*name)
743 case '_': obstack_grow (rtl_obstack, "__", 2); break;
744 case '<': obstack_grow (rtl_obstack, "_l", 2); break;
745 case '>': obstack_grow (rtl_obstack, "_g", 2); break;
746 default: obstack_1grow (rtl_obstack, *name); break;
749 obstack_1grow (rtl_obstack, '\0');
750 return XOBFINISH (rtl_obstack, const char *);
753 /* Add one constraint, of any sort, to the tables. NAME is its name;
754 REGCLASS is the register class, if any; EXP is the expression to
755 test, if any; IS_MEMORY and IS_ADDRESS indicate memory and address
756 constraints, respectively; LOC is the .md file location.
758 Not all combinations of arguments are valid; most importantly, REGCLASS
759 is mutually exclusive with EXP, and IS_MEMORY/IS_ADDRESS are only
760 meaningful for constraints with EXP.
762 This function enforces all syntactic and semantic rules about what
763 constraints can be defined. */
765 static void
766 add_constraint (const char *name, const char *regclass,
767 rtx exp, bool is_memory, bool is_address,
768 file_location loc)
770 struct constraint_data *c, **iter, **slot;
771 const char *p;
772 bool need_mangled_name = false;
773 bool is_const_int;
774 bool is_const_dbl;
775 size_t namelen;
777 if (strcmp (name, "TARGET_MEM_CONSTRAINT") == 0)
778 name = general_mem;
780 if (exp && validate_exp (exp, name, loc))
781 return;
783 for (p = name; *p; p++)
784 if (!ISALNUM (*p))
786 if (*p == '<' || *p == '>' || *p == '_')
787 need_mangled_name = true;
788 else
790 error_at (loc, "constraint name '%s' must be composed of letters,"
791 " digits, underscores, and angle brackets", name);
792 return;
796 if (strchr (generic_constraint_letters, name[0]))
798 if (name[1] == '\0')
799 error_at (loc, "constraint letter '%s' cannot be "
800 "redefined by the machine description", name);
801 else
802 error_at (loc, "constraint name '%s' cannot be defined by the machine"
803 " description, as it begins with '%c'", name, name[0]);
804 return;
808 namelen = strlen (name);
809 slot = &constraints_by_letter_table[(unsigned int)name[0]];
810 for (iter = slot; *iter; iter = &(*iter)->next_this_letter)
812 /* This causes slot to end up pointing to the
813 next_this_letter field of the last constraint with a name
814 of equal or greater length than the new constraint; hence
815 the new constraint will be inserted after all previous
816 constraints with names of the same length. */
817 if ((*iter)->namelen >= namelen)
818 slot = iter;
820 if (!strcmp ((*iter)->name, name))
822 error_at (loc, "redefinition of constraint '%s'", name);
823 message_at ((*iter)->loc, "previous definition is here");
824 return;
826 else if (!strncmp ((*iter)->name, name, (*iter)->namelen))
828 error_at (loc, "defining constraint '%s' here", name);
829 message_at ((*iter)->loc, "renders constraint '%s' "
830 "(defined here) a prefix", (*iter)->name);
831 return;
833 else if (!strncmp ((*iter)->name, name, namelen))
835 error_at (loc, "constraint '%s' is a prefix", name);
836 message_at ((*iter)->loc, "of constraint '%s' (defined here)",
837 (*iter)->name);
838 return;
842 is_const_int = strchr (const_int_constraints, name[0]) != 0;
843 is_const_dbl = strchr (const_dbl_constraints, name[0]) != 0;
845 if (is_const_int || is_const_dbl)
847 enum rtx_code appropriate_code
848 = is_const_int ? CONST_INT : CONST_DOUBLE;
850 /* Consider relaxing this requirement in the future. */
851 if (regclass
852 || GET_CODE (exp) != AND
853 || GET_CODE (XEXP (exp, 0)) != MATCH_CODE
854 || strcmp (XSTR (XEXP (exp, 0), 0),
855 GET_RTX_NAME (appropriate_code)))
857 if (name[1] == '\0')
858 error_at (loc, "constraint letter '%c' is reserved "
859 "for %s constraints", name[0],
860 GET_RTX_NAME (appropriate_code));
861 else
862 error_at (loc, "constraint names beginning with '%c' "
863 "(%s) are reserved for %s constraints",
864 name[0], name, GET_RTX_NAME (appropriate_code));
865 return;
868 if (is_memory)
870 if (name[1] == '\0')
871 error_at (loc, "constraint letter '%c' cannot be a "
872 "memory constraint", name[0]);
873 else
874 error_at (loc, "constraint name '%s' begins with '%c', "
875 "and therefore cannot be a memory constraint",
876 name, name[0]);
877 return;
879 else if (is_address)
881 if (name[1] == '\0')
882 error_at (loc, "constraint letter '%c' cannot be an "
883 "address constraint", name[0]);
884 else
885 error_at (loc, "constraint name '%s' begins with '%c', "
886 "and therefore cannot be an address constraint",
887 name, name[0]);
888 return;
893 c = XOBNEW (rtl_obstack, struct constraint_data);
894 c->name = name;
895 c->c_name = need_mangled_name ? mangle (name) : name;
896 c->loc = loc;
897 c->namelen = namelen;
898 c->regclass = regclass;
899 c->exp = exp;
900 c->is_register = regclass != 0;
901 c->is_const_int = is_const_int;
902 c->is_const_dbl = is_const_dbl;
903 c->is_extra = !(regclass || is_const_int || is_const_dbl);
904 c->is_memory = is_memory;
905 c->is_address = is_address;
906 c->maybe_allows_reg = true;
907 c->maybe_allows_mem = true;
908 if (exp)
910 char codes[NUM_RTX_CODE];
911 compute_test_codes (exp, loc, codes);
912 if (!codes[REG] && !codes[SUBREG])
913 c->maybe_allows_reg = false;
914 if (!codes[MEM])
915 c->maybe_allows_mem = false;
917 c->next_this_letter = *slot;
918 *slot = c;
920 /* Insert this constraint in the list of all constraints in textual
921 order. */
922 c->next_textual = 0;
923 *last_constraint_ptr = c;
924 last_constraint_ptr = &c->next_textual;
926 constraint_max_namelen = MAX (constraint_max_namelen, strlen (name));
927 have_register_constraints |= c->is_register;
928 have_const_int_constraints |= c->is_const_int;
929 have_extra_constraints |= c->is_extra;
930 have_memory_constraints |= c->is_memory;
931 have_address_constraints |= c->is_address;
932 num_constraints += 1;
935 /* Process a DEFINE_CONSTRAINT, DEFINE_MEMORY_CONSTRAINT, or
936 DEFINE_ADDRESS_CONSTRAINT expression, C. */
937 static void
938 process_define_constraint (md_rtx_info *info)
940 add_constraint (XSTR (info->def, 0), 0, XEXP (info->def, 2),
941 GET_CODE (info->def) == DEFINE_MEMORY_CONSTRAINT,
942 GET_CODE (info->def) == DEFINE_ADDRESS_CONSTRAINT,
943 info->loc);
946 /* Process a DEFINE_REGISTER_CONSTRAINT expression, C. */
947 static void
948 process_define_register_constraint (md_rtx_info *info)
950 add_constraint (XSTR (info->def, 0), XSTR (info->def, 1),
951 0, false, false, info->loc);
954 /* Put the constraints into enum order. We want to keep constraints
955 of the same type together so that query functions can be simple
956 range checks. */
957 static void
958 choose_enum_order (void)
960 struct constraint_data *c;
962 enum_order = XNEWVEC (const constraint_data *, num_constraints);
963 unsigned int next = 0;
965 register_start = next;
966 FOR_ALL_CONSTRAINTS (c)
967 if (c->is_register)
968 enum_order[next++] = c;
969 register_end = next;
971 satisfied_start = next;
973 const_int_start = next;
974 FOR_ALL_CONSTRAINTS (c)
975 if (c->is_const_int)
976 enum_order[next++] = c;
977 const_int_end = next;
979 memory_start = next;
980 FOR_ALL_CONSTRAINTS (c)
981 if (c->is_memory)
982 enum_order[next++] = c;
983 memory_end = next;
985 address_start = next;
986 FOR_ALL_CONSTRAINTS (c)
987 if (c->is_address)
988 enum_order[next++] = c;
989 address_end = next;
991 maybe_allows_none_start = next;
992 FOR_ALL_CONSTRAINTS (c)
993 if (!c->is_register && !c->is_const_int && !c->is_memory && !c->is_address
994 && !c->maybe_allows_reg && !c->maybe_allows_mem)
995 enum_order[next++] = c;
996 maybe_allows_none_end = next;
998 maybe_allows_reg_start = next;
999 FOR_ALL_CONSTRAINTS (c)
1000 if (!c->is_register && !c->is_const_int && !c->is_memory && !c->is_address
1001 && c->maybe_allows_reg && !c->maybe_allows_mem)
1002 enum_order[next++] = c;
1003 maybe_allows_reg_end = next;
1005 maybe_allows_mem_start = next;
1006 FOR_ALL_CONSTRAINTS (c)
1007 if (!c->is_register && !c->is_const_int && !c->is_memory && !c->is_address
1008 && !c->maybe_allows_reg && c->maybe_allows_mem)
1009 enum_order[next++] = c;
1010 maybe_allows_mem_end = next;
1012 FOR_ALL_CONSTRAINTS (c)
1013 if (!c->is_register && !c->is_const_int && !c->is_memory && !c->is_address
1014 && c->maybe_allows_reg && c->maybe_allows_mem)
1015 enum_order[next++] = c;
1016 gcc_assert (next == num_constraints);
1019 /* Write out an enumeration with one entry per machine-specific
1020 constraint. */
1021 static void
1022 write_enum_constraint_num (void)
1024 fputs ("#define CONSTRAINT_NUM_DEFINED_P 1\n", stdout);
1025 fputs ("enum constraint_num\n"
1026 "{\n"
1027 " CONSTRAINT__UNKNOWN = 0", stdout);
1028 for (unsigned int i = 0; i < num_constraints; ++i)
1029 printf (",\n CONSTRAINT_%s", enum_order[i]->c_name);
1030 puts (",\n CONSTRAINT__LIMIT\n};\n");
1033 /* Write out a function which looks at a string and determines what
1034 constraint name, if any, it begins with. */
1035 static void
1036 write_lookup_constraint_1 (void)
1038 unsigned int i;
1039 puts ("enum constraint_num\n"
1040 "lookup_constraint_1 (const char *str)\n"
1041 "{\n"
1042 " switch (str[0])\n"
1043 " {");
1045 for (i = 0; i < ARRAY_SIZE (constraints_by_letter_table); i++)
1047 struct constraint_data *c = constraints_by_letter_table[i];
1048 if (!c)
1049 continue;
1051 printf (" case '%c':\n", i);
1052 if (c->namelen == 1)
1053 printf (" return CONSTRAINT_%s;\n", c->c_name);
1054 else
1058 printf (" if (!strncmp (str + 1, \"%s\", %lu))\n"
1059 " return CONSTRAINT_%s;\n",
1060 c->name + 1, (unsigned long int) c->namelen - 1,
1061 c->c_name);
1062 c = c->next_this_letter;
1064 while (c);
1065 puts (" break;");
1069 puts (" default: break;\n"
1070 " }\n"
1071 " return CONSTRAINT__UNKNOWN;\n"
1072 "}\n");
1075 /* Write out an array that maps single-letter characters to their
1076 constraints (if that fits in a character) or 255 if lookup_constraint_1
1077 must be called. */
1078 static void
1079 write_lookup_constraint_array (void)
1081 unsigned int i;
1082 printf ("const unsigned char lookup_constraint_array[] = {\n ");
1083 for (i = 0; i < ARRAY_SIZE (constraints_by_letter_table); i++)
1085 if (i != 0)
1086 printf (",\n ");
1087 struct constraint_data *c = constraints_by_letter_table[i];
1088 if (!c)
1089 printf ("CONSTRAINT__UNKNOWN");
1090 else if (c->namelen == 1)
1091 printf ("MIN ((int) CONSTRAINT_%s, (int) UCHAR_MAX)", c->c_name);
1092 else
1093 printf ("UCHAR_MAX");
1095 printf ("\n};\n\n");
1098 /* Write out a function which looks at a string and determines what
1099 the constraint name length is. */
1100 static void
1101 write_insn_constraint_len (void)
1103 unsigned int i;
1105 puts ("static inline size_t\n"
1106 "insn_constraint_len (char fc, const char *str ATTRIBUTE_UNUSED)\n"
1107 "{\n"
1108 " switch (fc)\n"
1109 " {");
1111 for (i = 0; i < ARRAY_SIZE (constraints_by_letter_table); i++)
1113 struct constraint_data *c = constraints_by_letter_table[i];
1115 if (!c
1116 || c->namelen == 1)
1117 continue;
1119 /* Constraints with multiple characters should have the same
1120 length. */
1122 struct constraint_data *c2 = c->next_this_letter;
1123 size_t len = c->namelen;
1124 while (c2)
1126 if (c2->namelen != len)
1127 error ("Multi-letter constraints with first letter '%c' "
1128 "should have same length", i);
1129 c2 = c2->next_this_letter;
1133 printf (" case '%c': return %lu;\n",
1134 i, (unsigned long int) c->namelen);
1137 puts (" default: break;\n"
1138 " }\n"
1139 " return 1;\n"
1140 "}\n");
1143 /* Write out the function which computes the register class corresponding
1144 to a register constraint. */
1145 static void
1146 write_reg_class_for_constraint_1 (void)
1148 struct constraint_data *c;
1150 puts ("enum reg_class\n"
1151 "reg_class_for_constraint_1 (enum constraint_num c)\n"
1152 "{\n"
1153 " switch (c)\n"
1154 " {");
1156 FOR_ALL_CONSTRAINTS (c)
1157 if (c->is_register)
1158 printf (" case CONSTRAINT_%s: return %s;\n", c->c_name, c->regclass);
1160 puts (" default: break;\n"
1161 " }\n"
1162 " return NO_REGS;\n"
1163 "}\n");
1166 /* Write out the functions which compute whether a given value matches
1167 a given non-register constraint. */
1168 static void
1169 write_tm_constrs_h (void)
1171 struct constraint_data *c;
1173 printf ("\
1174 /* Generated automatically by the program '%s'\n\
1175 from the machine description file '%s'. */\n\n", progname, in_fname);
1177 puts ("\
1178 #ifndef GCC_TM_CONSTRS_H\n\
1179 #define GCC_TM_CONSTRS_H\n");
1181 FOR_ALL_CONSTRAINTS (c)
1182 if (!c->is_register)
1184 bool needs_ival = needs_variable (c->exp, "ival");
1185 bool needs_hval = needs_variable (c->exp, "hval");
1186 bool needs_lval = needs_variable (c->exp, "lval");
1187 bool needs_rval = needs_variable (c->exp, "rval");
1188 bool needs_mode = (needs_variable (c->exp, "mode")
1189 || needs_hval || needs_lval || needs_rval);
1190 bool needs_op = (needs_variable (c->exp, "op")
1191 || needs_ival || needs_mode);
1193 printf ("static inline bool\n"
1194 "satisfies_constraint_%s (rtx %s)\n"
1195 "{\n", c->c_name,
1196 needs_op ? "op" : "ARG_UNUSED (op)");
1197 if (needs_mode)
1198 puts (" machine_mode mode = GET_MODE (op);");
1199 if (needs_ival)
1200 puts (" HOST_WIDE_INT ival = 0;");
1201 if (needs_hval)
1202 puts (" HOST_WIDE_INT hval = 0;");
1203 if (needs_lval)
1204 puts (" unsigned HOST_WIDE_INT lval = 0;");
1205 if (needs_rval)
1206 puts (" const REAL_VALUE_TYPE *rval = 0;");
1208 if (needs_ival)
1209 puts (" if (CONST_INT_P (op))\n"
1210 " ival = INTVAL (op);");
1211 #if TARGET_SUPPORTS_WIDE_INT
1212 if (needs_lval || needs_hval)
1213 error ("you can't use lval or hval");
1214 #else
1215 if (needs_hval)
1216 puts (" if (GET_CODE (op) == CONST_DOUBLE && mode == VOIDmode)"
1217 " hval = CONST_DOUBLE_HIGH (op);");
1218 if (needs_lval)
1219 puts (" if (GET_CODE (op) == CONST_DOUBLE && mode == VOIDmode)"
1220 " lval = CONST_DOUBLE_LOW (op);");
1221 #endif
1222 if (needs_rval)
1223 puts (" if (GET_CODE (op) == CONST_DOUBLE && mode != VOIDmode)"
1224 " rval = CONST_DOUBLE_REAL_VALUE (op);");
1226 write_predicate_stmts (c->exp);
1227 fputs ("}\n", stdout);
1229 puts ("#endif /* tm-constrs.h */");
1232 /* Write out the wrapper function, constraint_satisfied_p, that maps
1233 a CONSTRAINT_xxx constant to one of the predicate functions generated
1234 above. */
1235 static void
1236 write_constraint_satisfied_p_array (void)
1238 if (satisfied_start == num_constraints)
1239 return;
1241 printf ("bool (*constraint_satisfied_p_array[]) (rtx) = {\n ");
1242 for (unsigned int i = satisfied_start; i < num_constraints; ++i)
1244 if (i != satisfied_start)
1245 printf (",\n ");
1246 printf ("satisfies_constraint_%s", enum_order[i]->c_name);
1248 printf ("\n};\n\n");
1251 /* Write out the function which computes whether a given value matches
1252 a given CONST_INT constraint. This doesn't just forward to
1253 constraint_satisfied_p because caller passes the INTVAL, not the RTX. */
1254 static void
1255 write_insn_const_int_ok_for_constraint (void)
1257 struct constraint_data *c;
1259 puts ("bool\n"
1260 "insn_const_int_ok_for_constraint (HOST_WIDE_INT ival, "
1261 "enum constraint_num c)\n"
1262 "{\n"
1263 " switch (c)\n"
1264 " {");
1266 FOR_ALL_CONSTRAINTS (c)
1267 if (c->is_const_int)
1269 printf (" case CONSTRAINT_%s:\n return ", c->c_name);
1270 /* c->exp is guaranteed to be (and (match_code "const_int") (...));
1271 we know at this point that we have a const_int, so we need not
1272 bother with that part of the test. */
1273 write_predicate_expr (XEXP (c->exp, 1));
1274 fputs (";\n\n", stdout);
1277 puts (" default: break;\n"
1278 " }\n"
1279 " return false;\n"
1280 "}\n");
1283 /* Write a definition for a function NAME that returns true if a given
1284 constraint_num is in the range [START, END). */
1285 static void
1286 write_range_function (const char *name, unsigned int start, unsigned int end)
1288 printf ("static inline bool\n");
1289 if (start != end)
1290 printf ("%s (enum constraint_num c)\n"
1291 "{\n"
1292 " return c >= CONSTRAINT_%s && c <= CONSTRAINT_%s;\n"
1293 "}\n\n",
1294 name, enum_order[start]->c_name, enum_order[end - 1]->c_name);
1295 else
1296 printf ("%s (enum constraint_num)\n"
1297 "{\n"
1298 " return false;\n"
1299 "}\n\n", name);
1302 /* Write a definition for insn_extra_constraint_allows_reg_mem function. */
1303 static void
1304 write_allows_reg_mem_function (void)
1306 printf ("static inline void\n"
1307 "insn_extra_constraint_allows_reg_mem (enum constraint_num c,\n"
1308 "\t\t\t\t bool *allows_reg, bool *allows_mem)\n"
1309 "{\n");
1310 if (maybe_allows_none_start != maybe_allows_none_end)
1311 printf (" if (c >= CONSTRAINT_%s && c <= CONSTRAINT_%s)\n"
1312 " return;\n",
1313 enum_order[maybe_allows_none_start]->c_name,
1314 enum_order[maybe_allows_none_end - 1]->c_name);
1315 if (maybe_allows_reg_start != maybe_allows_reg_end)
1316 printf (" if (c >= CONSTRAINT_%s && c <= CONSTRAINT_%s)\n"
1317 " {\n"
1318 " *allows_reg = true;\n"
1319 " return;\n"
1320 " }\n",
1321 enum_order[maybe_allows_reg_start]->c_name,
1322 enum_order[maybe_allows_reg_end - 1]->c_name);
1323 if (maybe_allows_mem_start != maybe_allows_mem_end)
1324 printf (" if (c >= CONSTRAINT_%s && c <= CONSTRAINT_%s)\n"
1325 " {\n"
1326 " *allows_mem = true;\n"
1327 " return;\n"
1328 " }\n",
1329 enum_order[maybe_allows_mem_start]->c_name,
1330 enum_order[maybe_allows_mem_end - 1]->c_name);
1331 printf (" (void) c;\n"
1332 " *allows_reg = true;\n"
1333 " *allows_mem = true;\n"
1334 "}\n\n");
1337 /* VEC is a list of key/value pairs, with the keys being lower bounds
1338 of a range. Output a decision tree that handles the keys covered by
1339 [VEC[START], VEC[END]), returning FALLBACK for keys lower then VEC[START]'s.
1340 INDENT is the number of spaces to indent the code. */
1341 static void
1342 print_type_tree (const vec <std::pair <unsigned int, const char *> > &vec,
1343 unsigned int start, unsigned int end, const char *fallback,
1344 unsigned int indent)
1346 while (start < end)
1348 unsigned int mid = (start + end) / 2;
1349 printf ("%*sif (c >= CONSTRAINT_%s)\n",
1350 indent, "", enum_order[vec[mid].first]->c_name);
1351 if (mid + 1 == end)
1352 print_type_tree (vec, mid + 1, end, vec[mid].second, indent + 2);
1353 else
1355 printf ("%*s{\n", indent + 2, "");
1356 print_type_tree (vec, mid + 1, end, vec[mid].second, indent + 4);
1357 printf ("%*s}\n", indent + 2, "");
1359 end = mid;
1361 printf ("%*sreturn %s;\n", indent, "", fallback);
1364 /* Write tm-preds.h. Unfortunately, it is impossible to forward-declare
1365 an enumeration in portable C, so we have to condition all these
1366 prototypes on HAVE_MACHINE_MODES. */
1367 static void
1368 write_tm_preds_h (void)
1370 struct pred_data *p;
1372 printf ("\
1373 /* Generated automatically by the program '%s'\n\
1374 from the machine description file '%s'. */\n\n", progname, in_fname);
1376 puts ("\
1377 #ifndef GCC_TM_PREDS_H\n\
1378 #define GCC_TM_PREDS_H\n\
1380 #ifdef HAVE_MACHINE_MODES");
1382 FOR_ALL_PREDICATES (p)
1383 printf ("extern int %s (rtx, machine_mode);\n", p->name);
1385 puts ("#endif /* HAVE_MACHINE_MODES */\n");
1387 if (constraint_max_namelen > 0)
1389 write_enum_constraint_num ();
1390 puts ("extern enum constraint_num lookup_constraint_1 (const char *);\n"
1391 "extern const unsigned char lookup_constraint_array[];\n"
1392 "\n"
1393 "/* Return the constraint at the beginning of P, or"
1394 " CONSTRAINT__UNKNOWN if it\n"
1395 " isn't recognized. */\n"
1396 "\n"
1397 "static inline enum constraint_num\n"
1398 "lookup_constraint (const char *p)\n"
1399 "{\n"
1400 " unsigned int index = lookup_constraint_array"
1401 "[(unsigned char) *p];\n"
1402 " return (index == UCHAR_MAX\n"
1403 " ? lookup_constraint_1 (p)\n"
1404 " : (enum constraint_num) index);\n"
1405 "}\n");
1406 if (satisfied_start == num_constraints)
1407 puts ("/* Return true if X satisfies constraint C. */\n"
1408 "\n"
1409 "static inline bool\n"
1410 "constraint_satisfied_p (rtx, enum constraint_num)\n"
1411 "{\n"
1412 " return false;\n"
1413 "}\n");
1414 else
1415 printf ("extern bool (*constraint_satisfied_p_array[]) (rtx);\n"
1416 "\n"
1417 "/* Return true if X satisfies constraint C. */\n"
1418 "\n"
1419 "static inline bool\n"
1420 "constraint_satisfied_p (rtx x, enum constraint_num c)\n"
1421 "{\n"
1422 " int i = (int) c - (int) CONSTRAINT_%s;\n"
1423 " return i >= 0 && constraint_satisfied_p_array[i] (x);\n"
1424 "}\n"
1425 "\n",
1426 enum_order[satisfied_start]->name);
1428 write_range_function ("insn_extra_register_constraint",
1429 register_start, register_end);
1430 write_range_function ("insn_extra_memory_constraint",
1431 memory_start, memory_end);
1432 write_range_function ("insn_extra_address_constraint",
1433 address_start, address_end);
1434 write_allows_reg_mem_function ();
1436 if (constraint_max_namelen > 1)
1438 write_insn_constraint_len ();
1439 puts ("#define CONSTRAINT_LEN(c_,s_) "
1440 "insn_constraint_len (c_,s_)\n");
1442 else
1443 puts ("#define CONSTRAINT_LEN(c_,s_) 1\n");
1444 if (have_register_constraints)
1445 puts ("extern enum reg_class reg_class_for_constraint_1 "
1446 "(enum constraint_num);\n"
1447 "\n"
1448 "static inline enum reg_class\n"
1449 "reg_class_for_constraint (enum constraint_num c)\n"
1450 "{\n"
1451 " if (insn_extra_register_constraint (c))\n"
1452 " return reg_class_for_constraint_1 (c);\n"
1453 " return NO_REGS;\n"
1454 "}\n");
1455 else
1456 puts ("static inline enum reg_class\n"
1457 "reg_class_for_constraint (enum constraint_num)\n"
1458 "{\n"
1459 " return NO_REGS;\n"
1460 "}\n");
1461 if (have_const_int_constraints)
1462 puts ("extern bool insn_const_int_ok_for_constraint "
1463 "(HOST_WIDE_INT, enum constraint_num);\n"
1464 "#define CONST_OK_FOR_CONSTRAINT_P(v_,c_,s_) \\\n"
1465 " insn_const_int_ok_for_constraint (v_, "
1466 "lookup_constraint (s_))\n");
1467 else
1468 puts ("static inline bool\n"
1469 "insn_const_int_ok_for_constraint (HOST_WIDE_INT,"
1470 " enum constraint_num)\n"
1471 "{\n"
1472 " return false;\n"
1473 "}\n");
1475 puts ("enum constraint_type\n"
1476 "{\n"
1477 " CT_REGISTER,\n"
1478 " CT_CONST_INT,\n"
1479 " CT_MEMORY,\n"
1480 " CT_ADDRESS,\n"
1481 " CT_FIXED_FORM\n"
1482 "};\n"
1483 "\n"
1484 "static inline enum constraint_type\n"
1485 "get_constraint_type (enum constraint_num c)\n"
1486 "{");
1487 auto_vec <std::pair <unsigned int, const char *>, 4> values;
1488 if (const_int_start != const_int_end)
1489 values.safe_push (std::make_pair (const_int_start, "CT_CONST_INT"));
1490 if (memory_start != memory_end)
1491 values.safe_push (std::make_pair (memory_start, "CT_MEMORY"));
1492 if (address_start != address_end)
1493 values.safe_push (std::make_pair (address_start, "CT_ADDRESS"));
1494 if (address_end != num_constraints)
1495 values.safe_push (std::make_pair (address_end, "CT_FIXED_FORM"));
1496 print_type_tree (values, 0, values.length (), "CT_REGISTER", 2);
1497 puts ("}");
1500 puts ("#endif /* tm-preds.h */");
1503 /* Write insn-preds.c.
1504 N.B. the list of headers to include was copied from genrecog; it
1505 may not be ideal.
1507 FUTURE: Write #line markers referring back to the machine
1508 description. (Can't practically do this now since we don't know
1509 the line number of the C block - just the line number of the enclosing
1510 expression.) */
1511 static void
1512 write_insn_preds_c (void)
1514 struct pred_data *p;
1516 printf ("\
1517 /* Generated automatically by the program '%s'\n\
1518 from the machine description file '%s'. */\n\n", progname, in_fname);
1520 puts ("\
1521 #include \"config.h\"\n\
1522 #include \"system.h\"\n\
1523 #include \"coretypes.h\"\n\
1524 #include \"backend.h\"\n\
1525 #include \"predict.h\"\n\
1526 #include \"tree.h\"\n\
1527 #include \"rtl.h\"\n\
1528 #include \"alias.h\"\n\
1529 #include \"varasm.h\"\n\
1530 #include \"stor-layout.h\"\n\
1531 #include \"calls.h\"\n\
1532 #include \"tm_p.h\"\n\
1533 #include \"insn-config.h\"\n\
1534 #include \"recog.h\"\n\
1535 #include \"output.h\"\n\
1536 #include \"flags.h\"\n\
1537 #include \"df.h\"\n\
1538 #include \"resource.h\"\n\
1539 #include \"diagnostic-core.h\"\n\
1540 #include \"reload.h\"\n\
1541 #include \"regs.h\"\n\
1542 #include \"emit-rtl.h\"\n\
1543 #include \"tm-constrs.h\"\n");
1545 FOR_ALL_PREDICATES (p)
1546 write_one_predicate_function (p);
1548 if (constraint_max_namelen > 0)
1550 write_lookup_constraint_1 ();
1551 write_lookup_constraint_array ();
1552 if (have_register_constraints)
1553 write_reg_class_for_constraint_1 ();
1554 write_constraint_satisfied_p_array ();
1556 if (have_const_int_constraints)
1557 write_insn_const_int_ok_for_constraint ();
1561 /* Argument parsing. */
1562 static bool gen_header;
1563 static bool gen_constrs;
1565 static bool
1566 parse_option (const char *opt)
1568 if (!strcmp (opt, "-h"))
1570 gen_header = true;
1571 return 1;
1573 else if (!strcmp (opt, "-c"))
1575 gen_constrs = true;
1576 return 1;
1578 else
1579 return 0;
1582 /* Master control. */
1584 main (int argc, char **argv)
1586 progname = argv[0];
1587 if (argc <= 1)
1588 fatal ("no input file name");
1589 if (!init_rtx_reader_args_cb (argc, argv, parse_option))
1590 return FATAL_EXIT_CODE;
1592 md_rtx_info info;
1593 while (read_md_rtx (&info))
1594 switch (GET_CODE (info.def))
1596 case DEFINE_PREDICATE:
1597 case DEFINE_SPECIAL_PREDICATE:
1598 process_define_predicate (&info);
1599 break;
1601 case DEFINE_CONSTRAINT:
1602 case DEFINE_MEMORY_CONSTRAINT:
1603 case DEFINE_ADDRESS_CONSTRAINT:
1604 process_define_constraint (&info);
1605 break;
1607 case DEFINE_REGISTER_CONSTRAINT:
1608 process_define_register_constraint (&info);
1609 break;
1611 default:
1612 break;
1615 choose_enum_order ();
1617 if (gen_header)
1618 write_tm_preds_h ();
1619 else if (gen_constrs)
1620 write_tm_constrs_h ();
1621 else
1622 write_insn_preds_c ();
1624 if (have_error || ferror (stdout) || fflush (stdout) || fclose (stdout))
1625 return FATAL_EXIT_CODE;
1627 return SUCCESS_EXIT_CODE;