OSDN Git Service

(read_braced_string): Check for EOF. If encountered issue an error message.
[pf3gnuchains/gcc-fork.git] / gcc / read-rtl.c
index 959a6f3..9d08da4 100644 (file)
@@ -1,5 +1,5 @@
-/* RTL reader for GNU C Compiler.
-   Copyright (C) 1987, 1988, 1991, 1994, 1997, 1998, 1999, 2000, 2001
+/* RTL reader for GCC.
+   Copyright (C) 1987, 1988, 1991, 1994, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -19,15 +19,14 @@ along with GCC; see the file COPYING.  If not, write to the Free
 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.  */
 
-#include "hconfig.h"
+#include "bconfig.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "rtl.h"
 #include "obstack.h"
 #include "hashtab.h"
 
-#define        obstack_chunk_alloc     xmalloc
-#define        obstack_chunk_free      free
-
 static htab_t md_constants;
 
 static void fatal_with_file_and_line PARAMS ((FILE *, const char *, ...))
@@ -38,9 +37,10 @@ static char *read_string     PARAMS ((struct obstack *, FILE *, int));
 static char *read_quoted_string        PARAMS ((struct obstack *, FILE *));
 static char *read_braced_string        PARAMS ((struct obstack *, FILE *));
 static void read_escape                PARAMS ((struct obstack *, FILE *));
-static unsigned def_hash PARAMS ((const void *));
+static hashval_t def_hash      PARAMS ((const void *));
 static int def_name_eq_p PARAMS ((const void *, const void *));
 static void read_constants PARAMS ((FILE *infile, char *tmp_char));
+static void validate_const_int PARAMS ((FILE *, const char *));
 
 /* Subroutines of read_rtx.  */
 
@@ -51,30 +51,21 @@ int read_rtx_lineno = 1;
 const char *read_rtx_filename = "<unknown>";
 
 static void
-fatal_with_file_and_line VPARAMS ((FILE *infile, const char *msg, ...))
+fatal_with_file_and_line (FILE *infile, const char *msg, ...)
 {
-#ifndef ANSI_PROTOTYPES
-  FILE *infile;
-  const char *msg;
-#endif
-  va_list ap;
   char context[64];
   size_t i;
   int c;
+  va_list ap;
 
-  VA_START (ap, msg);
-
-#ifndef ANSI_PROTOTYPES
-  infile = va_arg (ap, FILE *);
-  msg = va_arg (ap, const char *);
-#endif
+  va_start (ap, msg);
 
   fprintf (stderr, "%s:%d: ", read_rtx_filename, read_rtx_lineno);
   vfprintf (stderr, msg, ap);
   putc ('\n', stderr);
 
   /* Gather some following context.  */
-  for (i = 0; i < sizeof(context)-1; ++i)
+  for (i = 0; i < sizeof (context)-1; ++i)
     {
       c = getc (infile);
       if (c == EOF)
@@ -113,7 +104,8 @@ int
 read_skip_spaces (infile)
      FILE *infile;
 {
-  register int c;
+  int c;
+
   while (1)
     {
       c = getc (infile);
@@ -135,7 +127,7 @@ read_skip_spaces (infile)
 
        case '/':
          {
-           register int prevc;
+           int prevc;
            c = getc (infile);
            if (c != '*')
              fatal_expected_char (infile, '*', c);
@@ -166,10 +158,10 @@ read_name (str, infile)
      char *str;
      FILE *infile;
 {
-  register char *p;
-  register int c;
+  char *p;
+  int c;
 
-  c = read_skip_spaces(infile);
+  c = read_skip_spaces (infile);
 
   p = str;
   while (1)
@@ -220,6 +212,7 @@ read_escape (ob, infile)
      FILE *infile;
 {
   int c = getc (infile);
+
   switch (c)
     {
       /* Backslash-newline is replaced by nothing, as in C.  */
@@ -264,7 +257,7 @@ read_escape (ob, infile)
 
   obstack_1grow (ob, c);
 }
-      
+
 
 /* Read a double-quoted string onto the obstack.  Caller has scanned
    the leading quote.  */
@@ -274,6 +267,7 @@ read_quoted_string (ob, infile)
      FILE *infile;
 {
   int c;
+
   while (1)
     {
       c = getc (infile); /* Read the string  */
@@ -304,11 +298,13 @@ read_braced_string (ob, infile)
 {
   int c;
   int brace_depth = 1;  /* caller-processed */
+  unsigned long starting_read_rtx_lineno = read_rtx_lineno;
 
   obstack_1grow (ob, '{');
   while (brace_depth)
     {
       c = getc (infile); /* Read the string  */
+
       if (c == '\n')
        read_rtx_lineno++;
       else if (c == '{')
@@ -320,10 +316,14 @@ read_braced_string (ob, infile)
          read_escape (ob, infile);
          continue;
        }
+      else if (c == EOF)
+       fatal_with_file_and_line
+         (infile, "missing closing } for opening brace on line %lu",
+          starting_read_rtx_lineno);      
 
       obstack_1grow (ob, c);
     }
-      
+
   obstack_1grow (ob, 0);
   return obstack_finish (ob);
 }
@@ -359,7 +359,7 @@ read_string (ob, infile, star_if_braced)
     }
   else
     fatal_with_file_and_line (infile, "expected `\"' or `{', found `%c'", c);
-       
+
   if (saw_paren)
     {
       c = read_skip_spaces (infile);
@@ -373,14 +373,16 @@ read_string (ob, infile, star_if_braced)
 /* Provide a version of a function to read a long long if the system does
    not provide one.  */
 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ)
+HOST_WIDE_INT atoll PARAMS ((const char *));
+
 HOST_WIDE_INT
-atoll(p)
+atoll (p)
     const char *p;
 {
   int neg = 0;
   HOST_WIDE_INT tmp_wide;
 
-  while (ISSPACE(*p))
+  while (ISSPACE (*p))
     p++;
   if (*p == '-')
     neg = 1, p++;
@@ -388,13 +390,13 @@ atoll(p)
     p++;
 
   tmp_wide = 0;
-  while (ISDIGIT(*p))
+  while (ISDIGIT (*p))
     {
       HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0');
       if (new_wide < tmp_wide)
        {
          /* Return INT_MAX equiv on overflow.  */
-         tmp_wide = (~(unsigned HOST_WIDE_INT)0) >> 1;
+         tmp_wide = (~(unsigned HOST_WIDE_INT) 0) >> 1;
          break;
        }
       tmp_wide = new_wide;
@@ -408,12 +410,12 @@ atoll(p)
 #endif
 
 /* Given a constant definition, return a hash code for its name.  */
-static unsigned
+static hashval_t
 def_hash (def)
      const void *def;
 {
   unsigned result, i;
-  const char *string = ((const struct md_constant *)def)->name;
+  const char *string = ((const struct md_constant *) def)->name;
 
   for (result = i = 0;*string++ != '\0'; i++)
     result += ((unsigned char) *string << (i % CHAR_BIT));
@@ -425,8 +427,8 @@ static int
 def_name_eq_p (def1, def2)
      const void *def1, *def2;
 {
-  return ! strcmp (((const struct md_constant *)def1)->name,
-                  ((const struct md_constant *)def2)->name);
+  return ! strcmp (((const struct md_constant *) def1)->name,
+                  ((const struct md_constant *) def2)->name);
 }
 
 /* INFILE is a FILE pointer to read text from.  TMP_CHAR is a buffer suitable
@@ -499,6 +501,28 @@ traverse_md_constants (callback, info)
     htab_traverse (md_constants, callback, info);
 }
 
+static void
+validate_const_int (infile, string)
+     FILE *infile;
+     const char *string;
+{
+  const char *cp;
+  int valid = 1;
+
+  cp = string;
+  while (*cp && ISSPACE (*cp))
+    cp++;
+  if (*cp == '-' || *cp == '+')
+    cp++;
+  if (*cp == 0)
+    valid = 0;
+  for (; *cp; cp++)
+    if (! ISDIGIT (*cp))
+      valid = 0;
+  if (!valid)
+    fatal_with_file_and_line (infile, "invalid decimal constant \"%s\"\n", string);
+}
+
 /* Read an rtx in printed representation from INFILE
    and return an actual rtx in core constructed accordingly.
    read_rtx is not used in the compiler proper, but rather in
@@ -508,15 +532,15 @@ rtx
 read_rtx (infile)
      FILE *infile;
 {
-  register int i, j;
+  int i, j;
   RTX_CODE tmp_code;
-  register const char *format_ptr;
+  const char *format_ptr;
   /* tmp_char is a buffer used for reading decimal integers
      and names of rtx types and machine modes.
      Therefore, 256 must be enough.  */
   char tmp_char[256];
   rtx return_rtx;
-  register int c;
+  int c;
   int tmp_int;
   HOST_WIDE_INT tmp_wide;
 
@@ -615,7 +639,7 @@ again:
          {
            XVEC (return_rtx, i) = 0;
            break;
-         }
+         }
        /* Now process the vector.  */
 
       case 'E':
@@ -635,7 +659,7 @@ again:
            {
              ungetc (c, infile);
              list_counter++;
-             obstack_ptr_grow (&vector_stack, (PTR) read_rtx (infile));
+             obstack_ptr_grow (&vector_stack, read_rtx (infile));
            }
          if (list_counter > 0)
            {
@@ -670,7 +694,7 @@ again:
             gets a star inserted as its first character, if it is
             written with a brace block instead of a string constant.  */
          int star_if_braced = (format_ptr[-1] == 'T');
-           
+
          stringbuf = read_string (&rtl_obstack, infile, star_if_braced);
 
          /* For insn patterns, we want to provide a default name
@@ -704,6 +728,7 @@ again:
 
       case 'w':
        read_name (tmp_char, infile);
+       validate_const_int (infile, tmp_char);
 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
        tmp_wide = atoi (tmp_char);
 #else
@@ -725,6 +750,7 @@ again:
       case 'i':
       case 'n':
        read_name (tmp_char, infile);
+       validate_const_int (infile, tmp_char);
        tmp_int = atoi (tmp_char);
        XINT (return_rtx, i) = tmp_int;
        break;