From 6eb15e68971819d2f6b8a68428c46ab89612e4c1 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 13 Apr 2016 10:46:44 -0400
Subject: [PATCH 074/101] FIXME: move read_md_filename into rtx_reader

---
 gcc/read-md.c  | 33 +++++++++++++++++----------------
 gcc/read-md.h  |  3 ++-
 gcc/read-rtl.c |  1 +
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/gcc/read-md.c b/gcc/read-md.c
index 2a0bc95..816742b 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -59,9 +59,6 @@ static htab_t joined_conditions;
 /* An obstack for allocating joined_conditions entries.  */
 static struct obstack joined_conditions_obstack;
 
-/* The filename of READ_MD_FILE.  */
-const char *read_md_filename;
-
 /* The name of the toplevel file that indirectly included READ_MD_FILE.  */
 const char *in_fname;
 
@@ -309,7 +306,8 @@ fatal_with_file_and_line (const char *msg, ...)
 
   va_start (ap, msg);
 
-  fprintf (stderr, "%s:%d: ", read_md_filename, rtx_reader_ptr->get_lineno ());
+  fprintf (stderr, "%s:%d: ", rtx_reader_ptr->get_filename (),
+	   rtx_reader_ptr->get_lineno ());
   vfprintf (stderr, msg, ap);
   putc ('\n', stderr);
 
@@ -333,7 +331,8 @@ fatal_with_file_and_line (const char *msg, ...)
   context[i] = '\0';
 
   fprintf (stderr, "%s:%d: following context is `%s'\n",
-	   read_md_filename, rtx_reader_ptr->get_lineno (), context);
+	   rtx_reader_ptr->get_filename (), rtx_reader_ptr->get_lineno (),
+	   context);
 
   va_end (ap);
 
@@ -665,7 +664,8 @@ read_escape (void)
       /* pass anything else through, but issue a warning.  */
     default:
       fprintf (stderr, "%s:%d: warning: unrecognized escape \\%c\n",
-	       read_md_filename, rtx_reader_ptr->get_lineno (), c);
+	       rtx_reader_ptr->get_filename (), rtx_reader_ptr->get_lineno (),
+	       c);
       obstack_1grow (&string_obstack, '\\');
       break;
     }
@@ -777,7 +777,7 @@ read_string (int star_if_braced)
   if (saw_paren)
     require_char_ws (')');
 
-  set_md_ptr_loc (stringbuf, read_md_filename, old_lineno);
+  set_md_ptr_loc (stringbuf, rtx_reader_ptr->get_filename (), old_lineno);
   return stringbuf;
 }
 
@@ -1072,6 +1072,7 @@ static line_maps *rtx_reader_line_table;
 rtx_reader::rtx_reader (line_maps *line_table)
 : m_line_table (line_table),
   m_current_linemap (NULL),
+  m_read_md_filename (NULL),
   m_read_md_lineno (0),
   m_read_md_colno (0)
 {
@@ -1147,7 +1148,7 @@ rtx_reader::handle_include (file_location loc)
      function is the beginning of the include statement, while
      read_md_lineno has already been advanced.  */
   old_file = m_read_md_file;
-  old_filename = read_md_filename;
+  old_filename = m_read_md_filename;
   old_lineno = m_read_md_lineno;
   old_colno = m_read_md_colno;
 
@@ -1155,13 +1156,13 @@ rtx_reader::handle_include (file_location loc)
     include_callback (pathname);
 
   m_read_md_file = input_file;
-  read_md_filename = pathname;
+  m_read_md_filename = pathname;
   /* FIXME: update line_maps */
   handle_file ();
 
   /* Restore the old cursor.  */
   m_read_md_file = old_file;
-  read_md_filename = old_filename;
+  m_read_md_filename = old_filename;
   m_read_md_lineno = old_lineno;
   m_read_md_colno = old_colno;
   /* FIXME: update line_maps */
@@ -1212,7 +1213,7 @@ rtx_reader::handle_toplevel_file ()
 {
   const char *base;
 
-  in_fname = read_md_filename;
+  in_fname = m_read_md_filename;
   base = lbasename (in_fname);
   if (base == in_fname)
     base_dir = NULL;
@@ -1345,7 +1346,7 @@ rtx_reader::read_md_files (int argc, const char **argv,
 		fatal ("cannot read standard input twice");
 
 	      m_read_md_file = stdin;
-	      read_md_filename = "<stdin>";
+	      m_read_md_filename = "<stdin>";
 	      handle_toplevel_file ();
 	      already_read_stdin = true;
 	      continue;
@@ -1362,11 +1363,11 @@ rtx_reader::read_md_files (int argc, const char **argv,
 
       /* If we get here we are looking at a non-option argument, i.e.
 	 a file to be processed.  */
-      read_md_filename = argv[i];
-      m_read_md_file = fopen (read_md_filename, "r");
+      m_read_md_filename = argv[i];
+      m_read_md_file = fopen (m_read_md_filename, "r");
       if (m_read_md_file == 0)
 	{
-	  perror (read_md_filename);
+	  perror (m_read_md_filename);
 	  return false;
 	}
       handle_toplevel_file ();
@@ -1378,7 +1379,7 @@ rtx_reader::read_md_files (int argc, const char **argv,
   if (num_files == 0 && !already_read_stdin)
     {
       m_read_md_file = stdin;
-      read_md_filename = "<stdin>";
+      m_read_md_filename = "<stdin>";
       handle_toplevel_file ();
     }
 
diff --git a/gcc/read-md.h b/gcc/read-md.h
index c085574..032e597 100644
--- a/gcc/read-md.h
+++ b/gcc/read-md.h
@@ -136,6 +136,7 @@ class rtx_reader
   int read_char (void);
   void unread_char (int ch);
 
+  const char *get_filename () const { return m_read_md_filename; }
   int get_lineno () const { return m_read_md_lineno; }
 
  private:
@@ -150,6 +151,7 @@ class rtx_reader
   /* The file we are reading.  */
   FILE *m_read_md_file;
 
+  const char *m_read_md_filename;
   int m_read_md_lineno;
   int m_read_md_colno;
 };
@@ -167,7 +169,6 @@ class noop_reader : public rtx_reader
 };
 
 extern const char *in_fname;
-extern const char *read_md_filename;
 extern struct obstack string_obstack;
 extern void (*include_callback) (const char *);
 
diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c
index 51f1fc2..1ce9dd3 100644
--- a/gcc/read-rtl.c
+++ b/gcc/read-rtl.c
@@ -1516,6 +1516,7 @@ read_rtx_code (const char *code_name)
 		  || GET_CODE (return_rtx) == DEFINE_INSN_AND_SPLIT))
 	    {
 	      char line_name[20];
+	      const char *read_md_filename = rtx_reader_ptr->get_filename ();
 	      const char *fn = (read_md_filename ? read_md_filename : "rtx");
 	      const char *slash;
 	      for (slash = fn; *slash; slash ++)
-- 
1.8.5.3

