summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-01-13 14:47:48 -0700
committerBrian <[email protected]>2007-01-13 14:47:48 -0700
commit5daa99d2a40fa12d51043c4e326bf62f66ef727d (patch)
tree21646a1f0b4329bc55f2a63e14a73cb034f72072
parent97c7937c65ddcab2437e6b201d24bf0503a01f1b (diff)
slang_variable_scope now stores array of pointers to slang_variables.
-rw-r--r--src/mesa/shader/slang/slang_assemble.c18
-rw-r--r--src/mesa/shader/slang/slang_assemble.h9
-rw-r--r--src/mesa/shader/slang/slang_compile_function.c4
-rw-r--r--src/mesa/shader/slang/slang_compile_struct.c4
-rw-r--r--src/mesa/shader/slang/slang_compile_variable.c61
-rw-r--r--src/mesa/shader/slang/slang_compile_variable.h6
6 files changed, 63 insertions, 39 deletions
diff --git a/src/mesa/shader/slang/slang_assemble.c b/src/mesa/shader/slang/slang_assemble.c
index c318a0b79bb..a9d2baedb92 100644
--- a/src/mesa/shader/slang/slang_assemble.c
+++ b/src/mesa/shader/slang/slang_assemble.c
@@ -218,7 +218,7 @@ sizeof_variables(slang_assemble_ctx * A, slang_variable_scope * vars,
GLuint i;
for (i = start; i < stop; i++)
- if (!sizeof_variable2(A, &vars->variables[i], size))
+ if (!sizeof_variable2(A, vars->variables[i], size))
return GL_FALSE;
return GL_TRUE;
}
@@ -270,7 +270,7 @@ _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name,
return NULL;
}
if (!slang_type_specifier_equal(&ti.spec,
- &f->parameters->variables[j/* + haveRetValue*/].type.specifier)) {
+ &f->parameters->variables[j/* + haveRetValue*/]->type.specifier)) {
slang_assembly_typeinfo_destruct(&ti);
break;
}
@@ -278,8 +278,8 @@ _slang_locate_function(const slang_function_scope * funcs, slang_atom a_name,
/* "out" and "inout" formal parameter requires the actual parameter to be l-value */
if (!ti.can_be_referenced &&
- (f->parameters->variables[j/* + haveRetValue*/].type.qualifier == slang_qual_out ||
- f->parameters->variables[j/* + haveRetValue*/].type.qualifier == slang_qual_inout))
+ (f->parameters->variables[j/* + haveRetValue*/]->type.qualifier == slang_qual_out ||
+ f->parameters->variables[j/* + haveRetValue*/]->type.qualifier == slang_qual_inout))
break;
}
if (j == num_args)
@@ -599,8 +599,8 @@ _slang_assemble_function_call(slang_assemble_ctx * A, slang_function * fun,
/* push the actual parameters on the stack */
for (i = 0; i < param_count; i++) {
- if (fun->parameters->variables[i /*+ haveRetValue*/].type.qualifier == slang_qual_inout ||
- fun->parameters->variables[i /*+ haveRetValue*/].type.qualifier == slang_qual_out) {
+ if (fun->parameters->variables[i /*+ haveRetValue*/]->type.qualifier == slang_qual_inout ||
+ fun->parameters->variables[i /*+ haveRetValue*/]->type.qualifier == slang_qual_out) {
if (!PLAB2(A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
return GL_FALSE;
/* TODO: optimize the "out" parameter case */
@@ -644,8 +644,8 @@ _slang_assemble_function_call(slang_assemble_ctx * A, slang_function * fun,
A->swz = p_swz[j];
A->ref = p_ref[j];
- if (fun->parameters->variables[j /*+ haveRetValue*/].type.qualifier == slang_qual_inout ||
- fun->parameters->variables[j/* + haveRetValue*/].type.qualifier == slang_qual_out) {
+ if (fun->parameters->variables[j /*+ haveRetValue*/]->type.qualifier == slang_qual_inout ||
+ fun->parameters->variables[j/* + haveRetValue*/]->type.qualifier == slang_qual_out) {
/* for output parameter copy the contents of the formal parameter
* back to the original actual parameter
*/
@@ -1088,7 +1088,7 @@ handle_field(slang_assemble_ctx * A, slang_assembly_typeinfo * tia,
slang_storage_aggregate agg;
GLuint size;
- field = &tib->spec._struct->fields->variables[i];
+ field = tib->spec._struct->fields->variables[i];
if (!slang_storage_aggregate_construct(&agg))
RETURN_NIL();
if (!_slang_aggregate_variable(&agg, &field->type.specifier,
diff --git a/src/mesa/shader/slang/slang_assemble.h b/src/mesa/shader/slang/slang_assemble.h
index 8aafeb012ff..e801ea249d9 100644
--- a/src/mesa/shader/slang/slang_assemble.h
+++ b/src/mesa/shader/slang/slang_assemble.h
@@ -28,6 +28,7 @@
#include "imports.h"
#include "mtypes.h"
#include "slang_utility.h"
+#include "slang_vartable.h"
#if defined __cplusplus
extern "C" {
@@ -243,12 +244,6 @@ typedef struct slang_assembly_name_space_
} slang_assembly_name_space;
-typedef struct {
- GLboolean TempUsed[MAX_PROGRAM_TEMPS];
- GLuint NumSamplers;
-} slang_gen_context;
-
-
typedef struct slang_assemble_ctx_
{
slang_assembly_file *file;
@@ -260,7 +255,7 @@ typedef struct slang_assemble_ctx_
slang_ref_type ref;
slang_swizzle swz;
struct gl_program *program;
- slang_gen_context *codegen;
+ slang_var_table *vartable;
} slang_assemble_ctx;
extern struct slang_function_ *
diff --git a/src/mesa/shader/slang/slang_compile_function.c b/src/mesa/shader/slang/slang_compile_function.c
index 58a453d4c23..3642b12e92a 100644
--- a/src/mesa/shader/slang/slang_compile_function.c
+++ b/src/mesa/shader/slang/slang_compile_function.c
@@ -196,8 +196,8 @@ slang_function_scope_find(slang_function_scope * funcs, slang_function * fun,
continue;
for (j = haveRetValue; j < fun->param_count; j++) {
if (!slang_type_specifier_equal
- (&fun->parameters->variables[j].type.specifier,
- &f->parameters->variables[j].type.specifier))
+ (&fun->parameters->variables[j]->type.specifier,
+ &f->parameters->variables[j]->type.specifier))
break;
}
if (j == fun->param_count) {
diff --git a/src/mesa/shader/slang/slang_compile_struct.c b/src/mesa/shader/slang/slang_compile_struct.c
index 15585a62afe..5033a6cb108 100644
--- a/src/mesa/shader/slang/slang_compile_struct.c
+++ b/src/mesa/shader/slang/slang_compile_struct.c
@@ -153,8 +153,8 @@ int slang_struct_equal (const slang_struct *x, const slang_struct *y)
return 0;
for (i = 0; i < x->fields->num_variables; i++)
{
- slang_variable *varx = &x->fields->variables[i];
- slang_variable *vary = &y->fields->variables[i];
+ slang_variable *varx = x->fields->variables[i];
+ slang_variable *vary = y->fields->variables[i];
if (varx->a_name != vary->a_name)
return 0;
diff --git a/src/mesa/shader/slang/slang_compile_variable.c b/src/mesa/shader/slang/slang_compile_variable.c
index 046db2cefca..b19615b0850 100644
--- a/src/mesa/shader/slang/slang_compile_variable.c
+++ b/src/mesa/shader/slang/slang_compile_variable.c
@@ -123,6 +123,29 @@ slang_fully_specified_type_copy(slang_fully_specified_type * x,
return 1;
}
+
+static slang_variable *
+slang_variable_new(void)
+{
+ slang_variable *v = (slang_variable *) malloc(sizeof(slang_variable));
+ if (v) {
+ if (!slang_variable_construct(v)) {
+ free(v);
+ v = NULL;
+ }
+ }
+ return v;
+}
+
+
+static void
+slang_variable_delete(slang_variable * var)
+{
+ slang_variable_destruct(var);
+ free(var);
+}
+
+
/*
* slang_variable_scope
*/
@@ -152,8 +175,10 @@ slang_variable_scope_destruct(slang_variable_scope * scope)
if (!scope)
return;
- for (i = 0; i < scope->num_variables; i++)
- slang_variable_destruct(scope->variables + i);
+ for (i = 0; i < scope->num_variables; i++) {
+ if (scope->variables[i])
+ slang_variable_delete(scope->variables[i]);
+ }
slang_alloc_free(scope->variables);
/* do not free scope->outer_scope */
}
@@ -166,21 +191,22 @@ slang_variable_scope_copy(slang_variable_scope * x,
unsigned int i;
_slang_variable_scope_ctr(&z);
- z.variables = (slang_variable *)
- slang_alloc_malloc(y->num_variables * sizeof(slang_variable));
+ z.variables = (slang_variable **)
+ _mesa_calloc(y->num_variables * sizeof(slang_variable *));
if (z.variables == NULL) {
slang_variable_scope_destruct(&z);
return 0;
}
for (z.num_variables = 0; z.num_variables < y->num_variables;
z.num_variables++) {
- if (!slang_variable_construct(&z.variables[z.num_variables])) {
+ z.variables[z.num_variables] = slang_variable_new();
+ if (!z.variables[z.num_variables]) {
slang_variable_scope_destruct(&z);
return 0;
}
}
for (i = 0; i < z.num_variables; i++) {
- if (!slang_variable_copy(&z.variables[i], &y->variables[i])) {
+ if (!slang_variable_copy(z.variables[i], y->variables[i])) {
slang_variable_scope_destruct(&z);
return 0;
}
@@ -200,19 +226,20 @@ slang_variable *
slang_variable_scope_grow(slang_variable_scope *scope)
{
const int n = scope->num_variables;
- scope->variables = (slang_variable *)
+ scope->variables = (slang_variable **)
slang_alloc_realloc(scope->variables,
- n * sizeof(slang_variable),
- (n + 1) * sizeof(slang_variable));
+ n * sizeof(slang_variable *),
+ (n + 1) * sizeof(slang_variable *));
if (!scope->variables)
return NULL;
scope->num_variables++;
- if (!slang_variable_construct(scope->variables + n))
+ scope->variables[n] = slang_variable_new();
+ if (!scope->variables[n])
return NULL;
- return scope->variables + n;
+ return scope->variables[n];
}
@@ -230,12 +257,13 @@ slang_variable_construct(slang_variable * var)
var->address = ~0;
var->size = 0;
var->global = GL_FALSE;
- var->declared = GL_FALSE;
+ var->isTemp = GL_FALSE;
var->used = GL_FALSE;
var->aux = NULL;
return 1;
}
+
void
slang_variable_destruct(slang_variable * var)
{
@@ -246,6 +274,7 @@ slang_variable_destruct(slang_variable * var)
}
}
+
int
slang_variable_copy(slang_variable * x, const slang_variable * y)
{
@@ -291,8 +320,8 @@ _slang_locate_variable(const slang_variable_scope * scope,
GLuint i;
for (i = 0; i < scope->num_variables; i++)
- if (a_name == scope->variables[i].a_name)
- return &scope->variables[i];
+ if (a_name == scope->variables[i]->a_name)
+ return scope->variables[i];
if (all && scope->outer_scope != NULL)
return _slang_locate_variable(scope->outer_scope, a_name, 1);
return NULL;
@@ -384,7 +413,7 @@ build_quant(slang_export_data_quant * q, const slang_variable * var)
slang_export_data_quant_ctr(&q->structure[i]);
for (i = 0; i < q->u.field_count; i++) {
if (!build_quant(&q->structure[i],
- &spec->_struct->fields->variables[i]))
+ spec->_struct->fields->variables[i]))
return GL_FALSE;
}
}
@@ -400,7 +429,7 @@ _slang_build_export_data_table(slang_export_data_table * tbl,
GLuint i;
for (i = 0; i < vars->num_variables; i++) {
- const slang_variable *var = &vars->variables[i];
+ const slang_variable *var = vars->variables[i];
slang_export_data_entry *e;
e = slang_export_data_table_add(tbl);
diff --git a/src/mesa/shader/slang/slang_compile_variable.h b/src/mesa/shader/slang/slang_compile_variable.h
index d52e2660dc0..82800b32b53 100644
--- a/src/mesa/shader/slang/slang_compile_variable.h
+++ b/src/mesa/shader/slang/slang_compile_variable.h
@@ -81,7 +81,7 @@ typedef struct slang_variable_
GLuint size; /**< Variable's size in bytes */
GLboolean global; /**< A global var? */
GLboolean used; /**< Ever referenced by code? */
- GLboolean declared; /**< Declared by slang_variable_decl? */
+ GLboolean isTemp; /**< a named temporary (__resultTmp) */
void *aux; /**< Used during code gen */
} slang_variable;
@@ -91,7 +91,7 @@ typedef struct slang_variable_
*/
typedef struct slang_variable_scope_
{
- slang_variable *variables; /**< Array [num_variables] */
+ slang_variable **variables; /**< Array [num_variables] of ptrs to vars */
GLuint num_variables;
struct slang_variable_scope_ *outer_scope;
} slang_variable_scope;
@@ -110,7 +110,7 @@ extern int
slang_variable_scope_copy(slang_variable_scope *,
const slang_variable_scope *);
-slang_variable *
+extern slang_variable *
slang_variable_scope_grow(slang_variable_scope *);
extern int