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.
#define saber_stop()
#endif
+/* Include getopt.h for the sake of getopt_long. */
+#include "getopt.h"
+
#ifndef __LINE__
#define __LINE__ 0
#endif
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)
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;
} 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 */
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 */
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 */
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 *));
};
\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
}
\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. */
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;
{
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++;
}
{
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])
{
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])
(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);
{
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);
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);
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);
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);
/* 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;
/* 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);
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 );
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:
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];
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"));
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;
\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);
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);
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);
fprintf (stderr, "line:\t%s\n", cur_line_start);
had_errors++;
- VA_CLOSE (ap);
+ va_end (ap);
saber_stop ();
}