_slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper);
-
-
-/**
- * Lookup a named constant and allocate storage for the parameter in
- * the given parameter list.
- * \param swizzleOut returns swizzle mask for accessing the constant
- * \return position of the constant in the paramList.
- */
-static GLint
-slang_lookup_constant(const char *name,
- struct gl_program_parameter_list *paramList,
- GLuint *swizzleOut)
-{
- GLint value = _slang_lookup_constant(name);
- if (value >= 0) {
- /* XXX named constant! */
- GLfloat fvalue = (GLfloat) value;
- GLint pos;
- pos = _mesa_add_unnamed_constant(paramList, &fvalue, 1, swizzleOut);
- return pos;
- }
- return -1;
-}
-
-
static GLboolean
is_sampler_type(const slang_fully_specified_type *t)
{
/**
- * Allocate storage info for an IR node (n->Store).
- * If n is an IR_VAR_DECL, allocate a temporary for the variable.
- * Otherwise, if n is an IR_VAR, check if it's a uniform or constant
- * that needs to have storage allocated.
+ * Establish the binding between a slang_ir_node and a slang_variable.
+ * Then, allocate/attach a slang_ir_storage object to the IR node if needed.
+ * The IR node must be a IR_VAR or IR_VAR_DECL node.
+ * \param n the IR node
+ * \param var the variable to associate with the IR node
*/
static void
-slang_allocate_storage(slang_assemble_ctx *A, slang_ir_node *n)
+slang_attach_storage(slang_ir_node *n, slang_variable *var)
{
- assert(A->vartable);
assert(n);
+ assert(var);
+ assert(n->Opcode == IR_VAR || n->Opcode == IR_VAR_DECL);
+ assert(!n->Var || n->Var == var);
+
+ n->Var = var;
if (!n->Store) {
- /* allocate storage info for this node */
+ /* need to setup storage */
if (n->Var && n->Var->aux) {
/* node storage info = var storage info */
n->Store = (slang_ir_storage *) n->Var->aux;
assert(n->Var->aux);
}
}
-
- if (n->Opcode == IR_VAR_DECL) {
- /* variable declaration */
- assert(n->Var);
- assert(!is_sampler_type(&n->Var->type));
- n->Store->File = PROGRAM_TEMPORARY;
- n->Store->Size = _slang_sizeof_type_specifier(&n->Var->type.specifier);
- assert(n->Store->Size > 0);
- return;
- }
- else {
- assert(n->Opcode == IR_VAR);
- assert(n->Var);
-
- if (n->Store->Index < 0) {
- const char *varName = (char *) n->Var->a_name;
- struct gl_program *prog = A->program;
- assert(prog);
-
- if (n->Store->File == PROGRAM_CONSTANT) {
- /* XXX compile-time constants should be converted to literals */
- GLint i = slang_lookup_constant(varName, prog->Parameters,
- &n->Store->Swizzle);
- assert(i >= 0);
- assert(n->Store->Size == 1);
- n->Store->Index = i;
- }
- }
- }
}
static slang_ir_node *
new_var(slang_assemble_ctx *A, slang_operation *oper, slang_atom name)
{
- slang_variable *v = _slang_locate_variable(oper->locals, name, GL_TRUE);
- slang_ir_node *n = new_node0(IR_VAR);
- if (!v)
+ slang_ir_node *n;
+ slang_variable *var = _slang_locate_variable(oper->locals, name, GL_TRUE);
+ if (!var)
return NULL;
- assert(!oper->var || oper->var == v);
- v->used = GL_TRUE;
- n->Var = v;
- slang_allocate_storage(A, n);
+ assert(!oper->var || oper->var == var);
+
+ n = new_node0(IR_VAR);
+ if (n) {
+ var->used = GL_TRUE;
+ slang_attach_storage(n, var);
+ }
return n;
}
_slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var)
{
slang_ir_node *n;
+ assert(!is_sampler_type(&var->type));
n = new_node0(IR_VAR_DECL);
if (n) {
- n->Var = var;
- slang_allocate_storage(A, n);
+ slang_attach_storage(n, var);
+
+ assert(var->aux);
+ assert(n->Store == var->aux);
assert(n->Store);
assert(n->Store->Index < 0);
+
+ n->Store->File = PROGRAM_TEMPORARY;
+ n->Store->Size = _slang_sizeof_type_specifier(&n->Var->type.specifier);
assert(n->Store->Size > 0);
- assert(var->aux);
- assert(n->Store == var->aux);
}
return n;
}
abort();
return new_node0(IR_NOP);
}
- abort();
+
return NULL;
}