121 #include "../begin.h" 131 #define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A))) 140 #define __PTR_ALIGN(B, P, A) \ 141 __BPTR_ALIGN (sizeof (ptrdiff_t) < sizeof (void *) ? (B) : (char *) 0, \ 147 #include "funcattr.h" 149 struct _obstack_chunk
152 struct _obstack_chunk *prev;
158 ptrdiff_t chunk_size;
159 struct _obstack_chunk *chunk;
172 struct _obstack_chunk *(*chunkfun) (
void *, ptrdiff_t);
173 void (*freefun) (
void *,
struct _obstack_chunk *);
175 unsigned use_extra_arg:1;
176 unsigned maybe_empty_object:1;
180 unsigned alloc_failed:1;
187 FIRM_API
void _obstack_newchunk (
struct obstack *, ptrdiff_t);
188 FIRM_API
int _obstack_begin (
struct obstack *,
int,
int,
189 void *(*) (ptrdiff_t),
void (*) (
void *));
190 FIRM_API
int _obstack_begin_1 (
struct obstack *,
int,
int,
191 void *(*) (
void *, ptrdiff_t),
192 void (*) (
void *,
void *),
void *);
193 FIRM_API ptrdiff_t _obstack_memory_used (
struct obstack *);
195 FIRM_API
void obstack_free (
struct obstack *obstack,
void *block);
201 FIRM_API FIRM_NORETURN_FUNCPTR (*obstack_alloc_failed_handler) (void);
204 FIRM_API
int obstack_exit_failure;
210 #define obstack_base(h) ((void *) (h)->object_base) 214 #define obstack_chunk_size(h) ((h)->chunk_size) 218 #define obstack_next_free(h) ((h)->next_free) 222 #define obstack_alignment_mask(h) ((h)->alignment_mask) 225 #define obstack_init(h) \ 226 _obstack_begin ((h), 0, 0, \ 227 (void *(*) (ptrdiff_t)) obstack_chunk_alloc, \ 228 (void (*) (void *)) obstack_chunk_free) 230 #define obstack_begin(h, size) \ 231 _obstack_begin ((h), (size), 0, \ 232 (void *(*) (ptrdiff_t)) obstack_chunk_alloc, \ 233 (void (*) (void *)) obstack_chunk_free) 235 #define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ 236 _obstack_begin ((h), (size), (alignment), \ 237 (void *(*) (ptrdiff_t)) (chunkfun), \ 238 (void (*) (void *)) (freefun)) 240 #define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ 241 _obstack_begin_1 ((h), (size), (alignment), \ 242 (void *(*) (void *, ptrdiff_t)) (chunkfun), \ 243 (void (*) (void *, void *)) (freefun), (arg)) 245 #define obstack_chunkfun(h, newchunkfun) \ 246 ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, ptrdiff_t)) (newchunkfun)) 248 #define obstack_freefun(h, newfreefun) \ 249 ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun)) 251 #define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar)) 253 #define obstack_blank_fast(h,n) ((h)->next_free += (n)) 255 #define obstack_memory_used(h) _obstack_memory_used (h) 257 #if defined __GNUC__ && defined __STDC__ && __STDC__ 261 # if __GNUC__ < 2 || (defined __NeXT__ && __NeXT__ && !__GNUC_MINOR__) 262 # define __extension__ 270 # define obstack_object_size(OBSTACK) \ 272 ({ struct obstack const *__o = (OBSTACK); \ 273 (unsigned) (__o->next_free - __o->object_base); }) 275 # define obstack_room(OBSTACK) \ 277 ({ struct obstack const *__o = (OBSTACK); \ 278 (unsigned) (__o->chunk_limit - __o->next_free); }) 280 # define obstack_make_room(OBSTACK,length) \ 282 ({ struct obstack *__o = (OBSTACK); \ 283 ptrdiff_t __len = (length); \ 284 if (__o->chunk_limit - __o->next_free < __len) \ 285 _obstack_newchunk (__o, __len); \ 288 # define obstack_empty_p(OBSTACK) \ 290 ({ struct obstack const *__o = (OBSTACK); \ 291 (__o->chunk->prev == 0 \ 292 && __o->next_free == __PTR_ALIGN ((char *) __o->chunk, \ 293 __o->chunk->contents, \ 294 __o->alignment_mask)); }) 296 # define obstack_grow(OBSTACK,where,length) \ 298 ({ struct obstack *__o = (OBSTACK); \ 299 ptrdiff_t __len = (length); \ 300 if (__o->next_free + __len > __o->chunk_limit) \ 301 _obstack_newchunk (__o, __len); \ 302 memcpy (__o->next_free, where, __len); \ 303 __o->next_free += __len; \ 306 # define obstack_grow0(OBSTACK,where,length) \ 308 ({ struct obstack *__o = (OBSTACK); \ 309 ptrdiff_t __len = (length); \ 310 if (__o->next_free + __len + 1 > __o->chunk_limit) \ 311 _obstack_newchunk (__o, __len + 1); \ 312 memcpy (__o->next_free, where, __len); \ 313 __o->next_free += __len; \ 314 *(__o->next_free)++ = 0; \ 317 # define obstack_1grow(OBSTACK,datum) \ 319 ({ struct obstack *__o = (OBSTACK); \ 320 if (__o->next_free + 1 > __o->chunk_limit) \ 321 _obstack_newchunk (__o, 1); \ 322 obstack_1grow_fast (__o, datum); \ 329 # define obstack_ptr_grow(OBSTACK,datum) \ 331 ({ struct obstack *__o = (OBSTACK); \ 332 if (__o->next_free + sizeof (void *) > __o->chunk_limit) \ 333 _obstack_newchunk (__o, sizeof (void *)); \ 334 obstack_ptr_grow_fast (__o, datum); }) \ 336 # define obstack_int_grow(OBSTACK,datum) \ 338 ({ struct obstack *__o = (OBSTACK); \ 339 if (__o->next_free + sizeof (int) > __o->chunk_limit) \ 340 _obstack_newchunk (__o, sizeof (int)); \ 341 obstack_int_grow_fast (__o, datum); }) 343 # define obstack_ptr_grow_fast(OBSTACK,aptr) \ 345 ({ struct obstack *__o1 = (OBSTACK); \ 346 *(const void **) __o1->next_free = (aptr); \ 347 __o1->next_free += sizeof (const void *); \ 350 # define obstack_int_grow_fast(OBSTACK,aint) \ 352 ({ struct obstack *__o1 = (OBSTACK); \ 353 *(int *) __o1->next_free = (aint); \ 354 __o1->next_free += sizeof (int); \ 357 # define obstack_blank(OBSTACK,length) \ 359 ({ struct obstack *__o = (OBSTACK); \ 360 ptrdiff_t __len = (length); \ 361 if (__o->chunk_limit - __o->next_free < __len) \ 362 _obstack_newchunk (__o, __len); \ 363 obstack_blank_fast (__o, __len); \ 366 # define obstack_alloc(OBSTACK,length) \ 368 ({ struct obstack *__h = (OBSTACK); \ 369 obstack_blank (__h, (length)); \ 370 obstack_finish (__h); }) 372 # define obstack_copy(OBSTACK,where,length) \ 374 ({ struct obstack *__h = (OBSTACK); \ 375 obstack_grow (__h, (where), (length)); \ 376 obstack_finish (__h); }) 378 # define obstack_copy0(OBSTACK,where,length) \ 380 ({ struct obstack *__h = (OBSTACK); \ 381 obstack_grow0 (__h, (where), (length)); \ 382 obstack_finish (__h); }) 386 # define obstack_finish(OBSTACK) \ 388 ({ struct obstack *__o1 = (OBSTACK); \ 389 void *__value = (void *) __o1->object_base; \ 390 if (__o1->next_free == __value) \ 391 __o1->maybe_empty_object = 1; \ 393 = __PTR_ALIGN (__o1->object_base, __o1->next_free, \ 394 __o1->alignment_mask); \ 395 if (__o1->next_free - (char *)__o1->chunk \ 396 > __o1->chunk_limit - (char *)__o1->chunk) \ 397 __o1->next_free = __o1->chunk_limit; \ 398 __o1->object_base = __o1->next_free; \ 401 # define obstack_free(OBSTACK, OBJ) \ 403 ({ struct obstack *__o = (OBSTACK); \ 404 void *__obj = (OBJ); \ 405 if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \ 406 __o->next_free = __o->object_base = (char *)__obj; \ 407 else (obstack_free) (__o, __obj); }) 411 # define obstack_object_size(h) \ 412 (unsigned) ((h)->next_free - (h)->object_base) 414 # define obstack_room(h) \ 415 (unsigned) ((h)->chunk_limit - (h)->next_free) 417 # define obstack_empty_p(h) \ 418 ((h)->chunk->prev == 0 \ 419 && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk, \ 420 (h)->chunk->contents, \ 421 (h)->alignment_mask)) 429 # define obstack_make_room(h,length) \ 430 ( (h)->temp.tempint = (length), \ 431 (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \ 432 ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0)) 434 # define obstack_grow(h,where,length) \ 435 ( (h)->temp.tempint = (length), \ 436 (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \ 437 ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \ 438 memcpy ((h)->next_free, where, (h)->temp.tempint), \ 439 (h)->next_free += (h)->temp.tempint) 441 # define obstack_grow0(h,where,length) \ 442 ( (h)->temp.tempint = (length), \ 443 (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit) \ 444 ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0), \ 445 memcpy ((h)->next_free, where, (h)->temp.tempint), \ 446 (h)->next_free += (h)->temp.tempint, \ 447 *((h)->next_free)++ = 0) 449 # define obstack_1grow(h,datum) \ 450 ( (((h)->next_free + 1 > (h)->chunk_limit) \ 451 ? (_obstack_newchunk ((h), 1), 0) : 0), \ 452 obstack_1grow_fast (h, datum)) 454 # define obstack_ptr_grow(h,datum) \ 455 ( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \ 456 ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \ 457 obstack_ptr_grow_fast (h, datum)) 459 # define obstack_int_grow(h,datum) \ 460 ( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \ 461 ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \ 462 obstack_int_grow_fast (h, datum)) 464 # define obstack_ptr_grow_fast(h,aptr) \ 465 (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr)) 467 # define obstack_int_grow_fast(h,aint) \ 468 (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint)) 470 # define obstack_blank(h,length) \ 471 ( (h)->temp.tempint = (length), \ 472 (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint) \ 473 ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \ 474 obstack_blank_fast (h, (h)->temp.tempint)) 476 # define obstack_alloc(h,length) \ 477 (obstack_blank ((h), (length)), obstack_finish ((h))) 479 # define obstack_copy(h,where,length) \ 480 (obstack_grow ((h), (where), (length)), obstack_finish ((h))) 482 # define obstack_copy0(h,where,length) \ 483 (obstack_grow0 ((h), (where), (length)), obstack_finish ((h))) 485 # define obstack_finish(h) \ 486 ( ((h)->next_free == (h)->object_base \ 487 ? (((h)->maybe_empty_object = 1), 0) \ 489 (h)->temp.tempptr = (h)->object_base, \ 491 = __PTR_ALIGN ((h)->object_base, (h)->next_free, \ 492 (h)->alignment_mask), \ 493 (((h)->next_free - (char *) (h)->chunk \ 494 > (h)->chunk_limit - (char *) (h)->chunk) \ 495 ? ((h)->next_free = (h)->chunk_limit) : 0), \ 496 (h)->object_base = (h)->next_free, \ 499 # define obstack_free(h,obj) \ 500 ( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \ 501 ((((h)->temp.tempint > 0 \ 502 && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \ 503 ? (ptrdiff_t) ((h)->next_free = (h)->object_base \ 504 = (h)->temp.tempint + (char *) (h)->chunk) \ 505 : (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0))) 512 FIRM_API
int obstack_printf(
struct obstack *obst,
const char *fmt, ...)
513 FIRM_NOTHROW FIRM_PRINTF(2, 3);
514 FIRM_API
int obstack_vprintf(struct obstack *obst, const
char *fmt, va_list ap)
515 FIRM_NOTHROW FIRM_PRINTF(2, 0);