summaryrefslogtreecommitdiffstats
path: root/src/glsl/ast_function.cpp
diff options
context:
space:
mode:
authorChristian König <[email protected]>2010-12-11 13:43:44 +0100
committerChristian König <[email protected]>2010-12-11 13:43:44 +0100
commit772b25e1f366edc857e77b8c1ccdc5297d82cc41 (patch)
tree88d38b52e80319dbd4a0c5b5e038d92f1105110a /src/glsl/ast_function.cpp
parentab130400cf91ab471e265e58193c95f04c7aeeda (diff)
parentb3d2ec9942303d1d03e28a25b030eb060415abfb (diff)
Merge remote branch 'origin/master' into pipe-video
Conflicts: src/gallium/drivers/r600/r600_pipe.c src/gallium/drivers/r600/r600_texture.c
Diffstat (limited to 'src/glsl/ast_function.cpp')
-rw-r--r--src/glsl/ast_function.cpp75
1 files changed, 46 insertions, 29 deletions
diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 1e66033348c..6ecf779c935 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -93,13 +93,40 @@ prototype_string(const glsl_type *return_type, const char *name,
static ir_rvalue *
-process_call(exec_list *instructions, ir_function *f,
- YYLTYPE *loc, exec_list *actual_parameters,
- struct _mesa_glsl_parse_state *state)
+match_function_by_name(exec_list *instructions, const char *name,
+ YYLTYPE *loc, exec_list *actual_parameters,
+ struct _mesa_glsl_parse_state *state)
{
void *ctx = state;
+ ir_function *f = state->symbols->get_function(name);
+ ir_function_signature *sig;
+
+ sig = f ? f->matching_signature(actual_parameters) : NULL;
+
+ /* FINISHME: This doesn't handle the case where shader X contains a
+ * FINISHME: matching signature but shader X + N contains an _exact_
+ * FINISHME: matching signature.
+ */
+ if (sig == NULL && (f == NULL || state->es_shader || !f->has_user_signature()) && state->symbols->get_type(name) == NULL && (state->language_version == 110 || state->symbols->get_variable(name) == NULL)) {
+ /* The current shader doesn't contain a matching function or signature.
+ * Before giving up, look for the prototype in the built-in functions.
+ */
+ for (unsigned i = 0; i < state->num_builtins_to_link; i++) {
+ ir_function *builtin;
+ builtin = state->builtins_to_link[i]->symbols->get_function(name);
+ sig = builtin ? builtin->matching_signature(actual_parameters) : NULL;
+ if (sig != NULL) {
+ if (f == NULL) {
+ f = new(ctx) ir_function(name);
+ state->symbols->add_global_function(f);
+ emit_function(state, instructions, f);
+ }
- ir_function_signature *sig = f->matching_signature(actual_parameters);
+ f->add_signature(sig->clone_prototype(f, NULL));
+ break;
+ }
+ }
+ }
if (sig != NULL) {
/* Verify that 'out' and 'inout' actual parameters are lvalues. This
@@ -164,45 +191,35 @@ process_call(exec_list *instructions, ir_function *f,
return NULL;
}
} else {
- char *str = prototype_string(NULL, f->name, actual_parameters);
+ char *str = prototype_string(NULL, name, actual_parameters);
_mesa_glsl_error(loc, state, "no matching function for call to `%s'",
str);
talloc_free(str);
const char *prefix = "candidates are: ";
- foreach_list (node, &f->signatures) {
- ir_function_signature *sig = (ir_function_signature *) node;
- str = prototype_string(sig->return_type, f->name, &sig->parameters);
- _mesa_glsl_error(loc, state, "%s%s\n", prefix, str);
- talloc_free(str);
+ for (int i = -1; i < state->num_builtins_to_link; i++) {
+ glsl_symbol_table *syms = i >= 0 ? state->builtins_to_link[i]->symbols
+ : state->symbols;
+ f = syms->get_function(name);
+ if (f == NULL)
+ continue;
- prefix = " ";
- }
+ foreach_list (node, &f->signatures) {
+ ir_function_signature *sig = (ir_function_signature *) node;
- return ir_call::get_error_instruction(ctx);
- }
-}
+ str = prototype_string(sig->return_type, f->name, &sig->parameters);
+ _mesa_glsl_error(loc, state, "%s%s\n", prefix, str);
+ talloc_free(str);
+ prefix = " ";
+ }
-static ir_rvalue *
-match_function_by_name(exec_list *instructions, const char *name,
- YYLTYPE *loc, exec_list *actual_parameters,
- struct _mesa_glsl_parse_state *state)
-{
- void *ctx = state;
- ir_function *f = state->symbols->get_function(name);
+ }
- if (f == NULL) {
- _mesa_glsl_error(loc, state, "function `%s' undeclared", name);
return ir_call::get_error_instruction(ctx);
}
-
- /* Once we've determined that the function being called might exist, try
- * to find an overload of the function that matches the parameters.
- */
- return process_call(instructions, f, loc, actual_parameters, state);
}