[Mesa-dev] [PATCH 05/14] glsl: Add IR builder support for function calls.
Francisco Jerez
currojerez at riseup.net
Tue Oct 1 19:15:35 PDT 2013
---
src/glsl/ir_builder.cpp | 25 +++++++++++++++++++++++++
src/glsl/ir_builder.h | 8 ++++++++
2 files changed, 33 insertions(+)
diff --git a/src/glsl/ir_builder.cpp b/src/glsl/ir_builder.cpp
index 98b4322..1913c72 100644
--- a/src/glsl/ir_builder.cpp
+++ b/src/glsl/ir_builder.cpp
@@ -21,6 +21,7 @@
* IN THE SOFTWARE.
*/
+#include <stdarg.h>
#include "ir_builder.h"
#include "program/prog_instruction.h"
@@ -535,4 +536,28 @@ if_tree(operand condition,
return result;
}
+ir_call *
+call(ir_function *f, ir_variable *ret, int num_params, ...)
+{
+ void *ctx = ralloc_parent(f);
+ exec_list actual_parameters;
+ va_list ap;
+
+ va_start(ap, num_params);
+ for (int i = 0; i < num_params; ++i)
+ actual_parameters.push_tail(va_arg(ap, operand).val);
+ va_end(ap);
+
+ ir_function_signature *sig =
+ f->exact_matching_signature(NULL, &actual_parameters);
+ if (!sig)
+ return NULL;
+
+ ir_dereference_variable *deref =
+ (sig->return_type->is_void() ? NULL :
+ new(ctx) ir_dereference_variable(ret));
+
+ return new(ctx) ir_call(sig, deref, &actual_parameters);
+}
+
} /* namespace ir_builder */
diff --git a/src/glsl/ir_builder.h b/src/glsl/ir_builder.h
index 6a5f771..80b4b2c 100644
--- a/src/glsl/ir_builder.h
+++ b/src/glsl/ir_builder.h
@@ -210,4 +210,12 @@ ir_if *if_tree(operand condition,
ir_instruction *then_branch,
ir_instruction *else_branch);
+/**
+ * Call function \param f with \param num_params parameters which are
+ * passed as a variable number of \c operand type arguments. \param
+ * ret should point to the ir_variable that will hold the function
+ * return value, or be \c NULL if the function has void return type.
+ */
+ir_call *call(ir_function *f, ir_variable *ret, int num_params, ...);
+
} /* namespace ir_builder */
--
1.8.3.4
More information about the mesa-dev
mailing list