From 77cd4a2e993b3b57c72883b60e62aab381401010 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 7 Apr 2016 07:30:02 -0400
Subject: [PATCH 31/55] FIXME: move lineno/colno into rtx_reader

---
 gcc/read-md.c  | 49 +++++++++++++++++++++++++------------------------
 gcc/read-md.h  |  6 ++++--
 gcc/read-rtl.c |  2 +-
 3 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/gcc/read-md.c b/gcc/read-md.c
index 5262cad..d7aeaab 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -65,12 +65,6 @@ FILE *read_md_file;
 /* The filename of READ_MD_FILE.  */
 const char *read_md_filename;
 
-/* The current line number in READ_MD_FILE.  */
-int read_md_lineno;
-
-/* FIXME.  */
-int read_md_colno;
-
 /* The name of the toplevel file that indirectly included READ_MD_FILE.  */
 const char *in_fname;
 
@@ -318,7 +312,7 @@ fatal_with_file_and_line (const char *msg, ...)
 
   va_start (ap, msg);
 
-  fprintf (stderr, "%s:%d: ", read_md_filename, read_md_lineno);
+  fprintf (stderr, "%s:%d: ", read_md_filename, rtx_reader_ptr->get_lineno ());
   vfprintf (stderr, msg, ap);
   putc ('\n', stderr);
 
@@ -338,7 +332,7 @@ fatal_with_file_and_line (const char *msg, ...)
   context[i] = '\0';
 
   fprintf (stderr, "%s:%d: following context is `%s'\n",
-	   read_md_filename, read_md_lineno, context);
+	   read_md_filename, rtx_reader_ptr->get_lineno (), context);
 
   va_end (ap);
 
@@ -438,11 +432,11 @@ rtx_reader::read_char (void)
   ch = getc (read_md_file);
   if (ch == '\n')
     {
-      read_md_lineno++;
-      read_md_colno = 0;
+      m_read_md_lineno++;
+      m_read_md_colno = 0;
     }
   else
-    read_md_colno++;
+    m_read_md_colno++;
 
   update_location (true);
 
@@ -456,9 +450,9 @@ rtx_reader::unread_char (int ch)
 {
   /* FIXME: what about colno when unreading a '\n'? */
   if (ch == '\n')
-    read_md_lineno--;
+    m_read_md_lineno--;
   else
-    read_md_colno--;
+    m_read_md_colno--;
   update_location (false);
   ungetc (ch, read_md_file);
 }
@@ -610,7 +604,7 @@ read_escape (void)
       /* pass anything else through, but issue a warning.  */
     default:
       fprintf (stderr, "%s:%d: warning: unrecognized escape \\%c\n",
-	       read_md_filename, read_md_lineno, c);
+	       read_md_filename, rtx_reader_ptr->get_lineno (), c);
       obstack_1grow (&string_obstack, '\\');
       break;
     }
@@ -653,7 +647,7 @@ read_braced_string (void)
 {
   int c;
   int brace_depth = 1;  /* caller-processed */
-  unsigned long starting_read_md_lineno = read_md_lineno;
+  unsigned long starting_read_md_lineno = rtx_reader_ptr->get_lineno ();
 
   obstack_1grow (&string_obstack, '{');
   while (brace_depth)
@@ -699,7 +693,7 @@ read_string (int star_if_braced)
       c = read_skip_spaces ();
     }
 
-  old_lineno = read_md_lineno;
+  old_lineno = rtx_reader_ptr->get_lineno ();
   if (c == '"')
     stringbuf = read_quoted_string ();
   else if (c == '{')
@@ -1018,7 +1012,9 @@ 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_current_linemap (NULL),
+  m_read_md_lineno (0),
+  m_read_md_colno (0)
 {
   rtx_reader_line_table = m_line_table;
   rtx_reader_ptr = this;
@@ -1045,6 +1041,7 @@ rtx_reader::handle_include (file_location loc)
   const char *filename;
   const char *old_filename;
   int old_lineno;
+  int old_colno;
   char *pathname;
   FILE *input_file, *old_file;
 
@@ -1092,7 +1089,8 @@ rtx_reader::handle_include (file_location loc)
      read_md_lineno has already been advanced.  */
   old_file = read_md_file;
   old_filename = read_md_filename;
-  old_lineno = read_md_lineno;
+  old_lineno = m_read_md_lineno;
+  old_colno = m_read_md_colno;
 
   if (include_callback)
     include_callback (pathname);
@@ -1105,7 +1103,8 @@ rtx_reader::handle_include (file_location loc)
   /* Restore the old cursor.  */
   read_md_file = old_file;
   read_md_filename = old_filename;
-  read_md_lineno = old_lineno;
+  m_read_md_lineno = old_lineno;
+  m_read_md_colno = old_colno;
   /* FIXME: update line_maps */
 
   /* Do not free the pathname.  It is attached to the various rtx
@@ -1122,7 +1121,7 @@ rtx_reader::handle_file ()
   struct md_name directive;
   int c;
 
-  read_md_lineno = 1;
+  m_read_md_lineno = 1;
   while ((c = read_skip_spaces ()) != EOF)
     {
       file_location loc = get_current_location ();
@@ -1175,7 +1174,8 @@ rtx_reader::get_current_location () const
 {
   return linemap_position_for_line_and_column (m_line_table,
 					       m_current_linemap,
-					       read_md_lineno, read_md_colno);
+					       m_read_md_lineno,
+					       m_read_md_colno);
 }
 
 /* FIXME.  */
@@ -1185,9 +1185,10 @@ rtx_reader::update_location (bool advancing)
 {
   if (advancing)
     {
-      if (read_md_lineno == 0)
-	linemap_line_start (m_line_table, read_md_lineno, 1024 /* max_column_hint */);
-      linemap_position_for_column (m_line_table, read_md_colno);
+      if (m_read_md_lineno == 0)
+	linemap_line_start (m_line_table, m_read_md_lineno,
+			    1024 /* max_column_hint */);
+      linemap_position_for_column (m_line_table, m_read_md_colno);
     }
 }
 
diff --git a/gcc/read-md.h b/gcc/read-md.h
index 46bfda1..876de10 100644
--- a/gcc/read-md.h
+++ b/gcc/read-md.h
@@ -106,6 +106,8 @@ class rtx_reader
   int read_char (void);
   void unread_char (int ch);
 
+  int get_lineno () const { return m_read_md_lineno; }
+
  private:
   void handle_file ();
   void handle_toplevel_file ();
@@ -114,6 +116,8 @@ class rtx_reader
  private:
   line_maps *m_line_table;
   const line_map_ordinary *m_current_linemap;
+  int m_read_md_lineno;
+  int m_read_md_colno;
 };
 
 /* Global singleton.  */
@@ -130,8 +134,6 @@ class noop_reader : public rtx_reader
 
 extern const char *in_fname;
 extern FILE *read_md_file;
-extern int read_md_lineno;
-extern int read_md_colno;
 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 cee03ee..ad5e847 100644
--- a/gcc/read-rtl.c
+++ b/gcc/read-rtl.c
@@ -1426,7 +1426,7 @@ read_rtx_code (const char *code_name)
 		  fn = slash + 1;
 	      obstack_1grow (&string_obstack, '*');
 	      obstack_grow (&string_obstack, fn, strlen (fn));
-	      sprintf (line_name, ":%d", read_md_lineno);
+	      sprintf (line_name, ":%d", rtx_reader_ptr->get_lineno ());
 	      obstack_grow (&string_obstack, line_name, strlen (line_name)+1);
 	      stringbuf = XOBFINISH (&string_obstack, char *);
 	    }
-- 
1.8.5.3

