Commit cc472607 by Richard Sandiford Committed by Richard Sandiford

read-md.h (file_location): New structure.

gcc/
	* read-md.h (file_location): New structure.
	(directive_handler_t): Take a file_location rather than a line number.
	(message_at, error_at): Declare.
	(read_skip_construct): Delete.
	* read-md.c (message_with_line_1): Replace with...
	(message_at_1): ...this new function.
	(message_at, error_at): New functions.
	(message_with_line, error_with_line): Update to use message_at_1.
	(handle_enum): Take a file_location rather than a line number
	and use error_at for error reporting.
	(handle_include): Likewise.
	(read_skip_construct): Likewise.  Make static.
	(handle_file): Update after above changes.  Pass a file_location
	rather than a line number to handle_directive.
	* gensupport.c (queue_elem): Replace separate filename and lineno
	with a file_location.
	(queue_pattern): Replace filename and lineno arguments with a
	file_location.  Update after change to queue_elem.
	(process_define_predicate): Replace lineno argument with a
	file_location and use error_at for error reporting.  Update
	after above changes.
	(process_rtx): Likewise.
	(subst_pattern_match): Likewise.
	(get_alternatives_number): Likewise.
	(alter_predicate_for_insn): Likewise.
	(rtx_handle_directive): Likewise.
	(is_predicable): Update after above changes, using error_at rather
	than error_with_line.
	(has_subst_attribute): Likewise.
	(identify_predicable_attribute): Likewise.
	(alter_attrs_for_subst_insn): Likewise.
	(process_one_cond_exec): Likewise.
	(process_substs_on_one_elem): Likewise.
	(process_define_subst): Likewise.
	(check_define_attr_duplicates): Likewise.
	(read_md_rtx): Update after change to queue_elem.

From-SVN: r225879
parent 1e2e5efa
2015-07-16 Richard Sandiford <richard.sandiford@arm.com>
* read-md.h (file_location): New structure.
(directive_handler_t): Take a file_location rather than a line number.
(message_at, error_at): Declare.
(read_skip_construct): Delete.
* read-md.c (message_with_line_1): Replace with...
(message_at_1): ...this new function.
(message_at, error_at): New functions.
(message_with_line, error_with_line): Update to use message_at_1.
(handle_enum): Take a file_location rather than a line number
and use error_at for error reporting.
(handle_include): Likewise.
(read_skip_construct): Likewise. Make static.
(handle_file): Update after above changes. Pass a file_location
rather than a line number to handle_directive.
* gensupport.c (queue_elem): Replace separate filename and lineno
with a file_location.
(queue_pattern): Replace filename and lineno arguments with a
file_location. Update after change to queue_elem.
(process_define_predicate): Replace lineno argument with a
file_location and use error_at for error reporting. Update
after above changes.
(process_rtx): Likewise.
(subst_pattern_match): Likewise.
(get_alternatives_number): Likewise.
(alter_predicate_for_insn): Likewise.
(rtx_handle_directive): Likewise.
(is_predicable): Update after above changes, using error_at rather
than error_with_line.
(has_subst_attribute): Likewise.
(identify_predicable_attribute): Likewise.
(alter_attrs_for_subst_insn): Likewise.
(process_one_cond_exec): Likewise.
(process_substs_on_one_elem): Likewise.
(process_define_subst): Likewise.
(check_define_attr_duplicates): Likewise.
(read_md_rtx): Update after change to queue_elem.
2015-07-16 Richard Sandiford <richard.sandiford@arm.com>
* genoutput.c (next_index_number): Delete.
(data): Remove index_number.
(gen_insn, gen_peephole, gen_expand, gen_split): Update accordingly.
......
......@@ -245,13 +245,38 @@ print_c_condition (const char *cond)
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. */
......@@ -261,7 +286,7 @@ message_with_line (int lineno, const char *msg, ...)
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);
}
......@@ -273,7 +298,7 @@ error_with_line (int lineno, const char *msg, ...)
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;
}
......@@ -593,8 +618,8 @@ read_string (int star_if_braced)
/* 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;
......@@ -604,7 +629,7 @@ read_skip_construct (int depth, int lineno)
c = read_skip_spaces ();
if (c == EOF)
{
error_with_line (lineno, "unterminated construct");
error_at (loc, "unterminated construct");
exit (1);
}
switch (c)
......@@ -794,7 +819,7 @@ md_decimal_string (int number)
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;
......@@ -809,8 +834,8 @@ handle_enum (int lineno, bool md_p)
{
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
{
......@@ -831,7 +856,7 @@ handle_enum (int lineno, bool md_p)
{
if (c == EOF)
{
error_with_line (lineno, "unterminated construct");
error_at (loc, "unterminated construct");
exit (1);
}
unread_char (c);
......@@ -883,7 +908,7 @@ traverse_enum_types (htab_trav callback, void *info)
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;
......@@ -926,7 +951,7 @@ handle_include (int lineno, directive_handler_t handle_directive)
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;
}
......@@ -961,12 +986,12 @@ static void
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);
......@@ -974,15 +999,15 @@ handle_file (directive_handler_t handle_directive)
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 != ')')
......
......@@ -22,6 +22,18 @@ along with GCC; see the file COPYING3. If not see
#include "obstack.h"
/* Records a position in the file. */
struct file_location {
file_location () {}
file_location (const char *, int);
const char *filename;
int lineno;
};
inline file_location::file_location (const char *filename_in, int lineno_in)
: filename (filename_in), lineno (lineno_in) {}
/* Holds one symbol or number in the .md file. */
struct md_name {
/* The name as it appeared in the .md file. Names are syntactically
......@@ -79,10 +91,10 @@ struct enum_type {
};
/* A callback that handles a single .md-file directive, up to but not
including the closing ')'. It takes two arguments: the line number on
which the directive started, and the name of the directive. The next
including the closing ')'. It takes two arguments: the file position
at which the directive started, and the name of the directive. The next
unread character is the optional space after the directive name. */
typedef void (*directive_handler_t) (int, const char *);
typedef void (*directive_handler_t) (file_location, const char *);
extern const char *in_fname;
extern FILE *read_md_file;
......@@ -122,6 +134,8 @@ extern void fprint_md_ptr_loc (FILE *, const void *);
extern const char *join_c_conditions (const char *, const char *);
extern void print_c_condition (const char *);
extern void fprint_c_condition (FILE *, const char *);
extern void message_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2;
extern void error_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2;
extern void message_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2;
extern void error_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2;
extern void fatal_with_file_and_line (const char *, ...)
......@@ -131,7 +145,6 @@ extern int read_skip_spaces (void);
extern void read_name (struct md_name *);
extern char *read_quoted_string (void);
extern char *read_string (int);
extern void read_skip_construct (int, int);
extern int n_comma_elts (const char *);
extern const char *scan_comma_elt (const char **);
extern void upcase_string (char *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment