diff options
author | Brian <[email protected]> | 2007-03-07 12:59:01 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2007-03-07 12:59:01 -0700 |
commit | 35d25c0ce4104d41feead679573543427f99a031 (patch) | |
tree | 7165ff01cef64558b5a215105756c6957aa87e07 /src/mesa/shader/slang | |
parent | 5b5a80d011d143f1bbd9be39dc4ca6a0af4bad7c (diff) |
Fix problem with nested function calls such as y = f(f(x))
Replace CurFunction with curFuncEndLabel.
Diffstat (limited to 'src/mesa/shader/slang')
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 43 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_emit.c | 4 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_typeinfo.h | 2 |
3 files changed, 26 insertions, 23 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index d1e3544b545..fc000dbf7be 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -437,6 +437,7 @@ static slang_ir_node * new_label(slang_label *label) { slang_ir_node *n = new_node0(IR_LABEL); + assert(label); if (n) n->Label = label; return n; @@ -474,6 +475,7 @@ static slang_ir_node * new_jump(slang_label *dest) { slang_ir_node *n = new_node0(IR_JUMP); + assert(dest); if (n) n->Label = dest; return n; @@ -1007,7 +1009,7 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun, &inlined->children, inlined->num_children); lab->type = SLANG_OPER_LABEL; - lab->label = A->CurFunction->end_label; + lab->label = A->curFuncEndLabel; } for (i = 0; i < totalArgs; i++) { @@ -1049,16 +1051,13 @@ _slang_gen_function_call(slang_assemble_ctx *A, slang_function *fun, { slang_ir_node *n; slang_operation *inlined; - slang_function *prevFunc; + slang_label *prevFuncEndLabel; + char name[200]; - prevFunc = A->CurFunction; - A->CurFunction = fun; - - if (!A->CurFunction->end_label) { - char name[200]; - sprintf(name, "__endOfFunc_%s_", (char *) A->CurFunction->header.a_name); - A->CurFunction->end_label = _slang_label_new(name); - } + prevFuncEndLabel = A->curFuncEndLabel; + sprintf(name, "__endOfFunc_%s_", (char *) fun->header.a_name); + A->curFuncEndLabel = _slang_label_new(name); + assert(A->curFuncEndLabel); if (slang_is_asm_function(fun) && !dest) { /* assemble assembly function - tree style */ @@ -1088,9 +1087,9 @@ _slang_gen_function_call(slang_assemble_ctx *A, slang_function *fun, n = _slang_gen_operation(A, oper); - A->CurFunction->end_label = NULL; /* XXX delete/free? */ - - A->CurFunction = prevFunc; + /*_slang_label_delete(A->curFuncEndLabel);*/ + A->curFuncEndLabel = prevFuncEndLabel; + assert(A->curFuncEndLabel); return n; } @@ -1712,7 +1711,8 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) slang_operation gotoOp; slang_operation_construct(&gotoOp); gotoOp.type = SLANG_OPER_GOTO; - gotoOp.label = A->CurFunction->end_label; + gotoOp.label = A->curFuncEndLabel; + assert(gotoOp.label); /* assemble the new code */ n = _slang_gen_operation(A, &gotoOp); @@ -1767,9 +1767,10 @@ _slang_gen_return(slang_assemble_ctx * A, slang_operation *oper) /* child[1]: goto __endOfFunction */ jump = &block->children[1]; jump->type = SLANG_OPER_GOTO; - assert(A->CurFunction->end_label); + assert(A->curFuncEndLabel); /* XXX don't call function? */ - jump->label = A->CurFunction->end_label; + jump->label = A->curFuncEndLabel; + assert(jump->label); #if 0 /* debug */ printf("NEW RETURN:\n"); @@ -2679,11 +2680,8 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) /* fold constant expressions, etc. */ _slang_simplify(fun->body, &A->space, A->atoms); - A->CurFunction = fun; - /* Create an end-of-function label */ - if (!A->CurFunction->end_label) - A->CurFunction->end_label = _slang_label_new("__endOfFunc__main"); + A->curFuncEndLabel = _slang_label_new("__endOfFunc__main"); /* push new vartable scope */ _slang_push_var_table(A->vartable); @@ -2702,9 +2700,10 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) } /* append an end-of-function-label to IR tree */ - n = new_seq(n, new_label(fun->end_label)); + n = new_seq(n, new_label(A->curFuncEndLabel)); - A->CurFunction = NULL; + /*_slang_label_delete(A->curFuncEndLabel);*/ + A->curFuncEndLabel = NULL; #if 0 printf("************* New AST for %s *****\n", (char*)fun->header.a_name); diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 9532e070f78..55338d64596 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -899,6 +899,8 @@ static struct prog_instruction * emit_jump(slang_emit_info *emitInfo, slang_ir_node *n) { struct prog_instruction *inst; + assert(n); + assert(n->Label); inst = new_instruction(emitInfo, OPCODE_BRA); inst->DstReg.CondMask = COND_TR; /* always branch */ inst->BranchTarget = _slang_label_get_location(n->Label); @@ -1557,6 +1559,8 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n) case IR_LABEL: return emit_label(emitInfo, n); case IR_JUMP: + assert(n); + assert(n->Label); return emit_jump(emitInfo, n); case IR_CJUMP0: return emit_cjump(emitInfo, n, 0); diff --git a/src/mesa/shader/slang/slang_typeinfo.h b/src/mesa/shader/slang/slang_typeinfo.h index 62cf0009d3c..bde2e67ae23 100644 --- a/src/mesa/shader/slang/slang_typeinfo.h +++ b/src/mesa/shader/slang/slang_typeinfo.h @@ -62,7 +62,7 @@ typedef struct slang_assemble_ctx_ struct gl_program *program; slang_var_table *vartable; slang_info_log *log; - struct slang_function_ *CurFunction; + struct slang_label_ *curFuncEndLabel; struct slang_ir_node_ *CurLoop; } slang_assemble_ctx; |