121 #include "../begin.h"
130 #ifdef __PTRDIFF_TYPE__
131 # define PTR_INT_TYPE __PTRDIFF_TYPE__
134 # define PTR_INT_TYPE ptrdiff_t
141 #define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
150 #define __PTR_ALIGN(B, P, A) \
151 __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
157 #include "funcattr.h"
159 struct _obstack_chunk
162 struct _obstack_chunk *prev;
168 PTR_INT_TYPE chunk_size;
169 struct _obstack_chunk *chunk;
175 PTR_INT_TYPE tempint;
182 struct _obstack_chunk *(*chunkfun) (
void *, PTR_INT_TYPE);
183 void (*freefun) (
void *,
struct _obstack_chunk *);
185 unsigned use_extra_arg:1;
186 unsigned maybe_empty_object:1;
190 unsigned alloc_failed:1;
197 FIRM_API
void _obstack_newchunk (
struct obstack *, PTR_INT_TYPE);
198 FIRM_API
int _obstack_begin (
struct obstack *,
int,
int,
199 void *(*) (PTR_INT_TYPE),
void (*) (
void *));
200 FIRM_API
int _obstack_begin_1 (
struct obstack *,
int,
int,
201 void *(*) (
void *, PTR_INT_TYPE),
202 void (*) (
void *,
void *),
void *);
203 FIRM_API PTR_INT_TYPE _obstack_memory_used (
struct obstack *);
205 FIRM_API
void obstack_free (
struct obstack *obstack,
void *block);
211 FIRM_API FIRM_NORETURN_FUNCPTR (*obstack_alloc_failed_handler) (void);
214 FIRM_API
int obstack_exit_failure;
220 #define obstack_base(h) ((void *) (h)->object_base)
224 #define obstack_chunk_size(h) ((h)->chunk_size)
228 #define obstack_next_free(h) ((h)->next_free)
232 #define obstack_alignment_mask(h) ((h)->alignment_mask)
235 #define obstack_init(h) \
236 _obstack_begin ((h), 0, 0, \
237 (void *(*) (PTR_INT_TYPE)) obstack_chunk_alloc, \
238 (void (*) (void *)) obstack_chunk_free)
240 #define obstack_begin(h, size) \
241 _obstack_begin ((h), (size), 0, \
242 (void *(*) (PTR_INT_TYPE)) obstack_chunk_alloc, \
243 (void (*) (void *)) obstack_chunk_free)
245 #define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
246 _obstack_begin ((h), (size), (alignment), \
247 (void *(*) (PTR_INT_TYPE)) (chunkfun), \
248 (void (*) (void *)) (freefun))
250 #define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
251 _obstack_begin_1 ((h), (size), (alignment), \
252 (void *(*) (void *, PTR_INT_TYPE)) (chunkfun), \
253 (void (*) (void *, void *)) (freefun), (arg))
255 #define obstack_chunkfun(h, newchunkfun) \
256 ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, PTR_INT_TYPE)) (newchunkfun))
258 #define obstack_freefun(h, newfreefun) \
259 ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
261 #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
263 #define obstack_blank_fast(h,n) ((h)->next_free += (n))
265 #define obstack_memory_used(h) _obstack_memory_used (h)
267 #if defined __GNUC__ && defined __STDC__ && __STDC__
271 # if __GNUC__ < 2 || (defined __NeXT__ && __NeXT__ && !__GNUC_MINOR__)
272 # define __extension__
280 # define obstack_object_size(OBSTACK) \
282 ({ struct obstack const *__o = (OBSTACK); \
283 (unsigned) (__o->next_free - __o->object_base); })
285 # define obstack_room(OBSTACK) \
287 ({ struct obstack const *__o = (OBSTACK); \
288 (unsigned) (__o->chunk_limit - __o->next_free); })
290 # define obstack_make_room(OBSTACK,length) \
292 ({ struct obstack *__o = (OBSTACK); \
293 PTR_INT_TYPE __len = (length); \
294 if (__o->chunk_limit - __o->next_free < __len) \
295 _obstack_newchunk (__o, __len); \
298 # define obstack_empty_p(OBSTACK) \
300 ({ struct obstack const *__o = (OBSTACK); \
301 (__o->chunk->prev == 0 \
302 && __o->next_free == __PTR_ALIGN ((char *) __o->chunk, \
303 __o->chunk->contents, \
304 __o->alignment_mask)); })
306 # define obstack_grow(OBSTACK,where,length) \
308 ({ struct obstack *__o = (OBSTACK); \
309 PTR_INT_TYPE __len = (length); \
310 if (__o->next_free + __len > __o->chunk_limit) \
311 _obstack_newchunk (__o, __len); \
312 memcpy (__o->next_free, where, __len); \
313 __o->next_free += __len; \
316 # define obstack_grow0(OBSTACK,where,length) \
318 ({ struct obstack *__o = (OBSTACK); \
319 PTR_INT_TYPE __len = (length); \
320 if (__o->next_free + __len + 1 > __o->chunk_limit) \
321 _obstack_newchunk (__o, __len + 1); \
322 memcpy (__o->next_free, where, __len); \
323 __o->next_free += __len; \
324 *(__o->next_free)++ = 0; \
327 # define obstack_1grow(OBSTACK,datum) \
329 ({ struct obstack *__o = (OBSTACK); \
330 if (__o->next_free + 1 > __o->chunk_limit) \
331 _obstack_newchunk (__o, 1); \
332 obstack_1grow_fast (__o, datum); \
339 # define obstack_ptr_grow(OBSTACK,datum) \
341 ({ struct obstack *__o = (OBSTACK); \
342 if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
343 _obstack_newchunk (__o, sizeof (void *)); \
344 obstack_ptr_grow_fast (__o, datum); }) \
346 # define obstack_int_grow(OBSTACK,datum) \
348 ({ struct obstack *__o = (OBSTACK); \
349 if (__o->next_free + sizeof (int) > __o->chunk_limit) \
350 _obstack_newchunk (__o, sizeof (int)); \
351 obstack_int_grow_fast (__o, datum); })
353 # define obstack_ptr_grow_fast(OBSTACK,aptr) \
355 ({ struct obstack *__o1 = (OBSTACK); \
356 *(const void **) __o1->next_free = (aptr); \
357 __o1->next_free += sizeof (const void *); \
360 # define obstack_int_grow_fast(OBSTACK,aint) \
362 ({ struct obstack *__o1 = (OBSTACK); \
363 *(int *) __o1->next_free = (aint); \
364 __o1->next_free += sizeof (int); \
367 # define obstack_blank(OBSTACK,length) \
369 ({ struct obstack *__o = (OBSTACK); \
370 PTR_INT_TYPE __len = (length); \
371 if (__o->chunk_limit - __o->next_free < __len) \
372 _obstack_newchunk (__o, __len); \
373 obstack_blank_fast (__o, __len); \
376 # define obstack_alloc(OBSTACK,length) \
378 ({ struct obstack *__h = (OBSTACK); \
379 obstack_blank (__h, (length)); \
380 obstack_finish (__h); })
382 # define obstack_copy(OBSTACK,where,length) \
384 ({ struct obstack *__h = (OBSTACK); \
385 obstack_grow (__h, (where), (length)); \
386 obstack_finish (__h); })
388 # define obstack_copy0(OBSTACK,where,length) \
390 ({ struct obstack *__h = (OBSTACK); \
391 obstack_grow0 (__h, (where), (length)); \
392 obstack_finish (__h); })
396 # define obstack_finish(OBSTACK) \
398 ({ struct obstack *__o1 = (OBSTACK); \
399 void *__value = (void *) __o1->object_base; \
400 if (__o1->next_free == __value) \
401 __o1->maybe_empty_object = 1; \
403 = __PTR_ALIGN (__o1->object_base, __o1->next_free, \
404 __o1->alignment_mask); \
405 if (__o1->next_free - (char *)__o1->chunk \
406 > __o1->chunk_limit - (char *)__o1->chunk) \
407 __o1->next_free = __o1->chunk_limit; \
408 __o1->object_base = __o1->next_free; \
411 # define obstack_free(OBSTACK, OBJ) \
413 ({ struct obstack *__o = (OBSTACK); \
414 void *__obj = (OBJ); \
415 if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
416 __o->next_free = __o->object_base = (char *)__obj; \
417 else (obstack_free) (__o, __obj); })
421 # define obstack_object_size(h) \
422 (unsigned) ((h)->next_free - (h)->object_base)
424 # define obstack_room(h) \
425 (unsigned) ((h)->chunk_limit - (h)->next_free)
427 # define obstack_empty_p(h) \
428 ((h)->chunk->prev == 0 \
429 && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk, \
430 (h)->chunk->contents, \
431 (h)->alignment_mask))
439 # define obstack_make_room(h,length) \
440 ( (h)->temp.tempint = (length), \
441 (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
442 ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
444 # define obstack_grow(h,where,length) \
445 ( (h)->temp.tempint = (length), \
446 (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
447 ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
448 memcpy ((h)->next_free, where, (h)->temp.tempint), \
449 (h)->next_free += (h)->temp.tempint)
451 # define obstack_grow0(h,where,length) \
452 ( (h)->temp.tempint = (length), \
453 (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit) \
454 ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0), \
455 memcpy ((h)->next_free, where, (h)->temp.tempint), \
456 (h)->next_free += (h)->temp.tempint, \
457 *((h)->next_free)++ = 0)
459 # define obstack_1grow(h,datum) \
460 ( (((h)->next_free + 1 > (h)->chunk_limit) \
461 ? (_obstack_newchunk ((h), 1), 0) : 0), \
462 obstack_1grow_fast (h, datum))
464 # define obstack_ptr_grow(h,datum) \
465 ( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
466 ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
467 obstack_ptr_grow_fast (h, datum))
469 # define obstack_int_grow(h,datum) \
470 ( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
471 ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
472 obstack_int_grow_fast (h, datum))
474 # define obstack_ptr_grow_fast(h,aptr) \
475 (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
477 # define obstack_int_grow_fast(h,aint) \
478 (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
480 # define obstack_blank(h,length) \
481 ( (h)->temp.tempint = (length), \
482 (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint) \
483 ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
484 obstack_blank_fast (h, (h)->temp.tempint))
486 # define obstack_alloc(h,length) \
487 (obstack_blank ((h), (length)), obstack_finish ((h)))
489 # define obstack_copy(h,where,length) \
490 (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
492 # define obstack_copy0(h,where,length) \
493 (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
495 # define obstack_finish(h) \
496 ( ((h)->next_free == (h)->object_base \
497 ? (((h)->maybe_empty_object = 1), 0) \
499 (h)->temp.tempptr = (h)->object_base, \
501 = __PTR_ALIGN ((h)->object_base, (h)->next_free, \
502 (h)->alignment_mask), \
503 (((h)->next_free - (char *) (h)->chunk \
504 > (h)->chunk_limit - (char *) (h)->chunk) \
505 ? ((h)->next_free = (h)->chunk_limit) : 0), \
506 (h)->object_base = (h)->next_free, \
509 # define obstack_free(h,obj) \
510 ( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \
511 ((((h)->temp.tempint > 0 \
512 && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \
513 ? (PTR_INT_TYPE) ((h)->next_free = (h)->object_base \
514 = (h)->temp.tempint + (char *) (h)->chunk) \
515 : (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))
522 FIRM_API
int obstack_printf(
struct obstack *obst,
const char *fmt, ...)
523 FIRM_NOTHROW FIRM_PRINTF(2, 3);
524 FIRM_API
int obstack_vprintf(struct obstack *obst, const
char *fmt, va_list ap)
525 FIRM_NOTHROW FIRM_PRINTF(2, 0);