OSDN Git Service

Added fixup for __STDC__ == 0 and __STDC__ == 1
[pf3gnuchains/gcc-fork.git] / gcc / halfpic.c
index 0f81cf0..6447539 100644 (file)
@@ -20,7 +20,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* The OSF/rose half-pic model assumes that the non-library code does
    not need to have full PIC (position independent code), but rather,
    that pointers to external references are put into the data section
-   and derefenced as normal pointers.  References to static data does
+   and dereferenced as normal pointers.  References to static data does
    not need to be PIC-ized.
 
    Another optimization is to have the compiler know what symbols are
@@ -34,7 +34,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "tree.h"
 #include "rtl.h"
 #include <stdio.h>
-#include <string.h>
 #include "obstack.h"
 
 #define obstack_chunk_alloc xmalloc
@@ -46,7 +45,10 @@ extern rtx eliminate_constant_term ();
 extern void assemble_name ();
 extern void output_addr_const ();
 
-int flag_half_pic;             /* Global half-pic flag.  */
+int flag_half_pic              = 0;    /* Global half-pic flag.  */
+int half_pic_number_ptrs       = 0;    /* # distinct pointers found */
+int half_pic_number_refs       = 0;    /* # half-pic references */
+int (*ptr_half_pic_address_p)() = half_pic_address_p;
 
 /* Obstack to hold generated pic names.  */
 static struct obstack half_pic_obstack;
@@ -207,14 +209,26 @@ half_pic_encode (decl)
   if (code != VAR_DECL && code != FUNCTION_DECL)
     return;
 
-  /* If this is not an external reference, it can't be half-pic.  */
-  if (!TREE_EXTERNAL (decl))
-    return;
-
   asm_name = DECL_ASSEMBLER_NAME (decl);
+
   if (!asm_name)
     return;
 
+#ifdef HALF_PIC_DEBUG
+  if (HALF_PIC_DEBUG)
+    {
+      if (HALF_PIC_DEBUG)
+       fprintf (stderr, "\n========== Half_pic_encode %.*s\n",
+                IDENTIFIER_LENGTH (asm_name),
+                IDENTIFIER_POINTER (asm_name));
+      debug_tree (decl);
+    }
+#endif
+
+  /* If this is not an external reference, it can't be half-pic.  */
+  if (!DECL_EXTERNAL (decl) && (code != VAR_DECL || !TREE_PUBLIC (decl)))
+    return;
+
   ptr = half_pic_hash (IDENTIFIER_POINTER (asm_name),
                       IDENTIFIER_LENGTH (asm_name),
                       TRUE);
@@ -223,7 +237,7 @@ half_pic_encode (decl)
 
 #ifdef HALF_PIC_DEBUG
   if (HALF_PIC_DEBUG)
-    fprintf (stderr, "\n========== Half_pic_encode %.*s\n",
+    fprintf (stderr, "\n%.*s is half-pic\n",
             IDENTIFIER_LENGTH (asm_name),
             IDENTIFIER_POINTER (asm_name));
 #endif
@@ -275,7 +289,7 @@ half_pic_address_p (addr)
     case CONST:
       {
        rtx offset = const0_rtx;
-       addr = eliminate_constant_term (addr, &offset);
+       addr = eliminate_constant_term (XEXP (addr, 0), &offset);
        if (GET_CODE (addr) != SYMBOL_REF)
          return FALSE;
       }
@@ -351,8 +365,10 @@ half_pic_ptr (operand)
       p->pointer_p = TRUE;
 
       half_pic_names = p;
+      half_pic_number_ptrs++;
     }
 
+  half_pic_number_refs++;
   return gen_rtx (SYMBOL_REF, Pmode, p->ref_name);
 }