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> 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. * genoutput.c (next_index_number): Delete.
(data): Remove index_number. (data): Remove index_number.
(gen_insn, gen_peephole, gen_expand, gen_split): Update accordingly. (gen_insn, gen_peephole, gen_expand, gen_split): Update accordingly.
......
...@@ -245,13 +245,38 @@ print_c_condition (const char *cond) ...@@ -245,13 +245,38 @@ print_c_condition (const char *cond)
of the current MD file. */ of the current MD file. */
static void ATTRIBUTE_PRINTF(2,0) 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); vfprintf (stderr, msg, ap);
fputc ('\n', stderr); 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 /* A printf-like function for reporting an error against line LINENO
in the current MD file. */ in the current MD file. */
...@@ -261,7 +286,7 @@ message_with_line (int lineno, const char *msg, ...) ...@@ -261,7 +286,7 @@ message_with_line (int lineno, const char *msg, ...)
va_list ap; va_list ap;
va_start (ap, msg); 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_end (ap);
} }
...@@ -273,7 +298,7 @@ error_with_line (int lineno, const char *msg, ...) ...@@ -273,7 +298,7 @@ error_with_line (int lineno, const char *msg, ...)
va_list ap; va_list ap;
va_start (ap, msg); 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_end (ap);
have_error = 1; have_error = 1;
} }
...@@ -593,8 +618,8 @@ read_string (int star_if_braced) ...@@ -593,8 +618,8 @@ read_string (int star_if_braced)
/* Skip the rest of a construct that started at line LINENO and that /* Skip the rest of a construct that started at line LINENO and that
is currently nested by DEPTH levels of parentheses. */ is currently nested by DEPTH levels of parentheses. */
void static void
read_skip_construct (int depth, int lineno) read_skip_construct (int depth, file_location loc)
{ {
struct md_name name; struct md_name name;
int c; int c;
...@@ -604,7 +629,7 @@ read_skip_construct (int depth, int lineno) ...@@ -604,7 +629,7 @@ read_skip_construct (int depth, int lineno)
c = read_skip_spaces (); c = read_skip_spaces ();
if (c == EOF) if (c == EOF)
{ {
error_with_line (lineno, "unterminated construct"); error_at (loc, "unterminated construct");
exit (1); exit (1);
} }
switch (c) switch (c)
...@@ -794,7 +819,7 @@ md_decimal_string (int number) ...@@ -794,7 +819,7 @@ md_decimal_string (int number)
directive is a define_enum rather than a define_c_enum. */ directive is a define_enum rather than a define_c_enum. */
static void static void
handle_enum (int lineno, bool md_p) handle_enum (file_location loc, bool md_p)
{ {
char *enum_name, *value_name; char *enum_name, *value_name;
struct md_name name; struct md_name name;
...@@ -809,8 +834,8 @@ handle_enum (int lineno, bool md_p) ...@@ -809,8 +834,8 @@ handle_enum (int lineno, bool md_p)
{ {
def = (struct enum_type *) *slot; def = (struct enum_type *) *slot;
if (def->md_p != md_p) if (def->md_p != md_p)
error_with_line (lineno, "redefining `%s' as a different type of enum", error_at (loc, "redefining `%s' as a different type of enum",
enum_name); enum_name);
} }
else else
{ {
...@@ -831,7 +856,7 @@ handle_enum (int lineno, bool md_p) ...@@ -831,7 +856,7 @@ handle_enum (int lineno, bool md_p)
{ {
if (c == EOF) if (c == EOF)
{ {
error_with_line (lineno, "unterminated construct"); error_at (loc, "unterminated construct");
exit (1); exit (1);
} }
unread_char (c); unread_char (c);
...@@ -883,7 +908,7 @@ traverse_enum_types (htab_trav callback, void *info) ...@@ -883,7 +908,7 @@ traverse_enum_types (htab_trav callback, void *info)
which the "include" occurred. */ which the "include" occurred. */
static void 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 *filename;
const char *old_filename; const char *old_filename;
...@@ -926,7 +951,7 @@ handle_include (int lineno, directive_handler_t handle_directive) ...@@ -926,7 +951,7 @@ handle_include (int lineno, directive_handler_t handle_directive)
if (input_file == NULL) if (input_file == NULL)
{ {
free (pathname); free (pathname);
error_with_line (lineno, "include file `%s' not found", filename); error_at (loc, "include file `%s' not found", filename);
return; return;
} }
...@@ -961,12 +986,12 @@ static void ...@@ -961,12 +986,12 @@ static void
handle_file (directive_handler_t handle_directive) handle_file (directive_handler_t handle_directive)
{ {
struct md_name directive; struct md_name directive;
int c, lineno; int c;
read_md_lineno = 1; read_md_lineno = 1;
while ((c = read_skip_spaces ()) != EOF) while ((c = read_skip_spaces ()) != EOF)
{ {
lineno = read_md_lineno; file_location loc (read_md_filename, read_md_lineno);
if (c != '(') if (c != '(')
fatal_expected_char ('(', c); fatal_expected_char ('(', c);
...@@ -974,15 +999,15 @@ handle_file (directive_handler_t handle_directive) ...@@ -974,15 +999,15 @@ handle_file (directive_handler_t handle_directive)
if (strcmp (directive.string, "define_constants") == 0) if (strcmp (directive.string, "define_constants") == 0)
handle_constants (); handle_constants ();
else if (strcmp (directive.string, "define_enum") == 0) 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) else if (strcmp (directive.string, "define_c_enum") == 0)
handle_enum (lineno, false); handle_enum (loc, false);
else if (strcmp (directive.string, "include") == 0) else if (strcmp (directive.string, "include") == 0)
handle_include (lineno, handle_directive); handle_include (loc, handle_directive);
else if (handle_directive) else if (handle_directive)
handle_directive (lineno, directive.string); handle_directive (loc, directive.string);
else else
read_skip_construct (1, lineno); read_skip_construct (1, loc);
c = read_skip_spaces (); c = read_skip_spaces ();
if (c != ')') if (c != ')')
......
...@@ -22,6 +22,18 @@ along with GCC; see the file COPYING3. If not see ...@@ -22,6 +22,18 @@ along with GCC; see the file COPYING3. If not see
#include "obstack.h" #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. */ /* Holds one symbol or number in the .md file. */
struct md_name { struct md_name {
/* The name as it appeared in the .md file. Names are syntactically /* The name as it appeared in the .md file. Names are syntactically
...@@ -79,10 +91,10 @@ struct enum_type { ...@@ -79,10 +91,10 @@ struct enum_type {
}; };
/* A callback that handles a single .md-file directive, up to but not /* A callback that handles a single .md-file directive, up to but not
including the closing ')'. It takes two arguments: the line number on including the closing ')'. It takes two arguments: the file position
which the directive started, and the name of the directive. The next at which the directive started, and the name of the directive. The next
unread character is the optional space after the directive name. */ 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 const char *in_fname;
extern FILE *read_md_file; extern FILE *read_md_file;
...@@ -122,6 +134,8 @@ extern void fprint_md_ptr_loc (FILE *, const void *); ...@@ -122,6 +134,8 @@ extern void fprint_md_ptr_loc (FILE *, const void *);
extern const char *join_c_conditions (const char *, const char *); extern const char *join_c_conditions (const char *, const char *);
extern void print_c_condition (const char *); extern void print_c_condition (const char *);
extern void fprint_c_condition (FILE *, 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 message_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2;
extern void error_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 *, ...) extern void fatal_with_file_and_line (const char *, ...)
...@@ -131,7 +145,6 @@ extern int read_skip_spaces (void); ...@@ -131,7 +145,6 @@ extern int read_skip_spaces (void);
extern void read_name (struct md_name *); extern void read_name (struct md_name *);
extern char *read_quoted_string (void); extern char *read_quoted_string (void);
extern char *read_string (int); extern char *read_string (int);
extern void read_skip_construct (int, int);
extern int n_comma_elts (const char *); extern int n_comma_elts (const char *);
extern const char *scan_comma_elt (const char **); extern const char *scan_comma_elt (const char **);
extern void upcase_string (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