Rev 5222 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5222 | Rev 6324 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* frags.c - manage frags - |
1 | /* frags.c - manage frags - |
2 | Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
- | |
3 | 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 |
- | |
4 | Free Software Foundation, Inc. |
2 | Copyright (C) 1987-2015 Free Software Foundation, Inc. |
Line 5... | Line 3... | ||
5 | 3 | ||
Line 6... | Line 4... | ||
6 | This file is part of GAS, the GNU Assembler. |
4 | This file is part of GAS, the GNU Assembler. |
7 | 5 | ||
Line 25... | Line 23... | ||
25 | #include "obstack.h" |
23 | #include "obstack.h" |
Line 26... | Line 24... | ||
26 | 24 | ||
27 | extern fragS zero_address_frag; |
25 | extern fragS zero_address_frag; |
28 | extern fragS predefined_address_frag; |
26 | extern fragS predefined_address_frag; |
- | 27 | ||
- | 28 | static int totalfrags; |
|
- | 29 | ||
- | 30 | int |
|
- | 31 | get_frag_count (void) |
|
- | 32 | { |
|
- | 33 | return totalfrags; |
|
- | 34 | } |
|
- | 35 | ||
- | 36 | void |
|
- | 37 | clear_frag_count (void) |
|
- | 38 | { |
|
- | 39 | totalfrags = 0; |
|
- | 40 | } |
|
29 | 41 | ||
Line 30... | Line 42... | ||
30 | /* Initialization for frag routines. */ |
42 | /* Initialization for frag routines. */ |
31 | 43 | ||
32 | void |
44 | void |
Line 70... | Line 82... | ||
70 | oalign = obstack_alignment_mask (ob); |
82 | oalign = obstack_alignment_mask (ob); |
71 | obstack_alignment_mask (ob) = 0; |
83 | obstack_alignment_mask (ob) = 0; |
72 | ptr = (fragS *) obstack_alloc (ob, SIZEOF_STRUCT_FRAG); |
84 | ptr = (fragS *) obstack_alloc (ob, SIZEOF_STRUCT_FRAG); |
73 | obstack_alignment_mask (ob) = oalign; |
85 | obstack_alignment_mask (ob) = oalign; |
74 | memset (ptr, 0, SIZEOF_STRUCT_FRAG); |
86 | memset (ptr, 0, SIZEOF_STRUCT_FRAG); |
- | 87 | totalfrags++; |
|
75 | return ptr; |
88 | return ptr; |
76 | } |
89 | } |
77 | 90 | ||
78 | /* Try to augment current frag by nchars chars. |
91 | /* Try to augment current frag by nchars chars. |
79 | If there is no room, close of the current frag with a ".fill 0" |
92 | If there is no room, close of the current frag with a ".fill 0" |
80 | and begin a new frag. Unless the new frag has nchars chars available |
93 | and begin a new frag. Unless the new frag has nchars chars available |
81 | do not return. Do not set up any fields of *now_frag. */ |
94 | do not return. Do not set up any fields of *now_frag. */ |
Line 82... | Line 95... | ||
82 | 95 | ||
83 | void |
96 | void |
84 | frag_grow (unsigned int nchars) |
97 | frag_grow (size_t nchars) |
85 | { |
98 | { |
86 | if (obstack_room (&frchain_now->frch_obstack) < nchars) |
99 | if (obstack_room (&frchain_now->frch_obstack) < nchars) |
87 | { |
100 | { |
88 | long oldc; |
101 | size_t oldc; |
Line 89... | Line 102... | ||
89 | long newc; |
102 | size_t newc; |
90 | 103 | ||
91 | /* Try to allocate a bit more than needed right now. But don't do |
104 | /* Try to allocate a bit more than needed right now. But don't do |
92 | this if we would waste too much memory. Especially necessary |
105 | this if we would waste too much memory. Especially necessary |
Line 96... | Line 109... | ||
96 | else |
109 | else |
97 | newc = nchars + 0x10000; |
110 | newc = nchars + 0x10000; |
98 | newc += SIZEOF_STRUCT_FRAG; |
111 | newc += SIZEOF_STRUCT_FRAG; |
Line 99... | Line 112... | ||
99 | 112 | ||
100 | /* Check for possible overflow. */ |
113 | /* Check for possible overflow. */ |
101 | if (newc < 0) |
114 | if (newc < nchars) |
Line 102... | Line 115... | ||
102 | as_fatal (_("can't extend frag %u chars"), nchars); |
115 | as_fatal (_("can't extend frag %lu chars"), (unsigned long) nchars); |
103 | 116 | ||
104 | /* Force to allocate at least NEWC bytes, but not less than the |
117 | /* Force to allocate at least NEWC bytes, but not less than the |
105 | default. */ |
118 | default. */ |
Line 137... | Line 150... | ||
137 | 150 | ||
138 | Make a new frag, initialising some components. Link new frag at end |
151 | Make a new frag, initialising some components. Link new frag at end |
Line 139... | Line 152... | ||
139 | of frchain_now. */ |
152 | of frchain_now. */ |
140 | 153 | ||
141 | void |
154 | void |
142 | frag_new (int old_frags_var_max_size |
155 | frag_new (size_t old_frags_var_max_size |
143 | /* Number of chars (already allocated on obstack frags) in |
156 | /* Number of chars (already allocated on obstack frags) in |
144 | variable_length part of frag. */) |
157 | variable_length part of frag. */) |
145 | { |
158 | { |
Line 189... | Line 202... | ||
189 | 202 | ||
190 | Return the address of the 1st char to write into. Advance |
203 | Return the address of the 1st char to write into. Advance |
Line 191... | Line 204... | ||
191 | frag_now_growth past the new chars. */ |
204 | frag_now_growth past the new chars. */ |
192 | 205 | ||
193 | char * |
206 | char * |
194 | frag_more (int nchars) |
207 | frag_more (size_t nchars) |
Line 195... | Line 208... | ||
195 | { |
208 | { |
196 | register char *retval; |
209 | char *retval; |
197 | 210 | ||
198 | frag_alloc_check (&frchain_now->frch_obstack); |
211 | frag_alloc_check (&frchain_now->frch_obstack); |
199 | frag_grow (nchars); |
212 | frag_grow (nchars); |
200 | retval = obstack_next_free (&frchain_now->frch_obstack); |
213 | retval = obstack_next_free (&frchain_now->frch_obstack); |
201 | obstack_blank_fast (&frchain_now->frch_obstack, nchars); |
214 | obstack_blank_fast (&frchain_now->frch_obstack, nchars); |
202 | return (retval); |
215 | return retval; |
203 | } |
216 | } |
Line 204... | Line 217... | ||
204 | 217 | ||
205 | /* Close the current frag, setting its fields for a relaxable frag. Start a |
218 | /* Close the current frag, setting its fields for a relaxable frag. Start a |
206 | new frag. */ |
219 | new frag. */ |
207 | 220 | ||
208 | static void |
221 | static void |
209 | frag_var_init (relax_stateT type, int max_chars, int var, |
222 | frag_var_init (relax_stateT type, size_t max_chars, size_t var, |
210 | relax_substateT subtype, symbolS *symbol, offsetT offset, |
223 | relax_substateT subtype, symbolS *symbol, offsetT offset, |
Line 235... | Line 248... | ||
235 | Set up a machine_dependent relaxable frag, then start a new frag. |
248 | Set up a machine_dependent relaxable frag, then start a new frag. |
236 | Return the address of the 1st char of the var part of the old frag |
249 | Return the address of the 1st char of the var part of the old frag |
237 | to write into. */ |
250 | to write into. */ |
Line 238... | Line 251... | ||
238 | 251 | ||
239 | char * |
252 | char * |
240 | frag_var (relax_stateT type, int max_chars, int var, relax_substateT subtype, |
253 | frag_var (relax_stateT type, size_t max_chars, size_t var, |
- | 254 | relax_substateT subtype, symbolS *symbol, offsetT offset, |
|
241 | symbolS *symbol, offsetT offset, char *opcode) |
255 | char *opcode) |
242 | { |
256 | { |
Line 243... | Line 257... | ||
243 | register char *retval; |
257 | char *retval; |
244 | 258 | ||
245 | frag_grow (max_chars); |
259 | frag_grow (max_chars); |
246 | retval = obstack_next_free (&frchain_now->frch_obstack); |
260 | retval = obstack_next_free (&frchain_now->frch_obstack); |
Line 252... | Line 266... | ||
252 | /* OVE: This variant of frag_var assumes that space for the tail has been |
266 | /* OVE: This variant of frag_var assumes that space for the tail has been |
253 | allocated by caller. |
267 | allocated by caller. |
254 | No call to frag_grow is done. */ |
268 | No call to frag_grow is done. */ |
Line 255... | Line 269... | ||
255 | 269 | ||
256 | char * |
270 | char * |
257 | frag_variant (relax_stateT type, int max_chars, int var, |
271 | frag_variant (relax_stateT type, size_t max_chars, size_t var, |
258 | relax_substateT subtype, symbolS *symbol, offsetT offset, |
272 | relax_substateT subtype, symbolS *symbol, offsetT offset, |
259 | char *opcode) |
273 | char *opcode) |
260 | { |
274 | { |
Line 261... | Line 275... | ||
261 | register char *retval; |
275 | char *retval; |
262 | 276 | ||
Line 263... | Line 277... | ||
263 | retval = obstack_next_free (&frchain_now->frch_obstack); |
277 | retval = obstack_next_free (&frchain_now->frch_obstack); |
264 | frag_var_init (type, max_chars, var, subtype, symbol, offset, opcode); |
278 | frag_var_init (type, max_chars, var, subtype, symbol, offset, opcode); |
265 | 279 | ||
266 | return retval; |
280 | return retval; |
Line 267... | Line 281... | ||
267 | } |
281 | } |
268 | 282 | ||
269 | /* Reduce the variable end of a frag to a harmless state. */ |
283 | /* Reduce the variable end of a frag to a harmless state. */ |
270 | 284 | ||
271 | void |
285 | void |
272 | frag_wane (register fragS *fragP) |
286 | frag_wane (fragS *fragP) |
273 | { |
287 | { |
274 | fragP->fr_type = rs_fill; |
288 | fragP->fr_type = rs_fill; |
275 | fragP->fr_offset = 0; |
289 | fragP->fr_offset = 0; |
Line 276... | Line 290... | ||
276 | fragP->fr_var = 0; |
290 | fragP->fr_var = 0; |
277 | } |
291 | } |
278 | 292 | ||
279 | /* Return the number of bytes by which the current frag can be grown. */ |
293 | /* Return the number of bytes by which the current frag can be grown. */ |
280 | 294 | ||
281 | int |
295 | size_t |
Line 321... | Line 335... | ||
321 | FILL_PATTERN. MAX is the maximum number of characters to skip when |
335 | FILL_PATTERN. MAX is the maximum number of characters to skip when |
322 | doing the alignment, or 0 if there is no maximum. */ |
336 | doing the alignment, or 0 if there is no maximum. */ |
Line 323... | Line 337... | ||
323 | 337 | ||
324 | void |
338 | void |
325 | frag_align_pattern (int alignment, const char *fill_pattern, |
339 | frag_align_pattern (int alignment, const char *fill_pattern, |
326 | int n_fill, int max) |
340 | size_t n_fill, int max) |
327 | { |
341 | { |
Line 328... | Line 342... | ||
328 | char *p; |
342 | char *p; |
329 | 343 |