OSDN Git Service

* collect2.c (find_a_file): Use HAVE_DOS_BASED_FILE_SYSTEM in place
[pf3gnuchains/gcc-fork.git] / gcc / genextract.c
index 471a439..dc5cbd3 100644 (file)
@@ -1,5 +1,5 @@
 /* Generate code from machine description to extract operands from insn as rtl.
-   Copyright (C) 1987, 1991, 1992, 1993 Free Software Foundation, Inc.
+   Copyright (C) 1987, 91-93, 97-98, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -19,8 +19,8 @@ the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
 
-#include <stdio.h>
 #include "hconfig.h"
+#include "system.h"
 #include "rtl.h"
 #include "obstack.h"
 #include "insn-config.h"
@@ -31,9 +31,6 @@ struct obstack *rtl_obstack = &obstack;
 #define obstack_chunk_alloc xmalloc
 #define obstack_chunk_free free
 
-extern void free ();
-extern rtx read_rtx ();
-
 /* Names for patterns.  Need to allow linking with print-rtl.  */
 char **insn_name_ptr;
 
@@ -98,14 +95,12 @@ static int dupnums[MAX_DUP_OPERANDS];
 
 static struct code_ptr *peepholes;
 
-static void walk_rtx ();
-static void print_path ();
-char *xmalloc ();
-char *xrealloc ();
-static void fatal ();
-static char *copystr ();
-static void mybzero ();
-void fancy_abort ();
+static void gen_insn PROTO ((rtx));
+static void walk_rtx PROTO ((rtx, const char *));
+static void print_path PROTO ((char *));
+static void fatal PVPROTO ((const char *, ...))
+  ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
+void fancy_abort PROTO ((void)) ATTRIBUTE_NORETURN;
 \f
 static void
 gen_insn (insn)
@@ -119,7 +114,7 @@ gen_insn (insn)
   dup_count = 0;
 
   /* No operands seen so far in this pattern.  */
-  mybzero (oplocs, sizeof oplocs);
+  memset (oplocs, 0, sizeof oplocs);
 
   /* Walk the insn's pattern, remembering at all times the path
      down to the walking point.  */
@@ -190,13 +185,12 @@ gen_insn (insn)
 static void
 walk_rtx (x, path)
      rtx x;
-     char *path;
+     const char *path;
 {
   register RTX_CODE code;
   register int i;
   register int len;
   register char *fmt;
-  register struct code_ptr *link;
   int depth = strlen (path);
   char *newpath;
 
@@ -215,19 +209,19 @@ walk_rtx (x, path)
 
     case MATCH_OPERAND:
     case MATCH_SCRATCH:
-      oplocs[XINT (x, 0)] = copystr (path);
+      oplocs[XINT (x, 0)] = xstrdup (path);
       op_count = MAX (op_count, XINT (x, 0) + 1);
       break;
 
     case MATCH_DUP:
     case MATCH_PAR_DUP:
-      duplocs[dup_count] = copystr (path);
+      duplocs[dup_count] = xstrdup (path);
       dupnums[dup_count] = XINT (x, 0);
       dup_count++;
       break;
 
     case MATCH_OP_DUP:
-      duplocs[dup_count] = copystr (path);
+      duplocs[dup_count] = xstrdup (path);
       dupnums[dup_count] = XINT (x, 0);
       dup_count++;
       
@@ -243,7 +237,7 @@ walk_rtx (x, path)
       return;
       
     case MATCH_OPERATOR:
-      oplocs[XINT (x, 0)] = copystr (path);
+      oplocs[XINT (x, 0)] = xstrdup (path);
       op_count = MAX (op_count, XINT (x, 0) + 1);
 
       newpath = (char *) alloca (depth + 2);
@@ -258,7 +252,7 @@ walk_rtx (x, path)
       return;
 
     case MATCH_PARALLEL:
-      oplocs[XINT (x, 0)] = copystr (path);
+      oplocs[XINT (x, 0)] = xstrdup (path);
       op_count = MAX (op_count, XINT (x, 0) + 1);
 
       newpath = (char *) alloca (depth + 2);
@@ -275,6 +269,9 @@ walk_rtx (x, path)
     case ADDRESS:
       walk_rtx (XEXP (x, 0), path);
       return;
+
+    default:
+      break;
     }
 
   newpath = (char *) alloca (depth + 2);
@@ -313,6 +310,14 @@ print_path (path)
   register int len = strlen (path);
   register int i;
 
+  if (len == 0)
+    {
+      /* Don't emit "pat", since we may try to take the address of it,
+        which isn't what is intended.  */
+      printf("PATTERN (insn)");
+      return;
+    }
+
   /* We first write out the operations (XEXP or XVECEXP) in reverse
      order, then write "insn", then the indices in forward order.  */
 
@@ -339,34 +344,49 @@ print_path (path)
     }
 }
 \f
-char *
+PTR
 xmalloc (size)
-     unsigned size;
+  size_t size;
 {
-  register char *val = (char *) malloc (size);
+  register PTR val = (PTR) malloc (size);
 
   if (val == 0)
     fatal ("virtual memory exhausted");
   return val;
 }
 
-char *
-xrealloc (ptr, size)
-     char *ptr;
-     unsigned size;
+PTR
+xrealloc (old, size)
+  PTR old;
+  size_t size;
 {
-  char *result = (char *) realloc (ptr, size);
-  if (!result)
+  register PTR ptr;
+  if (old)
+    ptr = (PTR) realloc (old, size);
+  else
+    ptr = (PTR) malloc (size);
+  if (!ptr)
     fatal ("virtual memory exhausted");
-  return result;
+  return ptr;
 }
 
 static void
-fatal (s, a1, a2)
-     char *s;
+fatal VPROTO ((const char *format, ...))
 {
+#ifndef ANSI_PROTOTYPES
+  const char *format;
+#endif
+  va_list ap;
+
+  VA_START (ap, format);
+
+#ifndef ANSI_PROTOTYPES
+  format = va_arg (ap, const char *);
+#endif
+
   fprintf (stderr, "genextract: ");
-  fprintf (stderr, s, a1, a2);
+  vfprintf (stderr, format, ap);
+  va_end (ap);
   fprintf (stderr, "\n");
   exit (FATAL_EXIT_CODE);
 }
@@ -380,28 +400,14 @@ fancy_abort ()
   fatal ("Internal gcc abort.");
 }
 
-static char *
-copystr (s1)
-     char *s1;
-{
-  register char *tem;
-
-  if (s1 == 0)
-    return 0;
-
-  tem = (char *) xmalloc (strlen (s1) + 1);
-  strcpy (tem, s1);
-
-  return tem;
-}
-
-static void
-mybzero (b, length)
-     register char *b;
-     register unsigned length;
+char *
+xstrdup (input)
+  const char *input;
 {
-  while (length-- > 0)
-    *b++ = 0;
+  register size_t len = strlen (input) + 1;
+  register char *output = xmalloc (len);
+  memcpy (output, input, len);
+  return output;
 }
 \f
 int
@@ -438,16 +444,15 @@ main (argc, argv)
 from the machine description file `md'.  */\n\n");
 
   printf ("#include \"config.h\"\n");
-  printf ("#include \"rtl.h\"\n\n");
+  printf ("#include \"system.h\"\n");
+  printf ("#include \"rtl.h\"\n");
+  printf ("#include \"insn-config.h\"\n");
+  printf ("#include \"recog.h\"\n");
+  printf ("#include \"toplev.h\"\n\n");
 
   /* This variable exists only so it can be the "location"
      of any missing operand whose numbers are skipped by a given pattern.  */
-  printf ("static rtx junk;\n");
-
-  printf ("extern rtx recog_operand[];\n");
-  printf ("extern rtx *recog_operand_loc[];\n");
-  printf ("extern rtx *recog_dup_loc[];\n");
-  printf ("extern char recog_dup_num[];\n");
+  printf ("static rtx junk ATTRIBUTE_UNUSED;\n");
 
   printf ("void\ninsn_extract (insn)\n");
   printf ("     rtx insn;\n");
@@ -455,6 +460,9 @@ from the machine description file `md'.  */\n\n");
   printf ("  register rtx *ro = recog_operand;\n");
   printf ("  register rtx **ro_loc = recog_operand_loc;\n");
   printf ("  rtx pat = PATTERN (insn);\n");
+  printf ("  int i ATTRIBUTE_UNUSED;\n\n");
+  printf ("  memset (ro, 0, sizeof (*ro) * MAX_RECOG_OPERANDS);\n");
+  printf ("  memset (ro_loc, 0, sizeof (*ro_loc) * MAX_RECOG_OPERANDS);\n");
   printf ("  switch (INSN_CODE (insn))\n");
   printf ("    {\n");
   printf ("    case -1:\n");
@@ -502,11 +510,8 @@ from the machine description file `md'.  */\n\n");
       /* The vector in the insn says how many operands it has.
         And all it contains are operands.  In fact, the vector was
         created just for the sake of this function.  */
-      printf ("#if __GNUC__ > 1 && !defined (bcopy)\n");
-      printf ("#define bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)\n");
-      printf ("#endif\n");
-      printf ("      bcopy (&XVECEXP (pat, 0, 0), ro,\n");
-      printf ("             sizeof (rtx) * XVECLEN (pat, 0));\n");
+      printf ("      for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)\n");
+      printf ("          ro[i] = XVECEXP (pat, 0, i);\n");
       printf ("      break;\n\n");
     }