diff options
author | Ian Romanick <ian.d.romanick@intel.com> | 2010-03-29 14:11:25 -0700 |
---|---|---|
committer | Ian Romanick <ian.d.romanick@intel.com> | 2010-03-29 15:17:11 -0700 |
commit | 3c6fea3048a0d9add2fec621d30c32f3519d8868 (patch) | |
tree | c281f08097ed8365da51444c99f119cce15b0747 /ast_to_hir.cpp | |
parent | 721efc04da96451297ca1defe703fe755c212baa (diff) |
Implement ir_if (for if-statments) and conversion from AST
The following tests now pass:
glslparsertest/shaders/if1.frag
glslparsertest/shaders/if2.frag
The following tests that used to pass now fail. It appears that most
of these fail because ast_nequal and ast_equal are not converted to HIR.
shaders/glsl-unused-varying.frag
shaders/glsl-fs-sqrt-branch.frag
Diffstat (limited to 'ast_to_hir.cpp')
-rw-r--r-- | ast_to_hir.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index 7b1db0c481..0a505bf414 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -1318,3 +1318,52 @@ ast_jump_statement::hir(exec_list *instructions, */ return NULL; } + + +ir_rvalue * +ast_selection_statement::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + ir_rvalue *const condition = this->condition->hir(instructions, state); + struct simple_node *ptr; + + /* From page 66 (page 72 of the PDF) of the GLSL 1.50 spec: + * + * "Any expression whose type evaluates to a Boolean can be used as the + * conditional expression bool-expression. Vector types are not accepted + * as the expression to if." + * + * The checks are separated so that higher quality diagnostics can be + * generated for cases where both rules are violated. + */ + if (!condition->type->is_boolean() || !condition->type->is_scalar()) { + YYLTYPE loc = this->condition->get_location(); + + _mesa_glsl_error(& loc, state, "if-statement condition must be scalar " + "boolean"); + } + + ir_if *const stmt = new ir_if(condition); + + if (then_statement != NULL) { + ast_node *node = (ast_node *) then_statement; + do { + node->hir(& stmt->then_instructions, state); + node = (ast_node *) node->next; + } while (node != then_statement); + } + + if (else_statement != NULL) { + ast_node *node = (ast_node *) else_statement; + do { + node->hir(& stmt->else_instructions, state); + node = (ast_node *) node->next; + } while (node != else_statement); + } + + instructions->push_tail(stmt); + + /* if-statements do not have r-values. + */ + return NULL; +} |