RFA: fold EOF check into read_rtx()

Richard Sandiford rsandifo@redhat.com
Fri Aug 27 07:08:00 GMT 2004


Richard Sandiford <rsandifo@redhat.com> writes:
> Richard Earnshaw <rearnsha@gcc.gnu.org> writes:
>> Not directly related to this change, but more some general
>> observations.  I did some brief experiments last night with the ARM
>> description to find out how this all worked.
>>
>> 1) There seems to be a small bug in the expansion of macros.  If the
>> last insn in the machine description contains macro expansions then only
>> the very first permutation is generated and none of the others (very
>> confusing for a beginner who just happens to be experimenting by adding
>> dummy patterns at the end of the description :-)
>
> Doh!  I'd forgotten that it's the caller of read_rtx() that checks
> for EOF, not read_rtx() itself.  This also shows up another little
> problem: for second and subsequent expansions of macros, the caller
> will remember the line number of the following rtx instead.
>
> I'm testing a fix now.

Attached.  It changes the interface of read_rtx() so that it returns
true on success and provides the caller with both the rtx and the
line number of the definition.

Bootstrapped & regression tested on mips-sgi-irix6.5.  I also checked
that the patch had no effect on insn-output.c for MIPS other than
fixing the line numbers of second and subsequence macro expansions.
OK to install?

Richard


	* rtl.h (read_rtx): Change prototype.
	* read-rtl.c (read_rtx): Provide the caller with both an rtx and a
	line number.  Return true on success.
	* gensupport.c (process_include, init_md_reader_args_cb): Adjust
	callers accordingly.

Index: rtl.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.h,v
retrieving revision 1.506
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.506 rtl.h
--- rtl.h	23 Aug 2004 11:56:54 -0000	1.506
+++ rtl.h	26 Aug 2004 17:27:32 -0000
@@ -2147,7 +2147,7 @@ struct md_constant { char *name, *value;
 
 /* In read-rtl.c */
 extern int read_skip_spaces (FILE *);
-extern rtx read_rtx (FILE *);
+extern bool read_rtx (FILE *, rtx *, int *);
 extern const char *read_rtx_filename;
 extern int read_rtx_lineno;
 
Index: read-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/read-rtl.c,v
retrieving revision 1.29
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.29 read-rtl.c
--- read-rtl.c	23 Aug 2004 05:55:46 -0000	1.29
+++ read-rtl.c	26 Aug 2004 17:27:33 -0000
@@ -1066,16 +1066,20 @@ check_code_macro (struct mapping *macro,
   bellwether_codes[macro->index] = bellwether;
 }
 
-/* Read an rtx in printed representation from INFILE
-   and return an actual rtx in core constructed accordingly.
+/* Read an rtx in printed representation from INFILE and store its
+   core representation in *X.  Also store the line number of the
+   opening '(' in *LINENO.  Return true on success or false if the
+   end of file has been reached.
+
    read_rtx is not used in the compiler proper, but rather in
    the utilities gen*.c that construct C code from machine descriptions.  */
 
-rtx
-read_rtx (FILE *infile)
+bool
+read_rtx (FILE *infile, rtx *x, int *lineno)
 {
   static rtx queue_head, queue_next;
-  rtx return_rtx;
+  static int queue_lineno;
+  int c;
 
   /* Do one-time initialization.  */
   if (queue_head == 0)
@@ -1087,8 +1091,13 @@ read_rtx (FILE *infile)
 
   if (queue_next == 0)
     {
-      queue_next = queue_head;
+      c = read_skip_spaces (infile);
+      if (c == EOF)
+	return false;
+      ungetc (c, infile);
 
+      queue_next = queue_head;
+      queue_lineno = read_rtx_lineno;
       XEXP (queue_next, 0) = read_rtx_1 (infile);
       XEXP (queue_next, 1) = 0;
 
@@ -1096,10 +1105,11 @@ read_rtx (FILE *infile)
       htab_traverse (codes.macros, apply_macro_traverse, queue_next);
     }
 
-  return_rtx = XEXP (queue_next, 0);
+  *x = XEXP (queue_next, 0);
+  *lineno = queue_lineno;
   queue_next = XEXP (queue_next, 1);
 
-  return return_rtx;
+  return true;
 }
 
 /* Subroutine of read_rtx that reads one construct from INFILE but
Index: gensupport.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gensupport.c,v
retrieving revision 1.55
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.55 gensupport.c
--- gensupport.c	12 Aug 2004 07:48:54 -0000	1.55
+++ gensupport.c	26 Aug 2004 17:27:34 -0000
@@ -246,20 +246,8 @@ process_include (rtx desc, int lineno)
   read_rtx_lineno = 1;
 
   /* Read the entire file.  */
-  while (1)
-    {
-      rtx desc;
-      int c;
-
-      c = read_skip_spaces (input_file);
-      if (c == EOF)
-	break;
-
-      ungetc (c, input_file);
-      lineno = read_rtx_lineno;
-      desc = read_rtx (input_file);
-      process_rtx (desc, lineno);
-    }
+  while (read_rtx (input_file, &desc, &lineno))
+    process_rtx (desc, lineno);
 
   /* Do not free pathname.  It is attached to the various rtx queue
      elements.  */
@@ -911,9 +899,10 @@ int
 init_md_reader_args_cb (int argc, char **argv, bool (*parse_opt)(const char *))
 {
   FILE *input_file;
-  int i;
+  int i, lineno;
   size_t ix;
   char *lastsl;
+  rtx desc;
 
   for (i = 1; i < argc; i++)
     {
@@ -991,19 +980,8 @@ init_md_reader_args_cb (int argc, char *
   sequence_num = 0;
 
   /* Read the entire file.  */
-  while (1)
-    {
-      rtx desc;
-      int lineno;
-      int c = read_skip_spaces (input_file);
-      if (c == EOF)
-        break;
-
-      ungetc (c, input_file);
-      lineno = read_rtx_lineno;
-      desc = read_rtx (input_file);
-      process_rtx (desc, lineno);
-    }
+  while (read_rtx (input_file, &desc, &lineno))
+    process_rtx (desc, lineno);
   fclose (input_file);
 
   /* Process define_cond_exec patterns.  */



More information about the Gcc-patches mailing list