diff options
author | Brian <brian@yutani.localnet.net> | 2007-04-21 12:08:56 -0600 |
---|---|---|
committer | Brian <brian@yutani.localnet.net> | 2007-04-21 12:30:58 -0600 |
commit | cd3e39340f057712fcf02a35dff85645e475053a (patch) | |
tree | a7c6e2d0d6be2ccaa882075539e38935b77b5522 /src | |
parent | ad3cc95485c488e3920f9c460b373338043000c5 (diff) |
Use new memory pool allocator. Lots of debug code still in place...
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 28 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile.c | 84 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_function.c | 25 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_operation.c | 27 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_struct.c | 29 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_variable.c | 36 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_emit.c | 9 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_ir.c | 6 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_label.c | 27 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_log.c | 12 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_mem.c | 117 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_mem.h | 10 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_storage.c | 29 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_typeinfo.c | 29 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_utility.c | 36 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_utility.h | 12 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_vartable.c | 24 |
17 files changed, 511 insertions, 29 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 6519040b662..71ef132e38b 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -48,6 +48,7 @@ #include "slang_codegen.h" #include "slang_compile.h" #include "slang_label.h" +#include "slang_mem.h" #include "slang_simplify.h" #include "slang_emit.h" #include "slang_vartable.h" @@ -459,7 +460,11 @@ static slang_ir_node * new_node3(slang_ir_opcode op, slang_ir_node *c0, slang_ir_node *c1, slang_ir_node *c2) { +#if USE_MEMPOOL + slang_ir_node *n = (slang_ir_node *) _slang_alloc(sizeof(slang_ir_node)); +#else slang_ir_node *n = (slang_ir_node *) calloc(1, sizeof(slang_ir_node)); +#endif if (n) { n->Opcode = op; n->Children[0] = c0; @@ -922,12 +927,21 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, assert(fun->param_count == totalArgs); /* allocate temporary arrays */ +#if USE_MEMPOOL + paramMode = (ParamMode *) + _slang_alloc(totalArgs * sizeof(ParamMode)); + substOld = (slang_variable **) + _slang_alloc(totalArgs * sizeof(slang_variable *)); + substNew = (slang_operation **) + _slang_alloc(totalArgs * sizeof(slang_operation *)); +#else paramMode = (ParamMode *) _mesa_calloc(totalArgs * sizeof(ParamMode)); substOld = (slang_variable **) _mesa_calloc(totalArgs * sizeof(slang_variable *)); substNew = (slang_operation **) _mesa_calloc(totalArgs * sizeof(slang_operation *)); +#endif #if 0 printf("Inline call to %s (total vars=%d nparams=%d)\n", @@ -1128,9 +1142,11 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, } } +#if !USE_MEMPOOL _mesa_free(paramMode); _mesa_free(substOld); _mesa_free(substNew); +#endif #if 0 printf("Done Inline call to %s (total vars=%d nparams=%d)\n", @@ -1188,7 +1204,9 @@ _slang_gen_function_call(slang_assemble_ctx *A, slang_function *fun, /* Replace the function call with the inlined block */ slang_operation_destruct(oper); *oper = *inlined; - /* XXX slang_operation_destruct(inlined) ??? */ +#if !USE_MEMPOOL + _mesa_free(inlined); +#endif #if 0 assert(inlined->locals); @@ -1318,7 +1336,9 @@ _slang_gen_asm(slang_assemble_ctx *A, slang_operation *oper, n->Store = n0->Store; n->Writemask = writemask; +#if !USE_MEMPOOL free(n0); +#endif } return n; @@ -1759,9 +1779,11 @@ _slang_gen_temporary(GLint size) if (n) { n->Store = store; } +#if !USE_MEMPOOL else { free(store); } +#endif } return n; } @@ -1871,9 +1893,11 @@ _slang_gen_logical_and(slang_assemble_ctx *A, slang_operation *oper) n = _slang_gen_select(A, select); +#if !USE_MEMPOOL /* xxx wrong */ free(select->children); free(select); +#endif return n; } @@ -1902,9 +1926,11 @@ _slang_gen_logical_or(slang_assemble_ctx *A, slang_operation *oper) n = _slang_gen_select(A, select); +#if !USE_MEMPOOL /* xxx wrong */ free(select->children); free(select); +#endif return n; } diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 7ea6cc064ed..d1c82a092d5 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -39,6 +39,7 @@ #include "slang_storage.h" #include "slang_emit.h" #include "slang_log.h" +#include "slang_mem.h" #include "slang_vartable.h" #include "slang_simplify.h" @@ -193,7 +194,11 @@ parse_float(slang_parse_ctx * C, float *number) parse_identifier_str(C, &fractional); parse_identifier_str(C, &exponent); +#if USE_MEMPOOL + whole = (char *) (_slang_alloc((_mesa_strlen(integral) + +#else whole = (char *) (slang_alloc_malloc((_mesa_strlen(integral) + +#endif _mesa_strlen(fractional) + _mesa_strlen(exponent) + 3) * sizeof(char))); if (whole == NULL) { @@ -209,7 +214,11 @@ parse_float(slang_parse_ctx * C, float *number) *number = (float) (_mesa_strtod(whole, (char **) NULL)); +#if USE_MEMPOOL + _slang_free(whole); +#else slang_alloc_free(whole); +#endif return 1; } @@ -288,7 +297,11 @@ convert_to_array(slang_parse_ctx * C, slang_variable * var, * parse the expression */ var->type.specifier.type = SLANG_SPEC_ARRAY; var->type.specifier._array = (slang_type_specifier *) +#if USE_MEMPOOL + _slang_alloc(sizeof(slang_type_specifier)); +#else slang_alloc_malloc(sizeof(slang_type_specifier)); +#endif if (var->type.specifier._array == NULL) { slang_info_log_memory(C->L); return GL_FALSE; @@ -371,13 +384,21 @@ parse_struct(slang_parse_ctx * C, slang_output_ctx * O, slang_struct ** st) } /* set-up a new struct */ +#if USE_MEMPOOL + *st = (slang_struct *) _slang_alloc(sizeof(slang_struct)); +#else *st = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct)); +#endif if (*st == NULL) { slang_info_log_memory(C->L); return 0; } if (!slang_struct_construct(*st)) { +#if USE_MEMPOOL + _slang_free(*st); +#else slang_alloc_free(*st); +#endif *st = NULL; slang_info_log_memory(C->L); return 0; @@ -403,7 +424,11 @@ parse_struct(slang_parse_ctx * C, slang_output_ctx * O, slang_struct ** st) slang_struct *s; O->structs->structs = +#if USE_MEMPOOL + (slang_struct *) _slang_realloc(O->structs->structs, +#else (slang_struct *) slang_alloc_realloc(O->structs->structs, +#endif O->structs->num_structs * sizeof(slang_struct), (O->structs->num_structs + @@ -617,13 +642,21 @@ parse_type_specifier(slang_parse_ctx * C, slang_output_ctx * O, } spec->_struct = +#if USE_MEMPOOL + (slang_struct *) _slang_alloc(sizeof(slang_struct)); +#else (slang_struct *) slang_alloc_malloc(sizeof(slang_struct)); +#endif if (spec->_struct == NULL) { slang_info_log_memory(C->L); return 0; } if (!slang_struct_construct(spec->_struct)) { +#if USE_MEMPOOL + _slang_free(spec->_struct); +#else slang_alloc_free(spec->_struct); +#endif spec->_struct = NULL; return 0; } @@ -905,7 +938,11 @@ handle_nary_expression(slang_parse_ctx * C, slang_operation * op, *total_ops -= n; *ops = (slang_operation *) +#if USE_MEMPOOL + _slang_realloc(*ops, +#else slang_alloc_realloc(*ops, +#endif (*total_ops + n) * sizeof(slang_operation), *total_ops * sizeof(slang_operation)); if (*ops == NULL) { @@ -938,7 +975,11 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, /* allocate default operation, becomes a no-op if not used */ ops = (slang_operation *) +#if USE_MEMPOOL + _slang_realloc(ops, +#else slang_alloc_realloc(ops, +#endif num_ops * sizeof(slang_operation), (num_ops + 1) * sizeof(slang_operation)); if (ops == NULL) { @@ -1182,7 +1223,11 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, slang_operation_destruct(oper); *oper = *ops; /* struct copy */ +#if USE_MEMPOOL + _slang_free(ops); +#else slang_alloc_free(ops); +#endif return 1; } @@ -1447,13 +1492,21 @@ parse_function_definition(slang_parse_ctx * C, slang_output_ctx * O, /* create function's body operation */ func->body = +#if USE_MEMPOOL + (slang_operation *) _slang_alloc(sizeof(slang_operation)); +#else (slang_operation *) slang_alloc_malloc(sizeof(slang_operation)); +#endif if (func->body == NULL) { slang_info_log_memory(C->L); return 0; } if (!slang_operation_construct(func->body)) { +#if USE_MEMPOOL + _slang_free(func->body); +#else slang_alloc_free(func->body); +#endif func->body = NULL; slang_info_log_memory(C->L); return 0; @@ -1485,7 +1538,11 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var) /* put the variable into operation's scope */ op_id.locals->variables = +#if USE_MEMPOOL + (slang_variable **) _slang_alloc(sizeof(slang_variable *)); +#else (slang_variable **) slang_alloc_malloc(sizeof(slang_variable *)); +#endif if (op_id.locals->variables == NULL) { slang_operation_destruct(&op_id); return GL_FALSE; @@ -1501,7 +1558,11 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var) } op_assign.type = SLANG_OPER_ASSIGN; op_assign.children = +#if USE_MEMPOOL + (slang_operation *) _slang_alloc(2 * sizeof(slang_operation)); +#else (slang_operation *) slang_alloc_malloc(2 * sizeof(slang_operation)); +#endif if (op_assign.children == NULL) { slang_operation_destruct(&op_assign); op_id.locals->num_variables = 0; @@ -1516,7 +1577,11 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var) /* carefully destroy the operations */ op_assign.num_children = 0; +#if USE_MEMPOOL + _slang_free(op_assign.children); +#else slang_alloc_free(op_assign.children); +#endif op_assign.children = NULL; slang_operation_destruct(&op_assign); op_id.locals->num_variables = 0; @@ -1577,13 +1642,21 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, if (!slang_type_specifier_copy(&var->type.specifier, &type->specifier)) return 0; var->initializer = +#if USE_MEMPOOL + (slang_operation *) _slang_alloc(sizeof(slang_operation)); +#else (slang_operation *) slang_alloc_malloc(sizeof(slang_operation)); +#endif if (var->initializer == NULL) { slang_info_log_memory(C->L); return 0; } if (!slang_operation_construct(var->initializer)) { +#if USE_MEMPOOL + _slang_free(var->initializer); +#else slang_alloc_free(var->initializer); +#endif var->initializer = NULL; slang_info_log_memory(C->L); return 0; @@ -1715,7 +1788,11 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition, if (found_func == NULL) { /* New function, add it to the function list */ O->funs->functions = +#if USE_MEMPOOL + (slang_function *) _slang_realloc(O->funs->functions, +#else (slang_function *) slang_alloc_realloc(O->funs->functions, +#endif O->funs->num_functions * sizeof(slang_function), (O->funs->num_functions + @@ -1862,6 +1939,8 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, C->I++; _slang_pop_var_table(o.vartable); + _slang_delete_var_table(o.vartable); + return GL_TRUE; } @@ -2121,6 +2200,8 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader) type = SLANG_UNIT_FRAGMENT_SHADER; } + ctx->Shader.MemPool = _slang_new_mempool(1024*1024); + /* XXX temporary hack */ if (!shader->Programs) { GLenum progTarget; @@ -2161,6 +2242,9 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader) slang_info_log_destruct(&info_log); _slang_code_object_dtr(&obj); + _slang_delete_mempool((slang_mempool *) ctx->Shader.MemPool); + ctx->Shader.MemPool = NULL; + return success; } diff --git a/src/mesa/shader/slang/slang_compile_function.c b/src/mesa/shader/slang/slang_compile_function.c index 2f74050b865..bb5be3feecd 100644 --- a/src/mesa/shader/slang/slang_compile_function.c +++ b/src/mesa/shader/slang/slang_compile_function.c @@ -30,6 +30,7 @@ #include "imports.h" #include "slang_compile.h" +#include "slang_mem.h" /* slang_fixup_table */ @@ -43,7 +44,11 @@ slang_fixup_table_init(slang_fixup_table * fix) void slang_fixup_table_free(slang_fixup_table * fix) { +#if USE_MEMPOOL + _slang_free(fix->table); +#else slang_alloc_free(fix->table); +#endif slang_fixup_table_init(fix); } @@ -54,7 +59,11 @@ GLboolean slang_fixup_save(slang_fixup_table *fixups, GLuint address) { fixups->table = (GLuint *) +#if USE_MEMPOOL + _slang_realloc(fixups->table, +#else slang_alloc_realloc(fixups->table, +#endif fixups->count * sizeof(GLuint), (fixups->count + 1) * sizeof(GLuint)); if (fixups->table == NULL) @@ -76,7 +85,11 @@ slang_function_construct(slang_function * func) return 0; func->parameters = (slang_variable_scope *) +#if USE_MEMPOOL + _slang_alloc(sizeof(slang_variable_scope)); +#else slang_alloc_malloc(sizeof(slang_variable_scope)); +#endif if (func->parameters == NULL) { slang_variable_destruct(&func->header); return 0; @@ -95,10 +108,18 @@ slang_function_destruct(slang_function * func) { slang_variable_destruct(&func->header); slang_variable_scope_destruct(func->parameters); +#if USE_MEMPOOL + _slang_free(func->parameters); +#else slang_alloc_free(func->parameters); +#endif if (func->body != NULL) { slang_operation_destruct(func->body); +#if USE_MEMPOOL + _slang_free(func->body); +#else slang_alloc_free(func->body); +#endif } slang_fixup_table_free(&func->fixups); } @@ -122,7 +143,11 @@ slang_function_scope_destruct(slang_function_scope * scope) for (i = 0; i < scope->num_functions; i++) slang_function_destruct(scope->functions + i); +#if USE_MEMPOOL + _slang_free(scope->functions); +#else slang_alloc_free(scope->functions); +#endif } diff --git a/src/mesa/shader/slang/slang_compile_operation.c b/src/mesa/shader/slang/slang_compile_operation.c index dfba1965ce6..c19a1b101bf 100644 --- a/src/mesa/shader/slang/slang_compile_operation.c +++ b/src/mesa/shader/slang/slang_compile_operation.c @@ -30,6 +30,7 @@ #include "imports.h" #include "slang_compile.h" +#include "slang_mem.h" /** @@ -60,9 +61,11 @@ slang_operation_destruct(slang_operation * oper) for (i = 0; i < oper->num_children; i++) slang_operation_destruct(oper->children + i); +#if !USE_MEMPOOL slang_alloc_free(oper->children); slang_variable_scope_destruct(oper->locals); slang_alloc_free(oper->locals); +#endif oper->children = NULL; oper->num_children = 0; oper->locals = NULL; @@ -82,7 +85,11 @@ slang_operation_copy(slang_operation * x, const slang_operation * y) return GL_FALSE; z.type = y->type; z.children = (slang_operation *) +#if USE_MEMPOOL + _slang_alloc(y->num_children * sizeof(slang_operation)); +#else slang_alloc_malloc(y->num_children * sizeof(slang_operation)); +#endif if (z.children == NULL) { slang_operation_destruct(&z); return GL_FALSE; @@ -128,7 +135,11 @@ slang_operation * slang_operation_new(GLuint count) { slang_operation *ops +#if USE_MEMPOOL + = (slang_operation *) _slang_alloc(count * sizeof(slang_operation)); +#else = (slang_operation *) _mesa_malloc(count * sizeof(slang_operation)); +#endif assert(count > 0); if (ops) { GLuint i; @@ -146,7 +157,9 @@ void slang_operation_delete(slang_operation *oper) { slang_operation_destruct(oper); +#if !USE_MEMPOOL _mesa_free(oper); +#endif } @@ -156,13 +169,19 @@ slang_operation_grow(GLuint *numChildren, slang_operation **children) slang_operation *ops; ops = (slang_operation *) +#if USE_MEMPOOL + _slang_realloc(*children, +#else slang_alloc_realloc(*children, +#endif *numChildren * sizeof(slang_operation), (*numChildren + 1) * sizeof(slang_operation)); if (ops) { slang_operation *newOp = ops + *numChildren; if (!slang_operation_construct(newOp)) { +#if !USE_MEMPOOL _mesa_free(ops); +#endif *children = NULL; return NULL; } @@ -189,7 +208,11 @@ slang_operation_insert(GLuint *numElements, slang_operation **array, assert(pos <= *numElements); ops = (slang_operation *) +#if USE_MEMPOOL + _slang_alloc((*numElements + 1) * sizeof(slang_operation)); +#else _mesa_malloc((*numElements + 1) * sizeof(slang_operation)); +#endif if (ops) { slang_operation *newOp; newOp = ops + pos; @@ -200,13 +223,17 @@ slang_operation_insert(GLuint *numElements, slang_operation **array, (*numElements - pos) * sizeof(slang_operation)); if (!slang_operation_construct(newOp)) { +#if !USE_MEMPOOL _mesa_free(ops); +#endif *numElements = 0; *array = NULL; return NULL; } +#if !USE_MEMPOOL if (*array) _mesa_free(*array); +#endif *array = ops; (*numElements)++; return newOp; diff --git a/src/mesa/shader/slang/slang_compile_struct.c b/src/mesa/shader/slang/slang_compile_struct.c index 89c79d431be..4a4773217a8 100644 --- a/src/mesa/shader/slang/slang_compile_struct.c +++ b/src/mesa/shader/slang/slang_compile_struct.c @@ -29,6 +29,7 @@ */ #include "imports.h" +#include "slang_mem.h" #include "slang_compile.h" @@ -47,7 +48,11 @@ slang_struct_scope_destruct(slang_struct_scope * scope) for (i = 0; i < scope->num_structs; i++) slang_struct_destruct(scope->structs + i); +#if USE_MEMPOOL + _slang_free(scope->structs); +#else slang_alloc_free(scope->structs); +#endif /* do not free scope->outer_scope */ } @@ -59,7 +64,11 @@ slang_struct_scope_copy(slang_struct_scope * x, const slang_struct_scope * y) _slang_struct_scope_ctr(&z); z.structs = +#if USE_MEMPOOL + (slang_struct *) _slang_alloc(y->num_structs * +#else (slang_struct *) slang_alloc_malloc(y->num_structs * +#endif sizeof(slang_struct)); if (z.structs == NULL) { slang_struct_scope_destruct(&z); @@ -102,16 +111,28 @@ slang_struct_construct(slang_struct * stru) { stru->a_name = SLANG_ATOM_NULL; stru->fields = (slang_variable_scope *) +#if USE_MEMPOOL + _slang_alloc(sizeof(slang_variable_scope)); +#else slang_alloc_malloc(sizeof(slang_variable_scope)); +#endif if (stru->fields == NULL) return 0; _slang_variable_scope_ctr(stru->fields); stru->structs = +#if USE_MEMPOOL + (slang_struct_scope *) _slang_alloc(sizeof(slang_struct_scope)); +#else (slang_struct_scope *) slang_alloc_malloc(sizeof(slang_struct_scope)); +#endif if (stru->structs == NULL) { slang_variable_scope_destruct(stru->fields); +#if USE_MEMPOOL + _slang_free(stru->fields); +#else slang_alloc_free(stru->fields); +#endif return 0; } _slang_struct_scope_ctr(stru->structs); @@ -122,9 +143,17 @@ void slang_struct_destruct(slang_struct * stru) { slang_variable_scope_destruct(stru->fields); +#if USE_MEMPOOL + _slang_free(stru->fields); +#else slang_alloc_free(stru->fields); +#endif slang_struct_scope_destruct(stru->structs); +#if USE_MEMPOOL + _slang_free(stru->structs); +#else slang_alloc_free(stru->structs); +#endif } int diff --git a/src/mesa/shader/slang/slang_compile_variable.c b/src/mesa/shader/slang/slang_compile_variable.c index 6632da9f8f3..aedf3d46632 100644 --- a/src/mesa/shader/slang/slang_compile_variable.c +++ b/src/mesa/shader/slang/slang_compile_variable.c @@ -30,8 +30,8 @@ #include "imports.h" #include "slang_compile.h" +#include "slang_mem.h" -/* slang_type_specifier_type */ typedef struct { @@ -135,10 +135,16 @@ slang_fully_specified_type_copy(slang_fully_specified_type * x, static slang_variable * slang_variable_new(void) { +#if USE_MEMPOOL + slang_variable *v = (slang_variable *) _slang_alloc(sizeof(slang_variable)); +#else slang_variable *v = (slang_variable *) malloc(sizeof(slang_variable)); +#endif if (v) { if (!slang_variable_construct(v)) { +#if !USE_MEMPOOL free(v); +#endif v = NULL; } } @@ -150,7 +156,9 @@ static void slang_variable_delete(slang_variable * var) { slang_variable_destruct(var); +#if !USE_MEMPOOL free(var); +#endif } @@ -162,7 +170,11 @@ slang_variable_scope * _slang_variable_scope_new(slang_variable_scope *parent) { slang_variable_scope *s; +#if USE_MEMPOOL + s = (slang_variable_scope *) _slang_alloc(sizeof(slang_variable_scope)); +#else s = (slang_variable_scope *) _mesa_calloc(sizeof(slang_variable_scope)); +#endif s->outer_scope = parent; return s; } @@ -187,7 +199,11 @@ slang_variable_scope_destruct(slang_variable_scope * scope) if (scope->variables[i]) slang_variable_delete(scope->variables[i]); } +#if USE_MEMPOOL + _slang_free(scope->variables); +#else slang_alloc_free(scope->variables); +#endif /* do not free scope->outer_scope */ } @@ -200,7 +216,11 @@ slang_variable_scope_copy(slang_variable_scope * x, _slang_variable_scope_ctr(&z); z.variables = (slang_variable **) +#if USE_MEMPOOL + _slang_alloc(y->num_variables * sizeof(slang_variable *)); +#else _mesa_calloc(y->num_variables * sizeof(slang_variable *)); +#endif if (z.variables == NULL) { slang_variable_scope_destruct(&z); return 0; @@ -235,7 +255,11 @@ slang_variable_scope_grow(slang_variable_scope *scope) { const int n = scope->num_variables; scope->variables = (slang_variable **) +#if USE_MEMPOOL + _slang_realloc(scope->variables, +#else slang_alloc_realloc(scope->variables, +#endif n * sizeof(slang_variable *), (n + 1) * sizeof(slang_variable *)); if (!scope->variables) @@ -276,7 +300,11 @@ slang_variable_destruct(slang_variable * var) slang_fully_specified_type_destruct(&var->type); if (var->initializer != NULL) { slang_operation_destruct(var->initializer); +#if USE_MEMPOOL + _slang_free(var->initializer); +#else slang_alloc_free(var->initializer); +#endif } #if 0 if (var->aux) { @@ -301,13 +329,19 @@ slang_variable_copy(slang_variable * x, const slang_variable * y) z.array_len = y->array_len; if (y->initializer != NULL) { z.initializer +#if USE_MEMPOOL + = (slang_operation *) _slang_alloc(sizeof(slang_operation)); +#else = (slang_operation *) slang_alloc_malloc(sizeof(slang_operation)); +#endif if (z.initializer == NULL) { slang_variable_destruct(&z); return 0; } if (!slang_operation_construct(z.initializer)) { +#if !USE_MEMPOOL slang_alloc_free(z.initializer); +#endif slang_variable_destruct(&z); return 0; } diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index badeb69b3fe..c6683720191 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -45,6 +45,7 @@ #include "prog_print.h" #include "slang_builtin.h" #include "slang_emit.h" +#include "slang_mem.h" #define PEEPHOLE_OPTIMIZATIONS 1 @@ -126,7 +127,11 @@ slang_ir_storage * _slang_new_ir_storage(enum register_file file, GLint index, GLint size) { slang_ir_storage *st; +#if USE_MEMPOOL + st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage)); +#else st = (slang_ir_storage *) _mesa_calloc(sizeof(slang_ir_storage)); +#endif if (st) { st->File = file; st->Index = index; @@ -151,7 +156,11 @@ alloc_temp_storage(slang_emit_info *emitInfo, slang_ir_node *n, GLint size) if (!_slang_alloc_temp(emitInfo->vt, n->Store)) { slang_info_log_error(emitInfo->log, "Ran out of registers, too many temporaries"); +#if USE_MEMPOOL + _slang_free(n->Store); +#else _mesa_free(n->Store); +#endif n->Store = NULL; return GL_FALSE; } diff --git a/src/mesa/shader/slang/slang_ir.c b/src/mesa/shader/slang/slang_ir.c index 0c2e65ab5e3..b99866761f3 100644 --- a/src/mesa/shader/slang/slang_ir.c +++ b/src/mesa/shader/slang/slang_ir.c @@ -143,7 +143,7 @@ _slang_free_ir(slang_ir_node *n) if (n->Store) { n->Store->RefCount--; if (n->Store->RefCount == 0) { -#if 0 +#if !USE_MEMPOOL free(n->Store); #endif n->Store = NULL; @@ -153,7 +153,9 @@ _slang_free_ir(slang_ir_node *n) for (i = 0; i < 3; i++) _slang_free_ir(n->Children[i]); /* Do not free n->List since it's a child elsewhere */ +#if !USE_MEMPOOL free(n); +#endif } @@ -163,8 +165,10 @@ _slang_free_ir(slang_ir_node *n) void _slang_free_ir_tree(slang_ir_node *n) { +#if 0 _slang_refcount_storage(n); _slang_free_ir(n); +#endif } diff --git a/src/mesa/shader/slang/slang_label.c b/src/mesa/shader/slang/slang_label.c index e6a03f9e4f0..a4529be74fb 100644 --- a/src/mesa/shader/slang/slang_label.c +++ b/src/mesa/shader/slang/slang_label.c @@ -8,14 +8,24 @@ #include "slang_label.h" +#include "slang_mem.h" + slang_label * _slang_label_new(const char *name) { +#if !USE_MEMPOOL slang_label *l = (slang_label *) _mesa_calloc(sizeof(slang_label)); +#else + slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label)); +#endif if (l) { +#if !USE_MEMPOOL l->Name = _mesa_strdup(name); +#else + l->Name = _slang_strdup(name); +#endif l->Location = -1; } return l; @@ -28,9 +38,17 @@ slang_label * _slang_label_new_unique(const char *name) { static int id = 1; +#if !USE_MEMPOOL slang_label *l = (slang_label *) _mesa_calloc(sizeof(slang_label)); +#else + slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label)); +#endif if (l) { +#if !USE_MEMPOOL l->Name = (char *) _mesa_malloc(_mesa_strlen(name) + 10); +#else + l->Name = (char *) _slang_alloc(_mesa_strlen(name) + 10); +#endif if (!l->Name) { _mesa_free(l); return NULL; @@ -45,11 +63,13 @@ _slang_label_new_unique(const char *name) void _slang_label_delete(slang_label *l) { +#if !USE_MEMPOOL if (l->Name) _mesa_free(l->Name); if (l->References) _mesa_free(l->References); _mesa_free(l); +#endif } @@ -58,8 +78,13 @@ _slang_label_add_reference(slang_label *l, GLuint inst) { const GLuint oldSize = l->NumReferences * sizeof(GLuint); assert(l->Location < 0); +#if !USE_MEMPOOL l->References = _mesa_realloc(l->References, oldSize, oldSize + sizeof(GLuint)); +#else + l->References = _slang_realloc(l->References, + oldSize, oldSize + sizeof(GLuint)); +#endif if (l->References) { l->References[l->NumReferences] = inst; l->NumReferences++; @@ -92,7 +117,9 @@ _slang_label_set_location(slang_label *l, GLint location, } if (l->References) { +#if !USE_MEMPOOL _mesa_free(l->References); +#endif l->References = NULL; } } diff --git a/src/mesa/shader/slang/slang_log.c b/src/mesa/shader/slang/slang_log.c index e8387444914..e9234bafec7 100644 --- a/src/mesa/shader/slang/slang_log.c +++ b/src/mesa/shader/slang/slang_log.c @@ -42,7 +42,11 @@ void slang_info_log_destruct(slang_info_log * log) { if (!log->dont_free_text) +#if 0 slang_alloc_free(log->text); +#else + _mesa_free(log->text); +#endif } static int @@ -59,10 +63,18 @@ slang_info_log_message(slang_info_log * log, const char *prefix, if (log->text != NULL) { GLuint old_len = slang_string_length(log->text); log->text = (char *) +#if 0 slang_alloc_realloc(log->text, old_len + 1, old_len + size); +#else + _mesa_realloc(log->text, old_len + 1, old_len + size); +#endif } else { +#if 0 log->text = (char *) (slang_alloc_malloc(size)); +#else + log->text = (char *) (_mesa_malloc(size)); +#endif if (log->text != NULL) log->text[0] = '\0'; } diff --git a/src/mesa/shader/slang/slang_mem.c b/src/mesa/shader/slang/slang_mem.c index c7be9a7dc1a..e1d1e6ba14e 100644 --- a/src/mesa/shader/slang/slang_mem.c +++ b/src/mesa/shader/slang/slang_mem.c @@ -33,18 +33,33 @@ */ #include "context.h" +#include "macros.h" #include "slang_mem.h" + #define GRANULARITY 8 #define ROUND_UP(B) ( ((B) + (GRANULARITY - 1)) & ~(GRANULARITY - 1) ) +/** If 1, use conventional malloc/free. Helpful for debugging */ +#define USE_MALLOC_FREE 0 + + +struct slang_mempool_ +{ + GLuint Size, Used, Count, Largest; + char *Data; + struct slang_mempool_ *Next; +}; + + slang_mempool * _slang_new_mempool(GLuint initialSize) { slang_mempool *pool = (slang_mempool *) _mesa_calloc(sizeof(slang_mempool)); if (pool) { pool->Data = (char *) _mesa_calloc(initialSize); + /*printf("ALLOC MEMPOOL %d at %p\n", initialSize, pool->Data);*/ if (!pool->Data) { _mesa_free(pool); return NULL; @@ -62,13 +77,45 @@ _slang_delete_mempool(slang_mempool *pool) GLuint total = 0; while (pool) { slang_mempool *next = pool->Next; + /* + printf("DELETE MEMPOOL %u / %u count=%u largest=%u\n", + pool->Used, pool->Size, pool->Count, pool->Largest); + */ total += pool->Used; _mesa_free(pool->Data); _mesa_free(pool); pool = next; } - printf("TOTAL USED %u\n", total); + /*printf("TOTAL ALLOCATED: %u\n", total);*/ +} + + +#ifdef DEBUG +static void +check_zero(const char *addr, GLuint n) +{ + GLuint i; + for (i = 0; i < n; i++) { + assert(addr[i]==0); + } +} +#endif + + +#ifdef DEBUG +static GLboolean +is_valid_address(const slang_mempool *pool, void *addr) +{ + while (pool) { + if ((char *) addr >= pool->Data && + (char *) addr < pool->Data + pool->Used) + return GL_TRUE; + + pool = pool->Next; + } + return GL_FALSE; } +#endif /** @@ -77,16 +124,26 @@ _slang_delete_mempool(slang_mempool *pool) void * _slang_alloc(GLuint bytes) { +#if USE_MALLOC_FREE + return _mesa_calloc(bytes); +#else slang_mempool *pool; GET_CURRENT_CONTEXT(ctx); - pool = (slang_mempool *) ctx->Shader.MemPool; + if (bytes == 0) + bytes = 1; + while (pool) { if (pool->Used + bytes <= pool->Size) { /* found room */ void *addr = (void *) (pool->Data + pool->Used); +#ifdef DEBUG + check_zero((char*) addr, bytes); +#endif pool->Used += ROUND_UP(bytes); + pool->Largest = MAX2(pool->Largest, bytes); + pool->Count++; /*printf("alloc %u Used %u\n", bytes, pool->Used);*/ return addr; } @@ -96,30 +153,54 @@ _slang_alloc(GLuint bytes) } else { /* alloc new pool */ - assert(bytes <= pool->Size); /* XXX or max2() */ - pool->Next = _slang_new_mempool(pool->Size); + const GLuint sz = MAX2(bytes, pool->Size); + pool->Next = _slang_new_mempool(sz); if (!pool->Next) { /* we're _really_ out of memory */ return NULL; } else { + pool = pool->Next; + pool->Largest = bytes; + pool->Count++; pool->Used = ROUND_UP(bytes); +#ifdef DEBUG + check_zero((char*) pool->Data, bytes); +#endif return (void *) pool->Data; } } } return NULL; +#endif } void * _slang_realloc(void *oldBuffer, GLuint oldSize, GLuint newSize) { - const GLuint copySize = (oldSize < newSize) ? oldSize : newSize; - void *newBuffer = _slang_alloc(newSize); - if (newBuffer && oldBuffer && copySize > 0) - _mesa_memcpy(newBuffer, oldBuffer, copySize); - return newBuffer; +#if USE_MALLOC_FREE + return _mesa_realloc(oldBuffer, oldSize, newSize); +#else + GET_CURRENT_CONTEXT(ctx); + slang_mempool *pool = (slang_mempool *) ctx->Shader.MemPool; + + if (newSize < oldSize) { + return oldBuffer; + } + else { + const GLuint copySize = (oldSize < newSize) ? oldSize : newSize; + void *newBuffer = _slang_alloc(newSize); + + if (oldBuffer) + ASSERT(is_valid_address(pool, oldBuffer)); + + if (newBuffer && oldBuffer && copySize > 0) + _mesa_memcpy(newBuffer, oldBuffer, copySize); + + return newBuffer; + } +#endif } @@ -140,3 +221,21 @@ _slang_strdup(const char *s) return NULL; } } + + +/** + * Don't actually free memory, but mark it (for debugging). + */ +void +_slang_free(void *addr) +{ +#if USE_MALLOC_FREE + _mesa_free(addr); +#else + if (addr) { + GET_CURRENT_CONTEXT(ctx); + slang_mempool *pool = (slang_mempool *) ctx->Shader.MemPool; + ASSERT(is_valid_address(pool, addr)); + } +#endif +} diff --git a/src/mesa/shader/slang/slang_mem.h b/src/mesa/shader/slang/slang_mem.h index f44892666bf..a91c2b8791f 100644 --- a/src/mesa/shader/slang/slang_mem.h +++ b/src/mesa/shader/slang/slang_mem.h @@ -30,12 +30,7 @@ #include "imports.h" -typedef struct slang_mempool_ -{ - GLuint Size, Used; - char *Data; - struct slang_mempool_ *Next; -} slang_mempool; +typedef struct slang_mempool_ slang_mempool; extern slang_mempool * @@ -53,6 +48,9 @@ _slang_realloc(void *oldBuffer, GLuint oldSize, GLuint newSize); extern char * _slang_strdup(const char *s); +extern void +_slang_free(void *addr); + #define USE_MEMPOOL 1 /* XXX temporary */ diff --git a/src/mesa/shader/slang/slang_storage.c b/src/mesa/shader/slang/slang_storage.c index ecd60481b6b..e7fb63c289a 100644 --- a/src/mesa/shader/slang/slang_storage.c +++ b/src/mesa/shader/slang/slang_storage.c @@ -30,6 +30,7 @@ #include "imports.h" #include "slang_storage.h" +#include "slang_mem.h" /* slang_storage_array */ @@ -47,7 +48,11 @@ slang_storage_array_destruct(slang_storage_array * arr) { if (arr->aggregate != NULL) { slang_storage_aggregate_destruct(arr->aggregate); +#if USE_MEMPOOL + _slang_free(arr->aggregate); +#else slang_alloc_free(arr->aggregate); +#endif } } @@ -68,7 +73,11 @@ slang_storage_aggregate_destruct(slang_storage_aggregate * agg) for (i = 0; i < agg->count; i++) slang_storage_array_destruct(agg->arrays + i); +#if USE_MEMPOOL + _slang_free(agg->arrays); +#else slang_alloc_free(agg->arrays); +#endif } static slang_storage_array * @@ -77,7 +86,11 @@ slang_storage_aggregate_push_new(slang_storage_aggregate * agg) slang_storage_array *arr = NULL; agg->arrays = (slang_storage_array *) +#if USE_MEMPOOL + _slang_realloc(agg->arrays, +#else slang_alloc_realloc(agg->arrays, +#endif agg->count * sizeof(slang_storage_array), (agg->count + 1) * sizeof(slang_storage_array)); if (agg->arrays != NULL) { @@ -114,11 +127,19 @@ aggregate_matrix(slang_storage_aggregate * agg, slang_storage_type basic_type, arr->length = columns; arr->aggregate = (slang_storage_aggregate *) +#if USE_MEMPOOL + _slang_alloc(sizeof(slang_storage_aggregate)); +#else slang_alloc_malloc(sizeof(slang_storage_aggregate)); +#endif if (arr->aggregate == NULL) return GL_FALSE; if (!slang_storage_aggregate_construct(arr->aggregate)) { +#if USE_MEMPOOL + _slang_free(arr->aggregate); +#else slang_alloc_free(arr->aggregate); +#endif arr->aggregate = NULL; return GL_FALSE; } @@ -221,11 +242,19 @@ _slang_aggregate_variable(slang_storage_aggregate * agg, arr->type = SLANG_STORE_AGGREGATE; arr->aggregate = (slang_storage_aggregate *) +#if USE_MEMPOOL + _slang_alloc(sizeof(slang_storage_aggregate)); +#else slang_alloc_malloc(sizeof(slang_storage_aggregate)); +#endif if (arr->aggregate == NULL) return GL_FALSE; if (!slang_storage_aggregate_construct(arr->aggregate)) { +#if USE_MEMPOOL + _slang_free(arr->aggregate); +#else slang_alloc_free(arr->aggregate); +#endif arr->aggregate = NULL; return GL_FALSE; } diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c index 957c302c5b3..c688423d8d2 100644 --- a/src/mesa/shader/slang/slang_typeinfo.c +++ b/src/mesa/shader/slang/slang_typeinfo.c @@ -32,6 +32,7 @@ #include "slang_typeinfo.h" #include "slang_compile.h" #include "slang_log.h" +#include "slang_mem.h" #include "prog_instruction.h" @@ -178,11 +179,19 @@ slang_type_specifier_dtr(slang_type_specifier * self) { if (self->_struct != NULL) { slang_struct_destruct(self->_struct); +#if USE_MEMPOOL + _slang_free(self->_struct); +#else slang_alloc_free(self->_struct); +#endif } if (self->_array != NULL) { slang_type_specifier_dtr(self->_array); +#if USE_MEMPOOL + _slang_free(self->_array); +#else slang_alloc_free(self->_array); +#endif } } @@ -195,13 +204,21 @@ slang_type_specifier_copy(slang_type_specifier * x, slang_type_specifier_ctr(&z); z.type = y->type; if (z.type == SLANG_SPEC_STRUCT) { +#if USE_MEMPOOL + z._struct = (slang_struct *) _slang_alloc(sizeof(slang_struct)); +#else z._struct = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct)); +#endif if (z._struct == NULL) { slang_type_specifier_dtr(&z); return GL_FALSE; } if (!slang_struct_construct(z._struct)) { +#if USE_MEMPOOL + _slang_free(z._struct); +#else slang_alloc_free(z._struct); +#endif slang_type_specifier_dtr(&z); return GL_FALSE; } @@ -213,7 +230,11 @@ slang_type_specifier_copy(slang_type_specifier * x, else if (z.type == SLANG_SPEC_ARRAY) { z._array = (slang_type_specifier *) +#if USE_MEMPOOL + _slang_alloc(sizeof(slang_type_specifier)); +#else slang_alloc_malloc(sizeof(slang_type_specifier)); +#endif if (z._array == NULL) { slang_type_specifier_dtr(&z); return GL_FALSE; @@ -596,11 +617,19 @@ _slang_typeof_operation_(slang_operation * op, /* struct initializer */ ti->spec.type = SLANG_SPEC_STRUCT; ti->spec._struct = +#if USE_MEMPOOL + (slang_struct *) _slang_alloc(sizeof(slang_struct)); +#else (slang_struct *) slang_alloc_malloc(sizeof(slang_struct)); +#endif if (ti->spec._struct == NULL) return GL_FALSE; if (!slang_struct_construct(ti->spec._struct)) { +#if USE_MEMPOOL + _slang_free(ti->spec._struct); +#else slang_alloc_free(ti->spec._struct); +#endif ti->spec._struct = NULL; return GL_FALSE; } diff --git a/src/mesa/shader/slang/slang_utility.c b/src/mesa/shader/slang/slang_utility.c index 0fbfcc5840a..786b8990dfe 100644 --- a/src/mesa/shader/slang/slang_utility.c +++ b/src/mesa/shader/slang/slang_utility.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.6 + * Version: 6.5.3 * - * Copyright (C) 2005-2006 Brian Paul All Rights Reserved. + * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -30,6 +30,7 @@ #include "imports.h" #include "slang_utility.h" +#include "slang_mem.h" char * slang_string_concat (char *dst, const char *src) @@ -155,8 +156,13 @@ slang_atom_pool_destruct (slang_atom_pool * pool) slang_atom_entry *next; next = entry->next; +#if USE_MEMPOOL + _slang_free(entry->id); + _slang_free(entry); +#else slang_alloc_free(entry->id); slang_alloc_free(entry); +#endif entry = next; } } @@ -165,7 +171,8 @@ slang_atom_pool_destruct (slang_atom_pool * pool) /* * Search the atom pool for an atom with a given name. * If atom is not found, create and add it to the pool. - * Returns ATOM_NULL if the atom was not found and the function failed to create a new atom. + * Returns ATOM_NULL if the atom was not found and the function failed + * to create a new atom. */ slang_atom slang_atom_pool_atom(slang_atom_pool * pool, const char * id) @@ -187,8 +194,10 @@ slang_atom_pool_atom(slang_atom_pool * pool, const char * id) } hash %= SLANG_ATOM_POOL_SIZE; - /* Now the hash points to a linked list of atoms with names that have the same hash value. - * Search the linked list for a given name. */ + /* Now the hash points to a linked list of atoms with names that + * have the same hash value. Search the linked list for a given + * name. + */ entry = &pool->entries[hash]; while (*entry != NULL) { /* If the same, return the associated atom. */ @@ -199,15 +208,26 @@ slang_atom_pool_atom(slang_atom_pool * pool, const char * id) } /* Okay, we have not found an atom. Create a new entry for it. - * Note that the <entry> points to the last entry's <next> field. */ + * Note that the <entry> points to the last entry's <next> field. + */ +#if USE_MEMPOOL + *entry = (slang_atom_entry *) (_slang_alloc(sizeof(slang_atom_entry))); +#else *entry = (slang_atom_entry *) (slang_alloc_malloc(sizeof(slang_atom_entry))); +#endif if (*entry == NULL) return SLANG_ATOM_NULL; - /* Initialize a new entry. Because we'll need the actual name of the atom, we use the pointer - * to this string as an actual atom's value. */ + /* Initialize a new entry. Because we'll need the actual name of + * the atom, we use the pointer to this string as an actual atom's + * value. + */ (**entry).next = NULL; +#if USE_MEMPOOL + (**entry).id = _slang_strdup(id); +#else (**entry).id = slang_string_duplicate(id); +#endif if ((**entry).id == NULL) return SLANG_ATOM_NULL; return (slang_atom) (**entry).id; diff --git a/src/mesa/shader/slang/slang_utility.h b/src/mesa/shader/slang/slang_utility.h index 360241916f8..98a4cd59912 100644 --- a/src/mesa/shader/slang/slang_utility.h +++ b/src/mesa/shader/slang/slang_utility.h @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.6 + * Version: 6.5.3 * - * Copyright (C) 2005-2006 Brian Paul All Rights Reserved. + * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -22,21 +22,27 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if !defined SLANG_UTILITY_H +#ifndef SLANG_UTILITY_H #define SLANG_UTILITY_H +#include "slang_mem.h" + /* Compile-time assertions. If the expression is zero, try to declare an * array of size [-1] to cause compilation error. */ #define static_assert(expr) do { int _array[(expr) ? 1 : -1]; (void) _array[0]; } while (0) +#if !USE_MEMPOOL #define slang_alloc_free(ptr) _mesa_free (ptr) #define slang_alloc_malloc(size) _mesa_malloc (size) #define slang_alloc_realloc(ptr, old_size, size) _mesa_realloc (ptr, old_size, size) +#endif #define slang_string_compare(str1, str2) _mesa_strcmp (str1, str2) #define slang_string_copy(dst, src) _mesa_strcpy (dst, src) +#if !USE_MEMPOOL #define slang_string_duplicate(src) _mesa_strdup (src) +#endif #define slang_string_length(str) _mesa_strlen (str) char *slang_string_concat (char *, const char *); diff --git a/src/mesa/shader/slang/slang_vartable.c b/src/mesa/shader/slang/slang_vartable.c index e3efa179085..27f8aeb4bde 100644 --- a/src/mesa/shader/slang/slang_vartable.c +++ b/src/mesa/shader/slang/slang_vartable.c @@ -2,6 +2,7 @@ #include "imports.h" #include "slang_compile.h" #include "slang_compile_variable.h" +#include "slang_mem.h" #include "slang_vartable.h" #include "slang_ir.h" #include "prog_instruction.h" @@ -49,7 +50,11 @@ slang_var_table * _slang_new_var_table(GLuint maxRegisters) { slang_var_table *vt +#if USE_MEMPOOL + = (slang_var_table *) _slang_alloc(sizeof(slang_var_table)); +#else = (slang_var_table *) _mesa_calloc(sizeof(slang_var_table)); +#endif if (vt) { vt->MaxRegisters = maxRegisters; } @@ -64,7 +69,9 @@ _slang_delete_var_table(slang_var_table *vt) _mesa_problem(NULL, "non-empty var table in _slang_delete_var_table()"); return; } +#if !USE_MEMPOOL _mesa_free(vt); +#endif } @@ -77,7 +84,11 @@ _slang_delete_var_table(slang_var_table *vt) void _slang_push_var_table(slang_var_table *vt) { +#if USE_MEMPOOL + struct table *t = (struct table *) _slang_alloc(sizeof(struct table)); +#else struct table *t = (struct table *) _mesa_calloc(sizeof(struct table)); +#endif if (t) { t->Level = vt->CurLevel++; t->Parent = vt->Top; @@ -137,10 +148,16 @@ _slang_pop_var_table(slang_var_table *vt) } if (t->Vars) +#if USE_MEMPOOL + t->Vars = NULL; +#else free(t->Vars); +#endif vt->Top = t->Parent; +#if !USE_MEMPOOL free(t); +#endif vt->CurLevel--; } @@ -156,7 +173,14 @@ _slang_add_variable(slang_var_table *vt, slang_variable *v) t = vt->Top; assert(t); if (dbg) printf("Adding var %s\n", (char *) v->a_name); +#if USE_MEMPOOL + t->Vars = + (slang_variable **) _slang_realloc(t->Vars, + t->NumVars * sizeof(slang_variable *), + (t->NumVars + 1) * sizeof(slang_variable *)); +#else t->Vars = realloc(t->Vars, (t->NumVars + 1) * sizeof(slang_variable *)); +#endif t->Vars[t->NumVars] = v; t->NumVars++; } |