diff options
author | Alan Hourihane <[email protected]> | 2008-11-25 09:28:36 +0000 |
---|---|---|
committer | Alan Hourihane <[email protected]> | 2008-11-25 09:28:36 +0000 |
commit | 4b7a84a36108eff8f17cbdf2c511593eb3260fd2 (patch) | |
tree | 28c740637a85fe3b997f20b5daf39bb4c131f150 /src/mesa/shader/slang/slang_codegen.c | |
parent | 4af0d940a35536f096a9289470af0268a79402b3 (diff) | |
parent | 8d95e66cf78921cd067c4bcf6a1053a7ec3a2ed4 (diff) |
Merge commit 'origin/master' into gallium-0.2
Diffstat (limited to 'src/mesa/shader/slang/slang_codegen.c')
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index f2cb75f8722..8d2655ec517 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -2042,6 +2042,46 @@ _slang_gen_function_call_name(slang_assemble_ctx *A, const char *name, } +static slang_ir_node * +_slang_gen_method_call(slang_assemble_ctx *A, slang_operation *oper) +{ + slang_atom *a_length = slang_atom_pool_atom(A->atoms, "length"); + slang_ir_node *n; + slang_variable *var; + + /* NOTE: In GLSL 1.20, there's only one kind of method + * call: array.length(). Anything else is an error. + */ + if (oper->a_id != a_length) { + slang_info_log_error(A->log, + "Undefined method call '%s'", (char *) oper->a_id); + return NULL; + } + + /* length() takes no arguments */ + if (oper->num_children > 0) { + slang_info_log_error(A->log, "Invalid arguments to length() method"); + return NULL; + } + + /* lookup the object/variable */ + var = _slang_locate_variable(oper->locals, oper->a_obj, GL_TRUE); + if (!var || var->type.specifier.type != SLANG_SPEC_ARRAY) { + slang_info_log_error(A->log, + "Undefined object '%s'", (char *) oper->a_obj); + return NULL; + } + + /* Create a float/literal IR node encoding the array length */ + n = new_node0(IR_FLOAT); + if (n) { + n->Value[0] = (float) var->array_len; + n->Store = _slang_new_ir_storage(PROGRAM_CONSTANT, -1, 1); + } + return n; +} + + static GLboolean _slang_is_constant_cond(const slang_operation *oper, GLboolean *value) { @@ -3534,6 +3574,8 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) case SLANG_OPER_CALL: return _slang_gen_function_call_name(A, (const char *) oper->a_id, oper, NULL); + case SLANG_OPER_METHOD: + return _slang_gen_method_call(A, oper); case SLANG_OPER_RETURN: return _slang_gen_return(A, oper); case SLANG_OPER_LABEL: |