diff --git a/src/packcc.c b/src/packcc.c index 6191a38..1d141f6 100644 --- a/src/packcc.c +++ b/src/packcc.c @@ -3577,16 +3577,17 @@ static bool_t generate(context_t *ctx) { ); stream__puts( &sstream, - "typedef struct pcc_recycle_list_tag {\n" - " struct pcc_recycle_list_tag *next;\n" - "} pcc_recycle_list_t;\n" - "typedef struct pcc_recycle_manager_tag {\n" - " pcc_recycle_list_t *list;\n" + "typedef struct pcc_recycling_list_tag {\n" + " struct pcc_recycling_list_tag *next;\n" + "} pcc_recycling_list_t;\n" + "\n" + "typedef struct pcc_memory_recycler_tag {\n" + " pcc_recycling_list_t *list;\n" " size_t element_size;\n" " size_t allocated;\n" " size_t inuse;\n" " void *base;\n" - "} pcc_recycle_manager_t;\n" + "} pcc_memory_recycler_t;\n" "\n" ); stream__printf( @@ -3600,9 +3601,9 @@ static bool_t generate(context_t *ctx) { " pcc_lr_stack_t lrstack;\n" " pcc_thunk_array_t thunks;\n" " pcc_auxil_t auxil;\n" - " pcc_recycle_manager_t thunk_chunk_recycle_manager;\n" - " pcc_recycle_manager_t lr_head_recycle_manager;\n" - " pcc_recycle_manager_t lr_answer_recycle_manager;\n" + " pcc_memory_recycler_t thunk_chunk_recycler;\n" + " pcc_memory_recycler_t lr_head_recycler;\n" + " pcc_memory_recycler_t lr_answer_recycler;\n" "};\n" "\n", get_prefix(ctx) @@ -3890,46 +3891,48 @@ static bool_t generate(context_t *ctx) { "}\n" "\n" ); - stream__puts( &sstream, - "static void *pcc_recycle_alloc(pcc_auxil_t auxil, pcc_recycle_manager_t *recycle_manager) {\n" - " if (recycle_manager->list) {\n" - " pcc_recycle_list_t *tmp = recycle_manager->list;\n" - " recycle_manager->list = tmp->next;\n" + "static void pcc_memory_recycler__init(pcc_auxil_t auxil, pcc_memory_recycler_t *recycler, size_t element_size) {\n" + " recycler->list = NULL;\n" + " recycler->element_size = element_size;\n" + " recycler->allocated = 1024 * 1024;\n" + " recycler->inuse = 0;\n" + " recycler->base = PCC_MALLOC(auxil, recycler->element_size * recycler->allocated);\n" + "}\n" + "\n" + "static void *pcc_memory_recycler__supply(pcc_auxil_t auxil, pcc_memory_recycler_t *recycler) {\n" + " if (recycler->list) {\n" + " pcc_recycling_list_t *tmp = recycler->list;\n" + " recycler->list = tmp->next;\n" " return tmp;\n" " }\n" - " if (recycle_manager->inuse < recycle_manager->allocated) {\n" - " char *base = recycle_manager->base;\n" - " char *tmp = base + (recycle_manager->inuse * recycle_manager->element_size);\n" - " recycle_manager->inuse++;\n" + " if (recycler->inuse < recycler->allocated) {\n" + " char *base = recycler->base;\n" + " char *tmp = base + (recycler->inuse * recycler->element_size);\n" + " recycler->inuse++;\n" " return tmp;\n" " }\n" - " return PCC_MALLOC(auxil, recycle_manager->element_size);\n" + " return PCC_MALLOC(auxil, recycler->element_size);\n" "}\n" - "static void pcc_recycle_return(pcc_recycle_manager_t *recycle_manager, void *obj) {\n" - " pcc_recycle_list_t *tmp = obj;\n" - " tmp->next = recycle_manager->list;\n" - " recycle_manager->list = tmp;\n" - "}\n" - "static void pcc_recycle_manager_alloc(pcc_auxil_t auxil, pcc_recycle_manager_t *manager, size_t element_size) {\n" - " manager->list = NULL;\n" - " manager->element_size = element_size;\n" - " manager->allocated = 1024 * 1024;\n" - " manager->inuse = 0;\n" - " manager->base = PCC_MALLOC(auxil, manager->element_size * manager->allocated);\n" + "\n" + "static void pcc_memory_recycler__recycle(pcc_auxil_t auxil, pcc_memory_recycler_t *recycler, void *obj) {\n" + " pcc_recycling_list_t *tmp = obj;\n" + " tmp->next = recycler->list;\n" + " recycler->list = tmp;\n" "}\n" - "static void pcc_recycle_manager_destroy(pcc_auxil_t auxil, pcc_recycle_manager_t *recycle_manager) {\n" - " char *start = recycle_manager->base;\n" - " char *end = recycle_manager->base + (recycle_manager->allocated * recycle_manager->element_size);\n" - " while (recycle_manager->list) {\n" - " pcc_recycle_list_t *tmp = recycle_manager->list;\n" - " recycle_manager->list = tmp->next;\n" + "\n" + "static void pcc_memory_recycler__term(pcc_auxil_t auxil, pcc_memory_recycler_t *recycler) {\n" + " char *start = recycler->base;\n" + " char *end = recycler->base + (recycler->allocated * recycler->element_size);\n" + " while (recycler->list) {\n" + " pcc_recycling_list_t *tmp = recycler->list;\n" + " recycler->list = tmp->next;\n" " if (start <= (char *)tmp && (char *)tmp < end)\n" " continue;\n" " PCC_FREE(auxil, tmp);\n" " }\n" - " PCC_FREE(auxil, recycle_manager->base);\n" + " PCC_FREE(auxil, recycler->base);\n" "}\n" "\n" ); @@ -3937,7 +3940,7 @@ static bool_t generate(context_t *ctx) { &sstream, "MARK_FUNC_AS_USED\n" "static pcc_thunk_chunk_t *pcc_thunk_chunk__create(%s_context_t *ctx) {\n" - " pcc_thunk_chunk_t *const chunk = (pcc_thunk_chunk_t *)pcc_recycle_alloc(ctx->auxil, &ctx->thunk_chunk_recycle_manager);\n" + " pcc_thunk_chunk_t *const chunk = (pcc_thunk_chunk_t *)pcc_memory_recycler__supply(ctx->auxil, &ctx->thunk_chunk_recycler);\n" " pcc_value_table__init(ctx->auxil, &chunk->values);\n" " pcc_capture_table__init(ctx->auxil, &chunk->capts);\n" " pcc_thunk_array__init(ctx->auxil, &chunk->thunks);\n" @@ -3950,7 +3953,7 @@ static bool_t generate(context_t *ctx) { " pcc_thunk_array__term(ctx->auxil, &chunk->thunks);\n" " pcc_capture_table__term(ctx->auxil, &chunk->capts);\n" " pcc_value_table__term(ctx->auxil, &chunk->values);\n" - " pcc_recycle_return(&ctx->thunk_chunk_recycle_manager, chunk);\n" + " pcc_memory_recycler__recycle(ctx->auxil, &ctx->thunk_chunk_recycler, chunk);\n" "}\n" "\n", get_prefix(ctx), get_prefix(ctx) @@ -4014,7 +4017,7 @@ static bool_t generate(context_t *ctx) { stream__printf( &sstream, "static pcc_lr_head_t *pcc_lr_head__create(%s_context_t *ctx, pcc_rule_t rule) {\n" - " pcc_lr_head_t *const head = (pcc_lr_head_t *)pcc_recycle_alloc(ctx->auxil, &ctx->lr_head_recycle_manager);\n" + " pcc_lr_head_t *const head = (pcc_lr_head_t *)pcc_memory_recycler__supply(ctx->auxil, &ctx->lr_head_recycler);\n" " head->rule = rule;\n" " pcc_rule_set__init(ctx->auxil, &head->invol);\n" " pcc_rule_set__init(ctx->auxil, &head->eval);\n" @@ -4027,7 +4030,7 @@ static bool_t generate(context_t *ctx) { " pcc_lr_head__destroy(ctx, head->hold);\n" " pcc_rule_set__term(ctx->auxil, &head->eval);\n" " pcc_rule_set__term(ctx->auxil, &head->invol);\n" - " pcc_recycle_return(&ctx->lr_head_recycle_manager, head);\n" + " pcc_memory_recycler__recycle(ctx->auxil, &ctx->lr_head_recycler, head);\n" "}\n" "\n", get_prefix(ctx), get_prefix(ctx) @@ -4037,7 +4040,7 @@ static bool_t generate(context_t *ctx) { "static void pcc_lr_entry__destroy(pcc_auxil_t auxil, pcc_lr_entry_t *lr);\n" "\n" "static pcc_lr_answer_t *pcc_lr_answer__create(%s_context_t *ctx, pcc_lr_answer_type_t type, size_t pos) {\n" - " pcc_lr_answer_t *answer = (pcc_lr_answer_t *)pcc_recycle_alloc(ctx->auxil, &ctx->lr_answer_recycle_manager);\n" + " pcc_lr_answer_t *answer = (pcc_lr_answer_t *)pcc_memory_recycler__supply(ctx->auxil, &ctx->lr_answer_recycler);\n" " answer->type = type;\n" " answer->pos = pos;\n" " answer->hold = NULL;\n" @@ -4086,7 +4089,7 @@ static bool_t generate(context_t *ctx) { " default: /* unknown */\n" " break;\n" " }\n" - " pcc_recycle_return(&ctx->lr_answer_recycle_manager, answer);\n" + " pcc_memory_recycler__recycle(ctx->auxil, &ctx->lr_answer_recycler, answer);\n" " answer = a;\n" " }\n" "}\n" @@ -4314,9 +4317,9 @@ static bool_t generate(context_t *ctx) { " pcc_lr_table__init(auxil, &ctx->lrtable);\n" " pcc_lr_stack__init(auxil, &ctx->lrstack);\n" " pcc_thunk_array__init(auxil, &ctx->thunks);\n" - " pcc_recycle_manager_alloc(auxil, &ctx->thunk_chunk_recycle_manager, sizeof(pcc_thunk_chunk_t));\n" - " pcc_recycle_manager_alloc(auxil, &ctx->lr_head_recycle_manager, sizeof(pcc_lr_head_t));\n" - " pcc_recycle_manager_alloc(auxil, &ctx->lr_answer_recycle_manager, sizeof(pcc_lr_answer_t));\n" + " pcc_memory_recycler__init(auxil, &ctx->thunk_chunk_recycler, sizeof(pcc_thunk_chunk_t));\n" + " pcc_memory_recycler__init(auxil, &ctx->lr_head_recycler, sizeof(pcc_lr_head_t));\n" + " pcc_memory_recycler__init(auxil, &ctx->lr_answer_recycler, sizeof(pcc_lr_answer_t));\n" " ctx->auxil = auxil;\n" " return ctx;\n" "}\n" @@ -4329,15 +4332,15 @@ static bool_t generate(context_t *ctx) { ); stream__puts( &sstream, - " pcc_recycle_list_t *tmp;\n" + " pcc_recycling_list_t *tmp;\n" " if (ctx == NULL) return;\n" " pcc_thunk_array__term(ctx->auxil, &ctx->thunks);\n" " pcc_lr_stack__term(ctx->auxil, &ctx->lrstack);\n" " pcc_lr_table__term(ctx, &ctx->lrtable);\n" " pcc_char_array__term(ctx->auxil, &ctx->buffer);\n" - " pcc_recycle_manager_destroy(ctx->auxil, &ctx->thunk_chunk_recycle_manager);\n" - " pcc_recycle_manager_destroy(ctx->auxil, &ctx->lr_head_recycle_manager);\n" - " pcc_recycle_manager_destroy(ctx->auxil, &ctx->lr_answer_recycle_manager);\n" + " pcc_memory_recycler__term(ctx->auxil, &ctx->thunk_chunk_recycler);\n" + " pcc_memory_recycler__term(ctx->auxil, &ctx->lr_head_recycler);\n" + " pcc_memory_recycler__term(ctx->auxil, &ctx->lr_answer_recycler);\n" " PCC_FREE(ctx->auxil, ctx);\n" "}\n" "\n"