IA MCU psABI support: changes to libraries
[gcc.git] / gcc / data-streamer-out.c
index aae4d471fb6756b348da3a629e1688e5d70a573e..e68d1fb283401a3f0bb9ff2f3d582ad008e42b43 100644 (file)
@@ -1,7 +1,7 @@
 /* Routines for saving various data types to a file stream.  This deals
    with various data types like strings, integers, enums, etc.
 
-   Copyright 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011-2015 Free Software Foundation, Inc.
    Contributed by Diego Novillo <dnovillo@google.com>
 
 This file is part of GCC.
@@ -23,15 +23,73 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "alias.h"
+#include "symtab.h"
+#include "options.h"
+#include "tree.h"
+#include "fold-const.h"
+#include "predict.h"
+#include "tm.h"
+#include "hard-reg-set.h"
+#include "function.h"
+#include "basic-block.h"
+#include "tree-ssa-alias.h"
+#include "internal-fn.h"
+#include "gimple-expr.h"
+#include "gimple.h"
+#include "cgraph.h"
 #include "data-streamer.h"
 
+
+/* Adds a new block to output stream OBS.  */
+
+void
+lto_append_block (struct lto_output_stream *obs)
+{
+  struct lto_char_ptr_base *new_block;
+
+  gcc_assert (obs->left_in_block == 0);
+
+  if (obs->first_block == NULL)
+    {
+      /* This is the first time the stream has been written
+        into.  */
+      obs->block_size = 1024;
+      new_block = (struct lto_char_ptr_base*) xmalloc (obs->block_size);
+      obs->first_block = new_block;
+    }
+  else
+    {
+      struct lto_char_ptr_base *tptr;
+      /* Get a new block that is twice as big as the last block
+        and link it into the list.  */
+      obs->block_size *= 2;
+      new_block = (struct lto_char_ptr_base*) xmalloc (obs->block_size);
+      /* The first bytes of the block are reserved as a pointer to
+        the next block.  Set the chain of the full block to the
+        pointer to the new block.  */
+      tptr = obs->current_block;
+      tptr->ptr = (char *) new_block;
+    }
+
+  /* Set the place for the next char at the first position after the
+     chain to the next block.  */
+  obs->current_pointer
+    = ((char *) new_block) + sizeof (struct lto_char_ptr_base);
+  obs->current_block = new_block;
+  /* Null out the newly allocated block's pointer to the next block.  */
+  new_block->ptr = NULL;
+  obs->left_in_block = obs->block_size - sizeof (struct lto_char_ptr_base);
+}
+
+
 /* Return index used to reference STRING of LEN characters in the string table
    in OB.  The string might or might not include a trailing '\0'.
    Then put the index onto the INDEX_STREAM.  
    When PERSISTENT is set, the string S is supposed to not change during
    duration of the OB and thus OB can keep pointer into it.  */
 
-unsigned
+static unsigned
 streamer_string_index (struct output_block *ob, const char *s, unsigned int len,
                       bool persistent)
 {
@@ -42,8 +100,7 @@ streamer_string_index (struct output_block *ob, const char *s, unsigned int len,
   s_slot.len = len;
   s_slot.slot_num = 0;
 
-  slot = (struct string_slot **) htab_find_slot (ob->string_hash_table,
-                                                &s_slot, INSERT);
+  slot = ob->string_hash_table->find_slot (&s_slot, INSERT);
   if (*slot == NULL)
     {
       struct lto_output_stream *string_stream = ob->string_stream;
@@ -65,7 +122,7 @@ streamer_string_index (struct output_block *ob, const char *s, unsigned int len,
       new_slot->slot_num = start;
       *slot = new_slot;
       streamer_write_uhwi_stream (string_stream, len);
-      lto_output_data_stream (string_stream, string, len);
+      streamer_write_data_stream (string_stream, string, len);
       return start + 1;
     }
   else
@@ -174,6 +231,13 @@ streamer_write_hwi (struct output_block *ob, HOST_WIDE_INT work)
   streamer_write_hwi_stream (ob->main_stream, work);
 }
 
+/* Write a gcov counter value WORK to OB->main_stream.  */
+
+void
+streamer_write_gcov_count (struct output_block *ob, gcov_type work)
+{
+  streamer_write_gcov_count_stream (ob->main_stream, work);
+}
 
 /* Write an unsigned HOST_WIDE_INT value WORK to OBS.  */
 
@@ -181,6 +245,11 @@ void
 streamer_write_uhwi_stream (struct lto_output_stream *obs,
                             unsigned HOST_WIDE_INT work)
 {
+  if (obs->left_in_block == 0)
+    lto_append_block (obs);
+  char *current_pointer = obs->current_pointer;
+  unsigned int left_in_block = obs->left_in_block;
+  unsigned int size = 0;
   do
     {
       unsigned int byte = (work & 0x7f);
@@ -189,9 +258,34 @@ streamer_write_uhwi_stream (struct lto_output_stream *obs,
        /* More bytes to follow.  */
        byte |= 0x80;
 
-      streamer_write_char_stream (obs, byte);
+      *(current_pointer++) = byte;
+      left_in_block--;
+      size++;
     }
-  while (work != 0);
+  while (work != 0 && left_in_block > 0);
+  if (work != 0)
+    {
+      obs->left_in_block = 0;
+      lto_append_block (obs);
+      current_pointer = obs->current_pointer;
+      left_in_block = obs->left_in_block;
+      do
+       {
+         unsigned int byte = (work & 0x7f);
+         work >>= 7;
+         if (work != 0)
+           /* More bytes to follow.  */
+           byte |= 0x80;
+
+         *(current_pointer++) = byte;
+         left_in_block--;
+         size++;
+       }
+      while (work != 0);
+    }
+  obs->current_pointer = current_pointer;
+  obs->left_in_block = left_in_block;
+  obs->total_size += size;
 }
 
 
@@ -200,19 +294,95 @@ streamer_write_uhwi_stream (struct lto_output_stream *obs,
 void
 streamer_write_hwi_stream (struct lto_output_stream *obs, HOST_WIDE_INT work)
 {
-  int more, byte;
-
+  if (obs->left_in_block == 0)
+    lto_append_block (obs);
+  char *current_pointer = obs->current_pointer;
+  unsigned int left_in_block = obs->left_in_block;
+  unsigned int size = 0;
+  bool more;
   do
     {
-      byte = (work & 0x7f);
-      /* arithmetic shift */
-      work >>= 7;
-      more = !((work == 0 && (byte & 0x40) == 0)
-              || (work == -1 && (byte & 0x40) != 0));
+      unsigned int byte = (work & 0x7f);
+      /* If the lower 7-bits are sign-extended 0 or -1 we are finished.  */
+      work >>= 6;
+      more = !(work == 0 || work == -1);
       if (more)
-       byte |= 0x80;
+       {
+         /* More bits to follow.  */
+         work >>= 1;
+         byte |= 0x80;
+       }
+
+      *(current_pointer++) = byte;
+      left_in_block--;
+      size++;
+    }
+  while (more && left_in_block > 0);
+  if (more)
+    {
+      obs->left_in_block = 0;
+      lto_append_block (obs);
+      current_pointer = obs->current_pointer;
+      left_in_block = obs->left_in_block;
+      do
+       {
+         unsigned int byte = (work & 0x7f);
+         work >>= 6;
+         more = !(work == 0 || work == -1);
+         if (more)
+           {
+             work >>= 1;
+             byte |= 0x80;
+           }
+
+         *(current_pointer++) = byte;
+         left_in_block--;
+         size++;
+       }
+      while (more);
+    }
+  obs->current_pointer = current_pointer;
+  obs->left_in_block = left_in_block;
+  obs->total_size += size;
+}
+
+/* Write a GCOV counter value WORK to OBS.  */
+
+void
+streamer_write_gcov_count_stream (struct lto_output_stream *obs, gcov_type work)
+{
+  gcc_assert (work >= 0);
+  gcc_assert ((HOST_WIDE_INT) work == work);
+  streamer_write_hwi_stream (obs, work);
+}
 
-      streamer_write_char_stream (obs, byte);
+/* Write raw DATA of length LEN to the output block OB.  */
+
+void
+streamer_write_data_stream (struct lto_output_stream *obs, const void *data,
+                           size_t len)
+{
+  while (len)
+    {
+      size_t copy;
+
+      /* No space left.  */
+      if (obs->left_in_block == 0)
+       lto_append_block (obs);
+
+      /* Determine how many bytes to copy in this loop.  */
+      if (len <= obs->left_in_block)
+       copy = len;
+      else
+       copy = obs->left_in_block;
+
+      /* Copy the data and do bookkeeping.  */
+      memcpy (obs->current_pointer, data, copy);
+      obs->current_pointer += copy;
+      obs->total_size += copy;
+      obs->left_in_block -= copy;
+      data = (const char *) data + copy;
+      len -= copy;
     }
-  while (more);
 }
+