#include "slang_compile.h"
#include "slang_compile_variable.h"
#include "slang_vartable.h"
+#include "slang_ir.h"
static int dbg = 0;
/**
* Create new table, put at head, return ptr to it.
+ * XXX we should take a maxTemps parameter to indicate how many temporaries
+ * are available for the current shader/program target.
*/
slang_var_table *
_slang_push_var_table(slang_var_table *parent)
{
slang_var_table *parent = t->parent;
int i;
+
if (dbg) printf("Popping level %d\n", t->level);
+
+ /* free the storage allocated for each variable */
+ for (i = 0; i < t->num_entries; i++) {
+ slang_ir_storage *store = (slang_ir_storage *) t->vars[i]->aux;
+ GLint j, sz4 = (store->Size + 3) / 4;
+ if (dbg) printf(" Free var %s, size %d\n",
+ (char*) t->vars[i]->a_name, store->Size);
+ for (j = 0; j < sz4; j++) {
+ assert(t->temps[store->Index + j] == VAR);
+ t->temps[store->Index + j] = FREE;
+ }
+ store->Index = -1;
+ }
if (t->parent) {
+ /* just verify that any remaining allocations in this scope
+ * were for temps
+ */
for (i = 0; i < MAX_PROGRAM_TEMPS; i++) {
- if (t->temps[i] && !t->parent->temps[i])
+ if (t->temps[i] && !t->parent->temps[i]) {
if (dbg) printf(" Free reg %d\n", i);
+ assert(t->temps[i] == TEMP);
+ }
}
}
- for (i = 0; i < t->num_entries; i++) {
- if (dbg) printf(" Free var %s\n", (char*) t->vars[i]->a_name);
- }
if (t->vars)
free(t->vars);
_slang_add_variable(slang_var_table *t, slang_variable *v)
{
assert(t);
+ if (dbg) printf("Adding var %s\n", (char *) v->a_name);
t->vars = realloc(t->vars, (t->num_entries + 1) * sizeof(slang_variable *));
t->vars[t->num_entries] = v;
t->num_entries++;
for (i = 0; i < MAX_PROGRAM_TEMPS; i++) {
GLuint found = 0;
for (j = 0; j < sz4; j++) {
- if (!t->temps[i + j]) {
+ if (i + j < MAX_PROGRAM_TEMPS && !t->temps[i + j]) {
found++;
}
else {