mesa: glsl: put var emit/ref code into separate functions

This commit is contained in:
Brian Paul
2008-08-19 10:05:11 -06:00
parent 146a0fba00
commit df9bd01ea0

View File

@@ -1636,45 +1636,21 @@ emit_struct_field(slang_emit_info *emitInfo, slang_ir_node *n)
}
/**
* Emit code for a variable declaration.
* This usually doesn't result in any code generation, but just
* memory allocation.
*/
static struct prog_instruction *
emit(slang_emit_info *emitInfo, slang_ir_node *n)
emit_var_decl(slang_emit_info *emitInfo, slang_ir_node *n)
{
struct prog_instruction *inst;
if (!n)
return NULL;
if (emitInfo->log->error_flag) {
return NULL;
}
switch (n->Opcode) {
case IR_SEQ:
/* sequence of two sub-trees */
assert(n->Children[0]);
assert(n->Children[1]);
emit(emitInfo, n->Children[0]);
if (emitInfo->log->error_flag)
return NULL;
inst = emit(emitInfo, n->Children[1]);
#if 0
assert(!n->Store);
#endif
n->Store = n->Children[1]->Store;
return inst;
case IR_SCOPE:
/* new variable scope */
_slang_push_var_table(emitInfo->vt);
inst = emit(emitInfo, n->Children[0]);
_slang_pop_var_table(emitInfo->vt);
return inst;
case IR_VAR_DECL:
/* Variable declaration - allocate a register for it */
assert(n->Store);
assert(n->Store->File != PROGRAM_UNDEFINED);
assert(n->Store->Size > 0);
/*assert(n->Store->Index < 0);*/
if (!n->Var || n->Var->isTemp) {
/* a nameless/temporary variable, will be freed after first use */
/*NEW*/
@@ -1710,16 +1686,21 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n)
return inst;
}
return NULL;
}
case IR_VAR:
/* Reference to a variable
* Storage should have already been resolved/allocated.
/**
* Emit code for a reference to a variable.
* Actually, no code is generated but we may do some memory alloation.
* In particular, state vars (uniforms) are allocated on an as-needed basis.
*/
static struct prog_instruction *
emit_var_ref(slang_emit_info *emitInfo, slang_ir_node *n)
{
assert(n->Store);
assert(n->Store->File != PROGRAM_UNDEFINED);
if (n->Store->File == PROGRAM_STATE_VAR &&
n->Store->Index < 0) {
if (n->Store->File == PROGRAM_STATE_VAR && n->Store->Index < 0) {
n->Store->Index = _slang_alloc_statevar(n, emitInfo->prog->Parameters);
}
@@ -1728,7 +1709,54 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n)
return NULL;
}
assert(n->Store->Size > 0);
break;
return NULL;
}
static struct prog_instruction *
emit(slang_emit_info *emitInfo, slang_ir_node *n)
{
struct prog_instruction *inst;
if (!n)
return NULL;
if (emitInfo->log->error_flag) {
return NULL;
}
switch (n->Opcode) {
case IR_SEQ:
/* sequence of two sub-trees */
assert(n->Children[0]);
assert(n->Children[1]);
emit(emitInfo, n->Children[0]);
if (emitInfo->log->error_flag)
return NULL;
inst = emit(emitInfo, n->Children[1]);
#if 0
assert(!n->Store);
#endif
n->Store = n->Children[1]->Store;
return inst;
case IR_SCOPE:
/* new variable scope */
_slang_push_var_table(emitInfo->vt);
inst = emit(emitInfo, n->Children[0]);
_slang_pop_var_table(emitInfo->vt);
return inst;
case IR_VAR_DECL:
/* Variable declaration - allocate a register for it */
inst = emit_var_decl(emitInfo, n);
return inst;
case IR_VAR:
/* Reference to a variable
* Storage should have already been resolved/allocated.
*/
return emit_var_ref(emitInfo, n);
case IR_ELEMENT:
return emit_array_element(emitInfo, n);