+ return q;
+}
+
+#ifdef USE_MD_CONSTRAINTS
+
+/* Record just enough information about a constraint to allow checking
+ of operand constraint strings above, in validate_insn_alternatives.
+ Does not validate most properties of the constraint itself; does
+ enforce no duplicate names, no overlap with MI constraints, and no
+ prefixes. EXP is the define_*constraint form, LINENO the line number
+ reported by the reader. */
+static void
+note_constraint (rtx exp, int lineno)
+{
+ const char *name = XSTR (exp, 0);
+ unsigned int namelen = strlen (name);
+ struct constraint_data **iter, **slot, *new;
+
+ if (strchr (indep_constraints, name[0]))
+ {
+ if (name[1] == '\0')
+ message_with_line (lineno, "constraint letter '%s' cannot be "
+ "redefined by the machine description", name);
+ else
+ message_with_line (lineno, "constraint name '%s' cannot be defined by "
+ "the machine description, as it begins with '%c'",
+ name, name[0]);
+ have_error = 1;
+ return;
+ }
+
+ slot = &constraints_by_letter_table[(unsigned int)name[0]];
+ for (iter = slot; *iter; iter = &(*iter)->next_this_letter)
+ {
+ /* This causes slot to end up pointing to the
+ next_this_letter field of the last constraint with a name
+ of equal or greater length than the new constraint; hence
+ the new constraint will be inserted after all previous
+ constraints with names of the same length. */
+ if ((*iter)->namelen >= namelen)
+ slot = iter;
+
+ if (!strcmp ((*iter)->name, name))
+ {
+ message_with_line (lineno, "redefinition of constraint '%s'", name);
+ message_with_line ((*iter)->lineno, "previous definition is here");
+ have_error = 1;
+ return;
+ }
+ else if (!strncmp ((*iter)->name, name, (*iter)->namelen))
+ {
+ message_with_line (lineno, "defining constraint '%s' here", name);
+ message_with_line ((*iter)->lineno, "renders constraint '%s' "
+ "(defined here) a prefix", (*iter)->name);
+ have_error = 1;
+ return;
+ }
+ else if (!strncmp ((*iter)->name, name, namelen))
+ {
+ message_with_line (lineno, "constraint '%s' is a prefix", name);
+ message_with_line ((*iter)->lineno, "of constraint '%s' "
+ "(defined here)", (*iter)->name);
+ have_error = 1;
+ return;
+ }
+ }
+ new = xmalloc (sizeof (struct constraint_data) + namelen);
+ strcpy ((char *)new + offsetof(struct constraint_data, name), name);
+ new->namelen = namelen;
+ new->lineno = lineno;
+ new->next_this_letter = *slot;
+ *slot = new;
+}
+
+/* Return the length of the constraint name beginning at position S
+ of an operand constraint string, or issue an error message if there
+ is no such constraint. Does not expect to be called for generic
+ constraints. */
+static int
+mdep_constraint_len (const char *s, int lineno, int opno)
+{
+ struct constraint_data *p;
+
+ p = constraints_by_letter_table[(unsigned int)s[0]];
+
+ if (p)
+ for (; p; p = p->next_this_letter)
+ if (!strncmp (s, p->name, p->namelen))
+ return p->namelen;
+
+ message_with_line (lineno,
+ "error: undefined machine-specific constraint "
+ "at this point: \"%s\"", s);
+ message_with_line (lineno, "note: in operand %d", opno);
+ have_error = 1;
+ return 1; /* safe */
+}
+
+#else
+/* Verify that DEFAULT_CONSTRAINT_LEN is used properly and not
+ tampered with. This isn't bullet-proof, but it should catch
+ most genuine mistakes. */
+static void
+check_constraint_len (void)
+{
+ const char *p;
+ int d;
+
+ for (p = ",#*+=&%!1234567890"; *p; p++)
+ for (d = -9; d < 9; d++)
+ gcc_assert (constraint_len (p, d) == d);
+}
+
+static int
+constraint_len (const char *p, int genoutput_default_constraint_len)
+{
+ /* Check that we still match defaults.h . First we do a generation-time
+ check that fails if the value is not the expected one... */
+ gcc_assert (DEFAULT_CONSTRAINT_LEN (*p, p) == 1);
+ /* And now a compile-time check that should give a diagnostic if the
+ definition doesn't exactly match. */
+#define DEFAULT_CONSTRAINT_LEN(C,STR) 1
+ /* Now re-define DEFAULT_CONSTRAINT_LEN so that we can verify it is
+ being used. */
+#undef DEFAULT_CONSTRAINT_LEN
+#define DEFAULT_CONSTRAINT_LEN(C,STR) \
+ ((C) != *p || STR != p ? -1 : genoutput_default_constraint_len)
+ return CONSTRAINT_LEN (*p, p);
+ /* And set it back. */
+#undef DEFAULT_CONSTRAINT_LEN
+#define DEFAULT_CONSTRAINT_LEN(C,STR) 1