/* frags.c - manage frags -
- Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009
- Free Software Foundation, Inc.
+ Copyright (C) 1987-2016 Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
#include "obstack.h"
extern fragS zero_address_frag;
-extern fragS bss_address_frag;
+extern fragS predefined_address_frag;
+
+static int totalfrags;
+
+int
+get_frag_count (void)
+{
+ return totalfrags;
+}
+
+void
+clear_frag_count (void)
+{
+ totalfrags = 0;
+}
\f
/* Initialization for frag routines. */
frag_init (void)
{
zero_address_frag.fr_type = rs_fill;
- bss_address_frag.fr_type = rs_fill;
+ predefined_address_frag.fr_type = rs_fill;
}
\f
/* Check that we're not trying to assemble into a section that can't
ptr = (fragS *) obstack_alloc (ob, SIZEOF_STRUCT_FRAG);
obstack_alignment_mask (ob) = oalign;
memset (ptr, 0, SIZEOF_STRUCT_FRAG);
+ totalfrags++;
return ptr;
}
\f
do not return. Do not set up any fields of *now_frag. */
void
-frag_grow (unsigned int nchars)
+frag_grow (size_t nchars)
{
if (obstack_room (&frchain_now->frch_obstack) < nchars)
{
- long oldc;
- long newc;
+ size_t oldc;
+ size_t newc;
/* Try to allocate a bit more than needed right now. But don't do
this if we would waste too much memory. Especially necessary
newc += SIZEOF_STRUCT_FRAG;
/* Check for possible overflow. */
- if (newc < 0)
- as_fatal (_("can't extend frag %u chars"), nchars);
+ if (newc < nchars)
+ as_fatal (_("can't extend frag %lu chars"), (unsigned long) nchars);
- /* Force to allocate at least NEWC bytes. */
+ /* Force to allocate at least NEWC bytes, but not less than the
+ default. */
oldc = obstack_chunk_size (&frchain_now->frch_obstack);
- obstack_chunk_size (&frchain_now->frch_obstack) = newc;
+ if (newc > oldc)
+ obstack_chunk_size (&frchain_now->frch_obstack) = newc;
while (obstack_room (&frchain_now->frch_obstack) < nchars)
{
of frchain_now. */
void
-frag_new (int old_frags_var_max_size
+frag_new (size_t old_frags_var_max_size
/* Number of chars (already allocated on obstack frags) in
variable_length part of frag. */)
{
gas_assert (former_last_fragP == frag_now);
frag_now = frag_alloc (&frchP->frch_obstack);
- as_where (&frag_now->fr_file, &frag_now->fr_line);
+ frag_now->fr_file = as_where (&frag_now->fr_line);
/* Generally, frag_now->points to an address rounded up to next
alignment. However, characters will add to obstack frags
frag_now_growth past the new chars. */
char *
-frag_more (int nchars)
+frag_more (size_t nchars)
{
- register char *retval;
+ char *retval;
frag_alloc_check (&frchain_now->frch_obstack);
frag_grow (nchars);
retval = obstack_next_free (&frchain_now->frch_obstack);
obstack_blank_fast (&frchain_now->frch_obstack, nchars);
- return (retval);
+ return retval;
}
\f
/* Close the current frag, setting its fields for a relaxable frag. Start a
new frag. */
static void
-frag_var_init (relax_stateT type, int max_chars, int var,
- relax_substateT subtype, symbolS *symbol, offsetT offset,
+frag_var_init (relax_stateT type, size_t max_chars, size_t var,
+ relax_substateT subtype, symbolS *symbol, offsetT offset,
char *opcode)
{
frag_now->fr_var = var;
#ifdef TC_FRAG_INIT
TC_FRAG_INIT (frag_now);
#endif
- as_where (&frag_now->fr_file, &frag_now->fr_line);
+ frag_now->fr_file = as_where (&frag_now->fr_line);
frag_new (max_chars);
}
to write into. */
char *
-frag_var (relax_stateT type, int max_chars, int var, relax_substateT subtype,
- symbolS *symbol, offsetT offset, char *opcode)
+frag_var (relax_stateT type, size_t max_chars, size_t var,
+ relax_substateT subtype, symbolS *symbol, offsetT offset,
+ char *opcode)
{
- register char *retval;
+ char *retval;
frag_grow (max_chars);
retval = obstack_next_free (&frchain_now->frch_obstack);
No call to frag_grow is done. */
char *
-frag_variant (relax_stateT type, int max_chars, int var,
+frag_variant (relax_stateT type, size_t max_chars, size_t var,
relax_substateT subtype, symbolS *symbol, offsetT offset,
char *opcode)
{
- register char *retval;
+ char *retval;
retval = obstack_next_free (&frchain_now->frch_obstack);
frag_var_init (type, max_chars, var, subtype, symbol, offset, opcode);
/* Reduce the variable end of a frag to a harmless state. */
void
-frag_wane (register fragS *fragP)
+frag_wane (fragS *fragP)
{
fragP->fr_type = rs_fill;
fragP->fr_offset = 0;
\f
/* Return the number of bytes by which the current frag can be grown. */
-int
+size_t
frag_room (void)
{
return obstack_room (&frchain_now->frch_obstack);
void
frag_align_pattern (int alignment, const char *fill_pattern,
- int n_fill, int max)
+ size_t n_fill, int max)
{
char *p;
not already accounted for in the frag FR_ADDRESS. */
bfd_boolean
-frag_offset_fixed_p (const fragS *frag1, const fragS *frag2, bfd_vma *offset)
+frag_offset_fixed_p (const fragS *frag1, const fragS *frag2, offsetT *offset)
{
const fragS *frag;
- bfd_vma off;
+ offsetT off;
/* Start with offset initialised to difference between the two frags.
Prior to assigning frag addresses this will be zero. */