Commit c5e88b39 by Richard Sandiford Committed by Richard Sandiford

read-md.h (read_md_file): Declare.

gcc/
	* read-md.h (read_md_file): Declare.
	(read_char, unread_char): New functions.
	(fatal_with_file_and_line, fatal_expected_char, read_skip_spaces)
	(read_quoted_string, read_string): Remove FILE * argument.
	* read-md.c (read_md_file): New variable.
	(read_md_filename, read_md_lineno): Update comments and remove
	unnecessary initialization.
	(fatal_with_file_and_line, fatal_expected_char, read_skip_spaces)
	(read_escape, read_quoted_string, read_braced_string, read_string):
	Remove FILE * argument.  Update calls accordingly, using read_char
	and unread_char instead of getc and ungetc.
	* rtl.h (read_rtx): Remove FILE * argument.
	* read-rtl.c (iterator_group): Remove FILE * argument from
	"find_builtin".
	(iterator_traverse_data): Remove "infile" field.
	(find_mode, find_code, apply_mode_maps, apply_iterator_to_rtx)
	(add_mapping, read_name, read_constants, read_conditions)
	(validate_const_int, find_iterator, read_mapping, check_code_iterator)
	(read_rtx, read_rtx_1, read_rtx_variadic): Remove FILE * argument.
	Remove file arguments from all calls, using read_char and unread_char
	instead of getc and ungetc.
	* gensupport.c (process_include): Preserve read_md_file around
	the include.  Set read_md_file to the handle of the included file.
	Update call to read_rtx.
	(init_md_reader_args_cb): Set read_md_file to the handle of the file
	and remove local FILE *.  Update calls to read_rtx.

From-SVN: r160572
parent d2a3ce4e
2010-06-10 Richard Sandiford <rdsandiford@googlemail.com> 2010-06-10 Richard Sandiford <rdsandiford@googlemail.com>
* read-md.h (read_md_file): Declare.
(read_char, unread_char): New functions.
(fatal_with_file_and_line, fatal_expected_char, read_skip_spaces)
(read_quoted_string, read_string): Remove FILE * argument.
* read-md.c (read_md_file): New variable.
(read_md_filename, read_md_lineno): Update comments and remove
unnecessary initialization.
(fatal_with_file_and_line, fatal_expected_char, read_skip_spaces)
(read_escape, read_quoted_string, read_braced_string, read_string):
Remove FILE * argument. Update calls accordingly, using read_char
and unread_char instead of getc and ungetc.
* rtl.h (read_rtx): Remove FILE * argument.
* read-rtl.c (iterator_group): Remove FILE * argument from
"find_builtin".
(iterator_traverse_data): Remove "infile" field.
(find_mode, find_code, apply_mode_maps, apply_iterator_to_rtx)
(add_mapping, read_name, read_constants, read_conditions)
(validate_const_int, find_iterator, read_mapping, check_code_iterator)
(read_rtx, read_rtx_1, read_rtx_variadic): Remove FILE * argument.
Remove file arguments from all calls, using read_char and unread_char
instead of getc and ungetc.
* gensupport.c (process_include): Preserve read_md_file around
the include. Set read_md_file to the handle of the included file.
Update call to read_rtx.
(init_md_reader_args_cb): Set read_md_file to the handle of the file
and remove local FILE *. Update calls to read_rtx.
2010-06-10 Richard Sandiford <rdsandiford@googlemail.com>
* read-md.h (read_rtx_lineno): Rename to... * read-md.h (read_rtx_lineno): Rename to...
(read_md_lineno): ...this. (read_md_lineno): ...this.
(read_rtx_filename): Rename to... (read_rtx_filename): Rename to...
......
...@@ -194,7 +194,7 @@ process_include (rtx desc, int lineno) ...@@ -194,7 +194,7 @@ process_include (rtx desc, int lineno)
const char *old_filename; const char *old_filename;
int old_lineno; int old_lineno;
char *pathname; char *pathname;
FILE *input_file; FILE *input_file, *old_file;
/* If specified file name is absolute, skip the include stack. */ /* If specified file name is absolute, skip the include stack. */
if (! IS_ABSOLUTE_PATH (filename)) if (! IS_ABSOLUTE_PATH (filename))
...@@ -231,8 +231,10 @@ process_include (rtx desc, int lineno) ...@@ -231,8 +231,10 @@ process_include (rtx desc, int lineno)
/* Save old cursor; setup new for the new file. Note that "lineno" the /* Save old cursor; setup new for the new file. Note that "lineno" the
argument to this function is the beginning of the include statement, argument to this function is the beginning of the include statement,
while read_md_lineno has already been advanced. */ while read_md_lineno has already been advanced. */
old_file = read_md_file;
old_filename = read_md_filename; old_filename = read_md_filename;
old_lineno = read_md_lineno; old_lineno = read_md_lineno;
read_md_file = input_file;
read_md_filename = pathname; read_md_filename = pathname;
read_md_lineno = 1; read_md_lineno = 1;
...@@ -240,12 +242,13 @@ process_include (rtx desc, int lineno) ...@@ -240,12 +242,13 @@ process_include (rtx desc, int lineno)
include_callback (pathname); include_callback (pathname);
/* Read the entire file. */ /* Read the entire file. */
while (read_rtx (input_file, &desc, &lineno)) while (read_rtx (&desc, &lineno))
process_rtx (desc, lineno); process_rtx (desc, lineno);
/* Do not free pathname. It is attached to the various rtx queue /* Do not free pathname. It is attached to the various rtx queue
elements. */ elements. */
read_md_file = old_file;
read_md_filename = old_filename; read_md_filename = old_filename;
read_md_lineno = old_lineno; read_md_lineno = old_lineno;
...@@ -902,7 +905,6 @@ save_string (const char *s, int len) ...@@ -902,7 +905,6 @@ save_string (const char *s, int len)
int int
init_md_reader_args_cb (int argc, char **argv, bool (*parse_opt)(const char *)) init_md_reader_args_cb (int argc, char **argv, bool (*parse_opt)(const char *))
{ {
FILE *input_file;
int c, i, lineno; int c, i, lineno;
char *lastsl; char *lastsl;
rtx desc; rtx desc;
...@@ -988,14 +990,14 @@ init_md_reader_args_cb (int argc, char **argv, bool (*parse_opt)(const char *)) ...@@ -988,14 +990,14 @@ init_md_reader_args_cb (int argc, char **argv, bool (*parse_opt)(const char *))
fatal ("cannot read standard input twice"); fatal ("cannot read standard input twice");
base_dir = NULL; base_dir = NULL;
read_md_file = stdin;
read_md_filename = in_fname = "<stdin>"; read_md_filename = in_fname = "<stdin>";
read_md_lineno = 1; read_md_lineno = 1;
input_file = stdin;
already_read_stdin = true; already_read_stdin = true;
while (read_rtx (input_file, &desc, &lineno)) while (read_rtx (&desc, &lineno))
process_rtx (desc, lineno); process_rtx (desc, lineno);
fclose (input_file); fclose (read_md_file);
continue; continue;
} }
else if (argv[i][1] == '-' && argv[i][2] == '\0') else if (argv[i][1] == '-' && argv[i][2] == '\0')
...@@ -1018,18 +1020,18 @@ init_md_reader_args_cb (int argc, char **argv, bool (*parse_opt)(const char *)) ...@@ -1018,18 +1020,18 @@ init_md_reader_args_cb (int argc, char **argv, bool (*parse_opt)(const char *))
else else
base_dir = NULL; base_dir = NULL;
read_md_filename = in_fname; read_md_file = fopen (in_fname, "r");
read_md_lineno = 1; if (read_md_file == 0)
input_file = fopen (in_fname, "r");
if (input_file == 0)
{ {
perror (in_fname); perror (in_fname);
return FATAL_EXIT_CODE; return FATAL_EXIT_CODE;
} }
read_md_filename = in_fname;
read_md_lineno = 1;
while (read_rtx (input_file, &desc, &lineno)) while (read_rtx (&desc, &lineno))
process_rtx (desc, lineno); process_rtx (desc, lineno);
fclose (input_file); fclose (read_md_file);
} }
/* If we get to this point without having seen any files to process, /* If we get to this point without having seen any files to process,
...@@ -1037,13 +1039,13 @@ init_md_reader_args_cb (int argc, char **argv, bool (*parse_opt)(const char *)) ...@@ -1037,13 +1039,13 @@ init_md_reader_args_cb (int argc, char **argv, bool (*parse_opt)(const char *))
if (!in_fname) if (!in_fname)
{ {
base_dir = NULL; base_dir = NULL;
read_md_file = stdin;
read_md_filename = in_fname = "<stdin>"; read_md_filename = in_fname = "<stdin>";
read_md_lineno = 1; read_md_lineno = 1;
input_file = stdin;
while (read_rtx (input_file, &desc, &lineno)) while (read_rtx (&desc, &lineno))
process_rtx (desc, lineno); process_rtx (desc, lineno);
fclose (input_file); fclose (read_md_file);
} }
/* Process define_cond_exec patterns. */ /* Process define_cond_exec patterns. */
......
...@@ -52,11 +52,14 @@ static htab_t joined_conditions; ...@@ -52,11 +52,14 @@ static htab_t joined_conditions;
/* An obstack for allocating joined_conditions entries. */ /* An obstack for allocating joined_conditions entries. */
static struct obstack joined_conditions_obstack; static struct obstack joined_conditions_obstack;
/* The current line number for the file. */ /* The file we are reading. */
int read_md_lineno = 1; FILE *read_md_file;
/* The filename for error reporting. */ /* The filename of READ_MD_FILE. */
const char *read_md_filename = "<unknown>"; const char *read_md_filename;
/* The current line number in READ_MD_FILE. */
int read_md_lineno;
/* Return a hash value for the pointer pointed to by DEF. */ /* Return a hash value for the pointer pointed to by DEF. */
...@@ -189,10 +192,10 @@ message_with_line (int lineno, const char *msg, ...) ...@@ -189,10 +192,10 @@ message_with_line (int lineno, const char *msg, ...)
} }
/* A printf-like function for reporting an error against the current /* A printf-like function for reporting an error against the current
position in the MD file, which is associated with INFILE. */ position in the MD file. */
void void
fatal_with_file_and_line (FILE *infile, const char *msg, ...) fatal_with_file_and_line (const char *msg, ...)
{ {
char context[64]; char context[64];
size_t i; size_t i;
...@@ -208,7 +211,7 @@ fatal_with_file_and_line (FILE *infile, const char *msg, ...) ...@@ -208,7 +211,7 @@ fatal_with_file_and_line (FILE *infile, const char *msg, ...)
/* Gather some following context. */ /* Gather some following context. */
for (i = 0; i < sizeof (context)-1; ++i) for (i = 0; i < sizeof (context)-1; ++i)
{ {
c = getc (infile); c = read_char ();
if (c == EOF) if (c == EOF)
break; break;
if (c == '\r' || c == '\n') if (c == '\r' || c == '\n')
...@@ -225,31 +228,30 @@ fatal_with_file_and_line (FILE *infile, const char *msg, ...) ...@@ -225,31 +228,30 @@ fatal_with_file_and_line (FILE *infile, const char *msg, ...)
} }
/* Report that we found character ACTUAL when we expected to find /* Report that we found character ACTUAL when we expected to find
character EXPECTED. INFILE is the file handle associated character EXPECTED. */
with the current file. */
void void
fatal_expected_char (FILE *infile, int expected, int actual) fatal_expected_char (int expected, int actual)
{ {
if (actual == EOF) if (actual == EOF)
fatal_with_file_and_line (infile, "expected character `%c', found EOF", fatal_with_file_and_line ("expected character `%c', found EOF",
expected); expected);
else else
fatal_with_file_and_line (infile, "expected character `%c', found `%c'", fatal_with_file_and_line ("expected character `%c', found `%c'",
expected, actual); expected, actual);
} }
/* Read chars from INFILE until a non-whitespace char and return that. /* Read chars from the MD file until a non-whitespace char and return that.
Comments, both Lisp style and C style, are treated as whitespace. */ Comments, both Lisp style and C style, are treated as whitespace. */
int int
read_skip_spaces (FILE *infile) read_skip_spaces (void)
{ {
int c; int c;
while (1) while (1)
{ {
c = getc (infile); c = read_char ();
switch (c) switch (c)
{ {
case '\n': case '\n':
...@@ -261,7 +263,7 @@ read_skip_spaces (FILE *infile) ...@@ -261,7 +263,7 @@ read_skip_spaces (FILE *infile)
case ';': case ';':
do do
c = getc (infile); c = read_char ();
while (c != '\n' && c != EOF); while (c != '\n' && c != EOF);
read_md_lineno++; read_md_lineno++;
break; break;
...@@ -269,12 +271,12 @@ read_skip_spaces (FILE *infile) ...@@ -269,12 +271,12 @@ read_skip_spaces (FILE *infile)
case '/': case '/':
{ {
int prevc; int prevc;
c = getc (infile); c = read_char ();
if (c != '*') if (c != '*')
fatal_expected_char (infile, '*', c); fatal_expected_char ('*', c);
prevc = 0; prevc = 0;
while ((c = getc (infile)) && c != EOF) while ((c = read_char ()) && c != EOF)
{ {
if (c == '\n') if (c == '\n')
read_md_lineno++; read_md_lineno++;
...@@ -295,9 +297,9 @@ read_skip_spaces (FILE *infile) ...@@ -295,9 +297,9 @@ read_skip_spaces (FILE *infile)
Caller has read the backslash, but not placed it into the obstack. */ Caller has read the backslash, but not placed it into the obstack. */
static void static void
read_escape (FILE *infile) read_escape (void)
{ {
int c = getc (infile); int c = read_char ();
switch (c) switch (c)
{ {
...@@ -348,18 +350,18 @@ read_escape (FILE *infile) ...@@ -348,18 +350,18 @@ read_escape (FILE *infile)
the leading quote. */ the leading quote. */
char * char *
read_quoted_string (FILE *infile) read_quoted_string (void)
{ {
int c; int c;
while (1) while (1)
{ {
c = getc (infile); /* Read the string */ c = read_char (); /* Read the string */
if (c == '\n') if (c == '\n')
read_md_lineno++; read_md_lineno++;
else if (c == '\\') else if (c == '\\')
{ {
read_escape (infile); read_escape ();
continue; continue;
} }
else if (c == '"' || c == EOF) else if (c == '"' || c == EOF)
...@@ -377,7 +379,7 @@ read_quoted_string (FILE *infile) ...@@ -377,7 +379,7 @@ read_quoted_string (FILE *infile)
the outermost braces _are_ included in the string constant. */ the outermost braces _are_ included in the string constant. */
static char * static char *
read_braced_string (FILE *infile) read_braced_string (void)
{ {
int c; int c;
int brace_depth = 1; /* caller-processed */ int brace_depth = 1; /* caller-processed */
...@@ -386,7 +388,7 @@ read_braced_string (FILE *infile) ...@@ -386,7 +388,7 @@ read_braced_string (FILE *infile)
obstack_1grow (&string_obstack, '{'); obstack_1grow (&string_obstack, '{');
while (brace_depth) while (brace_depth)
{ {
c = getc (infile); /* Read the string */ c = read_char (); /* Read the string */
if (c == '\n') if (c == '\n')
read_md_lineno++; read_md_lineno++;
...@@ -396,12 +398,12 @@ read_braced_string (FILE *infile) ...@@ -396,12 +398,12 @@ read_braced_string (FILE *infile)
brace_depth--; brace_depth--;
else if (c == '\\') else if (c == '\\')
{ {
read_escape (infile); read_escape ();
continue; continue;
} }
else if (c == EOF) else if (c == EOF)
fatal_with_file_and_line fatal_with_file_and_line
(infile, "missing closing } for opening brace on line %lu", ("missing closing } for opening brace on line %lu",
starting_read_md_lineno); starting_read_md_lineno);
obstack_1grow (&string_obstack, c); obstack_1grow (&string_obstack, c);
...@@ -416,36 +418,36 @@ read_braced_string (FILE *infile) ...@@ -416,36 +418,36 @@ read_braced_string (FILE *infile)
and dispatch to the appropriate string constant reader. */ and dispatch to the appropriate string constant reader. */
char * char *
read_string (FILE *infile, int star_if_braced) read_string (int star_if_braced)
{ {
char *stringbuf; char *stringbuf;
int saw_paren = 0; int saw_paren = 0;
int c, old_lineno; int c, old_lineno;
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c == '(') if (c == '(')
{ {
saw_paren = 1; saw_paren = 1;
c = read_skip_spaces (infile); c = read_skip_spaces ();
} }
old_lineno = read_md_lineno; old_lineno = read_md_lineno;
if (c == '"') if (c == '"')
stringbuf = read_quoted_string (infile); stringbuf = read_quoted_string ();
else if (c == '{') else if (c == '{')
{ {
if (star_if_braced) if (star_if_braced)
obstack_1grow (&string_obstack, '*'); obstack_1grow (&string_obstack, '*');
stringbuf = read_braced_string (infile); stringbuf = read_braced_string ();
} }
else else
fatal_with_file_and_line (infile, "expected `\"' or `{', found `%c'", c); fatal_with_file_and_line ("expected `\"' or `{', found `%c'", c);
if (saw_paren) if (saw_paren)
{ {
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != ')') if (c != ')')
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
} }
set_md_ptr_loc (stringbuf, read_md_filename, old_lineno); set_md_ptr_loc (stringbuf, read_md_filename, old_lineno);
......
...@@ -21,21 +21,38 @@ along with GCC; see the file COPYING3. If not see ...@@ -21,21 +21,38 @@ along with GCC; see the file COPYING3. If not see
#include "obstack.h" #include "obstack.h"
extern FILE *read_md_file;
extern int read_md_lineno; extern int read_md_lineno;
extern const char *read_md_filename; extern const char *read_md_filename;
extern struct obstack string_obstack; extern struct obstack string_obstack;
/* Read the next character from the MD file. */
static inline int
read_char (void)
{
return getc (read_md_file);
}
/* Put back CH, which was the last character read from the MD file. */
static inline void
unread_char (int ch)
{
ungetc (ch, read_md_file);
}
extern void copy_md_ptr_loc (const void *, const void *); extern void copy_md_ptr_loc (const void *, const void *);
extern void print_md_ptr_loc (const void *); extern void print_md_ptr_loc (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 message_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2; extern void message_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2;
extern void fatal_with_file_and_line (FILE *, const char *, ...) extern void fatal_with_file_and_line (const char *, ...)
ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN; ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
extern void fatal_expected_char (FILE *, int, int) ATTRIBUTE_NORETURN; extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN;
extern int read_skip_spaces (FILE *); extern int read_skip_spaces (void);
extern char *read_quoted_string (FILE *); extern char *read_quoted_string (void);
extern char *read_string (FILE *, int); extern char *read_string (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 init_md_reader (void); extern void init_md_reader (void);
...@@ -2361,7 +2361,7 @@ extern void traverse_md_constants (int (*) (void **, void *), void *); ...@@ -2361,7 +2361,7 @@ extern void traverse_md_constants (int (*) (void **, void *), void *);
struct md_constant { char *name, *value; }; struct md_constant { char *name, *value; };
/* In read-rtl.c */ /* In read-rtl.c */
extern bool read_rtx (FILE *, rtx *, int *); extern bool read_rtx (rtx *, int *);
/* In alias.c */ /* In alias.c */
extern rtx canon_rtx (rtx); extern rtx canon_rtx (rtx);
......
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