diff options
Diffstat (limited to 'ast_function.cpp')
-rw-r--r-- | ast_function.cpp | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/ast_function.cpp b/ast_function.cpp index ff2dfa502f..866cbc4ecd 100644 --- a/ast_function.cpp +++ b/ast_function.cpp @@ -54,6 +54,8 @@ process_call(exec_list *instructions, ir_function *f, YYLTYPE *loc, exec_list *actual_parameters, struct _mesa_glsl_parse_state *state) { + void *ctx = talloc_parent(state); + const ir_function_signature *sig = f->matching_signature(actual_parameters); @@ -93,7 +95,7 @@ process_call(exec_list *instructions, ir_function *f, /* FINISHME: The list of actual parameters needs to be modified to * FINISHME: include any necessary conversions. */ - return new ir_call(sig, actual_parameters); + return new(ctx) ir_call(sig, actual_parameters); } else { /* FINISHME: Log a better error message here. G++ will show the types * FINISHME: of the actual parameters and the set of candidate @@ -132,6 +134,7 @@ match_function_by_name(exec_list *instructions, const char *name, static ir_rvalue * convert_component(ir_rvalue *src, const glsl_type *desired_type) { + void *ctx = talloc_parent(src); const unsigned a = desired_type->base_type; const unsigned b = src->type->base_type; ir_expression *result = NULL; @@ -149,22 +152,22 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type) case GLSL_TYPE_UINT: case GLSL_TYPE_INT: if (b == GLSL_TYPE_FLOAT) - result = new ir_expression(ir_unop_f2i, desired_type, src, NULL); + result = new(ctx) ir_expression(ir_unop_f2i, desired_type, src, NULL); else { assert(b == GLSL_TYPE_BOOL); - result = new ir_expression(ir_unop_b2i, desired_type, src, NULL); + result = new(ctx) ir_expression(ir_unop_b2i, desired_type, src, NULL); } break; case GLSL_TYPE_FLOAT: switch (b) { case GLSL_TYPE_UINT: - result = new ir_expression(ir_unop_u2f, desired_type, src, NULL); + result = new(ctx) ir_expression(ir_unop_u2f, desired_type, src, NULL); break; case GLSL_TYPE_INT: - result = new ir_expression(ir_unop_i2f, desired_type, src, NULL); + result = new(ctx) ir_expression(ir_unop_i2f, desired_type, src, NULL); break; case GLSL_TYPE_BOOL: - result = new ir_expression(ir_unop_b2f, desired_type, src, NULL); + result = new(ctx) ir_expression(ir_unop_b2f, desired_type, src, NULL); break; } break; @@ -172,12 +175,12 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type) ir_constant *zero = NULL; switch (b) { - case GLSL_TYPE_UINT: zero = new ir_constant(unsigned(0)); break; - case GLSL_TYPE_INT: zero = new ir_constant(int(0)); break; - case GLSL_TYPE_FLOAT: zero = new ir_constant(0.0f); break; + case GLSL_TYPE_UINT: zero = new(ctx) ir_constant(unsigned(0)); break; + case GLSL_TYPE_INT: zero = new(ctx) ir_constant(int(0)); break; + case GLSL_TYPE_FLOAT: zero = new(ctx) ir_constant(0.0f); break; } - result = new ir_expression(ir_binop_nequal, desired_type, src, zero); + result = new(ctx) ir_expression(ir_binop_nequal, desired_type, src, zero); } } @@ -194,6 +197,7 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type) static ir_rvalue * dereference_component(ir_rvalue *src, unsigned component) { + void *ctx = talloc_parent(src); assert(component < src->type->components()); /* If the source is a constant, just create a new constant instead of a @@ -201,12 +205,12 @@ dereference_component(ir_rvalue *src, unsigned component) */ ir_constant *constant = src->as_constant(); if (constant) - return new ir_constant(constant, component); + return new(ctx) ir_constant(constant, component); if (src->type->is_scalar()) { return src; } else if (src->type->is_vector()) { - return new ir_swizzle(src, component, 0, 0, 0, 1); + return new(ctx) ir_swizzle(src, component, 0, 0, 0, 1); } else { assert(src->type->is_matrix()); @@ -215,8 +219,8 @@ dereference_component(ir_rvalue *src, unsigned component) */ const int c = component / src->type->column_type()->vector_elements; const int r = component % src->type->column_type()->vector_elements; - ir_constant *const col_index = new ir_constant(c); - ir_dereference *const col = new ir_dereference_array(src, col_index); + ir_constant *const col_index = new(ctx) ir_constant(c); + ir_dereference *const col = new(ctx) ir_dereference_array(src, col_index); col->type = src->type->column_type(); @@ -306,6 +310,7 @@ constant_record_constructor(const glsl_type *constructor_type, YYLTYPE *loc, exec_list *parameters, struct _mesa_glsl_parse_state *state) { + void *ctx = talloc_parent(state); bool all_parameters_are_constant = true; exec_node *node = parameters->head; @@ -338,7 +343,7 @@ constant_record_constructor(const glsl_type *constructor_type, if (!all_parameters_are_constant) return NULL; - return new ir_constant(constructor_type, parameters); + return new(ctx) ir_constant(constructor_type, parameters); } @@ -440,6 +445,7 @@ ir_rvalue * ast_function_expression::hir(exec_list *instructions, struct _mesa_glsl_parse_state *state) { + void *ctx = talloc_parent(state); /* There are three sorts of function calls. * * 1. contstructors - The first subexpression is an ast_type_specifier. @@ -574,11 +580,13 @@ ast_function_expression::hir(exec_list *instructions, * glsl-vs-constructor-call.shader_test. */ if (result->type->components() >= 1 && !result->as_constant()) { - result_var = new ir_variable(result->type, "constructor_tmp"); + result_var = new(ctx) ir_variable(result->type, + "constructor_tmp"); ir_dereference_variable *lhs; - lhs = new ir_dereference_variable(result_var); - instructions->push_tail(new ir_assignment(lhs, result, NULL)); + lhs = new(ctx) ir_dereference_variable(result_var); + instructions->push_tail(new(ctx) ir_assignment(lhs, + result, NULL)); } /* Process each of the components of the parameter. Dereference @@ -592,7 +600,7 @@ ast_function_expression::hir(exec_list *instructions, ir_rvalue *component; if (result_var) { - ir_dereference *d = new ir_dereference_variable(result_var); + ir_dereference *d = new(ctx) ir_dereference_variable(result_var); component = dereference_component(d, i); } else { component = dereference_component(result, i); @@ -674,7 +682,8 @@ ast_function_expression::hir(exec_list *instructions, */ if (all_parameters_are_constant) { if (components_used >= type_components) - return new ir_constant(sig->return_type, & actual_parameters); + return new(ctx) ir_constant(sig->return_type, + & actual_parameters); assert(sig->return_type->is_vector() || sig->return_type->is_matrix()); @@ -695,9 +704,9 @@ ast_function_expression::hir(exec_list *instructions, generate_constructor_vector(sig->return_type, initializer, &data); - return new ir_constant(sig->return_type, &data); + return new(ctx) ir_constant(sig->return_type, &data); } else - return new ir_call(sig, & actual_parameters); + return new(ctx) ir_call(sig, & actual_parameters); } else { /* FINISHME: Log a better error message here. G++ will show the * FINSIHME: types of the actual parameters and the set of |