diff --git a/tools/qfcc/source/emit.c b/tools/qfcc/source/emit.c index 4c6fa35d8..dcdaff05a 100644 --- a/tools/qfcc/source/emit.c +++ b/tools/qfcc/source/emit.c @@ -205,7 +205,7 @@ emit_assign_expr (int oper, expr_t *e) def_a = emit_sub_expr (e1, 0); if (def_a->constant) { if (options.code.cow) { - int size = pr_type_size[def_a->type->type]; + int size = type_size (def_a->type->type); int ofs = PR_NewLocation (def_a->type); memcpy (pr.globals + ofs, pr.globals + def_a->ofs, size); diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 2fe5fe381..85cdcc0ef 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -1990,14 +1990,14 @@ init_elements (def_t *def, expr_t *eles) } else if (e->type >= ex_string) { if (get_type (e) != def->type->aux_type) { error (e, "type mismatch in initializer"); - g += pr_type_size[def->type->aux_type->type]; + g += type_size (def->type->aux_type->type); } else { if (e->type == ex_string) { *(int*)g = ReuseString (e->e.string_val); } else { - memcpy (g, &e->e, pr_type_size[extract_type (e)] * 4); + memcpy (g, &e->e, type_size (extract_type (e)) * 4); } - g += pr_type_size[extract_type (e)]; + g += type_size (extract_type (e)); } } else { error (e, "non-constant initializer"); diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index a00faaeb1..56bf20aab 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -229,7 +229,7 @@ finish_function (function_t *f) if ((count = df->numparms) < 0) count = -count - 1; for (i = 0; i < count; i++) - df->parm_size[i] = pr_type_size[f->def->type->parm_types[i]->type]; + df->parm_size[i] = type_size (f->def->type->parm_types[i]->type); if (f->aux) { def_t *def; diff --git a/tools/qfcc/source/immediate.c b/tools/qfcc/source/immediate.c index 90e9a7871..2e31194b8 100644 --- a/tools/qfcc/source/immediate.c +++ b/tools/qfcc/source/immediate.c @@ -284,7 +284,7 @@ ReuseConstant (expr_t *expr, def_t *def) if (e.type == ex_string) e.e.integer_val = ReuseString (rep->str); - memcpy (pr.globals + cn->ofs, &e.e, 4 * pr_type_size[type->type]); + memcpy (pr.globals + cn->ofs, &e.e, 4 * type_size (type->type)); Hash_Add (tab, cn); diff --git a/tools/qfcc/source/pr_def.c b/tools/qfcc/source/pr_def.c index 14e7ee248..de99c1d01 100644 --- a/tools/qfcc/source/pr_def.c +++ b/tools/qfcc/source/pr_def.c @@ -47,6 +47,7 @@ typedef struct locref_s { static def_t *free_temps[4]; // indexted by type size static def_t temp_scope; +static def_t *free_defs; static locref_t *free_locs[4]; // indexted by type size static locref_t *free_free_locs; @@ -213,7 +214,15 @@ PR_NewDef (type_t *type, const char *name, def_t *scope) { def_t *def; - def = calloc (1, sizeof (def_t)); + if (!free_defs) { + int i; + free_defs = malloc (16384 * sizeof (def_t)); + for (i = 0; i < 16383; i++) + free_defs[i].next = &free_defs[i + 1]; + } + def = free_defs; + free_defs = free_defs->next; + memset (def, 0, sizeof (*def)); if (name) { *pr.def_tail = def; @@ -258,7 +267,7 @@ PR_NewLocation (type_t *type) void PR_FreeLocation (def_t *def) { - int size = pr_type_size[def->type->type]; + int size = type_size (def->type->type); locref_t *loc; if (!free_free_locs) { @@ -279,7 +288,7 @@ PR_FreeLocation (def_t *def) def_t * PR_GetTempDef (type_t *type, def_t *scope) { - int size = pr_type_size[type->type]; + int size = type_size (type->type); def_t *def; if (free_temps[size]) { @@ -289,7 +298,7 @@ PR_GetTempDef (type_t *type, def_t *scope) } else { def = PR_NewDef (type, 0, scope); def->ofs = *scope->alloc; - *scope->alloc += pr_type_size[size]; + *scope->alloc += type_size (size); } def->freed = def->removed = def->users = 0; def->next = temp_scope.next; @@ -313,7 +322,7 @@ PR_FreeTempDefs (void) printf ("%s:%d: warning: %s %3d %3d %d\n", pr.strings + d->file, d->line, pr_type_name[d->type->type], d->ofs, d->users, d->managed); - size = pr_type_size[d->type->type]; + size = type_size (d->type->type); if (d->expr) d->expr->e.temp.def = 0; diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 4b4935472..e8cec53f7 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -129,8 +129,8 @@ WriteData (int crc) FILE *h; int i; - globals = calloc (pr.num_globals, sizeof (ddef_t)); //FIXME - fields = calloc (pr.num_globals, sizeof (ddef_t)); //FIXME + globals = calloc (pr.num_globals, sizeof (ddef_t)); + fields = calloc (pr.num_globals, sizeof (ddef_t)); for (def = pr.def_head; def; def = def->def_next) { if (def->scope)