diff options
author | Brian Paul <[email protected]> | 2006-11-24 19:01:14 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2006-11-24 19:01:14 +0000 |
commit | e49d06e61955208b9cd3e18469034e7447394b95 (patch) | |
tree | adba3a8148477f400f369cef640b67a9fb2c86bf /src/mesa | |
parent | d4c4bdfa1e6bf35c84c4a2d5e18a70dbff11b101 (diff) |
new slang_variable_scope_grow() function
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/shader/slang/slang_compile.c | 46 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_variable.c | 21 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile_variable.h | 3 |
3 files changed, 38 insertions, 32 deletions
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 77a293ea45e..93c7fb0cdbf 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -1,6 +1,6 @@ /* * Mesa 3-D graphics library - * Version: 6.6 + * Version: 6.5.2 * * Copyright (C) 2005-2006 Brian Paul All Rights Reserved. * @@ -42,14 +42,16 @@ * may be accepted resulting in undefined behaviour. */ -/* slang_var_pool */ + +/** + * Allocate storage for a variable of 'size' bytes from given pool. + * Return the allocated address for the variable. + */ static GLuint slang_var_pool_alloc(slang_var_pool * pool, unsigned int size) { - GLuint addr; - - addr = pool->next_addr; + const GLuint addr = pool->next_addr; pool->next_addr += size; return addr; } @@ -432,22 +434,13 @@ parse_struct_field(slang_parse_ctx * C, slang_output_ctx * O, return 0; do { - slang_variable *var; - - st->fields->variables = - (slang_variable *) slang_alloc_realloc(st->fields->variables, - st->fields->num_variables * - sizeof(slang_variable), - (st->fields->num_variables + - 1) * sizeof(slang_variable)); - if (st->fields->variables == NULL) { + slang_variable *var = slang_variable_scope_grow(st->fields); + if (!var) { slang_info_log_memory(C->L); return 0; } - var = &st->fields->variables[st->fields->num_variables]; if (!slang_variable_construct(var)) return 0; - st->fields->num_variables++; if (!parse_struct_field_var(C, &o, var, sp)) return 0; } @@ -1222,6 +1215,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, if (!parse_child_operation(C, O, op, 0)) return 0; C->I++; + if (!C->parsing_builtin && !slang_function_scope_find_by_name(O->funs, op->a_id, 1)) { const char *id; @@ -1479,20 +1473,13 @@ parse_function_prototype(slang_parse_ctx * C, slang_output_ctx * O, /* parse function parameters */ while (*C->I++ == PARAMETER_NEXT) { - slang_variable *p; - - func->parameters->variables = (slang_variable *) - slang_alloc_realloc(func->parameters->variables, - func->parameters->num_variables * sizeof(slang_variable), - (func->parameters->num_variables + 1) * sizeof(slang_variable)); - if (func->parameters->variables == NULL) { + slang_variable *p = slang_variable_scope_grow(func->parameters); + if (!p) { slang_info_log_memory(C->L); return 0; } - p = &func->parameters->variables[func->parameters->num_variables]; if (!slang_variable_construct(p)) return 0; - func->parameters->num_variables++; if (!parse_parameter_declaration(C, O, p)) return 0; } @@ -1662,18 +1649,13 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, return 1; /* make room for the new variable and initialize it */ - O->vars->variables = (slang_variable *) - slang_alloc_realloc(O->vars->variables, - O->vars->num_variables * sizeof(slang_variable), - (O->vars->num_variables + 1) * sizeof(slang_variable)); - if (O->vars->variables == NULL) { + var = slang_variable_scope_grow(O->vars); + if (!var) { slang_info_log_memory(C->L); return 0; } - var = &O->vars->variables[O->vars->num_variables]; if (!slang_variable_construct(var)) return 0; - O->vars->num_variables++; /* copy the declarator qualifier type, parse the identifier */ var->global = C->global_scope; diff --git a/src/mesa/shader/slang/slang_compile_variable.c b/src/mesa/shader/slang/slang_compile_variable.c index 92951b85bbc..a37deddff10 100644 --- a/src/mesa/shader/slang/slang_compile_variable.c +++ b/src/mesa/shader/slang/slang_compile_variable.c @@ -181,6 +181,27 @@ slang_variable_scope_copy(slang_variable_scope * x, return 1; } + +/** + * Grow the variable list by one. + * \return pointer to space for the new variable. + */ +slang_variable * +slang_variable_scope_grow(slang_variable_scope *scope) +{ + const int n = scope->num_variables; + scope->variables = (slang_variable *) + slang_alloc_realloc(scope->variables, + n * sizeof(slang_variable), + (n + 1) * sizeof(slang_variable)); + if (!scope->variables) + return NULL; + scope->num_variables++; + return scope->variables + n; +} + + + /* slang_variable */ int diff --git a/src/mesa/shader/slang/slang_compile_variable.h b/src/mesa/shader/slang/slang_compile_variable.h index 2f358860f82..b0910e855ea 100644 --- a/src/mesa/shader/slang/slang_compile_variable.h +++ b/src/mesa/shader/slang/slang_compile_variable.h @@ -81,6 +81,7 @@ typedef struct slang_variable_ GLuint address2; /**< Storage location */ GLuint size; /**< Variable's size in bytes */ GLboolean global; /**< A global var? */ + void *aux; /**< Used during code gen */ } slang_variable; @@ -104,6 +105,8 @@ extern int slang_variable_scope_copy(slang_variable_scope *, const slang_variable_scope *); +slang_variable * +slang_variable_scope_grow(slang_variable_scope *); extern int slang_variable_construct(slang_variable *); |