2000-08-11 Kazu Hirata <kazu@hxi.com>
[deliverable/binutils-gdb.git] / gas / frags.c
index 240b2ee63a01f5671ac90d6cca308715a647791a..5c31b7e89318d527d9154691b739c7a442aff131 100644 (file)
@@ -1,5 +1,5 @@
 /* frags.c - manage frags -
-   Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 97, 1998
+   Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
@@ -74,11 +74,13 @@ frag_grow (nchars)
       frag_new (0);
       oldc = frchain_now->frch_obstack.chunk_size;
       frchain_now->frch_obstack.chunk_size = 2 * nchars + SIZEOF_STRUCT_FRAG;
-      while ((n = obstack_room (&frchain_now->frch_obstack)) < nchars)
-       {
-         frag_wane (frag_now);
-         frag_new (0);
-       }
+      if (frchain_now->frch_obstack.chunk_size > 0)
+       while ((n = obstack_room (&frchain_now->frch_obstack)) < nchars
+              && (unsigned long) frchain_now->frch_obstack.chunk_size > nchars)
+         {
+           frag_wane (frag_now);
+           frag_new (0);
+         }
       frchain_now->frch_obstack.chunk_size = oldc;
     }
   if (obstack_room (&frchain_now->frch_obstack) < nchars)
@@ -93,11 +95,14 @@ frag_grow (nchars)
  * [frchain_now remains the same but frag_now is updated.]
  * Because this calculates the correct value of fr_fix by
  * looking at the obstack 'frags', it needs to know how many
- * characters at the end of the old frag belong to (the maximal)
- * fr_var: the rest must belong to fr_fix.
- * It doesn't actually set up the old frag's fr_var: you may have
- * set fr_var == 1, but allocated 10 chars to the end of the frag:
- * in this case you pass old_frags_var_max_size == 10.
+ * characters at the end of the old frag belong to the maximal
+ * variable part;  The rest must belong to fr_fix.
+ * It doesn't actually set up the old frag's fr_var.  You may have
+ * set fr_var == 1, but allocated 10 chars to the end of the frag;
+ * In this case you pass old_frags_var_max_size == 10.
+ * In fact, you may use fr_var for something totally unrelated to the
+ * size of the variable part of the frag;  None of the generic frag
+ * handling code makes use of fr_var.
  *
  * Make a new frag, initialising some components. Link new frag at end
  * of frchain_now.
@@ -114,7 +119,7 @@ frag_new (old_frags_var_max_size)
   assert (frchain_now->frch_last == frag_now);
 
   /* Fix up old frag's fr_fix.  */
-  frag_now->fr_fix = frag_now_fix () - old_frags_var_max_size;
+  frag_now->fr_fix = frag_now_fix_octets () - old_frags_var_max_size;
   /* Make sure its type is valid.  */
   assert (frag_now->fr_type != 0);
 
@@ -298,9 +303,10 @@ frag_align (alignment, fill_character, max)
   if (now_seg == absolute_section)
     {
       addressT new_off;
+      addressT mask;
 
-      new_off = ((abs_section_offset + alignment - 1)
-                &~ ((1 << alignment) - 1));
+      mask = (~ (addressT) 0) << alignment;
+      new_off = (abs_section_offset + ~ mask) & mask;
       if (max == 0 || new_off - abs_section_offset <= (addressT) max)
        abs_section_offset = new_off;
     }
@@ -336,12 +342,19 @@ frag_align_pattern (alignment, fill_pattern, n_fill, max)
 }
 
 addressT
-frag_now_fix ()
+frag_now_fix_octets ()
 {
   if (now_seg == absolute_section)
     return abs_section_offset;
-  return (addressT) ((char*) obstack_next_free (&frchain_now->frch_obstack)
-                    - frag_now->fr_literal);
+
+  return ((char*) obstack_next_free (&frchain_now->frch_obstack)
+          - frag_now->fr_literal);
+}
+
+addressT
+frag_now_fix ()
+{
+  return frag_now_fix_octets() / OCTETS_PER_BYTE;
 }
 
 void
This page took 0.035316 seconds and 4 git commands to generate.