OSDN Git Service

(do_include): Diagnose #import and #include_next if pedantic and if
[pf3gnuchains/gcc-fork.git] / gcc / bc-emit.c
index 1fb3f36..c93195d 100644 (file)
@@ -1,5 +1,5 @@
 /* Output bytecodes for GNU C-compiler.
-   Copyright (C) 1993 Free Software Foundation, Inc.
+   Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -15,13 +15,16 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
-#include <stdio.h>
-#include <varargs.h>
-#include <string.h>
 #include "config.h"
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
 #include "machmode.h"
 #include "rtl.h"
 #include "real.h"
@@ -35,34 +38,30 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "bc-typecd.h"
 #include "bi-run.h"
 
-extern char *xmalloc(), *xrealloc();
-extern void free();
-
-extern struct obstack *rtl_obstack;
+#include <stdio.h>
 
-REAL_VALUE_TYPE dconst0;
-REAL_VALUE_TYPE dconst1;
-REAL_VALUE_TYPE dconst2;
-REAL_VALUE_TYPE dconstm1;
+extern char *xmalloc (), *xrealloc ();
 
+extern struct obstack *rtl_obstack;
 
 /* Indexed by mode class, gives the narrowest mode for each class.  */
 
-enum machine_mode class_narrowest_mode[(int) MAX_MODE_CLASS];
+extern enum machine_mode class_narrowest_mode[(int) MAX_MODE_CLASS];
 
 /* Commonly used modes.  */
 /* Mode whose width is BITS_PER_UNIT */
-enum machine_mode byte_mode;
+extern enum machine_mode byte_mode;
 
 /* Mode whose width is BITS_PER_WORD */
-enum machine_mode word_mode;
+extern enum machine_mode word_mode;
 
-/* Vector indexed by opcode giving info about the args for each opcode. */
+/* Vector indexed by opcode giving info about the args for each opcode.  */
 static struct arityvec arityvec[] = {
 #include "bc-arity.h"
 };
 
 /* How to print a symbol name for the assembler.  */
+
 static void
 prsym (file, s)
      FILE *file;
@@ -80,7 +79,7 @@ prsym (file, s)
 
 }
 
-/* Maintain a bucket hash table for symbol names. */
+/* Maintain a bucket hash table for symbol names.  */
 
 #define HASH_BITS 32
 #define HASH_SIZE 509
@@ -103,7 +102,8 @@ hash (name)
 }
 
 
-/* Look up the named symbol, creating it if it doesn't exist. */
+/* Look up the named symbol, creating it if it doesn't exist.  */
+
 struct bc_sym *
 sym_lookup (name)
      char *name;
@@ -111,7 +111,7 @@ sym_lookup (name)
   int i;
   struct bc_sym *s;
 
-  i = hash(name);
+  i = hash (name);
   for (s = hashtab[i]; s; s = s->next)
     if (!strcmp (s->name, name))
       return s;
@@ -128,6 +128,7 @@ sym_lookup (name)
 
 
 /* Write out .globl and common symbols to the named file.  */
+
 static void
 bc_sym_write (file)
      FILE *file;
@@ -147,14 +148,14 @@ bc_sym_write (file)
              {
                fprintf (file, "\n\t.comm ");
                prsym (file, s->name);
-               fprintf (file, ", %d\n", s->val);
+               fprintf (file, ", %lu\n", s->val);
              }
          }
        else if (s->common)
          {
            fprintf (file, "\n\t.lcomm ");
            prsym (file, s->name);
-           fprintf (file, ", %d\n", s->val);
+           fprintf (file, ", %lu\n", s->val);
          }
       }
 }
@@ -162,15 +163,16 @@ bc_sym_write (file)
 \f
 
 
-/* Create and initialize a new segment. */
+/* Create and initialize a new segment.  */
+
 static struct bc_seg *
 seg_create ()
 {
   struct bc_seg *result;
 
-  result = (struct bc_seg *) xmalloc(sizeof (struct bc_seg));
+  result = (struct bc_seg *) xmalloc (sizeof (struct bc_seg));
   result->alloc = 256;
-  result->data = xmalloc(result->alloc);
+  result->data = xmalloc (result->alloc);
   result->size = 0;
   result->syms = 0;
   result->relocs = 0;
@@ -178,7 +180,8 @@ seg_create ()
 }
 
 
-/* Advance the segment index to the next alignment boundary. */
+/* Advance the segment index to the next alignment boundary.  */
+
 static void
 seg_align (seg, log)
      struct bc_seg *seg;
@@ -191,13 +194,14 @@ seg_align (seg, log)
     {
       while (seg->size > seg->alloc)
        seg->alloc *= 2;
-      seg->data = xrealloc(seg->data, seg->alloc);
+      seg->data = xrealloc (seg->data, seg->alloc);
     }
-  memset(seg->data + oldsize, 0, seg->size - oldsize);
+  bzero (seg->data + oldsize, seg->size - oldsize);
 }
 
 
-/* Append the given data to the given segment. */
+/* Append the given data to the given segment.  */
+
 static void
 seg_data (seg, data, size)
      struct bc_seg *seg;
@@ -211,12 +215,13 @@ seg_data (seg, data, size)
       seg->data = xrealloc (seg->data, seg->alloc);
     }
 
-  memcpy (seg->data + seg->size, data, size);
+  bcopy (data, seg->data + seg->size, size);
   seg->size += size;
 }
 
 
 /* Append a zero-filled skip to the given segment.  */
+
 static void
 seg_skip (seg, size)
      struct bc_seg *seg;
@@ -236,7 +241,8 @@ seg_skip (seg, size)
 
 /* Define the given name as the current offset in the given segment.  It
    is an error if the name is already defined.  Return 0 or 1 indicating
-   failure or success respectively. */
+   failure or success respectively.  */
+
 static int
 seg_defsym (seg, name)
      struct bc_seg *seg;
@@ -245,13 +251,13 @@ seg_defsym (seg, name)
   struct bc_sym *sym;
   struct bc_segsym *segsym;
 
-  sym = sym_lookup(name);
+  sym = sym_lookup (name);
   if (sym->defined)
     return 0;
 
   sym->defined = 1;
   sym->val = seg->size;
-  segsym = (struct bc_segsym *) xmalloc(sizeof (struct bc_segsym));
+  segsym = (struct bc_segsym *) xmalloc (sizeof (struct bc_segsym));
   segsym->sym = sym;
   segsym->next = seg->syms;
   seg->syms = segsym;
@@ -260,7 +266,8 @@ seg_defsym (seg, name)
 
 
 /* Generate in seg's data a reference to the given sym, adjusted by
-   the given offset. */
+   the given offset.  */
+
 static void
 seg_refsym (seg, name, offset)
      struct bc_seg *seg;
@@ -270,17 +277,18 @@ seg_refsym (seg, name, offset)
   struct bc_sym *sym;
   struct bc_segreloc *segreloc;
 
-  sym = sym_lookup(name);
-  segreloc = (struct bc_segreloc *) xmalloc(sizeof (struct bc_segreloc));
+  sym = sym_lookup (name);
+  segreloc = (struct bc_segreloc *) xmalloc (sizeof (struct bc_segreloc));
   segreloc->offset = seg->size;
   segreloc->sym = sym;
   segreloc->next = seg->relocs;
   seg->relocs = segreloc;
-  seg_data(seg, (char *) &offset, sizeof offset);
+  seg_data (seg, (char *) &offset, sizeof offset);
 }
 
 
-/* Concatenate the contents of given segments into the first argument. */
+/* Concatenate the contents of given segments into the first argument.  */
+
 static void
 seg_concat (result, seg)
      struct bc_seg *result, *seg;
@@ -289,13 +297,13 @@ seg_concat (result, seg)
   struct bc_segsym *segsym;
   struct bc_segreloc *segreloc;
 
-  seg_align(result, MACHINE_SEG_ALIGN);
+  seg_align (result, MACHINE_SEG_ALIGN);
   fix = result->size;
-  seg_data(result, seg->data, seg->size);
-  free(seg->data);
+  seg_data (result, seg->data, seg->size);
+  free (seg->data);
 
   /* Go through the symbols and relocs of SEG, adjusting their offsets
-     for their new location in RESULT. */
+     for their new location in RESULT.  */
   if (seg->syms)
     {
       segsym = seg->syms;
@@ -315,10 +323,11 @@ seg_concat (result, seg)
       result->relocs = seg->relocs;
     }
 
-  free((char *) seg);
+  free ((char *) seg);
 }
 
 /* Write a segment to a file.  */
+
 static void
 bc_seg_write (seg, file)
      struct bc_seg *seg;
@@ -352,7 +361,7 @@ bc_seg_write (seg, file)
       while (segsym && segsym->sym->val == i)
        {
          if (i % 8 != 0)
-           putc('\n', file);
+           putc ('\n', file);
 
          BC_WRITE_SEGSYM (segsym, file);
          segsym = segsym->next;
@@ -363,7 +372,7 @@ bc_seg_write (seg, file)
          if (i % 8 != 0)
            putc ('\n', file);
 
-         offset = *(int *) (seg->data + i);
+         bcopy (seg->data + i, (char *) &offset, sizeof (int));
          i += sizeof (int) - 1;
 
          BC_WRITE_RELOC_ENTRY (segreloc, file, offset);
@@ -393,11 +402,12 @@ bc_seg_write (seg, file)
 
 \f
 
-/* Text and data segments of the object file in making. */
+/* Text and data segments of the object file in making.  */
 static struct bc_seg *bc_text_seg;
 static struct bc_seg *bc_data_seg;
 
-/* Called before anything else in this module. */
+/* Called before anything else in this module.  */
+
 void
 bc_initialize ()
 {
@@ -443,27 +453,28 @@ bc_initialize ()
 /* External addresses referenced in a function.  Rather than trying to
    work relocatable address directly into bytecoded functions (which would
    require us to provide hairy location info and possibly obey alignment
-   rules imposed by the architecture) we build an auxilary table of
+   rules imposed by the architecture) we build an auxiliary table of
    pointer constants, and encode just offsets into this table into the
-   actual bytecode. */
+   actual bytecode.  */
 static struct bc_seg *ptrconsts;
 
 /* Trampoline code for the function entry.  */
 struct bc_seg *trampoline;
 
-/* Actual byte code of the function. */
+/* Actual byte code of the function.  */
 struct bc_seg *bytecode;
 
-/* List of labels defined in the function. */
+/* List of labels defined in the function.  */
 struct bc_label *labels;
 
-/* List of label references in the function. */
+/* List of label references in the function.  */
 struct bc_labelref *labelrefs;
 
 
 /* Add symbol to pointer table.  Return offset into table where
    pointer was stored.  The offset usually goes into the bytecode
-   stream as a constP literal. */
+   stream as a constP literal.  */
+
 int
 bc_define_pointer (p)
      char *p;
@@ -476,6 +487,7 @@ bc_define_pointer (p)
 
 
 /* Begin a bytecoded function.  */
+
 int
 bc_begin_function (name)
     char *name;
@@ -488,6 +500,7 @@ bc_begin_function (name)
 
 
 /* Force alignment in inline bytecode.  */
+
 void
 bc_align_bytecode (align)
     int align;
@@ -497,6 +510,7 @@ bc_align_bytecode (align)
 
 
 /* Emit data inline into bytecode.  */
+
 void
 bc_emit_bytecode_const (data, size)
      char *data;
@@ -509,7 +523,8 @@ bc_emit_bytecode_const (data, size)
 
 /* Create a new "bytecode label", to have its value defined later.
    Bytecode labels have nothing to do with the object file symbol table,
-   and are purely local to a given bytecoded function. */
+   and are purely local to a given bytecoded function.  */
+
 struct bc_label *
 bc_get_bytecode_label ()
 {
@@ -524,7 +539,8 @@ bc_get_bytecode_label ()
 }
 
 
-/* Define the given label with the current location counter. */
+/* Define the given label with the current location counter.  */
+
 int
 bc_emit_bytecode_labeldef (label)
      struct bc_label *label;
@@ -547,7 +563,8 @@ bc_emit_bytecode_labeldef (label)
 
 
 /* Generate a location-relative reference to the given bytecode label.
-   It need not be defined yet; label references will be backpatched later. */
+   It need not be defined yet; label references will be backpatched later.  */
+
 void
 bc_emit_bytecode_labelref (label)
      struct bc_label *label;
@@ -570,7 +587,8 @@ bc_emit_bytecode_labelref (label)
 
 
 /* Emit a reference to an external address; generate the reference in the
-   ptrconst area, and emit an offset in the bytecode. */
+   ptrconst area, and emit an offset in the bytecode.  */
+
 void
 bc_emit_code_labelref (name, offset)
      char *name;
@@ -591,6 +609,7 @@ bc_emit_code_labelref (name, offset)
 /* Backpatch label references in the byte code, and concatenate the bytecode
    and pointer constant segments to the cumulative text for the object file.
    Return a label name for the pointer constants region.  */
+
 char *
 bc_end_function ()
 {
@@ -600,16 +619,15 @@ bc_end_function ()
   char ptrconsts_label[20];
   static int nlab;
 
-  /* Backpatch bytecode label references. */
+  /* Backpatch bytecode label references.  */
   for (ref = labelrefs; ref; ref = ref->next)
     if (ref->label->defined)
       {
        addr = ref->label->offset;
-       memcpy (bytecode->data + ref->offset, /* incest */
-               (char *) &addr, sizeof addr);
+       bcopy ((char *) &addr, bytecode->data + ref->offset, sizeof addr);
       }
 
-  /* Free the chains of labelrefs and labeldefs. */
+  /* Free the chains of labelrefs and labeldefs.  */
   for (ref = labelrefs; ref; ref = nextref)
     {
       nextref = ref->next;
@@ -638,7 +656,8 @@ bc_end_function ()
   return sym_lookup (ptrconsts_label)->name;
 }
 
-/* Force alignment in const data. */
+/* Force alignment in const data.  */
+
 void
 bc_align_const (align)
      int align;
@@ -646,7 +665,8 @@ bc_align_const (align)
   seg_align (bc_text_seg, align);
 }
 
-/* Emit const data. */
+/* Emit const data.  */
+
 void
 bc_emit_const (data, size)
      char *data;
@@ -655,7 +675,8 @@ bc_emit_const (data, size)
   seg_data (bc_text_seg, data, size);
 }
 
-/* Emit a zero-filled constant skip. */
+/* Emit a zero-filled constant skip.  */
+
 void
 bc_emit_const_skip (size)
      unsigned int size;
@@ -663,7 +684,8 @@ bc_emit_const_skip (size)
   seg_skip (bc_text_seg, size);
 }
 
-/* Emit a label definition in const data. */
+/* Emit a label definition in const data.  */
+
 int
 bc_emit_const_labeldef (name)
      char *name;
@@ -671,7 +693,8 @@ bc_emit_const_labeldef (name)
   return seg_defsym (bc_text_seg, name);
 }
 
-/* Emit a label reference in const data. */
+/* Emit a label reference in const data.  */
+
 void
 bc_emit_const_labelref (name, offset)
      char *name;
@@ -680,7 +703,8 @@ bc_emit_const_labelref (name, offset)
   seg_refsym (bc_text_seg, name, offset);
 }
 
-/* Force alignment in data. */
+/* Force alignment in data.  */
+
 void
 bc_align_data (align)
      int align;
@@ -688,9 +712,10 @@ bc_align_data (align)
   seg_align (bc_data_seg, align);
 }
 
-/* Emit data. */
+/* Emit data.  */
+
 void
-bc_emit_data(data, size)
+bc_emit_data (data, size)
      char *data;
      unsigned int size;
 {
@@ -698,41 +723,45 @@ bc_emit_data(data, size)
 }
 
 /* Emit a zero-filled data skip.  */
+
 void
 bc_emit_data_skip (size)
      unsigned int size;
 {
-  seg_skip(bc_data_seg, size);
+  seg_skip (bc_data_seg, size);
 }
 
-/* Emit label definition in data. */
+/* Emit label definition in data.  */
+
 int
-bc_emit_data_labeldef(name)
+bc_emit_data_labeldef (name)
      char *name;
 {
-  return seg_defsym(bc_data_seg, name);
+  return seg_defsym (bc_data_seg, name);
 }
 
-/* Emit label reference in data. */
+/* Emit label reference in data.  */
+
 void
-bc_emit_data_labelref(name, offset)
+bc_emit_data_labelref (name, offset)
      char *name;
      int offset;
 {
-  seg_refsym(bc_data_seg, name, offset);
+  seg_refsym (bc_data_seg, name, offset);
 }
 
 /* Emit a common block of the given name and size.  Note that
    when the .o file is actually written non-global "common"
    blocks will have to be turned into space in the data section.  */
+
 int
-bc_emit_common(name, size)
+bc_emit_common (name, size)
      char *name;
      unsigned int size;
 {
   struct bc_sym *sym;
 
-  sym = sym_lookup(name);
+  sym = sym_lookup (name);
   if (sym->defined)
     return 0;
 
@@ -742,14 +771,15 @@ bc_emit_common(name, size)
   return 1;
 }
 
-/* Globalize the given label. */
+/* Globalize the given label.  */
+
 void
-bc_globalize_label(name)
+bc_globalize_label (name)
      char *name;
 {
   struct bc_sym *sym;
 
-  sym = sym_lookup(name);
+  sym = sym_lookup (name);
   sym->global = 1;
 }
 
@@ -827,7 +857,9 @@ bc_write_file (file)
 }
 
 
-/* Allocate a new bytecode rtx. */
+/* Allocate a new bytecode rtx.
+   If you supply a null BC_LABEL, we generate one.  */
+
 rtx
 bc_gen_rtx (label, offset, bc_label)
      char *label;
@@ -836,34 +868,41 @@ bc_gen_rtx (label, offset, bc_label)
 {
   rtx r;
 
-  r = (rtx) obstack_alloc (rtl_obstack, sizeof (struct rtx_def));
-  r->label = label;            /* FIXME: Do we need to copy here?  */
-  r->offset = offset;
-  r->bc_label = bc_label;
+  if (bc_label == 0)
+    bc_label = (struct bc_label *) xmalloc (sizeof (struct bc_label));
+
+  r = gen_rtx (CODE_LABEL, VOIDmode, label, bc_label);
+  bc_label->offset = offset;
+
   return r;
 }
 
 
 /* Print bytecode rtx */
+
 void
 bc_print_rtl (fp, r)
      FILE *fp;
      rtx r;
 {
+#if 0 /* This needs to get fixed to really work again.  */
+  /* BC_WRITE_RTL has a definition
+     that doesn't even make sense for this use.  */
   BC_WRITE_RTL (r, fp);
+#endif
 }
 
 
 /* Emit a bytecode, keeping a running tally of the stack depth.  */
+
 void
 bc_emit_bytecode (bytecode)
      enum bytecode_opcode bytecode;
 {
   char byte;
-  int npushes = arityvec[bytecode].noutputs - arityvec[bytecode].ninputs;
   static int prev_lineno = -1;
 
-  byte = bytecode;
+  byte = (char) bytecode;
 
 #ifdef BCDEBUG_PRINT_CODE
   if (lineno != prev_lineno)
@@ -879,13 +918,13 @@ bc_emit_bytecode (bytecode)
      will cause an interpreter stack undeflow when executed.  Instead of
      dumping core on such occasions, we omit the bytecode.  Erroneous code
      should not be executed, regardless.  This makes life much easier, since
-     we don't have to deceive ourselves about the known stack depth. */
+     we don't have to deceive ourselves about the known stack depth.  */
 
   bc_emit_bytecode_const (&byte, 1);
 
-  if ((stack_depth -= arityvec[bytecode].ninputs) >= 0)
+  if ((stack_depth -= arityvec[(int) bytecode].ninputs) >= 0)
     {
-      if ((stack_depth += arityvec[bytecode].noutputs) > max_stack_depth)
+      if ((stack_depth += arityvec[(int) bytecode].noutputs) > max_stack_depth)
        max_stack_depth = stack_depth;
     }
 
@@ -903,28 +942,30 @@ bc_emit_bytecode (bytecode)
 
 /* Emit a complete bytecode instruction, expecting the correct number
    of literal values in the call.  First argument is the instruction, the
-   remaining arguments are literals of size HOST_WIDE_INT or smaller. */
+   remaining arguments are literals of size HOST_WIDE_INT or smaller.  */
+
 void
-bc_emit_instruction (va_alist)
-     va_dcl
+bc_emit_instruction VPROTO((enum bytecode_opcode opcode, ...))
 {
-  va_list arguments;
+#ifndef __STDC__
   enum bytecode_opcode opcode;
+#endif
+  va_list arguments;
   int nliteral, instruction;
 
+  VA_START (arguments, opcode);
 
-  va_start (arguments);
+#ifndef __STDC__
+  opcode = va_arg (arguments, enum bytecode_opcode);
+#endif
 
   /* Emit instruction bytecode */
-  opcode = va_arg (arguments, enum bytecode_opcode);
   bc_emit_bytecode (opcode);
   instruction = (int) opcode;
 
   /* Loop literals and emit as bytecode constants */
   for (nliteral = 0; nliteral < arityvec[instruction].nliterals; nliteral++)
     {
-      HOST_WIDE_INT literal;
-
       switch (arityvec[instruction].literals[nliteral])
        {
 /* This conditional is a kludge, but it's necessary
@@ -949,6 +990,8 @@ bc_emit_instruction (va_alist)
        }
     }
 
+  va_end (arguments);
+
 #ifdef BCDEBUG_PRINT_CODE
   fputc ('\n', stderr);
 #endif
@@ -958,6 +1001,7 @@ bc_emit_instruction (va_alist)
    coded function.  The argument is a label name of the interpreter
    bytecode callinfo structure; the return value is a label name for
    the beginning of the actual bytecode.  */
+
 char *
 bc_emit_trampoline (callinfo)
      char *callinfo;
@@ -972,15 +1016,3 @@ bc_emit_trampoline (callinfo)
   seg_defsym (bytecode, mylab);
   return sym_lookup (mylab)->name;
 }
-
-
-/* Simple strdup */
-char *
-bc_xstrdup (str)
-     char *str;
-{
-  char *tmp = xmalloc (strlen (str) + 1);
-
-  strcpy (tmp, str);
-  return tmp;
-}