Commit a96d1f1d by David Malcolm Committed by David Malcolm

Split class rtx_reader into md_reader vs rtx_reader

This moves read_rtx and friends into rtx_reader, and splits
rtx_reader into two classes:

class md_reader: has responsibility for reading chars, managing
include files, top-level directives etc.  It is the read-md.o part.

class rtx_reader, a subclass, has the code for reading hierarchical
rtx expressions using the format codes.   It is the read-rtl.o part.

This split is needed by a followup patch, which converts
read_rtx_operand to a virtual function of rtx_reader.  To do this,
instances of rtx_reader (or its subclasses) need a vtable, which
needs to include a ptr to the code in read-rtl.o.  Splitting it up
allows the gen* tools that currently purely use read-md.o to continue
to do so.

gcc/ChangeLog:
	* genpreds.c (write_tm_constrs_h): Update for renaming of
	rtx_reader_ptr to md_reader_ptr.
	(write_tm_preds_h): Likewise.
	(write_insn_preds_c): Likewise.
	* read-md.c (rtx_reader_ptr): Rename to...
	(md_reader_ptr): ...this, and convert from an
	rtx_reader * to a md_reader *.
	(rtx_reader::set_md_ptr_loc): Rename to...
	(md_reader::set_md_ptr_loc): ...this.
	(rtx_reader::get_md_ptr_loc): Rename to...
	(md_reader::get_md_ptr_loc): ...this.
	(rtx_reader::copy_md_ptr_loc): Rename to...
	(md_reader::copy_md_ptr_loc): ...this.
	(rtx_reader::fprint_md_ptr_loc): Rename to...
	(md_reader::fprint_md_ptr_loc): ...this.
	(rtx_reader::print_md_ptr_loc): Rename to...
	(md_reader::print_md_ptr_loc): ...this.
	(rtx_reader::join_c_conditions): Rename to...
	(md_reader::join_c_conditions): ...this.
	(rtx_reader::fprint_c_condition): ...this.
	(rtx_reader::print_c_condition): Rename to...
	(md_reader::print_c_condition): ...this.
	(fatal_with_file_and_line):  Update for renaming of
	rtx_reader_ptr to md_reader_ptr.
	(rtx_reader::require_char): Rename to...
	(md_reader::require_char): ...this.
	(rtx_reader::require_char_ws): Rename to...
	(md_reader::require_char_ws): ...this.
	(rtx_reader::require_word_ws): Rename to...
	(md_reader::require_word_ws): ...this.
	(rtx_reader::read_char): Rename to...
	(md_reader::read_char): ...this.
	(rtx_reader::unread_char): Rename to...
	(md_reader::unread_char): ...this.
	(rtx_reader::peek_char): Rename to...
	(md_reader::peek_char): ...this.
	(rtx_reader::read_name): Rename to...
	(md_reader::read_name): ...this.
	(rtx_reader::read_escape): Rename to...
	(md_reader::read_escape): ...this.
	(rtx_reader::read_quoted_string): Rename to...
	(md_reader::read_quoted_string): ...this.
	(rtx_reader::read_braced_string): Rename to...
	(md_reader::read_braced_string): ...this.
	(rtx_reader::read_string): Rename to...
	(md_reader::read_string): ...this.
	(rtx_reader::read_skip_construct): Rename to...
	(md_reader::read_skip_construct): ...this.
	(rtx_reader::handle_constants): Rename to...
	(md_reader::handle_constants): ...this.
	(rtx_reader::traverse_md_constants): Rename to...
	(md_reader::traverse_md_constants): ...this.
	(rtx_reader::handle_enum): Rename to...
	(md_reader::handle_enum): ...this.
	(rtx_reader::lookup_enum_type): Rename to...
	(md_reader::lookup_enum_type): ...this.
	(rtx_reader::traverse_enum_types): Rename to...
	(md_reader::traverse_enum_types): ...this.
	(rtx_reader::rtx_reader): Rename to...
	(md_reader::md_reader): ...this, and update for renaming of
	rtx_reader_ptr to md_reader_ptr.
	(rtx_reader::~rtx_reader): Rename to...
	(md_reader::~md_reader): ...this, and update for renaming of
	rtx_reader_ptr to md_reader_ptr.
	(rtx_reader::handle_include): Rename to...
	(md_reader::handle_include): ...this.
	(rtx_reader::handle_file): Rename to...
	(md_reader::handle_file): ...this.
	(rtx_reader::handle_toplevel_file): Rename to...
	(md_reader::handle_toplevel_file): ...this.
	(rtx_reader::get_current_location): Rename to...
	(md_reader::get_current_location): ...this.
	(rtx_reader::add_include_path): Rename to...
	(md_reader::add_include_path): ...this.
	(rtx_reader::read_md_files): Rename to...
	(md_reader::read_md_files): ...this.
	* read-md.h (class rtx_reader): Split into...
	(class md_reader): ...new class.
	(rtx_reader_ptr): Rename to...
	(md_reader_ptr): ...this, and convert to a md_reader *.
	(class noop_reader): Update base class to be md_reader.
	(class rtx_reader): Reintroduce as a subclass of md_reader.
	(rtx_reader_ptr): Reintroduce as a rtx_reader *.
	(read_char): Update for renaming of rtx_reader_ptr to
	md_reader_ptr.
	(unread_char): Likewise.
	* read-rtl.c (rtx_reader_ptr): New global.
	(rtx_reader::apply_iterator_to_string): Rename to...
	(md_reader::apply_iterator_to_string): ...this.
	(rtx_reader::copy_rtx_for_iterators): Rename to...
	(md_reader::copy_rtx_for_iterators): ...this.
	(rtx_reader::read_conditions): Rename to...
	(md_reader::read_conditions): ...this.
	(rtx_reader::record_potential_iterator_use): Rename to...
	(md_reader::record_potential_iterator_use): ...this.
	(rtx_reader::read_mapping): Rename to...
	(md_reader::read_mapping): ...this.
	(rtx_reader::read_rtx): Use rtx_reader_ptr when calling
	read_rtx_code.
	(rtx_reader::read_rtx_operand): Use get_string_obstack rather
	than directly accessing m_string_obstack.
	(rtx_reader::rtx_reader): New ctor.
	(rtx_reader::~rtx_reader): New dtor.

From-SVN: r243426
parent 776a8a92
2016-12-07 David Malcolm <dmalcolm@redhat.com>
* genpreds.c (write_tm_constrs_h): Update for renaming of
rtx_reader_ptr to md_reader_ptr.
(write_tm_preds_h): Likewise.
(write_insn_preds_c): Likewise.
* read-md.c (rtx_reader_ptr): Rename to...
(md_reader_ptr): ...this, and convert from an
rtx_reader * to a md_reader *.
(rtx_reader::set_md_ptr_loc): Rename to...
(md_reader::set_md_ptr_loc): ...this.
(rtx_reader::get_md_ptr_loc): Rename to...
(md_reader::get_md_ptr_loc): ...this.
(rtx_reader::copy_md_ptr_loc): Rename to...
(md_reader::copy_md_ptr_loc): ...this.
(rtx_reader::fprint_md_ptr_loc): Rename to...
(md_reader::fprint_md_ptr_loc): ...this.
(rtx_reader::print_md_ptr_loc): Rename to...
(md_reader::print_md_ptr_loc): ...this.
(rtx_reader::join_c_conditions): Rename to...
(md_reader::join_c_conditions): ...this.
(rtx_reader::fprint_c_condition): ...this.
(rtx_reader::print_c_condition): Rename to...
(md_reader::print_c_condition): ...this.
(fatal_with_file_and_line): Update for renaming of
rtx_reader_ptr to md_reader_ptr.
(rtx_reader::require_char): Rename to...
(md_reader::require_char): ...this.
(rtx_reader::require_char_ws): Rename to...
(md_reader::require_char_ws): ...this.
(rtx_reader::require_word_ws): Rename to...
(md_reader::require_word_ws): ...this.
(rtx_reader::read_char): Rename to...
(md_reader::read_char): ...this.
(rtx_reader::unread_char): Rename to...
(md_reader::unread_char): ...this.
(rtx_reader::peek_char): Rename to...
(md_reader::peek_char): ...this.
(rtx_reader::read_name): Rename to...
(md_reader::read_name): ...this.
(rtx_reader::read_escape): Rename to...
(md_reader::read_escape): ...this.
(rtx_reader::read_quoted_string): Rename to...
(md_reader::read_quoted_string): ...this.
(rtx_reader::read_braced_string): Rename to...
(md_reader::read_braced_string): ...this.
(rtx_reader::read_string): Rename to...
(md_reader::read_string): ...this.
(rtx_reader::read_skip_construct): Rename to...
(md_reader::read_skip_construct): ...this.
(rtx_reader::handle_constants): Rename to...
(md_reader::handle_constants): ...this.
(rtx_reader::traverse_md_constants): Rename to...
(md_reader::traverse_md_constants): ...this.
(rtx_reader::handle_enum): Rename to...
(md_reader::handle_enum): ...this.
(rtx_reader::lookup_enum_type): Rename to...
(md_reader::lookup_enum_type): ...this.
(rtx_reader::traverse_enum_types): Rename to...
(md_reader::traverse_enum_types): ...this.
(rtx_reader::rtx_reader): Rename to...
(md_reader::md_reader): ...this, and update for renaming of
rtx_reader_ptr to md_reader_ptr.
(rtx_reader::~rtx_reader): Rename to...
(md_reader::~md_reader): ...this, and update for renaming of
rtx_reader_ptr to md_reader_ptr.
(rtx_reader::handle_include): Rename to...
(md_reader::handle_include): ...this.
(rtx_reader::handle_file): Rename to...
(md_reader::handle_file): ...this.
(rtx_reader::handle_toplevel_file): Rename to...
(md_reader::handle_toplevel_file): ...this.
(rtx_reader::get_current_location): Rename to...
(md_reader::get_current_location): ...this.
(rtx_reader::add_include_path): Rename to...
(md_reader::add_include_path): ...this.
(rtx_reader::read_md_files): Rename to...
(md_reader::read_md_files): ...this.
* read-md.h (class rtx_reader): Split into...
(class md_reader): ...new class.
(rtx_reader_ptr): Rename to...
(md_reader_ptr): ...this, and convert to a md_reader *.
(class noop_reader): Update base class to be md_reader.
(class rtx_reader): Reintroduce as a subclass of md_reader.
(rtx_reader_ptr): Reintroduce as a rtx_reader *.
(read_char): Update for renaming of rtx_reader_ptr to
md_reader_ptr.
(unread_char): Likewise.
* read-rtl.c (rtx_reader_ptr): New global.
(rtx_reader::apply_iterator_to_string): Rename to...
(md_reader::apply_iterator_to_string): ...this.
(rtx_reader::copy_rtx_for_iterators): Rename to...
(md_reader::copy_rtx_for_iterators): ...this.
(rtx_reader::read_conditions): Rename to...
(md_reader::read_conditions): ...this.
(rtx_reader::record_potential_iterator_use): Rename to...
(md_reader::record_potential_iterator_use): ...this.
(rtx_reader::read_mapping): Rename to...
(md_reader::read_mapping): ...this.
(rtx_reader::read_rtx): Use rtx_reader_ptr when calling
read_rtx_code.
(rtx_reader::read_rtx_operand): Use get_string_obstack rather
than directly accessing m_string_obstack.
(rtx_reader::rtx_reader): New ctor.
(rtx_reader::~rtx_reader): New dtor.
2016-12-07 Martin Sebor <msebor@redhat.com> 2016-12-07 Martin Sebor <msebor@redhat.com>
PR middle-end/77784 PR middle-end/77784
...@@ -1205,7 +1205,7 @@ write_tm_constrs_h (void) ...@@ -1205,7 +1205,7 @@ write_tm_constrs_h (void)
printf ("\ printf ("\
/* Generated automatically by the program '%s'\n\ /* Generated automatically by the program '%s'\n\
from the machine description file '%s'. */\n\n", progname, from the machine description file '%s'. */\n\n", progname,
rtx_reader_ptr->get_top_level_filename ()); md_reader_ptr->get_top_level_filename ());
puts ("\ puts ("\
#ifndef GCC_TM_CONSTRS_H\n\ #ifndef GCC_TM_CONSTRS_H\n\
...@@ -1405,7 +1405,7 @@ write_tm_preds_h (void) ...@@ -1405,7 +1405,7 @@ write_tm_preds_h (void)
printf ("\ printf ("\
/* Generated automatically by the program '%s'\n\ /* Generated automatically by the program '%s'\n\
from the machine description file '%s'. */\n\n", progname, from the machine description file '%s'. */\n\n", progname,
rtx_reader_ptr->get_top_level_filename ()); md_reader_ptr->get_top_level_filename ());
puts ("\ puts ("\
#ifndef GCC_TM_PREDS_H\n\ #ifndef GCC_TM_PREDS_H\n\
...@@ -1555,7 +1555,7 @@ write_insn_preds_c (void) ...@@ -1555,7 +1555,7 @@ write_insn_preds_c (void)
printf ("\ printf ("\
/* Generated automatically by the program '%s'\n\ /* Generated automatically by the program '%s'\n\
from the machine description file '%s'. */\n\n", progname, from the machine description file '%s'. */\n\n", progname,
rtx_reader_ptr->get_top_level_filename ()); md_reader_ptr->get_top_level_filename ());
puts ("\ puts ("\
#include \"config.h\"\n\ #include \"config.h\"\n\
......
...@@ -39,7 +39,7 @@ void (*include_callback) (const char *); ...@@ -39,7 +39,7 @@ void (*include_callback) (const char *);
/* Global singleton. */ /* Global singleton. */
rtx_reader *rtx_reader_ptr; md_reader *md_reader_ptr;
/* Given an object that starts with a char * name field, return a hash /* Given an object that starts with a char * name field, return a hash
code for its name. */ code for its name. */
...@@ -79,7 +79,7 @@ leading_ptr_eq_p (const void *def1, const void *def2) ...@@ -79,7 +79,7 @@ leading_ptr_eq_p (const void *def1, const void *def2)
/* Associate PTR with the file position given by FILENAME and LINENO. */ /* Associate PTR with the file position given by FILENAME and LINENO. */
void void
rtx_reader::set_md_ptr_loc (const void *ptr, const char *filename, int lineno) md_reader::set_md_ptr_loc (const void *ptr, const char *filename, int lineno)
{ {
struct ptr_loc *loc; struct ptr_loc *loc;
...@@ -95,7 +95,7 @@ rtx_reader::set_md_ptr_loc (const void *ptr, const char *filename, int lineno) ...@@ -95,7 +95,7 @@ rtx_reader::set_md_ptr_loc (const void *ptr, const char *filename, int lineno)
position was set. */ position was set. */
const struct ptr_loc * const struct ptr_loc *
rtx_reader::get_md_ptr_loc (const void *ptr) md_reader::get_md_ptr_loc (const void *ptr)
{ {
return (const struct ptr_loc *) htab_find (m_ptr_locs, &ptr); return (const struct ptr_loc *) htab_find (m_ptr_locs, &ptr);
} }
...@@ -103,7 +103,7 @@ rtx_reader::get_md_ptr_loc (const void *ptr) ...@@ -103,7 +103,7 @@ rtx_reader::get_md_ptr_loc (const void *ptr)
/* Associate NEW_PTR with the same file position as OLD_PTR. */ /* Associate NEW_PTR with the same file position as OLD_PTR. */
void void
rtx_reader::copy_md_ptr_loc (const void *new_ptr, const void *old_ptr) md_reader::copy_md_ptr_loc (const void *new_ptr, const void *old_ptr)
{ {
const struct ptr_loc *loc = get_md_ptr_loc (old_ptr); const struct ptr_loc *loc = get_md_ptr_loc (old_ptr);
if (loc != 0) if (loc != 0)
...@@ -114,7 +114,7 @@ rtx_reader::copy_md_ptr_loc (const void *new_ptr, const void *old_ptr) ...@@ -114,7 +114,7 @@ rtx_reader::copy_md_ptr_loc (const void *new_ptr, const void *old_ptr)
directive for it to OUTF. */ directive for it to OUTF. */
void void
rtx_reader::fprint_md_ptr_loc (FILE *outf, const void *ptr) md_reader::fprint_md_ptr_loc (FILE *outf, const void *ptr)
{ {
const struct ptr_loc *loc = get_md_ptr_loc (ptr); const struct ptr_loc *loc = get_md_ptr_loc (ptr);
if (loc != 0) if (loc != 0)
...@@ -123,7 +123,7 @@ rtx_reader::fprint_md_ptr_loc (FILE *outf, const void *ptr) ...@@ -123,7 +123,7 @@ rtx_reader::fprint_md_ptr_loc (FILE *outf, const void *ptr)
/* Special fprint_md_ptr_loc for writing to STDOUT. */ /* Special fprint_md_ptr_loc for writing to STDOUT. */
void void
rtx_reader::print_md_ptr_loc (const void *ptr) md_reader::print_md_ptr_loc (const void *ptr)
{ {
fprint_md_ptr_loc (stdout, ptr); fprint_md_ptr_loc (stdout, ptr);
} }
...@@ -132,7 +132,7 @@ rtx_reader::print_md_ptr_loc (const void *ptr) ...@@ -132,7 +132,7 @@ rtx_reader::print_md_ptr_loc (const void *ptr)
may be null or empty. */ may be null or empty. */
const char * const char *
rtx_reader::join_c_conditions (const char *cond1, const char *cond2) md_reader::join_c_conditions (const char *cond1, const char *cond2)
{ {
char *result; char *result;
const void **entry; const void **entry;
...@@ -161,7 +161,7 @@ rtx_reader::join_c_conditions (const char *cond1, const char *cond2) ...@@ -161,7 +161,7 @@ rtx_reader::join_c_conditions (const char *cond1, const char *cond2)
directive for COND if its original file position is known. */ directive for COND if its original file position is known. */
void void
rtx_reader::fprint_c_condition (FILE *outf, const char *cond) md_reader::fprint_c_condition (FILE *outf, const char *cond)
{ {
const char **halves = (const char **) htab_find (m_joined_conditions, &cond); const char **halves = (const char **) htab_find (m_joined_conditions, &cond);
if (halves != 0) if (halves != 0)
...@@ -183,7 +183,7 @@ rtx_reader::fprint_c_condition (FILE *outf, const char *cond) ...@@ -183,7 +183,7 @@ rtx_reader::fprint_c_condition (FILE *outf, const char *cond)
/* Special fprint_c_condition for writing to STDOUT. */ /* Special fprint_c_condition for writing to STDOUT. */
void void
rtx_reader::print_c_condition (const char *cond) md_reader::print_c_condition (const char *cond)
{ {
fprint_c_condition (stdout, cond); fprint_c_condition (stdout, cond);
} }
...@@ -250,8 +250,9 @@ fatal_with_file_and_line (const char *msg, ...) ...@@ -250,8 +250,9 @@ fatal_with_file_and_line (const char *msg, ...)
va_start (ap, msg); va_start (ap, msg);
fprintf (stderr, "%s:%d:%d: error: ", rtx_reader_ptr->get_filename (), fprintf (stderr, "%s:%d:%d: error: ", md_reader_ptr->get_filename (),
rtx_reader_ptr->get_lineno (), rtx_reader_ptr->get_colno ()); md_reader_ptr->get_lineno (),
md_reader_ptr->get_colno ());
vfprintf (stderr, msg, ap); vfprintf (stderr, msg, ap);
putc ('\n', stderr); putc ('\n', stderr);
...@@ -271,8 +272,9 @@ fatal_with_file_and_line (const char *msg, ...) ...@@ -271,8 +272,9 @@ fatal_with_file_and_line (const char *msg, ...)
context[i] = '\0'; context[i] = '\0';
fprintf (stderr, "%s:%d:%d: note: following context is `%s'\n", fprintf (stderr, "%s:%d:%d: note: following context is `%s'\n",
rtx_reader_ptr->get_filename (), rtx_reader_ptr->get_lineno (), md_reader_ptr->get_filename (),
rtx_reader_ptr->get_colno (), context); md_reader_ptr->get_lineno (),
md_reader_ptr->get_colno (), context);
va_end (ap); va_end (ap);
exit (1); exit (1);
...@@ -344,7 +346,7 @@ read_skip_spaces (void) ...@@ -344,7 +346,7 @@ read_skip_spaces (void)
EXPECTED. */ EXPECTED. */
void void
rtx_reader::require_char (char expected) md_reader::require_char (char expected)
{ {
int ch = read_char (); int ch = read_char ();
if (ch != expected) if (ch != expected)
...@@ -355,7 +357,7 @@ rtx_reader::require_char (char expected) ...@@ -355,7 +357,7 @@ rtx_reader::require_char (char expected)
character, issuing a fatal error if it is not EXPECTED. */ character, issuing a fatal error if it is not EXPECTED. */
void void
rtx_reader::require_char_ws (char expected) md_reader::require_char_ws (char expected)
{ {
int ch = read_skip_spaces (); int ch = read_skip_spaces ();
if (ch != expected) if (ch != expected)
...@@ -366,7 +368,7 @@ rtx_reader::require_char_ws (char expected) ...@@ -366,7 +368,7 @@ rtx_reader::require_char_ws (char expected)
issuing a fatal error if it is not EXPECTED. */ issuing a fatal error if it is not EXPECTED. */
void void
rtx_reader::require_word_ws (const char *expected) md_reader::require_word_ws (const char *expected)
{ {
struct md_name name; struct md_name name;
read_name (&name); read_name (&name);
...@@ -377,7 +379,7 @@ rtx_reader::require_word_ws (const char *expected) ...@@ -377,7 +379,7 @@ rtx_reader::require_word_ws (const char *expected)
/* Read the next character from the file. */ /* Read the next character from the file. */
int int
rtx_reader::read_char (void) md_reader::read_char (void)
{ {
int ch; int ch;
...@@ -397,7 +399,7 @@ rtx_reader::read_char (void) ...@@ -397,7 +399,7 @@ rtx_reader::read_char (void)
/* Put back CH, which was the last character read from the file. */ /* Put back CH, which was the last character read from the file. */
void void
rtx_reader::unread_char (int ch) md_reader::unread_char (int ch)
{ {
if (ch == '\n') if (ch == '\n')
{ {
...@@ -412,7 +414,7 @@ rtx_reader::unread_char (int ch) ...@@ -412,7 +414,7 @@ rtx_reader::unread_char (int ch)
/* Peek at the next character from the file without consuming it. */ /* Peek at the next character from the file without consuming it. */
int int
rtx_reader::peek_char (void) md_reader::peek_char (void)
{ {
int ch = read_char (); int ch = read_char ();
unread_char (ch); unread_char (ch);
...@@ -423,7 +425,7 @@ rtx_reader::peek_char (void) ...@@ -423,7 +425,7 @@ rtx_reader::peek_char (void)
punctuation chars of rtx printed syntax. */ punctuation chars of rtx printed syntax. */
void void
rtx_reader::read_name (struct md_name *name) md_reader::read_name (struct md_name *name)
{ {
int c; int c;
size_t i; size_t i;
...@@ -489,7 +491,7 @@ rtx_reader::read_name (struct md_name *name) ...@@ -489,7 +491,7 @@ rtx_reader::read_name (struct md_name *name)
Caller has read the backslash, but not placed it into the obstack. */ Caller has read the backslash, but not placed it into the obstack. */
void void
rtx_reader::read_escape () md_reader::read_escape ()
{ {
int c = read_char (); int c = read_char ();
...@@ -542,7 +544,7 @@ rtx_reader::read_escape () ...@@ -542,7 +544,7 @@ rtx_reader::read_escape ()
the leading quote. */ the leading quote. */
char * char *
rtx_reader::read_quoted_string () md_reader::read_quoted_string ()
{ {
int c; int c;
...@@ -569,7 +571,7 @@ rtx_reader::read_quoted_string () ...@@ -569,7 +571,7 @@ rtx_reader::read_quoted_string ()
the outermost braces _are_ included in the string constant. */ the outermost braces _are_ included in the string constant. */
char * char *
rtx_reader::read_braced_string () md_reader::read_braced_string ()
{ {
int c; int c;
int brace_depth = 1; /* caller-processed */ int brace_depth = 1; /* caller-processed */
...@@ -606,7 +608,7 @@ rtx_reader::read_braced_string () ...@@ -606,7 +608,7 @@ rtx_reader::read_braced_string ()
and dispatch to the appropriate string constant reader. */ and dispatch to the appropriate string constant reader. */
char * char *
rtx_reader::read_string (int star_if_braced) md_reader::read_string (int star_if_braced)
{ {
char *stringbuf; char *stringbuf;
int saw_paren = 0; int saw_paren = 0;
...@@ -642,7 +644,7 @@ rtx_reader::read_string (int star_if_braced) ...@@ -642,7 +644,7 @@ rtx_reader::read_string (int star_if_braced)
is currently nested by DEPTH levels of parentheses. */ is currently nested by DEPTH levels of parentheses. */
void void
rtx_reader::read_skip_construct (int depth, file_location loc) md_reader::read_skip_construct (int depth, file_location loc)
{ {
struct md_name name; struct md_name name;
int c; int c;
...@@ -784,7 +786,7 @@ add_constant (htab_t defs, char *name, char *value, ...@@ -784,7 +786,7 @@ add_constant (htab_t defs, char *name, char *value,
after the "define_constants". */ after the "define_constants". */
void void
rtx_reader::handle_constants () md_reader::handle_constants ()
{ {
int c; int c;
htab_t defs; htab_t defs;
...@@ -815,7 +817,7 @@ rtx_reader::handle_constants () ...@@ -815,7 +817,7 @@ rtx_reader::handle_constants ()
Stop when CALLBACK returns zero. */ Stop when CALLBACK returns zero. */
void void
rtx_reader::traverse_md_constants (htab_trav callback, void *info) md_reader::traverse_md_constants (htab_trav callback, void *info)
{ {
htab_traverse (get_md_constants (), callback, info); htab_traverse (get_md_constants (), callback, info);
} }
...@@ -838,7 +840,7 @@ md_decimal_string (int number) ...@@ -838,7 +840,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. */
void void
rtx_reader::handle_enum (file_location loc, bool md_p) md_reader::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;
...@@ -904,7 +906,7 @@ rtx_reader::handle_enum (file_location loc, bool md_p) ...@@ -904,7 +906,7 @@ rtx_reader::handle_enum (file_location loc, bool md_p)
/* Try to find the definition of the given enum. Return null on failure. */ /* Try to find the definition of the given enum. Return null on failure. */
struct enum_type * struct enum_type *
rtx_reader::lookup_enum_type (const char *name) md_reader::lookup_enum_type (const char *name)
{ {
return (struct enum_type *) htab_find (m_enum_types, &name); return (struct enum_type *) htab_find (m_enum_types, &name);
} }
...@@ -914,15 +916,15 @@ rtx_reader::lookup_enum_type (const char *name) ...@@ -914,15 +916,15 @@ rtx_reader::lookup_enum_type (const char *name)
returns zero. */ returns zero. */
void void
rtx_reader::traverse_enum_types (htab_trav callback, void *info) md_reader::traverse_enum_types (htab_trav callback, void *info)
{ {
htab_traverse (m_enum_types, callback, info); htab_traverse (m_enum_types, callback, info);
} }
/* Constructor for rtx_reader. */ /* Constructor for md_reader. */
rtx_reader::rtx_reader () md_reader::md_reader ()
: m_toplevel_fname (NULL), : m_toplevel_fname (NULL),
m_base_dir (NULL), m_base_dir (NULL),
m_read_md_file (NULL), m_read_md_file (NULL),
...@@ -933,7 +935,7 @@ rtx_reader::rtx_reader () ...@@ -933,7 +935,7 @@ rtx_reader::rtx_reader ()
m_last_dir_md_include_ptr (&m_first_dir_md_include) m_last_dir_md_include_ptr (&m_first_dir_md_include)
{ {
/* Set the global singleton pointer. */ /* Set the global singleton pointer. */
rtx_reader_ptr = this; md_reader_ptr = this;
obstack_init (&m_string_obstack); obstack_init (&m_string_obstack);
...@@ -953,9 +955,9 @@ rtx_reader::rtx_reader () ...@@ -953,9 +955,9 @@ rtx_reader::rtx_reader ()
unlock_std_streams (); unlock_std_streams ();
} }
/* rtx_reader's destructor. */ /* md_reader's destructor. */
rtx_reader::~rtx_reader () md_reader::~md_reader ()
{ {
free (m_base_dir); free (m_base_dir);
...@@ -972,7 +974,7 @@ rtx_reader::~rtx_reader () ...@@ -972,7 +974,7 @@ rtx_reader::~rtx_reader ()
obstack_free (&m_string_obstack, NULL); obstack_free (&m_string_obstack, NULL);
/* Clear the global singleton pointer. */ /* Clear the global singleton pointer. */
rtx_reader_ptr = NULL; md_reader_ptr = NULL;
} }
/* Process an "include" directive, starting with the optional space /* Process an "include" directive, starting with the optional space
...@@ -981,7 +983,7 @@ rtx_reader::~rtx_reader () ...@@ -981,7 +983,7 @@ rtx_reader::~rtx_reader ()
which the "include" occurred. */ which the "include" occurred. */
void void
rtx_reader::handle_include (file_location loc) md_reader::handle_include (file_location loc)
{ {
const char *filename; const char *filename;
const char *old_filename; const char *old_filename;
...@@ -1059,7 +1061,7 @@ rtx_reader::handle_include (file_location loc) ...@@ -1059,7 +1061,7 @@ rtx_reader::handle_include (file_location loc)
unknown directives. */ unknown directives. */
void void
rtx_reader::handle_file () md_reader::handle_file ()
{ {
struct md_name directive; struct md_name directive;
int c; int c;
...@@ -1093,7 +1095,7 @@ rtx_reader::handle_file () ...@@ -1093,7 +1095,7 @@ rtx_reader::handle_file ()
and m_base_dir accordingly. */ and m_base_dir accordingly. */
void void
rtx_reader::handle_toplevel_file () md_reader::handle_toplevel_file ()
{ {
const char *base; const char *base;
...@@ -1108,7 +1110,7 @@ rtx_reader::handle_toplevel_file () ...@@ -1108,7 +1110,7 @@ rtx_reader::handle_toplevel_file ()
} }
file_location file_location
rtx_reader::get_current_location () const md_reader::get_current_location () const
{ {
return file_location (m_read_md_filename, m_read_md_lineno, m_read_md_colno); return file_location (m_read_md_filename, m_read_md_lineno, m_read_md_colno);
} }
...@@ -1116,7 +1118,7 @@ rtx_reader::get_current_location () const ...@@ -1116,7 +1118,7 @@ rtx_reader::get_current_location () const
/* Parse a -I option with argument ARG. */ /* Parse a -I option with argument ARG. */
void void
rtx_reader::add_include_path (const char *arg) md_reader::add_include_path (const char *arg)
{ {
struct file_name_list *dirtmp; struct file_name_list *dirtmp;
...@@ -1137,7 +1139,7 @@ rtx_reader::add_include_path (const char *arg) ...@@ -1137,7 +1139,7 @@ rtx_reader::add_include_path (const char *arg)
generic error should be reported. */ generic error should be reported. */
bool bool
rtx_reader::read_md_files (int argc, const char **argv, md_reader::read_md_files (int argc, const char **argv,
bool (*parse_opt) (const char *)) bool (*parse_opt) (const char *))
{ {
int i; int i;
...@@ -1233,7 +1235,7 @@ rtx_reader::read_md_files (int argc, const char **argv, ...@@ -1233,7 +1235,7 @@ rtx_reader::read_md_files (int argc, const char **argv,
return !have_error; return !have_error;
} }
/* class noop_reader : public rtx_reader */ /* class noop_reader : public md_reader */
/* A dummy implementation which skips unknown directives. */ /* A dummy implementation which skips unknown directives. */
void void
......
...@@ -91,11 +91,23 @@ struct enum_type { ...@@ -91,11 +91,23 @@ struct enum_type {
unsigned int num_values; unsigned int num_values;
}; };
class rtx_reader /* A class for reading .md files and RTL dump files.
Implemented in read-md.c.
This class has responsibility for reading chars from input files, and
for certain common top-level directives including the "include"
directive.
It does not handle parsing the hierarchically-nested expressions of
rtl.def; for that see the rtx_reader subclass below (implemented in
read-rtl.c). */
class md_reader
{ {
public: public:
rtx_reader (); md_reader ();
virtual ~rtx_reader (); virtual ~md_reader ();
bool read_md_files (int, const char **, bool (*) (const char *)); bool read_md_files (int, const char **, bool (*) (const char *));
...@@ -145,11 +157,6 @@ class rtx_reader ...@@ -145,11 +157,6 @@ class rtx_reader
void record_potential_iterator_use (struct iterator_group *group, void record_potential_iterator_use (struct iterator_group *group,
void *ptr, const char *name); void *ptr, const char *name);
struct mapping *read_mapping (struct iterator_group *group, htab_t table); struct mapping *read_mapping (struct iterator_group *group, htab_t table);
bool read_rtx (const char *rtx_name, vec<rtx> *rtxen);
rtx read_rtx_code (const char *code_name);
void read_rtx_operand (rtx return_rtx, int idx);
rtx read_nested_rtx ();
rtx read_rtx_variadic (rtx form);
const char *get_top_level_filename () const { return m_toplevel_fname; } const char *get_top_level_filename () const { return m_toplevel_fname; }
const char *get_filename () const { return m_read_md_filename; } const char *get_filename () const { return m_read_md_filename; }
...@@ -231,20 +238,42 @@ class rtx_reader ...@@ -231,20 +238,42 @@ class rtx_reader
htab_t m_enum_types; htab_t m_enum_types;
}; };
/* Global singleton. */ /* Global singleton; constrast with rtx_reader_ptr below. */
extern rtx_reader *rtx_reader_ptr; extern md_reader *md_reader_ptr;
/* An rtx_reader subclass which skips unknown directives. */ /* An md_reader subclass which skips unknown directives, for
the gen* tools that purely use read-md.o. */
class noop_reader : public rtx_reader class noop_reader : public md_reader
{ {
public: public:
noop_reader () : rtx_reader () {} noop_reader () : md_reader () {}
/* A dummy implementation which skips unknown directives. */ /* A dummy implementation which skips unknown directives. */
void handle_unknown_directive (file_location, const char *); void handle_unknown_directive (file_location, const char *);
}; };
/* An md_reader subclass that actually handles full hierarchical
rtx expressions.
Implemented in read-rtl.c. */
class rtx_reader : public md_reader
{
public:
rtx_reader ();
~rtx_reader ();
bool read_rtx (const char *rtx_name, vec<rtx> *rtxen);
rtx read_rtx_code (const char *code_name);
void read_rtx_operand (rtx return_rtx, int idx);
rtx read_nested_rtx ();
rtx read_rtx_variadic (rtx form);
};
/* Global singleton; constrast with md_reader_ptr above. */
extern rtx_reader *rtx_reader_ptr;
extern void (*include_callback) (const char *); extern void (*include_callback) (const char *);
/* Read the next character from the MD file. */ /* Read the next character from the MD file. */
...@@ -252,7 +281,7 @@ extern void (*include_callback) (const char *); ...@@ -252,7 +281,7 @@ extern void (*include_callback) (const char *);
static inline int static inline int
read_char (void) read_char (void)
{ {
return rtx_reader_ptr->read_char (); return md_reader_ptr->read_char ();
} }
/* Put back CH, which was the last character read from the MD file. */ /* Put back CH, which was the last character read from the MD file. */
...@@ -260,7 +289,7 @@ read_char (void) ...@@ -260,7 +289,7 @@ read_char (void)
static inline void static inline void
unread_char (int ch) unread_char (int ch)
{ {
rtx_reader_ptr->unread_char (ch); md_reader_ptr->unread_char (ch);
} }
extern hashval_t leading_string_hash (const void *); extern hashval_t leading_string_hash (const void *);
......
...@@ -107,6 +107,9 @@ const char *current_iterator_name; ...@@ -107,6 +107,9 @@ const char *current_iterator_name;
static void validate_const_int (const char *); static void validate_const_int (const char *);
/* Global singleton. */
rtx_reader *rtx_reader_ptr = NULL;
/* The mode and code iterator structures. */ /* The mode and code iterator structures. */
static struct iterator_group modes, codes, ints, substs; static struct iterator_group modes, codes, ints, substs;
...@@ -326,7 +329,7 @@ map_attr_string (const char *p) ...@@ -326,7 +329,7 @@ map_attr_string (const char *p)
if any changes were needed, otherwise return STRING itself. */ if any changes were needed, otherwise return STRING itself. */
const char * const char *
rtx_reader::apply_iterator_to_string (const char *string) md_reader::apply_iterator_to_string (const char *string)
{ {
char *base, *copy, *p, *start, *end; char *base, *copy, *p, *start, *end;
struct map_value *v; struct map_value *v;
...@@ -365,7 +368,7 @@ rtx_reader::apply_iterator_to_string (const char *string) ...@@ -365,7 +368,7 @@ rtx_reader::apply_iterator_to_string (const char *string)
values into any strings. */ values into any strings. */
rtx rtx
rtx_reader::copy_rtx_for_iterators (rtx original) md_reader::copy_rtx_for_iterators (rtx original)
{ {
const char *format_ptr, *p; const char *format_ptr, *p;
int i, j; int i, j;
...@@ -735,7 +738,7 @@ atoll (const char *p) ...@@ -735,7 +738,7 @@ atoll (const char *p)
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. */
void void
rtx_reader::read_conditions () md_reader::read_conditions ()
{ {
int c; int c;
...@@ -834,7 +837,7 @@ record_attribute_use (struct iterator_group *group, void *ptr, ...@@ -834,7 +837,7 @@ record_attribute_use (struct iterator_group *group, void *ptr,
callback. */ callback. */
void void
rtx_reader::record_potential_iterator_use (struct iterator_group *group, md_reader::record_potential_iterator_use (struct iterator_group *group,
void *ptr, const char *name) void *ptr, const char *name)
{ {
struct mapping *m; struct mapping *m;
...@@ -869,7 +872,7 @@ rtx_reader::record_potential_iterator_use (struct iterator_group *group, ...@@ -869,7 +872,7 @@ rtx_reader::record_potential_iterator_use (struct iterator_group *group,
(which belongs to GROUP) and return it. */ (which belongs to GROUP) and return it. */
struct mapping * struct mapping *
rtx_reader::read_mapping (struct iterator_group *group, htab_t table) md_reader::read_mapping (struct iterator_group *group, htab_t table)
{ {
struct md_name name; struct md_name name;
struct mapping *m; struct mapping *m;
...@@ -1072,7 +1075,7 @@ rtx_reader::read_rtx (const char *rtx_name, vec<rtx> *rtxen) ...@@ -1072,7 +1075,7 @@ rtx_reader::read_rtx (const char *rtx_name, vec<rtx> *rtxen)
return true; return true;
} }
apply_iterators (read_rtx_code (rtx_name), rtxen); apply_iterators (rtx_reader_ptr->read_rtx_code (rtx_name), rtxen);
iterator_uses.truncate (0); iterator_uses.truncate (0);
attribute_uses.truncate (0); attribute_uses.truncate (0);
...@@ -1270,6 +1273,7 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx) ...@@ -1270,6 +1273,7 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
{ {
char *stringbuf; char *stringbuf;
int star_if_braced; int star_if_braced;
struct obstack *string_obstack = get_string_obstack ();
c = read_skip_spaces (); c = read_skip_spaces ();
unread_char (c); unread_char (c);
...@@ -1306,11 +1310,11 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx) ...@@ -1306,11 +1310,11 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx)
for (slash = fn; *slash; slash ++) for (slash = fn; *slash; slash ++)
if (*slash == '/' || *slash == '\\' || *slash == ':') if (*slash == '/' || *slash == '\\' || *slash == ':')
fn = slash + 1; fn = slash + 1;
obstack_1grow (&m_string_obstack, '*'); obstack_1grow (string_obstack, '*');
obstack_grow (&m_string_obstack, fn, strlen (fn)); obstack_grow (string_obstack, fn, strlen (fn));
sprintf (line_name, ":%d", get_lineno ()); sprintf (line_name, ":%d", get_lineno ());
obstack_grow (&m_string_obstack, line_name, strlen (line_name)+1); obstack_grow (string_obstack, line_name, strlen (line_name)+1);
stringbuf = XOBFINISH (&m_string_obstack, char *); stringbuf = XOBFINISH (string_obstack, char *);
} }
/* Find attr-names in the string. */ /* Find attr-names in the string. */
...@@ -1447,3 +1451,20 @@ rtx_reader::read_rtx_variadic (rtx form) ...@@ -1447,3 +1451,20 @@ rtx_reader::read_rtx_variadic (rtx form)
unread_char (c); unread_char (c);
return form; return form;
} }
/* Constructor for class rtx_reader. */
rtx_reader::rtx_reader ()
: md_reader ()
{
/* Set the global singleton pointer. */
rtx_reader_ptr = this;
}
/* Destructor for class rtx_reader. */
rtx_reader::~rtx_reader ()
{
/* Clear the global singleton pointer. */
rtx_reader_ptr = NULL;
}
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