struct queue_elem
{
rtx data;
- const char *filename;
- int lineno;
+ file_location loc;
struct queue_elem *next;
/* In a DEFINE_INSN that came from a DEFINE_INSN_AND_SPLIT, SPLIT
points to the generated DEFINE_SPLIT. */
static struct queue_elem *define_subst_attr_queue;
static struct queue_elem **define_subst_attr_tail = &define_subst_attr_queue;
-static struct queue_elem *queue_pattern (rtx, struct queue_elem ***,
- const char *, int);
-
static void remove_constraints (rtx);
-static void process_rtx (rtx, int);
static int is_predicable (struct queue_elem *);
static void identify_predicable_attribute (void);
static int n_alternatives (const char *);
static void collect_insn_data (rtx, int *, int *);
-static rtx alter_predicate_for_insn (rtx, int, int, int);
static const char *alter_test_for_insn (struct queue_elem *,
struct queue_elem *);
static char *shift_output_template (char *, const char *, int);
static void record_insn_name (int, const char *);
static bool has_subst_attribute (struct queue_elem *, struct queue_elem *);
-static bool subst_pattern_match (rtx, rtx, int);
-static int get_alternatives_number (rtx, int *, int);
static const char * alter_output_for_subst_insn (rtx, int);
static void alter_attrs_for_subst_insn (struct queue_elem *, int);
static void process_substs_on_one_elem (struct queue_elem *,
return true;
}
-/* Process define_predicate directive DESC, which appears on line number
- LINENO. Compute the set of codes that can be matched, and record this
- as a known predicate. */
+/* Process define_predicate directive DESC, which appears at location LOC.
+ Compute the set of codes that can be matched, and record this as a known
+ predicate. */
static void
-process_define_predicate (rtx desc, int lineno)
+process_define_predicate (rtx desc, file_location loc)
{
struct pred_data *pred;
char codes[NUM_RTX_CODE];
if (!valid_predicate_name_p (XSTR (desc, 0)))
{
- error_with_line (lineno,
- "%s: predicate name must be a valid C function name",
- XSTR (desc, 0));
+ error_at (loc, "%s: predicate name must be a valid C function name",
+ XSTR (desc, 0));
return;
}
if (GET_CODE (desc) == DEFINE_SPECIAL_PREDICATE)
pred->special = true;
- compute_test_codes (XEXP (desc, 1), lineno, codes);
+ compute_test_codes (XEXP (desc, 1), loc.lineno, codes);
for (i = 0; i < NUM_RTX_CODE; i++)
if (codes[i] != N)
static struct queue_elem *
queue_pattern (rtx pattern, struct queue_elem ***list_tail,
- const char *filename, int lineno)
+ file_location loc)
{
struct queue_elem *e = XNEW (struct queue_elem);
e->data = pattern;
- e->filename = filename;
- e->lineno = lineno;
+ e->loc = loc;
e->next = NULL;
e->split = NULL;
**list_tail = e;
XEXP (t1, 2) = rtx_alloc (CONST_STRING);
XSTR (XEXP (t1, 2), 0) = "yes";
e->data = t1;
- e->filename = "built-in";
- e->lineno = -1;
+ e->loc = file_location ("built-in", -1);
e->next = define_attr_queue;
define_attr_queue = e;
/* Process a top level rtx in some way, queuing as appropriate. */
static void
-process_rtx (rtx desc, int lineno)
+process_rtx (rtx desc, file_location loc)
{
switch (GET_CODE (desc))
{
case DEFINE_INSN:
- queue_pattern (desc, &define_insn_tail, read_md_filename, lineno);
+ queue_pattern (desc, &define_insn_tail, loc);
break;
case DEFINE_COND_EXEC:
- queue_pattern (desc, &define_cond_exec_tail, read_md_filename, lineno);
+ queue_pattern (desc, &define_cond_exec_tail, loc);
break;
case DEFINE_SUBST:
- queue_pattern (desc, &define_subst_tail, read_md_filename, lineno);
+ queue_pattern (desc, &define_subst_tail, loc);
break;
case DEFINE_SUBST_ATTR:
- queue_pattern (desc, &define_subst_attr_tail, read_md_filename, lineno);
+ queue_pattern (desc, &define_subst_attr_tail, loc);
break;
case DEFINE_ATTR:
case DEFINE_ENUM_ATTR:
- queue_pattern (desc, &define_attr_tail, read_md_filename, lineno);
+ queue_pattern (desc, &define_attr_tail, loc);
break;
case DEFINE_PREDICATE:
case DEFINE_SPECIAL_PREDICATE:
- process_define_predicate (desc, lineno);
+ process_define_predicate (desc, loc);
/* Fall through. */
case DEFINE_CONSTRAINT:
case DEFINE_REGISTER_CONSTRAINT:
case DEFINE_MEMORY_CONSTRAINT:
case DEFINE_ADDRESS_CONSTRAINT:
- queue_pattern (desc, &define_pred_tail, read_md_filename, lineno);
+ queue_pattern (desc, &define_pred_tail, loc);
break;
case DEFINE_INSN_AND_SPLIT:
XVEC (desc, 4) = attr;
/* Queue them. */
- insn_elem
- = queue_pattern (desc, &define_insn_tail, read_md_filename,
- lineno);
- split_elem
- = queue_pattern (split, &other_tail, read_md_filename, lineno);
+ insn_elem = queue_pattern (desc, &define_insn_tail, loc);
+ split_elem = queue_pattern (split, &other_tail, loc);
insn_elem->split = split_elem;
break;
}
default:
- queue_pattern (desc, &other_tail, read_md_filename, lineno);
+ queue_pattern (desc, &other_tail, loc);
break;
}
}
case SET_ATTR_ALTERNATIVE:
if (strcmp (XSTR (sub, 0), "predicable") == 0)
{
- error_with_line (elem->lineno,
- "multiple alternatives for `predicable'");
+ error_at (elem->loc, "multiple alternatives for `predicable'");
return 0;
}
break;
/* ??? It would be possible to handle this if we really tried.
It's not easy though, and I'm not going to bother until it
really proves necessary. */
- error_with_line (elem->lineno,
- "non-constant value for `predicable'");
+ error_at (elem->loc, "non-constant value for `predicable'");
return 0;
default:
if (strcmp (value, predicable_false) == 0)
return 0;
- error_with_line (elem->lineno,
- "unknown value `%s' for `predicable' attribute", value);
+ error_at (elem->loc, "unknown value `%s' for `predicable' attribute", value);
return 0;
}
/* Only (set_attr "subst" "yes/no") and
(set (attr "subst" (const_string "yes/no")))
are currently allowed. */
- error_with_line (elem->lineno,
- "unsupported value for `%s'", subst_name);
+ error_at (elem->loc, "unsupported value for `%s'", subst_name);
return false;
case SET_ATTR_ALTERNATIVE:
- error_with_line (elem->lineno,
- "%s: `set_attr_alternative' is unsupported by "
- "`define_subst'",
- XSTR (elem->data, 0));
+ error_at (elem->loc,
+ "%s: `set_attr_alternative' is unsupported by "
+ "`define_subst'", XSTR (elem->data, 0));
return false;
if (strcmp (value, subst_false) == 0)
return false;
- error_with_line (elem->lineno,
- "unknown value `%s' for `%s' attribute", value, subst_name);
+ error_at (elem->loc, "unknown value `%s' for `%s' attribute",
+ value, subst_name);
return false;
}
define_subst PT. Return 1 if the templates match, 0 otherwise.
During the comparison, the routine also fills global_array OPERAND_DATA. */
static bool
-subst_pattern_match (rtx x, rtx pt, int lineno)
+subst_pattern_match (rtx x, rtx pt, file_location loc)
{
RTX_CODE code, code_pt;
int i, j, len;
return false;
for (j = 0; j < XVECLEN (pt, 2); j++)
if (!subst_pattern_match (XVECEXP (x, x_vecexp_pos, j),
- XVECEXP (pt, 2, j), lineno))
+ XVECEXP (pt, 2, j), loc))
return false;
}
if (GET_RTX_LENGTH (code) != XVECLEN (pt, 2))
return false;
for (j = 0; j < XVECLEN (pt, 2); j++)
- if (!subst_pattern_match (XEXP (x, j), XVECEXP (pt, 2, j), lineno))
+ if (!subst_pattern_match (XEXP (x, j), XVECEXP (pt, 2, j), loc))
return false;
}
/* Currently interface for these constructions isn't defined -
probably they aren't needed in input template of define_subst at all.
So, for now their usage in define_subst is forbidden. */
- error_with_line (lineno, "%s cannot be used in define_subst",
- GET_RTX_NAME (code_pt));
+ error_at (loc, "%s cannot be used in define_subst",
+ GET_RTX_NAME (code_pt));
}
gcc_assert (code != MATCH_PAR_DUP
continue;
case 'e': case 'u':
- if (!subst_pattern_match (XEXP (x, i), XEXP (pt, i), lineno))
+ if (!subst_pattern_match (XEXP (x, i), XEXP (pt, i), loc))
return false;
break;
case 'E':
if (XVECLEN (x, i) != XVECLEN (pt, i))
return false;
for (j = 0; j < XVECLEN (pt, i); j++)
- if (!subst_pattern_match (XVECEXP (x, i, j), XVECEXP (pt, i, j),
- lineno))
+ if (!subst_pattern_match (XVECEXP (x, i, j),
+ XVECEXP (pt, i, j), loc))
return false;
break;
}
if (strcmp (XSTR (elem->data, 0), "predicable") == 0)
goto found;
- error_with_line (define_cond_exec_queue->lineno,
- "attribute `predicable' not defined");
+ error_at (define_cond_exec_queue->loc,
+ "attribute `predicable' not defined");
return;
found:
p_true = strchr (p_false, ',');
if (p_true == NULL || strchr (++p_true, ',') != NULL)
{
- error_with_line (elem->lineno, "attribute `predicable' is not a boolean");
+ error_at (elem->loc, "attribute `predicable' is not a boolean");
free (p_false);
return;
}
break;
case CONST:
- error_with_line (elem->lineno, "attribute `predicable' cannot be const");
+ error_at (elem->loc, "attribute `predicable' cannot be const");
free (p_false);
return;
default:
- error_with_line (elem->lineno,
- "attribute `predicable' must have a constant default");
+ error_at (elem->loc,
+ "attribute `predicable' must have a constant default");
free (p_false);
return;
}
predicable_default = 0;
else
{
- error_with_line (elem->lineno,
- "unknown value `%s' for `predicable' attribute", value);
+ error_at (elem->loc, "unknown value `%s' for `predicable' attribute",
+ value);
free (p_false);
}
}
with different number of alternatives, error is emitted, and the
routine returns 0. If all match_operands in PATTERN have the same
number of alternatives, it's stored in N_ALT, and the routine returns 1.
- Argument LINENO is used in when the error is emitted. */
+ LOC is the location of PATTERN, for error reporting. */
static int
-get_alternatives_number (rtx pattern, int *n_alt, int lineno)
+get_alternatives_number (rtx pattern, int *n_alt, file_location loc)
{
const char *fmt;
enum rtx_code code;
else if (i && i != *n_alt)
{
- error_with_line (lineno,
- "wrong number of alternatives in operand %d",
- XINT (pattern, 0));
+ error_at (loc, "wrong number of alternatives in operand %d",
+ XINT (pattern, 0));
return 0;
}
switch (fmt[i])
{
case 'e': case 'u':
- if (!get_alternatives_number (XEXP (pattern, i), n_alt, lineno))
- return 0;
+ if (!get_alternatives_number (XEXP (pattern, i), n_alt, loc))
+ return 0;
break;
case 'V':
case 'E':
for (j = XVECLEN (pattern, i) - 1; j >= 0; --j)
- if (!get_alternatives_number (XVECEXP (pattern, i, j),
- n_alt, lineno))
- return 0;
+ if (!get_alternatives_number (XVECEXP (pattern, i, j), n_alt, loc))
+ return 0;
break;
case 'i': case 'r': case 'w': case '0': case 's': case 'S': case 'T':
}
static rtx
-alter_predicate_for_insn (rtx pattern, int alt, int max_op, int lineno)
+alter_predicate_for_insn (rtx pattern, int alt, int max_op,
+ file_location loc)
{
const char *fmt;
enum rtx_code code;
if (n_alternatives (c) != 1)
{
- error_with_line (lineno, "too many alternatives for operand %d",
- XINT (pattern, 0));
+ error_at (loc, "too many alternatives for operand %d",
+ XINT (pattern, 0));
return NULL;
}
switch (fmt[i])
{
case 'e': case 'u':
- r = alter_predicate_for_insn (XEXP (pattern, i), alt,
- max_op, lineno);
+ r = alter_predicate_for_insn (XEXP (pattern, i), alt, max_op, loc);
if (r == NULL)
return r;
break;
for (j = XVECLEN (pattern, i) - 1; j >= 0; --j)
{
r = alter_predicate_for_insn (XVECEXP (pattern, i, j),
- alt, max_op, lineno);
+ alt, max_op, loc);
if (r == NULL)
return r;
}
case SET_ATTR_ALTERNATIVE:
case SET:
- error_with_line (elem->lineno,
- "%s: `define_subst' does not support attributes "
- "assigned by `set' and `set_attr_alternative'",
- XSTR (elem->data, 0));
+ error_at (elem->loc,
+ "%s: `define_subst' does not support attributes "
+ "assigned by `set' and `set_attr_alternative'",
+ XSTR (elem->data, 0));
return;
default:
if (XVECLEN (ce_elem->data, 0) != 1)
{
- error_with_line (ce_elem->lineno, "too many patterns in predicate");
+ error_at (ce_elem->loc, "too many patterns in predicate");
return;
}
pred = copy_rtx (XVECEXP (ce_elem->data, 0, 0));
pred = alter_predicate_for_insn (pred, alternatives, max_operand,
- ce_elem->lineno);
+ ce_elem->loc);
if (pred == NULL)
return;
patterns into the define_insn chain just after their generator
is something we'll have to experiment with. */
- queue_pattern (insn, &other_tail, insn_elem->filename,
- insn_elem->lineno);
+ queue_pattern (insn, &other_tail, insn_elem->loc);
if (!insn_elem->split)
continue;
XVECEXP (split, 2, i) = pattern;
}
/* Add the new split to the queue. */
- queue_pattern (split, &other_tail, read_md_filename,
- insn_elem->split->lineno);
+ queue_pattern (split, &other_tail, insn_elem->split->loc);
}
}
{
if (!subst_pattern_match (XVECEXP (elem->data, 1, j),
XVECEXP (subst_elem->data, 1, j),
- subst_elem->lineno))
+ subst_elem->loc))
{
patterns_match = 0;
break;
}
if (!get_alternatives_number (XVECEXP (elem->data, 1, j),
- &alternatives, subst_elem->lineno))
+ &alternatives, subst_elem->loc))
{
patterns_match = 0;
break;
{
if (!get_alternatives_number (XVECEXP (subst_elem->data, 3, j),
&alternatives_subst,
- subst_elem->lineno))
+ subst_elem->loc))
{
patterns_match = 0;
break;
if (strcmp (XSTR (elem->data, 0), XSTR (elem_attr->data, 1)) == 0)
goto found;
- error_with_line (elem->lineno,
- "%s: `define_subst' must have at least one "
- "corresponding `define_subst_attr'",
- XSTR (elem->data, 0));
+ error_at (elem->loc,
+ "%s: `define_subst' must have at least one "
+ "corresponding `define_subst_attr'",
+ XSTR (elem->data, 0));
return;
found:
/* A read_md_files callback for reading an rtx. */
static void
-rtx_handle_directive (int lineno, const char *rtx_name)
+rtx_handle_directive (file_location loc, const char *rtx_name)
{
auto_vec<rtx, 32> subrtxs;
if (!read_rtx (rtx_name, &subrtxs))
rtx x;
unsigned int i;
FOR_EACH_VEC_ELT (subrtxs, i, x)
- process_rtx (x, lineno);
+ process_rtx (x, loc);
}
/* Comparison function for the mnemonic hash table. */
/* Duplicate. */
if (*slot)
{
- error_with_line (elem->lineno, "redefinition of attribute '%s'",
- attr_name);
+ error_at (elem->loc, "redefinition of attribute '%s'", attr_name);
htab_delete (attr_htab);
return;
}
elem = *queue;
*queue = elem->next;
desc = elem->data;
- read_md_filename = elem->filename;
- *lineno = elem->lineno;
+ read_md_filename = elem->loc.filename;
+ *lineno = elem->loc.lineno;
*seqnr = sequence_num;
free (elem);
of the current MD file. */
static void ATTRIBUTE_PRINTF(2,0)
-message_with_line_1 (int lineno, const char *msg, va_list ap)
+message_at_1 (file_location loc, const char *msg, va_list ap)
{
- fprintf (stderr, "%s:%d: ", read_md_filename, lineno);
+ fprintf (stderr, "%s:%d: ", loc.filename, loc.lineno);
vfprintf (stderr, msg, ap);
fputc ('\n', stderr);
}
+/* A printf-like function for reporting a message against location LOC. */
+
+void
+message_at (file_location loc, const char *msg, ...)
+{
+ va_list ap;
+
+ va_start (ap, msg);
+ message_at_1 (loc, msg, ap);
+ va_end (ap);
+}
+
+/* Like message_at, but treat the condition as an error. */
+
+void
+error_at (file_location loc, const char *msg, ...)
+{
+ va_list ap;
+
+ va_start (ap, msg);
+ message_at_1 (loc, msg, ap);
+ va_end (ap);
+ have_error = 1;
+}
+
/* A printf-like function for reporting an error against line LINENO
in the current MD file. */
va_list ap;
va_start (ap, msg);
- message_with_line_1 (lineno, msg, ap);
+ message_at_1 (file_location (read_md_filename, lineno), msg, ap);
va_end (ap);
}
va_list ap;
va_start (ap, msg);
- message_with_line_1 (lineno, msg, ap);
+ message_at_1 (file_location (read_md_filename, lineno), msg, ap);
va_end (ap);
have_error = 1;
}
/* Skip the rest of a construct that started at line LINENO and that
is currently nested by DEPTH levels of parentheses. */
-void
-read_skip_construct (int depth, int lineno)
+static void
+read_skip_construct (int depth, file_location loc)
{
struct md_name name;
int c;
c = read_skip_spaces ();
if (c == EOF)
{
- error_with_line (lineno, "unterminated construct");
+ error_at (loc, "unterminated construct");
exit (1);
}
switch (c)
directive is a define_enum rather than a define_c_enum. */
static void
-handle_enum (int lineno, bool md_p)
+handle_enum (file_location loc, bool md_p)
{
char *enum_name, *value_name;
struct md_name name;
{
def = (struct enum_type *) *slot;
if (def->md_p != md_p)
- error_with_line (lineno, "redefining `%s' as a different type of enum",
- enum_name);
+ error_at (loc, "redefining `%s' as a different type of enum",
+ enum_name);
}
else
{
{
if (c == EOF)
{
- error_with_line (lineno, "unterminated construct");
+ error_at (loc, "unterminated construct");
exit (1);
}
unread_char (c);
which the "include" occurred. */
static void
-handle_include (int lineno, directive_handler_t handle_directive)
+handle_include (file_location loc, directive_handler_t handle_directive)
{
const char *filename;
const char *old_filename;
if (input_file == NULL)
{
free (pathname);
- error_with_line (lineno, "include file `%s' not found", filename);
+ error_at (loc, "include file `%s' not found", filename);
return;
}
handle_file (directive_handler_t handle_directive)
{
struct md_name directive;
- int c, lineno;
+ int c;
read_md_lineno = 1;
while ((c = read_skip_spaces ()) != EOF)
{
- lineno = read_md_lineno;
+ file_location loc (read_md_filename, read_md_lineno);
if (c != '(')
fatal_expected_char ('(', c);
if (strcmp (directive.string, "define_constants") == 0)
handle_constants ();
else if (strcmp (directive.string, "define_enum") == 0)
- handle_enum (lineno, true);
+ handle_enum (loc, true);
else if (strcmp (directive.string, "define_c_enum") == 0)
- handle_enum (lineno, false);
+ handle_enum (loc, false);
else if (strcmp (directive.string, "include") == 0)
- handle_include (lineno, handle_directive);
+ handle_include (loc, handle_directive);
else if (handle_directive)
- handle_directive (lineno, directive.string);
+ handle_directive (loc, directive.string);
else
- read_skip_construct (1, lineno);
+ read_skip_construct (1, loc);
c = read_skip_spaces ();
if (c != ')')