OSDN Git Service

* (REG_CLASS_FROM_CONSTRAINT): Only define if not already defined.
[pf3gnuchains/gcc-fork.git] / gcc / mips-tfile.c
index 0f72aee..c7b7840 100644 (file)
@@ -2,8 +2,8 @@
    contain debugging information specified by the GNU compiler
    in the form of comments (the mips assembler does not support
    assembly access to debug information).
-   Copyright (C) 1991, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001
-   Free Software Foundation, Inc.
+   Copyright (C) 1991, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
+   2002, 2003 Free Software Foundation, Inc.
    Contributed by Michael Meissner (meissner@cygnus.com).
    
 This file is part of GCC.
@@ -611,6 +611,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #define saber_stop()
 #endif
 
+/* Include getopt.h for the sake of getopt_long.  */
+#include "getopt.h"
+
 #ifndef __LINE__
 #define __LINE__ 0
 #endif
@@ -895,13 +898,10 @@ enum alloc_type {
    pages.  On systems with a BSD malloc that define USE_MALLOC, the
    MAX_CLUSTER_PAGES should be 1 less than a power of two, since malloc
    adds its overhead, and rounds up to the next power of 2.  Pages are
-   linked together via a linked list.
-
-   If PAGE_SIZE is > 4096, the string length in the shash_t structure
-   can't be represented (assuming there are strings > 4096 bytes).  */
+   linked together via a linked list.  */
 
 #ifndef PAGE_SIZE
-#define PAGE_SIZE 4096         /* size of varray pages */
+#define PAGE_SIZE 32768                /* size of varray pages */
 #endif
 
 #define PAGE_USIZE ((Size_t) PAGE_SIZE)
@@ -950,6 +950,13 @@ typedef struct varray {
   OBJECTS_PER_PAGE (type),     /* objects_last_page */                 \
 }
 
+#define INITIALIZE_VARRAY(x,type)                      \
+do {                                                   \
+  (x)->object_size = sizeof (type);                    \
+  (x)->objects_per_page = OBJECTS_PER_PAGE (type);     \
+  (x)->objects_last_page = OBJECTS_PER_PAGE (type);    \
+} while (0)
+
 /* Master type for indexes within the symbol table.  */
 typedef unsigned long symint_t;
 
@@ -1066,90 +1073,8 @@ typedef struct efdr {
 } efdr_t;
 
 /* Pre-initialized extended file structure.  */
-static efdr_t init_file = 
-{
-  {                    /* FDR structure */
-#ifdef __alpha
-    0,                 /* adr:         memory address of beginning of file */
-    0,                 /* cbLineOffset: byte offset from header for this file ln's */
-    0,                 /* cbLine:      size of lines for this file */
-    0,                 /* cbSs:        number of bytes in the ss */
-    0,                 /* rss:         file name (of source, if known) */
-    0,                 /* issBase:     file's string space */
-    0,                 /* isymBase:    beginning of symbols */
-    0,                 /* csym:        count file's of symbols */
-    0,                 /* ilineBase:   file's line symbols */
-    0,                 /* cline:       count of file's line symbols */
-    0,                 /* ioptBase:    file's optimization entries */
-    0,                 /* copt:        count of file's optimization entries */
-    0,                 /* ipdFirst:    start of procedures for this file */
-    0,                 /* cpd:         count of procedures for this file */
-    0,                 /* iauxBase:    file's auxiliary entries */
-    0,                 /* caux:        count of file's auxiliary entries */
-    0,                 /* rfdBase:     index into the file indirect table */
-    0,                 /* crfd:        count file indirect entries */
-    langC,             /* lang:        language for this file */
-    1,                 /* fMerge:      whether this file can be merged */
-    0,                 /* fReadin:     true if read in (not just created) */
-#ifdef HOST_WORDS_BIG_ENDIAN
-    1,                 /* fBigendian:  if 1, compiled on big endian machine */
-#else
-    0,                 /* fBigendian:  if 1, compiled on big endian machine */
-#endif
-    0,                 /* fTrim:       whether the symbol table was trimmed */
-    GLEVEL_2,          /* glevel:      level this file was compiled with */
-    0,                 /* reserved:    reserved for future use */
-#else
-    0,                 /* adr:         memory address of beginning of file */
-    0,                 /* rss:         file name (of source, if known) */
-    0,                 /* issBase:     file's string space */
-    0,                 /* cbSs:        number of bytes in the ss */
-    0,                 /* isymBase:    beginning of symbols */
-    0,                 /* csym:        count file's of symbols */
-    0,                 /* ilineBase:   file's line symbols */
-    0,                 /* cline:       count of file's line symbols */
-    0,                 /* ioptBase:    file's optimization entries */
-    0,                 /* copt:        count of file's optimization entries */
-    0,                 /* ipdFirst:    start of procedures for this file */
-    0,                 /* cpd:         count of procedures for this file */
-    0,                 /* iauxBase:    file's auxiliary entries */
-    0,                 /* caux:        count of file's auxiliary entries */
-    0,                 /* rfdBase:     index into the file indirect table */
-    0,                 /* crfd:        count file indirect entries */
-    langC,             /* lang:        language for this file */
-    1,                 /* fMerge:      whether this file can be merged */
-    0,                 /* fReadin:     true if read in (not just created) */
-#ifdef HOST_WORDS_BIG_ENDIAN
-    1,                 /* fBigendian:  if 1, compiled on big endian machine */
-#else
-    0,                 /* fBigendian:  if 1, compiled on big endian machine */
-#endif
-    GLEVEL_2,          /* glevel:      level this file was compiled with */
-    0,                 /* reserved:    reserved for future use */
-    0,                 /* cbLineOffset: byte offset from header for this file ln's */
-    0,                 /* cbLine:      size of lines for this file */
-#endif
-  },
-
-  (FDR *) 0,           /* orig_fdr:    original file header pointer */
-  (char *) 0,          /* name:        pointer to filename */
-  0,                   /* name_len:    length of filename */
-  0,                   /* void_type:   ptr to aux node for void type */
-  0,                   /* int_type:    ptr to aux node for int type */
-  (scope_t *) 0,       /* cur_scope:   current scope being processed */
-  0,                   /* file_index:  current file # */
-  0,                   /* nested_scopes: # nested scopes */
-  INIT_VARRAY (char),  /* strings:     local string varray */
-  INIT_VARRAY (SYMR),  /* symbols:     local symbols varray */
-  INIT_VARRAY (PDR),   /* procs:       procedure varray */
-  INIT_VARRAY (AUXU),  /* aux_syms:    auxiliary symbols varray */
-
-  (struct efdr *) 0,   /* next_file:   next file structure */
-
-  (shash_t **) 0,      /* shash_head:  string hash table */
-  { 0 },               /* thash_head:  type hash table */
-};
-
+static int init_file_initialized = 0;
+static efdr_t init_file;
 
 static efdr_t *first_file;                     /* first file descriptor */
 static efdr_t **last_file_ptr = &first_file;   /* file descriptor tail */
@@ -1570,8 +1495,8 @@ static SYMR    *cur_oproc_begin   = (SYMR *) 0;   /* original proc. sym begin info *
 static SYMR    *cur_oproc_end  = (SYMR *) 0;   /* original proc. sym end info */
 static PDR     *cur_oproc_ptr  = (PDR *) 0;    /* current original procedure*/
 static thead_t *cur_tag_head   = (thead_t *) 0;/* current tag head */
-static long    file_offset     = 0;            /* current file offset */
-static long    max_file_offset = 0;            /* maximum file offset */
+static unsigned long file_offset       = 0;    /* current file offset */
+static unsigned long max_file_offset   = 0;    /* maximum file offset */
 static FILE    *object_stream  = (FILE *) 0;   /* file desc. to output .o */
 static FILE    *obj_in_stream  = (FILE *) 0;   /* file desc. to input .o */
 static char    *progname       = (char *) 0;   /* program name for errors */
@@ -1585,6 +1510,7 @@ static unsigned   cur_line_alloc  = 0;            /* # bytes total in buffer */
 static long    line_number     = 0;            /* current input line number */
 static int     debug           = 0;            /* trace functions */
 static int     version         = 0;            /* print version # */
+static int     verbose         = 0;
 static int     had_errors      = 0;            /* != 0 if errors were found */
 static int     rename_output   = 0;            /* != 0 if rename output file*/
 static int     delete_input    = 0;            /* != 0 if delete input after done */
@@ -1649,6 +1575,8 @@ STATIC void       add_unknown_tag PARAMS ((tag_t *));
 STATIC void    add_procedure   PARAMS ((const char *,
                                         const char *));
 
+STATIC void    initialize_init_file    PARAMS ((void));
+
 STATIC void    add_file        PARAMS ((const char *,
                                         const char *));
 
@@ -1737,6 +1665,15 @@ static const pseudo_ops_t pseudo_ops[] = {
 };
 
 \f
+/* Command line options for getopt_long.  */
+
+static const struct option options[] =
+{
+  { "version", 0, 0, 'V' },
+  { "verbose", 0, 0, 'v' },
+  { 0, 0, 0, 0 }
+};
+\f
 /* Add a page to a varray object.  */
 
 STATIC void
@@ -2473,6 +2410,29 @@ add_procedure (func_start, func_end_p1)
 }
 
 \f
+/* Initialize the init_file structure.  */
+
+STATIC void
+initialize_init_file ()
+{
+  memset ((void*) &init_file, 0, sizeof (init_file));
+
+  init_file.fdr.lang = langC;
+  init_file.fdr.fMerge = 1;
+  init_file.fdr.glevel = GLEVEL_2;
+
+#ifdef HOST_WORDS_BIG_ENDIAN
+  init_file.fdr.fBigendian = 1;
+#endif
+
+  INITIALIZE_VARRAY (&init_file.strings, char);
+  INITIALIZE_VARRAY (&init_file.symbols, SYMR);
+  INITIALIZE_VARRAY (&init_file.procs, PDR);
+  INITIALIZE_VARRAY (&init_file.aux_syms, AUXU);
+
+  init_file_initialized = 1;
+}
+
 /* Add a new filename, and set up all of the file relative
    virtual arrays (strings, symbols, aux syms, etc.).  Record
    where the current file structure lives.  */
@@ -2511,6 +2471,9 @@ add_file (file_start, file_end_p1)
       if (file_desc.objects_last_page == file_desc.objects_per_page)
        add_varray_page (&file_desc);
 
+      if (! init_file_initialized)
+       initialize_init_file ();
+
       file_ptr = cur_file_ptr
        = &file_desc.last->datum->file[ file_desc.objects_last_page++ ];
       *file_ptr = init_file;
@@ -2950,7 +2913,7 @@ parse_def (name_start)
        {
          int ch2;
          arg_number = strtol (arg_start, (char **) &arg_end_p1, 0);
-         if (arg_end_p1 != arg_start || (ch2 = *arg_end_p1 != ';') || ch2 != ',')
+         if (arg_end_p1 != arg_start || ((ch2 = *arg_end_p1) != ';') || ch2 != ',')
            arg_was_number++;
        }
 
@@ -3006,7 +2969,7 @@ parse_def (name_start)
                    {
                      int ch2;
                      arg_number = strtol (arg_start, (char **) &arg_end_p1, 0);
-                     if (arg_end_p1 != arg_start || (ch2 = *arg_end_p1 != ';') || ch2 != ',')
+                     if (arg_end_p1 != arg_start || ((ch2 = *arg_end_p1) != ';') || ch2 != ',')
                        arg_was_number++;
 
                      if (t_ptr == &temp_array[0])
@@ -3080,7 +3043,7 @@ parse_def (name_start)
                    {
                      int ch2;
                      arg_number = strtol (arg_start, (char **) &arg_end_p1, 0);
-                     if (arg_end_p1 != arg_start || (ch2 = *arg_end_p1 != ';') || ch2 != ',')
+                     if (arg_end_p1 != arg_start || ((ch2 = *arg_end_p1) != ';') || ch2 != ',')
                        arg_was_number++;
 
                      if (t_ptr == &temp_array[0])
@@ -4102,7 +4065,7 @@ write_varray (vp, offset, str)
               (unsigned long) offset, vp->num_allocated * vp->object_size, str);
     }
   
-  if (file_offset != offset
+  if (file_offset != (unsigned long) offset
       && fseek (object_stream, (long) offset, SEEK_SET) < 0)
     pfatal_with_name (object_name);
 
@@ -4165,7 +4128,7 @@ write_object ()
     {
       long sys_write;
 
-      if (file_offset != symbolic_header.cbLineOffset
+      if (file_offset != (unsigned long) symbolic_header.cbLineOffset
          && fseek (object_stream, symbolic_header.cbLineOffset, SEEK_SET) != 0)
        pfatal_with_name (object_name);
 
@@ -4200,7 +4163,7 @@ write_object ()
       long sys_write;
       long num_write = symbolic_header.ioptMax * sizeof (OPTR);
 
-      if (file_offset != symbolic_header.cbOptOffset
+      if (file_offset != (unsigned long) symbolic_header.cbOptOffset
          && fseek (object_stream, symbolic_header.cbOptOffset, SEEK_SET) != 0)
        pfatal_with_name (object_name);
 
@@ -4287,7 +4250,7 @@ write_object ()
   if (symbolic_header.ifdMax > 0)              /* file tables */
     {
       offset = symbolic_header.cbFdOffset;
-      if (file_offset != offset
+      if (file_offset != (unsigned long) offset
          && fseek (object_stream, (long) offset, SEEK_SET) < 0)
        pfatal_with_name (object_name);
 
@@ -4328,7 +4291,7 @@ write_object ()
       long sys_write;
       symint_t num_write = symbolic_header.crfd * sizeof (symint_t);
 
-      if (file_offset != symbolic_header.cbRfdOffset
+      if (file_offset != (unsigned long) symbolic_header.cbRfdOffset
          && fseek (object_stream, symbolic_header.cbRfdOffset, SEEK_SET) != 0)
        pfatal_with_name (object_name);
 
@@ -4393,7 +4356,7 @@ read_seek (size, offset, str)
 
   /* If we need to seek, and the distance is nearby, just do some reads,
      to speed things up.  */
-  if (file_offset != offset)
+  if (file_offset != (unsigned long) offset)
     {
       symint_t difference = offset - file_offset;
 
@@ -4571,7 +4534,7 @@ copy_object ()
 
 
   /* Abort if the symbol table is not last.  */
-  if (max_file_offset != stat_buf.st_size)
+  if (max_file_offset != (unsigned long) stat_buf.st_size)
     fatal ("symbol table is not last (symbol table ends at %ld, .o ends at %ld",
           max_file_offset,
           (long) stat_buf.st_size);
@@ -4625,7 +4588,7 @@ copy_object ()
   for (es = 0; es < orig_sym_hdr.iextMax; es++)
     {
       EXTR *eptr = orig_ext_syms + es;
-      unsigned ifd = eptr->ifd;
+      int ifd = eptr->ifd;
 
       (void) add_ext_symbol (eptr, ((long) ifd < orig_sym_hdr.ifdMax)
                             ? remap_file_number[ ifd ] : ifd );
@@ -4856,7 +4819,7 @@ main (argc, argv)
   void_type_info = type_info_init;
   void_type_info.basic_type = bt_Void;
 
-  while ((option = getopt (argc, argv, "d:i:I:o:v")) != EOF)
+  while ((option = getopt_long (argc, argv, "d:i:I:o:v", options, NULL)) != -1)
     switch (option)
       {
       default:
@@ -4896,10 +4859,24 @@ main (argc, argv)
        break;
 
       case 'v':
+       verbose++;
+       break;
+
+      case 'V':
        version++;
        break;
       }
 
+  if (version)
+    {
+      printf (_("mips-tfile (GCC) %s\n"), version_string);
+      fputs (_("Copyright (C) 2003 Free Software Foundation, Inc.\n"), stdout);
+      fputs (_("This is free software; see the source for copying conditions.  There is NO\n\
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
+            stdout);
+      exit (0);
+    }
+
   if (obj_in_name == (char *) 0 && optind <= argc - 2)
     obj_in_name = argv[--argc];
 
@@ -4915,7 +4892,19 @@ main (argc, argv)
       delete_input = 1;
     }
 
-  if (object_name == (char *) 0 || had_errors || optind != argc - 1)
+  if (optind != argc - 1)
+    had_errors++;
+
+  if (verbose || had_errors)
+    {
+      fprintf (stderr, _("mips-tfile (GCC) %s"), version_string);
+#ifdef TARGET_VERSION
+      TARGET_VERSION;
+#endif
+      fputc ('\n', stderr);
+    }
+
+  if (object_name == (char *) 0 || had_errors)
     {
       fprintf (stderr, _("Calling Sequence:\n"));
       fprintf (stderr, _("\tmips-tfile [-d <num>] [-v] [-i <o-in-file>] -o <o-out-file> <s-file> (or)\n"));
@@ -4930,16 +4919,6 @@ main (argc, argv)
       return 1;
     }
 
-
-  if (version)
-    {
-      fprintf (stderr, _("mips-tfile version %s"), version_string);
-#ifdef TARGET_VERSION
-      TARGET_VERSION;
-#endif
-      fputc ('\n', stderr);
-    }
-
   if (obj_in_name == (char *) 0)
     obj_in_name = object_name;
 
@@ -5559,12 +5538,12 @@ free_thead (ptr)
 \f
 /* Output an error message and exit */
 
-/*VARARGS*/
 void
-fatal VPARAMS ((const char *format, ...))
+fatal (const char *format, ...)
 {
-  VA_OPEN (ap, format);
-  VA_FIXEDARG (ap, const char *, format);
+  va_list ap;
+  
+  va_start (ap, format);
 
   if (line_number > 0)
     fprintf (stderr, "%s, %s:%ld ", progname, input_name, line_number);
@@ -5572,7 +5551,7 @@ fatal VPARAMS ((const char *format, ...))
     fprintf (stderr, "%s:", progname);
 
   vfprintf (stderr, format, ap);
-  VA_CLOSE (ap);
+  va_end (ap);
   fprintf (stderr, "\n");
   if (line_number > 0)
     fprintf (stderr, "line:\t%s\n", cur_line_start);
@@ -5581,12 +5560,12 @@ fatal VPARAMS ((const char *format, ...))
   exit (1);
 }
 
-/*VARARGS*/
 void
-error VPARAMS ((const char *format, ...))
+error (const char *format, ...)
 {
-  VA_OPEN (ap, format);
-  VA_FIXEDARG (ap, char *, format);
+  va_list ap;
+  
+  va_start (ap, format);
 
   if (line_number > 0)
     fprintf (stderr, "%s, %s:%ld ", progname, input_name, line_number);
@@ -5599,7 +5578,7 @@ error VPARAMS ((const char *format, ...))
     fprintf (stderr, "line:\t%s\n", cur_line_start);
 
   had_errors++;
-  VA_CLOSE (ap);
+  va_end (ap);
 
   saber_stop ();
 }