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 struct _obstack_chunk
160 struct _obstack_chunk *prev;
166 PTR_INT_TYPE chunk_size;
167 struct _obstack_chunk *chunk;
173 PTR_INT_TYPE tempint;
180 struct _obstack_chunk *(*chunkfun) (
void *, PTR_INT_TYPE);
181 void (*freefun) (
void *,
struct _obstack_chunk *);
183 unsigned use_extra_arg:1;
184 unsigned maybe_empty_object:1;
188 unsigned alloc_failed:1;
195 FIRM_API void _obstack_newchunk (
struct obstack *, PTR_INT_TYPE);
196 FIRM_API int _obstack_begin (
struct obstack *,
int,
int,
197 void *(*) (PTR_INT_TYPE),
void (*) (
void *));
198 FIRM_API int _obstack_begin_1 (
struct obstack *,
int,
int,
199 void *(*) (
void *, PTR_INT_TYPE),
200 void (*) (
void *,
void *),
void *);
201 FIRM_API PTR_INT_TYPE _obstack_memory_used (
struct obstack *);
203 FIRM_API void obstack_free (
struct obstack *obstack,
void *block);
210 FIRM_API void (*obstack_alloc_failed_handler) (void);
219 #define obstack_base(h) ((void *) (h)->object_base)
223 #define obstack_chunk_size(h) ((h)->chunk_size)
227 #define obstack_next_free(h) ((h)->next_free)
231 #define obstack_alignment_mask(h) ((h)->alignment_mask)
234 #define obstack_init(h) \
235 _obstack_begin ((h), 0, 0, \
236 (void *(*) (PTR_INT_TYPE)) obstack_chunk_alloc, \
237 (void (*) (void *)) obstack_chunk_free)
239 #define obstack_begin(h, size) \
240 _obstack_begin ((h), (size), 0, \
241 (void *(*) (PTR_INT_TYPE)) obstack_chunk_alloc, \
242 (void (*) (void *)) obstack_chunk_free)
244 #define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
245 _obstack_begin ((h), (size), (alignment), \
246 (void *(*) (PTR_INT_TYPE)) (chunkfun), \
247 (void (*) (void *)) (freefun))
249 #define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
250 _obstack_begin_1 ((h), (size), (alignment), \
251 (void *(*) (void *, PTR_INT_TYPE)) (chunkfun), \
252 (void (*) (void *, void *)) (freefun), (arg))
254 #define obstack_chunkfun(h, newchunkfun) \
255 ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, PTR_INT_TYPE)) (newchunkfun))
257 #define obstack_freefun(h, newfreefun) \
258 ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
260 #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
262 #define obstack_blank_fast(h,n) ((h)->next_free += (n))
264 #define obstack_memory_used(h) _obstack_memory_used (h)
266 #if defined __GNUC__ && defined __STDC__ && __STDC__
270 # if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
271 # define __extension__
279 # define obstack_object_size(OBSTACK) \
281 ({ struct obstack const *__o = (OBSTACK); \
282 (unsigned) (__o->next_free - __o->object_base); })
284 # define obstack_room(OBSTACK) \
286 ({ struct obstack const *__o = (OBSTACK); \
287 (unsigned) (__o->chunk_limit - __o->next_free); })
289 # define obstack_make_room(OBSTACK,length) \
291 ({ struct obstack *__o = (OBSTACK); \
292 int __len = (length); \
293 if (__o->chunk_limit - __o->next_free < __len) \
294 _obstack_newchunk (__o, __len); \
297 # define obstack_empty_p(OBSTACK) \
299 ({ struct obstack const *__o = (OBSTACK); \
300 (__o->chunk->prev == 0 \
301 && __o->next_free == __PTR_ALIGN ((char *) __o->chunk, \
302 __o->chunk->contents, \
303 __o->alignment_mask)); })
305 # define obstack_grow(OBSTACK,where,length) \
307 ({ struct obstack *__o = (OBSTACK); \
308 int __len = (length); \
309 if (__o->next_free + __len > __o->chunk_limit) \
310 _obstack_newchunk (__o, __len); \
311 memcpy (__o->next_free, where, __len); \
312 __o->next_free += __len; \
315 # define obstack_grow0(OBSTACK,where,length) \
317 ({ struct obstack *__o = (OBSTACK); \
318 int __len = (length); \
319 if (__o->next_free + __len + 1 > __o->chunk_limit) \
320 _obstack_newchunk (__o, __len + 1); \
321 memcpy (__o->next_free, where, __len); \
322 __o->next_free += __len; \
323 *(__o->next_free)++ = 0; \
326 # define obstack_1grow(OBSTACK,datum) \
328 ({ struct obstack *__o = (OBSTACK); \
329 if (__o->next_free + 1 > __o->chunk_limit) \
330 _obstack_newchunk (__o, 1); \
331 obstack_1grow_fast (__o, datum); \
338 # define obstack_ptr_grow(OBSTACK,datum) \
340 ({ struct obstack *__o = (OBSTACK); \
341 if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
342 _obstack_newchunk (__o, sizeof (void *)); \
343 obstack_ptr_grow_fast (__o, datum); }) \
345 # define obstack_int_grow(OBSTACK,datum) \
347 ({ struct obstack *__o = (OBSTACK); \
348 if (__o->next_free + sizeof (int) > __o->chunk_limit) \
349 _obstack_newchunk (__o, sizeof (int)); \
350 obstack_int_grow_fast (__o, datum); })
352 # define obstack_ptr_grow_fast(OBSTACK,aptr) \
354 ({ struct obstack *__o1 = (OBSTACK); \
355 *(const void **) __o1->next_free = (aptr); \
356 __o1->next_free += sizeof (const void *); \
359 # define obstack_int_grow_fast(OBSTACK,aint) \
361 ({ struct obstack *__o1 = (OBSTACK); \
362 *(int *) __o1->next_free = (aint); \
363 __o1->next_free += sizeof (int); \
366 # define obstack_blank(OBSTACK,length) \
368 ({ struct obstack *__o = (OBSTACK); \
369 int __len = (length); \
370 if (__o->chunk_limit - __o->next_free < __len) \
371 _obstack_newchunk (__o, __len); \
372 obstack_blank_fast (__o, __len); \
375 # define obstack_alloc(OBSTACK,length) \
377 ({ struct obstack *__h = (OBSTACK); \
378 obstack_blank (__h, (length)); \
379 obstack_finish (__h); })
381 # define obstack_copy(OBSTACK,where,length) \
383 ({ struct obstack *__h = (OBSTACK); \
384 obstack_grow (__h, (where), (length)); \
385 obstack_finish (__h); })
387 # define obstack_copy0(OBSTACK,where,length) \
389 ({ struct obstack *__h = (OBSTACK); \
390 obstack_grow0 (__h, (where), (length)); \
391 obstack_finish (__h); })
395 # define obstack_finish(OBSTACK) \
397 ({ struct obstack *__o1 = (OBSTACK); \
398 void *__value = (void *) __o1->object_base; \
399 if (__o1->next_free == __value) \
400 __o1->maybe_empty_object = 1; \
402 = __PTR_ALIGN (__o1->object_base, __o1->next_free, \
403 __o1->alignment_mask); \
404 if (__o1->next_free - (char *)__o1->chunk \
405 > __o1->chunk_limit - (char *)__o1->chunk) \
406 __o1->next_free = __o1->chunk_limit; \
407 __o1->object_base = __o1->next_free; \
410 # define obstack_free(OBSTACK, OBJ) \
412 ({ struct obstack *__o = (OBSTACK); \
413 void *__obj = (OBJ); \
414 if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
415 __o->next_free = __o->object_base = (char *)__obj; \
416 else (obstack_free) (__o, __obj); })
420 # define obstack_object_size(h) \
421 (unsigned) ((h)->next_free - (h)->object_base)
423 # define obstack_room(h) \
424 (unsigned) ((h)->chunk_limit - (h)->next_free)
426 # define obstack_empty_p(h) \
427 ((h)->chunk->prev == 0 \
428 && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk, \
429 (h)->chunk->contents, \
430 (h)->alignment_mask))
438 # define obstack_make_room(h,length) \
439 ( (h)->temp.tempint = (length), \
440 (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
441 ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
443 # define obstack_grow(h,where,length) \
444 ( (h)->temp.tempint = (length), \
445 (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
446 ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
447 memcpy ((h)->next_free, where, (h)->temp.tempint), \
448 (h)->next_free += (h)->temp.tempint)
450 # define obstack_grow0(h,where,length) \
451 ( (h)->temp.tempint = (length), \
452 (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit) \
453 ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0), \
454 memcpy ((h)->next_free, where, (h)->temp.tempint), \
455 (h)->next_free += (h)->temp.tempint, \
456 *((h)->next_free)++ = 0)
458 # define obstack_1grow(h,datum) \
459 ( (((h)->next_free + 1 > (h)->chunk_limit) \
460 ? (_obstack_newchunk ((h), 1), 0) : 0), \
461 obstack_1grow_fast (h, datum))
463 # define obstack_ptr_grow(h,datum) \
464 ( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
465 ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
466 obstack_ptr_grow_fast (h, datum))
468 # define obstack_int_grow(h,datum) \
469 ( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
470 ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
471 obstack_int_grow_fast (h, datum))
473 # define obstack_ptr_grow_fast(h,aptr) \
474 (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
476 # define obstack_int_grow_fast(h,aint) \
477 (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
479 # define obstack_blank(h,length) \
480 ( (h)->temp.tempint = (length), \
481 (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint) \
482 ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
483 obstack_blank_fast (h, (h)->temp.tempint))
485 # define obstack_alloc(h,length) \
486 (obstack_blank ((h), (length)), obstack_finish ((h)))
488 # define obstack_copy(h,where,length) \
489 (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
491 # define obstack_copy0(h,where,length) \
492 (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
494 # define obstack_finish(h) \
495 ( ((h)->next_free == (h)->object_base \
496 ? (((h)->maybe_empty_object = 1), 0) \
498 (h)->temp.tempptr = (h)->object_base, \
500 = __PTR_ALIGN ((h)->object_base, (h)->next_free, \
501 (h)->alignment_mask), \
502 (((h)->next_free - (char *) (h)->chunk \
503 > (h)->chunk_limit - (char *) (h)->chunk) \
504 ? ((h)->next_free = (h)->chunk_limit) : 0), \
505 (h)->object_base = (h)->next_free, \
508 # define obstack_free(h,obj) \
509 ( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \
510 ((((h)->temp.tempint > 0 \
511 && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \
512 ? (PTR_INT_TYPE) ((h)->next_free = (h)->object_base \
513 = (h)->temp.tempint + (char *) (h)->chunk) \
514 : (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))
523 # define FIRM_NOTHROW throw ()
525 # define FIRM_NOTHROW
533 #if defined(__GNUC__)
534 # define FIRM_PRINTF(a,b) __attribute__((__format__(__printf__, a, b)))
536 # define FIRM_PRINTF(a,b)
542 FIRM_API int obstack_printf(
struct obstack *obst,
const char *fmt, ...)
543 FIRM_NOTHROW FIRM_PRINTF(2, 3);
544 FIRM_API int obstack_vprintf(struct obstack *obst, const
char *fmt, va_list ap)
545 FIRM_NOTHROW FIRM_PRINTF(2, 0);