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);
...@@ -70,8 +70,8 @@ struct iterator_group { ...@@ -70,8 +70,8 @@ struct iterator_group {
int num_builtins; int num_builtins;
/* Treat the given string as the name of a standard mode or code and /* Treat the given string as the name of a standard mode or code and
return its integer value. Use the given file for error reporting. */ return its integer value. */
int (*find_builtin) (const char *, FILE *); int (*find_builtin) (const char *);
/* Return true if the given rtx uses the given mode or code. */ /* Return true if the given rtx uses the given mode or code. */
bool (*uses_iterator_p) (rtx, int); bool (*uses_iterator_p) (rtx, int);
...@@ -87,8 +87,6 @@ struct iterator_traverse_data { ...@@ -87,8 +87,6 @@ struct iterator_traverse_data {
rtx queue; rtx queue;
/* Attributes seen for modes. */ /* Attributes seen for modes. */
struct map_value *mode_maps; struct map_value *mode_maps;
/* Input file. */
FILE *infile;
/* The last unknown attribute used as a mode. */ /* The last unknown attribute used as a mode. */
const char *unknown_mode_attr; const char *unknown_mode_attr;
}; };
...@@ -98,35 +96,35 @@ struct iterator_traverse_data { ...@@ -98,35 +96,35 @@ struct iterator_traverse_data {
#define BELLWETHER_CODE(CODE) \ #define BELLWETHER_CODE(CODE) \
((CODE) < NUM_RTX_CODE ? CODE : bellwether_codes[CODE - NUM_RTX_CODE]) ((CODE) < NUM_RTX_CODE ? CODE : bellwether_codes[CODE - NUM_RTX_CODE])
static int find_mode (const char *, FILE *); static int find_mode (const char *);
static bool uses_mode_iterator_p (rtx, int); static bool uses_mode_iterator_p (rtx, int);
static void apply_mode_iterator (rtx, int); static void apply_mode_iterator (rtx, int);
static int find_code (const char *, FILE *); static int find_code (const char *);
static bool uses_code_iterator_p (rtx, int); static bool uses_code_iterator_p (rtx, int);
static void apply_code_iterator (rtx, int); static void apply_code_iterator (rtx, int);
static const char *apply_iterator_to_string (const char *, struct mapping *, int); static const char *apply_iterator_to_string (const char *, struct mapping *, int);
static rtx apply_iterator_to_rtx (rtx, struct mapping *, int, static rtx apply_iterator_to_rtx (rtx, struct mapping *, int,
struct map_value *, FILE *, const char **); struct map_value *, const char **);
static bool uses_iterator_p (rtx, struct mapping *); static bool uses_iterator_p (rtx, struct mapping *);
static const char *add_condition_to_string (const char *, const char *); static const char *add_condition_to_string (const char *, const char *);
static void add_condition_to_rtx (rtx, const char *); static void add_condition_to_rtx (rtx, const char *);
static int apply_iterator_traverse (void **, void *); static int apply_iterator_traverse (void **, void *);
static struct mapping *add_mapping (struct iterator_group *, htab_t t, static struct mapping *add_mapping (struct iterator_group *, htab_t t,
const char *, FILE *); const char *);
static struct map_value **add_map_value (struct map_value **, static struct map_value **add_map_value (struct map_value **,
int, const char *); int, const char *);
static void initialize_iterators (void); static void initialize_iterators (void);
static void read_name (char *, FILE *); static void read_name (char *);
static hashval_t def_hash (const void *); static hashval_t def_hash (const void *);
static int def_name_eq_p (const void *, const void *); static int def_name_eq_p (const void *, const void *);
static void read_constants (FILE *infile, char *tmp_char); static void read_constants (char *tmp_char);
static void read_conditions (FILE *infile, char *tmp_char); static void read_conditions (char *tmp_char);
static void validate_const_int (FILE *, const char *); static void validate_const_int (const char *);
static int find_iterator (struct iterator_group *, const char *, FILE *); static int find_iterator (struct iterator_group *, const char *);
static struct mapping *read_mapping (struct iterator_group *, htab_t, FILE *); static struct mapping *read_mapping (struct iterator_group *, htab_t);
static void check_code_iterator (struct mapping *, FILE *); static void check_code_iterator (struct mapping *);
static rtx read_rtx_1 (FILE *, struct map_value **); static rtx read_rtx_1 (struct map_value **);
static rtx read_rtx_variadic (FILE *, struct map_value **, rtx); static rtx read_rtx_variadic (struct map_value **, rtx);
/* The mode and code iterator structures. */ /* The mode and code iterator structures. */
static struct iterator_group modes, codes; static struct iterator_group modes, codes;
...@@ -137,7 +135,7 @@ static enum rtx_code *bellwether_codes; ...@@ -137,7 +135,7 @@ static enum rtx_code *bellwether_codes;
/* Implementations of the iterator_group callbacks for modes. */ /* Implementations of the iterator_group callbacks for modes. */
static int static int
find_mode (const char *name, FILE *infile) find_mode (const char *name)
{ {
int i; int i;
...@@ -145,7 +143,7 @@ find_mode (const char *name, FILE *infile) ...@@ -145,7 +143,7 @@ find_mode (const char *name, FILE *infile)
if (strcmp (GET_MODE_NAME (i), name) == 0) if (strcmp (GET_MODE_NAME (i), name) == 0)
return i; return i;
fatal_with_file_and_line (infile, "unknown mode `%s'", name); fatal_with_file_and_line ("unknown mode `%s'", name);
} }
static bool static bool
...@@ -163,7 +161,7 @@ apply_mode_iterator (rtx x, int mode) ...@@ -163,7 +161,7 @@ apply_mode_iterator (rtx x, int mode)
/* Implementations of the iterator_group callbacks for codes. */ /* Implementations of the iterator_group callbacks for codes. */
static int static int
find_code (const char *name, FILE *infile) find_code (const char *name)
{ {
int i; int i;
...@@ -171,7 +169,7 @@ find_code (const char *name, FILE *infile) ...@@ -171,7 +169,7 @@ find_code (const char *name, FILE *infile)
if (strcmp (GET_RTX_NAME (i), name) == 0) if (strcmp (GET_RTX_NAME (i), name) == 0)
return i; return i;
fatal_with_file_and_line (infile, "unknown rtx code `%s'", name); fatal_with_file_and_line ("unknown rtx code `%s'", name);
} }
static bool static bool
...@@ -252,13 +250,12 @@ mode_attr_index (struct map_value **mode_maps, const char *string) ...@@ -252,13 +250,12 @@ mode_attr_index (struct map_value **mode_maps, const char *string)
/* Apply MODE_MAPS to the top level of X, expanding cases where an /* Apply MODE_MAPS to the top level of X, expanding cases where an
attribute is used for a mode. ITERATOR is the current iterator we are attribute is used for a mode. ITERATOR is the current iterator we are
expanding, and VALUE is the value to which we are expanding it. expanding, and VALUE is the value to which we are expanding it.
INFILE is used for error messages. This sets *UNKNOWN to true if This sets *UNKNOWN to true if we find a mode attribute which has not
we find a mode attribute which has not yet been defined, and does yet been defined, and does not change it otherwise. */
not change it otherwise. */
static void static void
apply_mode_maps (rtx x, struct map_value *mode_maps, struct mapping *iterator, apply_mode_maps (rtx x, struct map_value *mode_maps, struct mapping *iterator,
int value, FILE *infile, const char **unknown) int value, const char **unknown)
{ {
unsigned int offset; unsigned int offset;
int indx; int indx;
...@@ -277,7 +274,7 @@ apply_mode_maps (rtx x, struct map_value *mode_maps, struct mapping *iterator, ...@@ -277,7 +274,7 @@ apply_mode_maps (rtx x, struct map_value *mode_maps, struct mapping *iterator,
v = map_attr_string (pm->string, iterator, value); v = map_attr_string (pm->string, iterator, value);
if (v) if (v)
PUT_MODE (x, (enum machine_mode) find_mode (v->string, infile)); PUT_MODE (x, (enum machine_mode) find_mode (v->string));
else else
*unknown = pm->string; *unknown = pm->string;
return; return;
...@@ -327,13 +324,12 @@ apply_iterator_to_string (const char *string, struct mapping *iterator, int valu ...@@ -327,13 +324,12 @@ apply_iterator_to_string (const char *string, struct mapping *iterator, int valu
/* Return a copy of ORIGINAL in which all uses of ITERATOR have been /* Return a copy of ORIGINAL in which all uses of ITERATOR have been
replaced by VALUE. MODE_MAPS holds information about attribute replaced by VALUE. MODE_MAPS holds information about attribute
strings used for modes. INFILE is used for error messages. This strings used for modes. This sets *UNKNOWN_MODE_ATTR to the value of
sets *UNKNOWN_MODE_ATTR to the value of an unknown mode attribute, an unknown mode attribute, and does not change it otherwise. */
and does not change it otherwise. */
static rtx static rtx
apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value, apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value,
struct map_value *mode_maps, FILE *infile, struct map_value *mode_maps,
const char **unknown_mode_attr) const char **unknown_mode_attr)
{ {
struct iterator_group *group; struct iterator_group *group;
...@@ -356,7 +352,7 @@ apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value, ...@@ -356,7 +352,7 @@ apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value,
group->apply_iterator (x, value); group->apply_iterator (x, value);
if (mode_maps) if (mode_maps)
apply_mode_maps (x, mode_maps, iterator, value, infile, unknown_mode_attr); apply_mode_maps (x, mode_maps, iterator, value, unknown_mode_attr);
/* Change each string and recursively change each rtx. */ /* Change each string and recursively change each rtx. */
format_ptr = GET_RTX_FORMAT (bellwether_code); format_ptr = GET_RTX_FORMAT (bellwether_code);
...@@ -374,8 +370,7 @@ apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value, ...@@ -374,8 +370,7 @@ apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value,
case 'e': case 'e':
XEXP (x, i) = apply_iterator_to_rtx (XEXP (x, i), iterator, value, XEXP (x, i) = apply_iterator_to_rtx (XEXP (x, i), iterator, value,
mode_maps, infile, mode_maps, unknown_mode_attr);
unknown_mode_attr);
break; break;
case 'V': case 'V':
...@@ -386,7 +381,6 @@ apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value, ...@@ -386,7 +381,6 @@ apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value,
for (j = 0; j < XVECLEN (x, i); j++) for (j = 0; j < XVECLEN (x, i); j++)
XVECEXP (x, i, j) = apply_iterator_to_rtx (XVECEXP (original, i, j), XVECEXP (x, i, j) = apply_iterator_to_rtx (XVECEXP (original, i, j),
iterator, value, mode_maps, iterator, value, mode_maps,
infile,
unknown_mode_attr); unknown_mode_attr);
} }
break; break;
...@@ -505,7 +499,7 @@ apply_iterator_traverse (void **slot, void *data) ...@@ -505,7 +499,7 @@ apply_iterator_traverse (void **slot, void *data)
for (v = iterator->values; v != 0; v = v->next) for (v = iterator->values; v != 0; v = v->next)
{ {
x = apply_iterator_to_rtx (original, iterator, v->number, x = apply_iterator_to_rtx (original, iterator, v->number,
mtd->mode_maps, mtd->infile, mtd->mode_maps,
&mtd->unknown_mode_attr); &mtd->unknown_mode_attr);
add_condition_to_rtx (x, v->string); add_condition_to_rtx (x, v->string);
if (v != iterator->values) if (v != iterator->values)
...@@ -524,12 +518,10 @@ apply_iterator_traverse (void **slot, void *data) ...@@ -524,12 +518,10 @@ apply_iterator_traverse (void **slot, void *data)
} }
/* Add a new "mapping" structure to hashtable TABLE. NAME is the name /* Add a new "mapping" structure to hashtable TABLE. NAME is the name
of the mapping, GROUP is the group to which it belongs, and INFILE of the mapping and GROUP is the group to which it belongs. */
is the file that defined the mapping. */
static struct mapping * static struct mapping *
add_mapping (struct iterator_group *group, htab_t table, add_mapping (struct iterator_group *group, htab_t table, const char *name)
const char *name, FILE *infile)
{ {
struct mapping *m; struct mapping *m;
void **slot; void **slot;
...@@ -542,7 +534,7 @@ add_mapping (struct iterator_group *group, htab_t table, ...@@ -542,7 +534,7 @@ add_mapping (struct iterator_group *group, htab_t table,
slot = htab_find_slot (table, m, INSERT); slot = htab_find_slot (table, m, INSERT);
if (*slot != 0) if (*slot != 0)
fatal_with_file_and_line (infile, "`%s' already defined", name); fatal_with_file_and_line ("`%s' already defined", name);
*slot = m; *slot = m;
return m; return m;
...@@ -590,8 +582,8 @@ initialize_iterators (void) ...@@ -590,8 +582,8 @@ initialize_iterators (void)
codes.uses_iterator_p = uses_code_iterator_p; codes.uses_iterator_p = uses_code_iterator_p;
codes.apply_iterator = apply_code_iterator; codes.apply_iterator = apply_code_iterator;
lower = add_mapping (&modes, modes.attrs, "mode", 0); lower = add_mapping (&modes, modes.attrs, "mode");
upper = add_mapping (&modes, modes.attrs, "MODE", 0); upper = add_mapping (&modes, modes.attrs, "MODE");
lower_ptr = &lower->values; lower_ptr = &lower->values;
upper_ptr = &upper->values; upper_ptr = &upper->values;
for (i = 0; i < MAX_MACHINE_MODE; i++) for (i = 0; i < MAX_MACHINE_MODE; i++)
...@@ -604,8 +596,8 @@ initialize_iterators (void) ...@@ -604,8 +596,8 @@ initialize_iterators (void)
lower_ptr = add_map_value (lower_ptr, i, copy); lower_ptr = add_map_value (lower_ptr, i, copy);
} }
lower = add_mapping (&codes, codes.attrs, "code", 0); lower = add_mapping (&codes, codes.attrs, "code");
upper = add_mapping (&codes, codes.attrs, "CODE", 0); upper = add_mapping (&codes, codes.attrs, "CODE");
lower_ptr = &lower->values; lower_ptr = &lower->values;
upper_ptr = &upper->values; upper_ptr = &upper->values;
for (i = 0; i < NUM_RTX_CODE; i++) for (i = 0; i < NUM_RTX_CODE; i++)
...@@ -623,12 +615,12 @@ initialize_iterators (void) ...@@ -623,12 +615,12 @@ initialize_iterators (void)
It is terminated by any of the punctuation chars of rtx printed syntax. */ It is terminated by any of the punctuation chars of rtx printed syntax. */
static void static void
read_name (char *str, FILE *infile) read_name (char *str)
{ {
char *p; char *p;
int c; int c;
c = read_skip_spaces (infile); c = read_skip_spaces ();
p = str; p = str;
while (1) while (1)
...@@ -638,14 +630,14 @@ read_name (char *str, FILE *infile) ...@@ -638,14 +630,14 @@ read_name (char *str, FILE *infile)
if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/' if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/'
|| c == '(' || c == '[') || c == '(' || c == '[')
{ {
ungetc (c, infile); unread_char (c);
break; break;
} }
*p++ = c; *p++ = c;
c = getc (infile); c = read_char ();
} }
if (p == str) if (p == str)
fatal_with_file_and_line (infile, "missing name or number"); fatal_with_file_and_line ("missing name or number");
if (c == '\n') if (c == '\n')
read_md_lineno++; read_md_lineno++;
...@@ -731,39 +723,37 @@ def_name_eq_p (const void *def1, const void *def2) ...@@ -731,39 +723,37 @@ def_name_eq_p (const void *def1, const void *def2)
*(const char *const *) def2); *(const char *const *) def2);
} }
/* INFILE is a FILE pointer to read text from. TMP_CHAR is a buffer suitable /* TMP_CHAR is a buffer suitable to read a name or number into. Process
to read a name or number into. Process a define_constants directive, a define_constants directive, starting with the optional space after
starting with the optional space after the "define_constants". */ the "define_constants". */
static void static void
read_constants (FILE *infile, char *tmp_char) read_constants (char *tmp_char)
{ {
int c; int c;
htab_t defs; htab_t defs;
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != '[') if (c != '[')
fatal_expected_char (infile, '[', c); fatal_expected_char ('[', c);
defs = md_constants; defs = md_constants;
if (! defs) if (! defs)
defs = htab_create (32, def_hash, def_name_eq_p, (htab_del) 0); defs = htab_create (32, def_hash, def_name_eq_p, (htab_del) 0);
/* Disable constant expansion during definition processing. */ /* Disable constant expansion during definition processing. */
md_constants = 0; md_constants = 0;
while ( (c = read_skip_spaces (infile)) != ']') while ( (c = read_skip_spaces ()) != ']')
{ {
struct md_constant *def; struct md_constant *def;
void **entry_ptr; void **entry_ptr;
if (c != '(') if (c != '(')
fatal_expected_char (infile, '(', c); fatal_expected_char ('(', c);
def = XNEW (struct md_constant); def = XNEW (struct md_constant);
def->name = tmp_char; def->name = tmp_char;
read_name (tmp_char, infile); read_name (tmp_char);
entry_ptr = htab_find_slot (defs, def, INSERT); entry_ptr = htab_find_slot (defs, def, INSERT);
if (! *entry_ptr) if (! *entry_ptr)
def->name = xstrdup (tmp_char); def->name = xstrdup (tmp_char);
c = read_skip_spaces (infile); read_name (tmp_char);
ungetc (c, infile);
read_name (tmp_char, infile);
if (! *entry_ptr) if (! *entry_ptr)
{ {
def->value = xstrdup (tmp_char); def->value = xstrdup (tmp_char);
...@@ -773,18 +763,17 @@ read_constants (FILE *infile, char *tmp_char) ...@@ -773,18 +763,17 @@ read_constants (FILE *infile, char *tmp_char)
{ {
def = (struct md_constant *) *entry_ptr; def = (struct md_constant *) *entry_ptr;
if (strcmp (def->value, tmp_char)) if (strcmp (def->value, tmp_char))
fatal_with_file_and_line (infile, fatal_with_file_and_line ("redefinition of %s, was %s, now %s",
"redefinition of %s, was %s, now %s",
def->name, def->value, tmp_char); def->name, def->value, tmp_char);
} }
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != ')') if (c != ')')
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
} }
md_constants = defs; md_constants = defs;
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != ')') if (c != ')')
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
} }
/* For every constant definition, call CALLBACK with two arguments: /* For every constant definition, call CALLBACK with two arguments:
...@@ -797,9 +786,8 @@ traverse_md_constants (htab_trav callback, void *info) ...@@ -797,9 +786,8 @@ traverse_md_constants (htab_trav callback, void *info)
htab_traverse (md_constants, callback, info); htab_traverse (md_constants, callback, info);
} }
/* INFILE is a FILE pointer to read text from. TMP_CHAR is a buffer /* TMP_CHAR is a buffer suitable to read a name or number into. Process
suitable to read a name or number into. Process a a define_conditions directive, starting with the optional space after
define_conditions directive, starting with the optional space after
the "define_conditions". The directive looks like this: the "define_conditions". The directive looks like this:
(define_conditions [ (define_conditions [
...@@ -813,44 +801,44 @@ traverse_md_constants (htab_trav callback, void *info) ...@@ -813,44 +801,44 @@ traverse_md_constants (htab_trav callback, void *info)
slipped in at the beginning of the sequence of MD files read by slipped in at the beginning of the sequence of MD files read by
most of the other generators. */ most of the other generators. */
static void static void
read_conditions (FILE *infile, char *tmp_char) read_conditions (char *tmp_char)
{ {
int c; int c;
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != '[') if (c != '[')
fatal_expected_char (infile, '[', c); fatal_expected_char ('[', c);
while ( (c = read_skip_spaces (infile)) != ']') while ( (c = read_skip_spaces ()) != ']')
{ {
char *expr; char *expr;
int value; int value;
if (c != '(') if (c != '(')
fatal_expected_char (infile, '(', c); fatal_expected_char ('(', c);
read_name (tmp_char, infile); read_name (tmp_char);
validate_const_int (infile, tmp_char); validate_const_int (tmp_char);
value = atoi (tmp_char); value = atoi (tmp_char);
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != '"') if (c != '"')
fatal_expected_char (infile, '"', c); fatal_expected_char ('"', c);
expr = read_quoted_string (infile); expr = read_quoted_string ();
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != ')') if (c != ')')
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
add_c_test (expr, value); add_c_test (expr, value);
} }
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != ')') if (c != ')')
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
} }
static void static void
validate_const_int (FILE *infile, const char *string) validate_const_int (const char *string)
{ {
const char *cp; const char *cp;
int valid = 1; int valid = 1;
...@@ -866,35 +854,35 @@ validate_const_int (FILE *infile, const char *string) ...@@ -866,35 +854,35 @@ validate_const_int (FILE *infile, const char *string)
if (! ISDIGIT (*cp)) if (! ISDIGIT (*cp))
valid = 0; valid = 0;
if (!valid) if (!valid)
fatal_with_file_and_line (infile, "invalid decimal constant \"%s\"\n", string); fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string);
} }
/* Search GROUP for a mode or code called NAME and return its numerical /* Search GROUP for a mode or code called NAME and return its numerical
identifier. INFILE is the file that contained NAME. */ identifier. */
static int static int
find_iterator (struct iterator_group *group, const char *name, FILE *infile) find_iterator (struct iterator_group *group, const char *name)
{ {
struct mapping *m; struct mapping *m;
m = (struct mapping *) htab_find (group->iterators, &name); m = (struct mapping *) htab_find (group->iterators, &name);
if (m != 0) if (m != 0)
return m->index + group->num_builtins; return m->index + group->num_builtins;
return group->find_builtin (name, infile); return group->find_builtin (name);
} }
/* Finish reading a declaration of the form: /* Finish reading a declaration of the form:
(define... <name> [<value1> ... <valuen>]) (define... <name> [<value1> ... <valuen>])
from INFILE, where each <valuei> is either a bare symbol name or a from the MD file, where each <valuei> is either a bare symbol name or a
"(<name> <string>)" pair. The "(define..." part has already been read. "(<name> <string>)" pair. The "(define..." part has already been read.
Represent the declaration as a "mapping" structure; add it to TABLE Represent the declaration as a "mapping" structure; add it to TABLE
(which belongs to GROUP) and return it. */ (which belongs to GROUP) and return it. */
static struct mapping * static struct mapping *
read_mapping (struct iterator_group *group, htab_t table, FILE *infile) read_mapping (struct iterator_group *group, htab_t table)
{ {
char tmp_char[256]; char tmp_char[256];
struct mapping *m; struct mapping *m;
...@@ -903,44 +891,44 @@ read_mapping (struct iterator_group *group, htab_t table, FILE *infile) ...@@ -903,44 +891,44 @@ read_mapping (struct iterator_group *group, htab_t table, FILE *infile)
int number, c; int number, c;
/* Read the mapping name and create a structure for it. */ /* Read the mapping name and create a structure for it. */
read_name (tmp_char, infile); read_name (tmp_char);
m = add_mapping (group, table, tmp_char, infile); m = add_mapping (group, table, tmp_char);
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != '[') if (c != '[')
fatal_expected_char (infile, '[', c); fatal_expected_char ('[', c);
/* Read each value. */ /* Read each value. */
end_ptr = &m->values; end_ptr = &m->values;
c = read_skip_spaces (infile); c = read_skip_spaces ();
do do
{ {
if (c != '(') if (c != '(')
{ {
/* A bare symbol name that is implicitly paired to an /* A bare symbol name that is implicitly paired to an
empty string. */ empty string. */
ungetc (c, infile); unread_char (c);
read_name (tmp_char, infile); read_name (tmp_char);
string = ""; string = "";
} }
else else
{ {
/* A "(name string)" pair. */ /* A "(name string)" pair. */
read_name (tmp_char, infile); read_name (tmp_char);
string = read_string (infile, false); string = read_string (false);
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != ')') if (c != ')')
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
} }
number = group->find_builtin (tmp_char, infile); number = group->find_builtin (tmp_char);
end_ptr = add_map_value (end_ptr, number, string); end_ptr = add_map_value (end_ptr, number, string);
c = read_skip_spaces (infile); c = read_skip_spaces ();
} }
while (c != ']'); while (c != ']');
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != ')') if (c != ')')
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
return m; return m;
} }
...@@ -949,7 +937,7 @@ read_mapping (struct iterator_group *group, htab_t table, FILE *infile) ...@@ -949,7 +937,7 @@ read_mapping (struct iterator_group *group, htab_t table, FILE *infile)
same format. Initialize the iterator's entry in bellwether_codes. */ same format. Initialize the iterator's entry in bellwether_codes. */
static void static void
check_code_iterator (struct mapping *iterator, FILE *infile) check_code_iterator (struct mapping *iterator)
{ {
struct map_value *v; struct map_value *v;
enum rtx_code bellwether; enum rtx_code bellwether;
...@@ -957,7 +945,7 @@ check_code_iterator (struct mapping *iterator, FILE *infile) ...@@ -957,7 +945,7 @@ check_code_iterator (struct mapping *iterator, FILE *infile)
bellwether = (enum rtx_code) iterator->values->number; bellwether = (enum rtx_code) iterator->values->number;
for (v = iterator->values->next; v != 0; v = v->next) for (v = iterator->values->next; v != 0; v = v->next)
if (strcmp (GET_RTX_FORMAT (bellwether), GET_RTX_FORMAT (v->number)) != 0) if (strcmp (GET_RTX_FORMAT (bellwether), GET_RTX_FORMAT (v->number)) != 0)
fatal_with_file_and_line (infile, "code iterator `%s' combines " fatal_with_file_and_line ("code iterator `%s' combines "
"different rtx formats", iterator->name); "different rtx formats", iterator->name);
bellwether_codes = XRESIZEVEC (enum rtx_code, bellwether_codes, bellwether_codes = XRESIZEVEC (enum rtx_code, bellwether_codes,
...@@ -965,8 +953,8 @@ check_code_iterator (struct mapping *iterator, FILE *infile) ...@@ -965,8 +953,8 @@ check_code_iterator (struct mapping *iterator, FILE *infile)
bellwether_codes[iterator->index] = bellwether; bellwether_codes[iterator->index] = bellwether;
} }
/* Read an rtx in printed representation from INFILE and store its /* Read an rtx in printed representation from the MD file and store
core representation in *X. Also store the line number of the its core representation in *X. Also store the line number of the
opening '(' in *LINENO. Return true on success or false if the opening '(' in *LINENO. Return true on success or false if the
end of file has been reached. end of file has been reached.
...@@ -974,7 +962,7 @@ check_code_iterator (struct mapping *iterator, FILE *infile) ...@@ -974,7 +962,7 @@ check_code_iterator (struct mapping *iterator, FILE *infile)
the utilities gen*.c that construct C code from machine descriptions. */ the utilities gen*.c that construct C code from machine descriptions. */
bool bool
read_rtx (FILE *infile, rtx *x, int *lineno) read_rtx (rtx *x, int *lineno)
{ {
static rtx queue_head, queue_next; static rtx queue_head, queue_next;
static int queue_lineno; static int queue_lineno;
...@@ -994,14 +982,14 @@ read_rtx (FILE *infile, rtx *x, int *lineno) ...@@ -994,14 +982,14 @@ read_rtx (FILE *infile, rtx *x, int *lineno)
struct iterator_traverse_data mtd; struct iterator_traverse_data mtd;
rtx from_file; rtx from_file;
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c == EOF) if (c == EOF)
return false; return false;
ungetc (c, infile); unread_char (c);
queue_lineno = read_md_lineno; queue_lineno = read_md_lineno;
mode_maps = 0; mode_maps = 0;
from_file = read_rtx_1 (infile, &mode_maps); from_file = read_rtx_1 (&mode_maps);
if (from_file == 0) if (from_file == 0)
return false; /* This confuses a top level (nil) with end of return false; /* This confuses a top level (nil) with end of
file, but a top level (nil) would have file, but a top level (nil) would have
...@@ -1013,13 +1001,11 @@ read_rtx (FILE *infile, rtx *x, int *lineno) ...@@ -1013,13 +1001,11 @@ read_rtx (FILE *infile, rtx *x, int *lineno)
mtd.queue = queue_next; mtd.queue = queue_next;
mtd.mode_maps = mode_maps; mtd.mode_maps = mode_maps;
mtd.infile = infile;
mtd.unknown_mode_attr = mode_maps ? mode_maps->string : NULL; mtd.unknown_mode_attr = mode_maps ? mode_maps->string : NULL;
htab_traverse (modes.iterators, apply_iterator_traverse, &mtd); htab_traverse (modes.iterators, apply_iterator_traverse, &mtd);
htab_traverse (codes.iterators, apply_iterator_traverse, &mtd); htab_traverse (codes.iterators, apply_iterator_traverse, &mtd);
if (mtd.unknown_mode_attr) if (mtd.unknown_mode_attr)
fatal_with_file_and_line (infile, fatal_with_file_and_line ("undefined attribute '%s' used for mode",
"undefined attribute '%s' used for mode",
mtd.unknown_mode_attr); mtd.unknown_mode_attr);
} }
...@@ -1030,11 +1016,11 @@ read_rtx (FILE *infile, rtx *x, int *lineno) ...@@ -1030,11 +1016,11 @@ read_rtx (FILE *infile, rtx *x, int *lineno)
return true; return true;
} }
/* Subroutine of read_rtx that reads one construct from INFILE but /* Subroutine of read_rtx that reads one construct from the MD file but
doesn't apply any iterators. */ doesn't apply any iterators. */
static rtx static rtx
read_rtx_1 (FILE *infile, struct map_value **mode_maps) read_rtx_1 (struct map_value **mode_maps)
{ {
int i; int i;
RTX_CODE real_code, bellwether_code; RTX_CODE real_code, bellwether_code;
...@@ -1056,55 +1042,54 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1056,55 +1042,54 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
}; };
again: again:
c = read_skip_spaces (infile); /* Should be open paren. */ c = read_skip_spaces (); /* Should be open paren. */
if (c == EOF) if (c == EOF)
return 0; return 0;
if (c != '(') if (c != '(')
fatal_expected_char (infile, '(', c); fatal_expected_char ('(', c);
read_name (tmp_char, infile); read_name (tmp_char);
if (strcmp (tmp_char, "nil") == 0) if (strcmp (tmp_char, "nil") == 0)
{ {
/* (nil) stands for an expression that isn't there. */ /* (nil) stands for an expression that isn't there. */
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != ')') if (c != ')')
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
return 0; return 0;
} }
if (strcmp (tmp_char, "define_constants") == 0) if (strcmp (tmp_char, "define_constants") == 0)
{ {
read_constants (infile, tmp_char); read_constants (tmp_char);
goto again; goto again;
} }
if (strcmp (tmp_char, "define_conditions") == 0) if (strcmp (tmp_char, "define_conditions") == 0)
{ {
read_conditions (infile, tmp_char); read_conditions (tmp_char);
goto again; goto again;
} }
if (strcmp (tmp_char, "define_mode_attr") == 0) if (strcmp (tmp_char, "define_mode_attr") == 0)
{ {
read_mapping (&modes, modes.attrs, infile); read_mapping (&modes, modes.attrs);
goto again; goto again;
} }
if (strcmp (tmp_char, "define_mode_iterator") == 0) if (strcmp (tmp_char, "define_mode_iterator") == 0)
{ {
read_mapping (&modes, modes.iterators, infile); read_mapping (&modes, modes.iterators);
goto again; goto again;
} }
if (strcmp (tmp_char, "define_code_attr") == 0) if (strcmp (tmp_char, "define_code_attr") == 0)
{ {
read_mapping (&codes, codes.attrs, infile); read_mapping (&codes, codes.attrs);
goto again; goto again;
} }
if (strcmp (tmp_char, "define_code_iterator") == 0) if (strcmp (tmp_char, "define_code_iterator") == 0)
{ {
check_code_iterator (read_mapping (&codes, codes.iterators, infile), check_code_iterator (read_mapping (&codes, codes.iterators));
infile);
goto again; goto again;
} }
real_code = (enum rtx_code) find_iterator (&codes, tmp_char, infile); real_code = (enum rtx_code) find_iterator (&codes, tmp_char);
bellwether_code = BELLWETHER_CODE (real_code); bellwether_code = BELLWETHER_CODE (real_code);
/* If we end up with an insn expression then we free this space below. */ /* If we end up with an insn expression then we free this space below. */
...@@ -1115,22 +1100,22 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1115,22 +1100,22 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
/* If what follows is `: mode ', read it and /* If what follows is `: mode ', read it and
store the mode in the rtx. */ store the mode in the rtx. */
i = read_skip_spaces (infile); i = read_skip_spaces ();
if (i == ':') if (i == ':')
{ {
unsigned int mode; unsigned int mode;
read_name (tmp_char, infile); read_name (tmp_char);
if (tmp_char[0] != '<' || tmp_char[strlen (tmp_char) - 1] != '>') if (tmp_char[0] != '<' || tmp_char[strlen (tmp_char) - 1] != '>')
mode = find_iterator (&modes, tmp_char, infile); mode = find_iterator (&modes, tmp_char);
else else
mode = mode_attr_index (mode_maps, tmp_char); mode = mode_attr_index (mode_maps, tmp_char);
PUT_MODE (return_rtx, (enum machine_mode) mode); PUT_MODE (return_rtx, (enum machine_mode) mode);
if (GET_MODE (return_rtx) != mode) if (GET_MODE (return_rtx) != mode)
fatal_with_file_and_line (infile, "mode too large"); fatal_with_file_and_line ("mode too large");
} }
else else
ungetc (i, infile); unread_char (i);
for (i = 0; format_ptr[i] != 0; i++) for (i = 0; format_ptr[i] != 0; i++)
switch (format_ptr[i]) switch (format_ptr[i])
...@@ -1142,14 +1127,14 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1142,14 +1127,14 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
case 'e': case 'e':
case 'u': case 'u':
XEXP (return_rtx, i) = read_rtx_1 (infile, mode_maps); XEXP (return_rtx, i) = read_rtx_1 (mode_maps);
break; break;
case 'V': case 'V':
/* 'V' is an optional vector: if a closeparen follows, /* 'V' is an optional vector: if a closeparen follows,
just store NULL for this element. */ just store NULL for this element. */
c = read_skip_spaces (infile); c = read_skip_spaces ();
ungetc (c, infile); unread_char (c);
if (c == ')') if (c == ')')
{ {
XVEC (return_rtx, i) = 0; XVEC (return_rtx, i) = 0;
...@@ -1164,19 +1149,19 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1164,19 +1149,19 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
int list_counter = 0; int list_counter = 0;
rtvec return_vec = NULL_RTVEC; rtvec return_vec = NULL_RTVEC;
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != '[') if (c != '[')
fatal_expected_char (infile, '[', c); fatal_expected_char ('[', c);
/* Add expressions to a list, while keeping a count. */ /* Add expressions to a list, while keeping a count. */
obstack_init (&vector_stack); obstack_init (&vector_stack);
while ((c = read_skip_spaces (infile)) && c != ']') while ((c = read_skip_spaces ()) && c != ']')
{ {
if (c == EOF) if (c == EOF)
fatal_expected_char (infile, ']', c); fatal_expected_char (']', c);
ungetc (c, infile); unread_char (c);
list_counter++; list_counter++;
obstack_ptr_grow (&vector_stack, read_rtx_1 (infile, mode_maps)); obstack_ptr_grow (&vector_stack, read_rtx_1 (mode_maps));
} }
if (list_counter > 0) if (list_counter > 0)
{ {
...@@ -1185,8 +1170,7 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1185,8 +1170,7 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
list_counter * sizeof (rtx)); list_counter * sizeof (rtx));
} }
else if (format_ptr[i] == 'E') else if (format_ptr[i] == 'E')
fatal_with_file_and_line (infile, fatal_with_file_and_line ("vector must have at least one element");
"vector must have at least one element");
XVEC (return_rtx, i) = return_vec; XVEC (return_rtx, i) = return_vec;
obstack_free (&vector_stack, NULL); obstack_free (&vector_stack, NULL);
/* close bracket gotten */ /* close bracket gotten */
...@@ -1200,8 +1184,8 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1200,8 +1184,8 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
char *stringbuf; char *stringbuf;
int star_if_braced; int star_if_braced;
c = read_skip_spaces (infile); c = read_skip_spaces ();
ungetc (c, infile); unread_char (c);
if (c == ')') if (c == ')')
{ {
/* 'S' fields are optional and should be NULL if no string /* 'S' fields are optional and should be NULL if no string
...@@ -1217,7 +1201,7 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1217,7 +1201,7 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
written with a brace block instead of a string constant. */ written with a brace block instead of a string constant. */
star_if_braced = (format_ptr[i] == 'T'); star_if_braced = (format_ptr[i] == 'T');
stringbuf = read_string (infile, star_if_braced); stringbuf = read_string (star_if_braced);
/* For insn patterns, we want to provide a default name /* For insn patterns, we want to provide a default name
based on the file and line, like "*foo.md:12", if the based on the file and line, like "*foo.md:12", if the
...@@ -1249,8 +1233,8 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1249,8 +1233,8 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
break; break;
case 'w': case 'w':
read_name (tmp_char, infile); read_name (tmp_char);
validate_const_int (infile, tmp_char); validate_const_int (tmp_char);
#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
tmp_wide = atoi (tmp_char); tmp_wide = atoi (tmp_char);
#else #else
...@@ -1271,8 +1255,8 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1271,8 +1255,8 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
case 'i': case 'i':
case 'n': case 'n':
read_name (tmp_char, infile); read_name (tmp_char);
validate_const_int (infile, tmp_char); validate_const_int (tmp_char);
tmp_int = atoi (tmp_char); tmp_int = atoi (tmp_char);
XINT (return_rtx, i) = tmp_int; XINT (return_rtx, i) = tmp_int;
break; break;
...@@ -1281,16 +1265,16 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1281,16 +1265,16 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
gcc_unreachable (); gcc_unreachable ();
} }
c = read_skip_spaces (infile); c = read_skip_spaces ();
if (c != ')') if (c != ')')
{ {
/* Syntactic sugar for AND and IOR, allowing Lisp-like /* Syntactic sugar for AND and IOR, allowing Lisp-like
arbitrary number of arguments for them. */ arbitrary number of arguments for them. */
if (c == '(' && (GET_CODE (return_rtx) == AND if (c == '(' && (GET_CODE (return_rtx) == AND
|| GET_CODE (return_rtx) == IOR)) || GET_CODE (return_rtx) == IOR))
return read_rtx_variadic (infile, mode_maps, return_rtx); return read_rtx_variadic (mode_maps, return_rtx);
else else
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
} }
return return_rtx; return return_rtx;
...@@ -1303,29 +1287,29 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps) ...@@ -1303,29 +1287,29 @@ read_rtx_1 (FILE *infile, struct map_value **mode_maps)
is just past the leading parenthesis of x3. Only works is just past the leading parenthesis of x3. Only works
for THINGs which are dyadic expressions, e.g. AND, IOR. */ for THINGs which are dyadic expressions, e.g. AND, IOR. */
static rtx static rtx
read_rtx_variadic (FILE *infile, struct map_value **mode_maps, rtx form) read_rtx_variadic (struct map_value **mode_maps, rtx form)
{ {
char c = '('; char c = '(';
rtx p = form, q; rtx p = form, q;
do do
{ {
ungetc (c, infile); unread_char (c);
q = rtx_alloc (GET_CODE (p)); q = rtx_alloc (GET_CODE (p));
PUT_MODE (q, GET_MODE (p)); PUT_MODE (q, GET_MODE (p));
XEXP (q, 0) = XEXP (p, 1); XEXP (q, 0) = XEXP (p, 1);
XEXP (q, 1) = read_rtx_1 (infile, mode_maps); XEXP (q, 1) = read_rtx_1 (mode_maps);
XEXP (p, 1) = q; XEXP (p, 1) = q;
p = q; p = q;
c = read_skip_spaces (infile); c = read_skip_spaces ();
} }
while (c == '('); while (c == '(');
if (c != ')') if (c != ')')
fatal_expected_char (infile, ')', c); fatal_expected_char (')', c);
return form; return form;
} }
...@@ -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