Move over patch from Bernd Schmidt from GC branch:
[gcc.git] / gcc / gengenrtl.c
index 8f811fc010eabf97251fb2d0037eba7d7f2a3452..29cb836df448cb1f4c628f8965d6c4db12b5941c 100644 (file)
@@ -1,5 +1,5 @@
 /* Generate code to allocate RTL structures.
-   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -52,6 +52,8 @@ static void genlegend PROTO((FILE *));
 static void genheader PROTO((FILE *));
 static void gencode PROTO((FILE *));
 
+/* Decode a format letter into a C type string.  */
+
 static const char *
 type_from_format (c)
      int c;
@@ -84,6 +86,8 @@ type_from_format (c)
     }
 }
 
+/* Decode a format letter into the proper accessor function.  */
+
 static const char *
 accessor_from_format (c)
      int c;
@@ -110,6 +114,8 @@ accessor_from_format (c)
     }
 }
 
+/* Return true if a format character doesn't need normal processing.  */
+
 static int
 special_format (fmt)
      const char *fmt;
@@ -120,15 +126,20 @@ special_format (fmt)
          || strchr (fmt, 'n') != 0);
 }
 
+/* Return true if an rtx requires special processing.  */
+
 static int
 special_rtx (idx)
      int idx;
 {
   return (strcmp (defs[idx].enumname, "CONST_INT") == 0
+         || strcmp (defs[idx].enumname, "CONST_DOUBLE") == 0
          || strcmp (defs[idx].enumname, "REG") == 0
          || strcmp (defs[idx].enumname, "MEM") == 0);
 }
 
+/* Fill `formats' with all unique format strings.  */
+
 static void
 find_formats ()
 {
@@ -142,7 +153,7 @@ find_formats ()
        continue;
 
       for (f = formats; *f ; ++f)
-       if (!strcmp(*f, defs[i].format))
+       if (! strcmp (*f, defs[i].format))
          break;
 
       if (!*f)
@@ -150,6 +161,8 @@ find_formats ()
     }
 }
 
+/* Emit a prototype for the rtx generator for a format.  */
+
 static void
 gendecl (f, format)
      FILE *f;
@@ -166,6 +179,8 @@ gendecl (f, format)
   fprintf (f, "));\n");
 }
 
+/* Emit a define mapping an rtx code to the generator for its format.  */
+
 static void 
 genmacro (f, idx)
      FILE *f;
@@ -189,6 +204,8 @@ genmacro (f, idx)
   fprintf (f, ")\n");
 }
 
+/* Emit the implementation for the rtx generator for a format.  */
+
 static void
 gendef (f, format)
      FILE *f;
@@ -225,14 +242,18 @@ gendef (f, format)
   fprintf (f, "\n  return rt;\n}\n\n");
 }
 
+/* Emit the `do not edit' banner.  */
+
 static void
 genlegend (f)
      FILE *f;
 {
-  fprintf (f, "/* Generated automaticaly by the program `gengenrtl'\n");
-  fprintf (f, "   from the RTL description file `rtl.def' */\n\n");
+  fputs ("/* Generated automaticaly by the program `gengenrtl'\n", f);
+  fputs ("   from the RTL description file `rtl.def' */\n\n", f);
 }
 
+/* Emit "genrtl.h".  */
+
 static void
 genheader (f)
      FILE *f;
@@ -243,7 +264,7 @@ genheader (f)
   for (fmt = formats; *fmt; ++fmt)
     gendecl (f, *fmt);
 
-  fprintf(f, "\n");
+  fprintf (f, "\n");
 
   for (i = 0; i < NUM_RTX_CODE; i++)
     {
@@ -253,6 +274,8 @@ genheader (f)
     }
 }
 
+/* Emit "genrtl.c".  */
+
 static void
 gencode (f)
      FILE *f;
@@ -268,7 +291,7 @@ gencode (f)
   fputs ("static rtx obstack_alloc_rtx (length)\n", f);
   fputs ("     register int length;\n{\n", f);
   fputs ("  rtx rt = (rtx) obstack_alloc (rtl_obstack, length);\n\n", f);
-  fputs ("  bzero((char *) rt, sizeof(struct rtx_def) - sizeof(rtunion));\n\n", f);
+  fputs ("  memset(rt, 0, sizeof(struct rtx_def) - sizeof(rtunion));\n\n", f);
   fputs ("  return rt;\n}\n\n", f);
 
   for (fmt = formats; *fmt; ++fmt)
@@ -308,22 +331,22 @@ main(argc, argv)
   f = fopen (argv[1], "w");
   if (f == NULL)
     {
-      perror(argv[1]);
+      perror (argv[1]);
       exit (1);
     }
   genlegend (f);
   genheader (f);
-  fclose(f);
+  fclose (f);
 
   f = fopen (argv[2], "w");
   if (f == NULL)
     {
-      perror(argv[2]);
+      perror (argv[2]);
       exit (1);
     }
   genlegend (f);
   gencode (f);
-  fclose(f);
+  fclose (f);
 
   exit (0);
 }