if (!var)
return NULL;
+ assert(var->declared);
+
assert(!oper->var || oper->var == var);
n = new_node0(IR_VAR);
}
-
/**
* Produce inline code for a call to an assembly instruction.
* This is typically used to compile a call to a built-in function like this:
}
}
+ /* Now add copies of the function's local vars to the new variable scope */
+ for (i = totalArgs; i < fun->parameters->num_variables; i++) {
+ slang_variable *p = fun->parameters->variables[i];
+ slang_variable *pCopy = slang_variable_scope_grow(inlined->locals);
+ pCopy->type = p->type;
+ pCopy->a_name = p->a_name;
+ pCopy->array_len = p->array_len;
+ }
+
+
/* New epilog statements:
* 1. Create end of function label to jump to from return statements.
* 2. Copy the 'out' parameter vars
_slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var)
{
slang_ir_node *n;
+ /*assert(!var->declared);*/
+ var->declared = GL_TRUE;
assert(!is_sampler_type(&var->type));
n = new_node0(IR_VAR_DECL);
if (n) {
if (store)
var->aux = store; /* save var's storage info */
+ var->declared = GL_TRUE;
+
return success;
}
oper->locals = NULL;
}
+
+/**
+ * Recursively traverse 'oper', replacing occurances of 'oldScope' with
+ * 'newScope' in the oper->locals->outer_scope field.
+ */
+void
+slang_replace_scope(slang_operation *oper,
+ slang_variable_scope *oldScope,
+ slang_variable_scope *newScope)
+{
+ GLuint i;
+ if (oper->locals != newScope &&
+ oper->locals->outer_scope == oldScope) {
+ oper->locals->outer_scope = newScope;
+ }
+ for (i = 0; i < oper->num_children; i++) {
+ slang_replace_scope(&oper->children[i], oldScope, newScope);
+ }
+}
+
+
/**
* Recursively copy a slang_operation node.
+ * \param x copy target
+ * \param y copy source
* \return GL_TRUE for success, GL_FALSE if failure
*/
GLboolean
#endif
slang_operation_destruct(x);
*x = z;
+
+ /* If this operation declares a new scope, we need to make sure
+ * all children point to it, not the original operation's scope!
+ */
+ if (x->type == SLANG_OPER_BLOCK_NEW_SCOPE) {
+ slang_replace_scope(x, y->locals, x->locals);
+ }
+
return GL_TRUE;
}
extern void
slang_operation_destruct(slang_operation *);
+extern void
+slang_replace_scope(slang_operation *oper,
+ slang_variable_scope *oldScope,
+ slang_variable_scope *newScope);
+
extern GLboolean
slang_operation_copy(slang_operation *, const slang_operation *);
GLuint address; /**< Storage location */
GLuint size; /**< Variable's size in bytes */
GLboolean isTemp; /**< a named temporary (__resultTmp) */
+ GLboolean declared; /**< for debug */
void *aux; /**< Used during code gen */
} slang_variable;