1 /* frags.c - manage frags -
3 Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 struct obstack frags
; /* All, and only, frags live here. */
27 extern fragS zero_address_frag
;
28 extern fragS bss_address_frag
;
30 /* Initialization for frag routines. */
34 zero_address_frag
.fr_type
= rs_fill
;
35 bss_address_frag
.fr_type
= rs_fill
;
36 obstack_begin (&frags
, 5000);
42 * Try to augment current frag by nchars chars.
43 * If there is no room, close of the current frag with a ".fill 0"
44 * and begin a new frag. Unless the new frag has nchars chars available
45 * do not return. Do not set up any fields of *now_frag.
51 if (obstack_room (&frags
) < nchars
)
59 oldc
= frags
.chunk_size
;
60 frags
.chunk_size
= 2 * nchars
;
61 while ((n
= obstack_room (&frags
)) < nchars
&& n
< oldn
)
67 frags
.chunk_size
= oldc
;
69 if (obstack_room (&frags
) < nchars
)
70 as_fatal ("Can't extend frag %d. chars", nchars
);
76 * Call this to close off a completed frag, and start up a new (empty)
77 * frag, in the same subsegment as the old frag.
78 * [frchain_now remains the same but frag_now is updated.]
79 * Because this calculates the correct value of fr_fix by
80 * looking at the obstack 'frags', it needs to know how many
81 * characters at the end of the old frag belong to (the maximal)
82 * fr_var: the rest must belong to fr_fix.
83 * It doesn't actually set up the old frag's fr_var: you may have
84 * set fr_var == 1, but allocated 10 chars to the end of the frag:
85 * in this case you pass old_frags_var_max_size == 10.
87 * Make a new frag, initialising some components. Link new frag at end
91 frag_new (old_frags_var_max_size
)
92 int old_frags_var_max_size
;/* Number of chars (already allocated on
94 /* in variable_length part of frag. */
96 register fragS
*former_last_fragP
;
97 register frchainS
*frchP
;
100 frag_now
->fr_fix
= frag_now_fix () - old_frags_var_max_size
;
101 /* Fix up old frag's fr_fix. */
103 obstack_finish (&frags
);
104 /* This will align the obstack so the next struct we allocate on it
105 will begin at a correct boundary. */
108 former_last_fragP
= frchP
->frch_last
;
109 know (former_last_fragP
);
110 know (former_last_fragP
== frag_now
);
111 obstack_blank (&frags
, SIZEOF_STRUCT_FRAG
);
112 /* We expect this will begin at a correct boundary for a struct. */
113 tmp
= obstack_alignment_mask (&frags
);
114 obstack_alignment_mask (&frags
) = 0; /* Turn off alignment */
115 /* If we ever hit a machine where strings must be aligned, we Lose
117 frag_now
= (fragS
*) obstack_finish (&frags
);
118 obstack_alignment_mask (&frags
) = tmp
; /* Restore alignment */
120 /* Just in case we don't get zero'd bytes */
121 memset (frag_now
, '\0', SIZEOF_STRUCT_FRAG
);
123 /* Generally, frag_now->points to an address rounded up to next
124 alignment. However, characters will add to obstack frags
125 IMMEDIATELY after the struct frag, even if they are not starting
126 at an alignment address. */
127 former_last_fragP
->fr_next
= frag_now
;
128 frchP
->frch_last
= frag_now
;
132 extern struct list_info_struct
*listing_tail
;
133 frag_now
->line
= listing_tail
;
137 frag_now
->fr_next
= NULL
;
143 * Start a new frag unless we have n more chars of room in the current frag.
144 * Close off the old frag with a .fill 0.
146 * Return the address of the 1st char to write into. Advance
147 * frag_now_growth past the new chars.
154 register char *retval
;
156 if (mri_common_symbol
!= NULL
)
158 as_bad ("attempt to allocate data in common section");
159 mri_common_symbol
= NULL
;
163 retval
= obstack_next_free (&frags
);
164 obstack_blank_fast (&frags
, nchars
);
171 * Start a new frag unless we have max_chars more chars of room in the current frag.
172 * Close off the old frag with a .fill 0.
174 * Set up a machine_dependent relaxable frag, then start a new frag.
175 * Return the address of the 1st char of the var part of the old frag
180 frag_var (type
, max_chars
, var
, subtype
, symbol
, offset
, opcode
)
184 relax_substateT subtype
;
189 register char *retval
;
191 frag_grow (max_chars
);
192 retval
= obstack_next_free (&frags
);
193 obstack_blank_fast (&frags
, max_chars
);
194 frag_now
->fr_var
= var
;
195 frag_now
->fr_type
= type
;
196 frag_now
->fr_subtype
= subtype
;
197 frag_now
->fr_symbol
= symbol
;
198 frag_now
->fr_offset
= offset
;
199 frag_now
->fr_opcode
= opcode
;
200 /* default these to zero. */
201 frag_now
->fr_pcrel_adjust
= 0;
202 frag_now
->fr_bsr
= 0;
203 frag_new (max_chars
);
210 * OVE: This variant of frag_var assumes that space for the tail has been
211 * allocated by caller.
212 * No call to frag_grow is done.
213 * Two new arguments have been added.
217 frag_variant (type
, max_chars
, var
, subtype
, symbol
, offset
, opcode
)
221 relax_substateT subtype
;
226 register char *retval
;
228 retval
= obstack_next_free (&frags
);
229 frag_now
->fr_var
= var
;
230 frag_now
->fr_type
= type
;
231 frag_now
->fr_subtype
= subtype
;
232 frag_now
->fr_symbol
= symbol
;
233 frag_now
->fr_offset
= offset
;
234 frag_now
->fr_opcode
= opcode
;
235 frag_now
->fr_pcrel_adjust
= 0;
236 frag_now
->fr_bsr
= 0;
237 frag_new (max_chars
);
239 } /* frag_variant() */
244 * Reduce the variable end of a frag to a harmless state.
248 register fragS
*fragP
;
250 fragP
->fr_type
= rs_fill
;
251 fragP
->fr_offset
= 0;
258 * Make a frag for ".align foo,bar". Call is "frag_align (foo,bar);".
259 * Foo & bar are absolute integers.
261 * Call to close off the current frag with a ".align", then start a new
262 * (so far empty) frag, in the same subsegment as the last frag.
266 frag_align (alignment
, fill_character
)
271 p
= frag_var (rs_align
, 1, 1, (relax_substateT
) 0,
272 (symbolS
*) 0, (long) alignment
, (char *) 0);
277 frag_align_pattern (alignment
, fill_pattern
, n_fill
)
279 const char *fill_pattern
;
283 p
= frag_var (rs_align
, n_fill
, n_fill
, (relax_substateT
) 0,
284 (symbolS
*) 0, (long) alignment
, (char *) 0);
285 memcpy (p
, fill_pattern
, n_fill
);
291 return (char*)obstack_next_free (&frags
) - frag_now
->fr_literal
;
295 frag_append_1_char (datum
)
298 if (obstack_room (&frags
) <= 1)
300 frag_wane (frag_now
);
303 obstack_1grow (&frags
, datum
);
This page took 0.036116 seconds and 4 git commands to generate.