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;
}
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;
}
/* "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)
/* 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 */
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
*/
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,
#include "imports.h"
#include "mtypes.h"
#include "slang_utility.h"
+#include "slang_vartable.h"
#if defined __cplusplus
extern "C" {
} 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;
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_ *
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) {
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;
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
*/
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 */
}
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;
}
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];
}
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)
{
}
}
+
int
slang_variable_copy(slang_variable * x, const slang_variable * y)
{
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;
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;
}
}
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);
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;
*/
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;
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