bessaconstr: Avoid duplicate map lookups.
[libfirm] / ir / obstack / obstack.c
index f048ea5..f801d06 100644 (file)
@@ -17,9 +17,7 @@
    License along with the GNU C Library; if not, write to the Free
    Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.  */
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
 
 #include "obstack.h"
 
    longer properly call the functions in this obstack.c.  */
 #define OBSTACK_INTERFACE_VERSION 1
 
-#include <stdio.h>             /* Random thing to get __GNU_LIBRARY__.  */
+#include <stdio.h>
 #include <stddef.h>
+#include <stdint.h>
 
 /* Determine default alignment.  */
 union fooround
 {
-  unsigned i;
+  uintmax_t i;
   long double d;
   void *p;
 };
@@ -83,7 +82,7 @@ int obstack_exit_failure = EXIT_FAILURE;
 # define CALL_CHUNKFUN(h, size) \
   (((h) -> use_extra_arg) \
    ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
-   : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
+   : (*(struct _obstack_chunk *(*) (PTR_INT_TYPE)) (h)->chunkfun) ((size)))
 
 # define CALL_FREEFUN(h, old_chunk) \
   do { \
@@ -93,7 +92,7 @@ int obstack_exit_failure = EXIT_FAILURE;
       (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
   } while (0)
 
-\f
+
 /* Initialize an obstack H for use.  Specify chunk size SIZE (0 means default).
    Objects start on multiples of ALIGNMENT (0 means use default).
    CHUNKFUN is the function to use to allocate chunks,
@@ -102,11 +101,8 @@ int obstack_exit_failure = EXIT_FAILURE;
    Return nonzero if successful, calls obstack_alloc_failed_handler if
    allocation fails.  */
 
-int
-_obstack_begin (struct obstack *h,
-               int size, int alignment,
-               void *(*chunkfun) (long),
-               void (*freefun) (void *))
+int _obstack_begin(struct obstack *h, int size, int alignment,
+                   void *(*chunkfun)(PTR_INT_TYPE), void (*freefun)(void *))
 {
   register struct _obstack_chunk *chunk; /* points to new chunk */
 
@@ -129,7 +125,7 @@ _obstack_begin (struct obstack *h,
       size = 4096 - extra;
     }
 
-  h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
+  h->chunkfun = (struct _obstack_chunk * (*)(void *, PTR_INT_TYPE)) chunkfun;
   h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
   h->chunk_size = size;
   h->alignment_mask = alignment - 1;
@@ -138,7 +134,7 @@ _obstack_begin (struct obstack *h,
   chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
   if (!chunk)
     (*obstack_alloc_failed_handler) ();
-  h->next_free = h->object_base = __PTR_ALIGN((char *) chunk, chunk->contents,
+  h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
                                               alignment - 1);
   h->chunk_limit = chunk->limit
     = (char *) chunk + h->chunk_size;
@@ -149,11 +145,9 @@ _obstack_begin (struct obstack *h,
   return 1;
 }
 
-int
-_obstack_begin_1 (struct obstack *h, int size, int alignment,
-                 void *(*chunkfun) (void *, long),
-                 void (*freefun) (void *, void *),
-                 void *arg)
+int _obstack_begin_1(struct obstack *h, int size, int alignment,
+                     void *(*chunkfun) (void *, PTR_INT_TYPE),
+                     void (*freefun) (void *, void *), void *arg)
 {
   register struct _obstack_chunk *chunk; /* points to new chunk */
 
@@ -176,7 +170,7 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment,
       size = 4096 - extra;
     }
 
-  h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
+  h->chunkfun = (struct _obstack_chunk * (*)(void *,PTR_INT_TYPE)) chunkfun;
   h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
   h->chunk_size = size;
   h->alignment_mask = alignment - 1;
@@ -203,15 +197,14 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment,
    Copies any partial object from the end of the old chunk
    to the beginning of the new one.  */
 
-void
-_obstack_newchunk (struct obstack *h, int length)
+void _obstack_newchunk(struct obstack *h, PTR_INT_TYPE length)
 {
   register struct _obstack_chunk *old_chunk = h->chunk;
   register struct _obstack_chunk *new_chunk;
-  register long        new_size;
-  register long obj_size = h->next_free - h->object_base;
-  register long i;
-  long already;
+  register PTR_INT_TYPE new_size;
+  register PTR_INT_TYPE obj_size = h->next_free - h->object_base;
+  register PTR_INT_TYPE i;
+  PTR_INT_TYPE already;
   char *object_base;
 
   /* Compute size for new chunk.  */
@@ -277,11 +270,10 @@ _obstack_newchunk (struct obstack *h, int length)
    obstack.h because it is just for debugging.  */
 int _obstack_allocated_p (struct obstack *h, void *obj);
 
-int
-_obstack_allocated_p (struct obstack *h, void *obj)
+int _obstack_allocated_p(struct obstack *h, void *obj)
 {
-  register struct _obstack_chunk *lp;  /* below addr of any objects in this chunk */
-  register struct _obstack_chunk *plp; /* point to previous chunk if any */
+  register struct _obstack_chunk *lp;   /* below addr of any objects in this chunk */
+  register struct _obstack_chunk *plp;  /* point to previous chunk if any */
 
   lp = (h)->chunk;
   /* We use >= rather than > since the object cannot be exactly at
@@ -294,17 +286,16 @@ _obstack_allocated_p (struct obstack *h, void *obj)
     }
   return lp != 0;
 }
-\f
+
 /* Free objects in obstack H, including OBJ and everything allocate
    more recently than OBJ.  If OBJ is zero, free everything in H.  */
 
 # undef obstack_free
 
-void
-obstack_free (struct obstack *h, void *obj)
+void obstack_free(struct obstack *h, void *obj)
 {
-  register struct _obstack_chunk *lp;  /* below addr of any objects in this chunk */
-  register struct _obstack_chunk *plp; /* point to previous chunk if any */
+  register struct _obstack_chunk *lp;   /* below addr of any objects in this chunk */
+  register struct _obstack_chunk *plp;  /* point to previous chunk if any */
 
   lp = h->chunk;
   /* We use >= because there cannot be an object at the beginning of a chunk.
@@ -330,11 +321,10 @@ obstack_free (struct obstack *h, void *obj)
     abort ();
 }
 
-int
-_obstack_memory_used (struct obstack *h)
+PTR_INT_TYPE _obstack_memory_used(struct obstack *h)
 {
   register struct _obstack_chunk* lp;
-  register int nbytes = 0;
+  register PTR_INT_TYPE nbytes = 0;
 
   for (lp = h->chunk; lp != 0; lp = lp->prev)
     {
@@ -343,9 +333,7 @@ _obstack_memory_used (struct obstack *h)
   return nbytes;
 }
 
-static void
-__attribute__ ((noreturn))
-print_and_abort (void)
+static void __attribute__((noreturn)) print_and_abort(void)
 {
   /* Don't change any of these strings.  Yes, it would be possible to add
      the newline to the string and use fputs or so.  But this must not