glsl2: Use i2b and f2b IR opcodes for casting int or float to bool
[mesa.git] / src / glsl / ast_function.cpp
1 /*
2 * Copyright © 2010 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "glsl_symbol_table.h"
25 #include "ast.h"
26 #include "glsl_types.h"
27 #include "ir.h"
28
29 static unsigned
30 process_parameters(exec_list *instructions, exec_list *actual_parameters,
31 exec_list *parameters,
32 struct _mesa_glsl_parse_state *state)
33 {
34 unsigned count = 0;
35
36 foreach_list (n, parameters) {
37 ast_node *const ast = exec_node_data(ast_node, n, link);
38 ir_rvalue *result = ast->hir(instructions, state);
39
40 ir_constant *const constant = result->constant_expression_value();
41 if (constant != NULL)
42 result = constant;
43
44 actual_parameters->push_tail(result);
45 count++;
46 }
47
48 return count;
49 }
50
51
52 static ir_rvalue *
53 process_call(exec_list *instructions, ir_function *f,
54 YYLTYPE *loc, exec_list *actual_parameters,
55 struct _mesa_glsl_parse_state *state)
56 {
57 void *ctx = talloc_parent(state);
58
59 const ir_function_signature *sig =
60 f->matching_signature(actual_parameters);
61
62 /* The instructions param will be used when the FINISHMEs below are done */
63 (void) instructions;
64
65 if (sig != NULL) {
66 /* Verify that 'out' and 'inout' actual parameters are lvalues. This
67 * isn't done in ir_function::matching_signature because that function
68 * cannot generate the necessary diagnostics.
69 */
70 exec_list_iterator actual_iter = actual_parameters->iterator();
71 exec_list_iterator formal_iter = sig->parameters.iterator();
72
73 while (actual_iter.has_next()) {
74 ir_rvalue *actual = (ir_rvalue *) actual_iter.get();
75 ir_variable *formal = (ir_variable *) formal_iter.get();
76
77 assert(actual != NULL);
78 assert(formal != NULL);
79
80 if ((formal->mode == ir_var_out)
81 || (formal->mode == ir_var_inout)) {
82 if (! actual->is_lvalue()) {
83 /* FINISHME: Log a better diagnostic here. There is no way
84 * FINISHME: to tell the user which parameter is invalid.
85 */
86 _mesa_glsl_error(loc, state, "`%s' parameter is not lvalue",
87 (formal->mode == ir_var_out) ? "out" : "inout");
88 }
89 }
90
91 actual_iter.next();
92 formal_iter.next();
93 }
94
95 /* FINISHME: The list of actual parameters needs to be modified to
96 * FINISHME: include any necessary conversions.
97 */
98 return new(ctx) ir_call(sig, actual_parameters);
99 } else {
100 /* FINISHME: Log a better error message here. G++ will show the types
101 * FINISHME: of the actual parameters and the set of candidate
102 * FINISHME: functions. A different error should also be logged when
103 * FINISHME: multiple functions match.
104 */
105 _mesa_glsl_error(loc, state, "no matching function for call to `%s'",
106 f->name);
107 return ir_call::get_error_instruction(ctx);
108 }
109 }
110
111
112 static ir_rvalue *
113 match_function_by_name(exec_list *instructions, const char *name,
114 YYLTYPE *loc, exec_list *actual_parameters,
115 struct _mesa_glsl_parse_state *state)
116 {
117 void *ctx = talloc_parent(state);
118 ir_function *f = state->symbols->get_function(name);
119
120 if (f == NULL) {
121 _mesa_glsl_error(loc, state, "function `%s' undeclared", name);
122 return ir_call::get_error_instruction(ctx);
123 }
124
125 /* Once we've determined that the function being called might exist, try
126 * to find an overload of the function that matches the parameters.
127 */
128 return process_call(instructions, f, loc, actual_parameters, state);
129 }
130
131
132 /**
133 * Perform automatic type conversion of constructor parameters
134 */
135 static ir_rvalue *
136 convert_component(ir_rvalue *src, const glsl_type *desired_type)
137 {
138 void *ctx = talloc_parent(src);
139 const unsigned a = desired_type->base_type;
140 const unsigned b = src->type->base_type;
141 ir_expression *result = NULL;
142
143 if (src->type->is_error())
144 return src;
145
146 assert(a <= GLSL_TYPE_BOOL);
147 assert(b <= GLSL_TYPE_BOOL);
148
149 if ((a == b) || (src->type->is_integer() && desired_type->is_integer()))
150 return src;
151
152 switch (a) {
153 case GLSL_TYPE_UINT:
154 case GLSL_TYPE_INT:
155 if (b == GLSL_TYPE_FLOAT)
156 result = new(ctx) ir_expression(ir_unop_f2i, desired_type, src, NULL);
157 else {
158 assert(b == GLSL_TYPE_BOOL);
159 result = new(ctx) ir_expression(ir_unop_b2i, desired_type, src, NULL);
160 }
161 break;
162 case GLSL_TYPE_FLOAT:
163 switch (b) {
164 case GLSL_TYPE_UINT:
165 result = new(ctx) ir_expression(ir_unop_u2f, desired_type, src, NULL);
166 break;
167 case GLSL_TYPE_INT:
168 result = new(ctx) ir_expression(ir_unop_i2f, desired_type, src, NULL);
169 break;
170 case GLSL_TYPE_BOOL:
171 result = new(ctx) ir_expression(ir_unop_b2f, desired_type, src, NULL);
172 break;
173 }
174 break;
175 case GLSL_TYPE_BOOL:
176 switch (b) {
177 case GLSL_TYPE_UINT:
178 case GLSL_TYPE_INT:
179 result = new(ctx) ir_expression(ir_unop_i2b, desired_type, src, NULL);
180 break;
181 case GLSL_TYPE_FLOAT:
182 result = new(ctx) ir_expression(ir_unop_f2b, desired_type, src, NULL);
183 break;
184 }
185 break;
186 }
187
188 assert(result != NULL);
189
190 ir_constant *const constant = result->constant_expression_value();
191 return (constant != NULL) ? (ir_rvalue *) constant : (ir_rvalue *) result;
192 }
193
194
195 /**
196 * Dereference a specific component from a scalar, vector, or matrix
197 */
198 static ir_rvalue *
199 dereference_component(ir_rvalue *src, unsigned component)
200 {
201 void *ctx = talloc_parent(src);
202 assert(component < src->type->components());
203
204 /* If the source is a constant, just create a new constant instead of a
205 * dereference of the existing constant.
206 */
207 ir_constant *constant = src->as_constant();
208 if (constant)
209 return new(ctx) ir_constant(constant, component);
210
211 if (src->type->is_scalar()) {
212 return src;
213 } else if (src->type->is_vector()) {
214 return new(ctx) ir_swizzle(src, component, 0, 0, 0, 1);
215 } else {
216 assert(src->type->is_matrix());
217
218 /* Dereference a row of the matrix, then call this function again to get
219 * a specific element from that row.
220 */
221 const int c = component / src->type->column_type()->vector_elements;
222 const int r = component % src->type->column_type()->vector_elements;
223 ir_constant *const col_index = new(ctx) ir_constant(c);
224 ir_dereference *const col = new(ctx) ir_dereference_array(src, col_index);
225
226 col->type = src->type->column_type();
227
228 return dereference_component(col, r);
229 }
230
231 assert(!"Should not get here.");
232 return NULL;
233 }
234
235
236 static ir_rvalue *
237 process_array_constructor(exec_list *instructions,
238 const glsl_type *constructor_type,
239 YYLTYPE *loc, exec_list *parameters,
240 struct _mesa_glsl_parse_state *state)
241 {
242 void *ctx = talloc_parent(state);
243 /* Array constructors come in two forms: sized and unsized. Sized array
244 * constructors look like 'vec4[2](a, b)', where 'a' and 'b' are vec4
245 * variables. In this case the number of parameters must exactly match the
246 * specified size of the array.
247 *
248 * Unsized array constructors look like 'vec4[](a, b)', where 'a' and 'b'
249 * are vec4 variables. In this case the size of the array being constructed
250 * is determined by the number of parameters.
251 *
252 * From page 52 (page 58 of the PDF) of the GLSL 1.50 spec:
253 *
254 * "There must be exactly the same number of arguments as the size of
255 * the array being constructed. If no size is present in the
256 * constructor, then the array is explicitly sized to the number of
257 * arguments provided. The arguments are assigned in order, starting at
258 * element 0, to the elements of the constructed array. Each argument
259 * must be the same type as the element type of the array, or be a type
260 * that can be converted to the element type of the array according to
261 * Section 4.1.10 "Implicit Conversions.""
262 */
263 exec_list actual_parameters;
264 const unsigned parameter_count =
265 process_parameters(instructions, &actual_parameters, parameters, state);
266
267 if ((parameter_count == 0)
268 || ((constructor_type->length != 0)
269 && (constructor_type->length != parameter_count))) {
270 const unsigned min_param = (constructor_type->length == 0)
271 ? 1 : constructor_type->length;
272
273 _mesa_glsl_error(loc, state, "array constructor must have %s %u "
274 "parameter%s",
275 (constructor_type->length != 0) ? "at least" : "exactly",
276 min_param, (min_param <= 1) ? "" : "s");
277 return ir_call::get_error_instruction(ctx);
278 }
279
280 if (constructor_type->length == 0) {
281 constructor_type =
282 glsl_type::get_array_instance(state,
283 constructor_type->element_type(),
284 parameter_count);
285 assert(constructor_type != NULL);
286 assert(constructor_type->length == parameter_count);
287 }
288
289 ir_function *f = state->symbols->get_function(constructor_type->name);
290
291 /* If the constructor for this type of array does not exist, generate the
292 * prototype and add it to the symbol table.
293 */
294 if (f == NULL) {
295 f = constructor_type->generate_constructor(state->symbols);
296 }
297
298 ir_rvalue *const r =
299 process_call(instructions, f, loc, &actual_parameters, state);
300
301 assert(r != NULL);
302 assert(r->type->is_error() || (r->type == constructor_type));
303
304 return r;
305 }
306
307
308 /**
309 * Try to convert a record constructor to a constant expression
310 */
311 static ir_constant *
312 constant_record_constructor(const glsl_type *constructor_type,
313 YYLTYPE *loc, exec_list *parameters,
314 struct _mesa_glsl_parse_state *state)
315 {
316 void *ctx = talloc_parent(state);
317 bool all_parameters_are_constant = true;
318
319 exec_node *node = parameters->head;
320 for (unsigned i = 0; i < constructor_type->length; i++) {
321 ir_instruction *ir = (ir_instruction *) node;
322
323 if (node->is_tail_sentinal()) {
324 _mesa_glsl_error(loc, state,
325 "insufficient parameters to constructor for `%s'",
326 constructor_type->name);
327 return NULL;
328 }
329
330 if (ir->type != constructor_type->fields.structure[i].type) {
331 _mesa_glsl_error(loc, state,
332 "parameter type mismatch in constructor for `%s' "
333 " (%s vs %s)",
334 constructor_type->name,
335 ir->type->name,
336 constructor_type->fields.structure[i].type->name);
337 return NULL;
338 }
339
340 if (ir->as_constant() == NULL)
341 all_parameters_are_constant = false;
342
343 node = node->next;
344 }
345
346 if (!all_parameters_are_constant)
347 return NULL;
348
349 return new(ctx) ir_constant(constructor_type, parameters);
350 }
351
352
353 /**
354 * Generate data for a constant matrix constructor w/a single scalar parameter
355 *
356 * Matrix constructors in GLSL can be passed a single scalar of the
357 * approriate type. In these cases, the resulting matrix is the identity
358 * matrix multipled by the specified scalar. This function generates data for
359 * that matrix.
360 *
361 * \param type Type of the desired matrix.
362 * \param initializer Scalar value used to initialize the matrix diagonal.
363 * \param data Location to store the resulting matrix.
364 */
365 void
366 generate_constructor_matrix(const glsl_type *type, ir_constant *initializer,
367 ir_constant_data *data)
368 {
369 switch (type->base_type) {
370 case GLSL_TYPE_UINT:
371 case GLSL_TYPE_INT:
372 for (unsigned i = 0; i < type->components(); i++)
373 data->u[i] = 0;
374
375 for (unsigned i = 0; i < type->matrix_columns; i++) {
376 /* The array offset of the ith row and column of the matrix.
377 */
378 const unsigned idx = (i * type->vector_elements) + i;
379
380 data->u[idx] = initializer->value.u[0];
381 }
382 break;
383
384 case GLSL_TYPE_FLOAT:
385 for (unsigned i = 0; i < type->components(); i++)
386 data->f[i] = 0;
387
388 for (unsigned i = 0; i < type->matrix_columns; i++) {
389 /* The array offset of the ith row and column of the matrix.
390 */
391 const unsigned idx = (i * type->vector_elements) + i;
392
393 data->f[idx] = initializer->value.f[0];
394 }
395
396 break;
397
398 default:
399 assert(!"Should not get here.");
400 break;
401 }
402 }
403
404
405 /**
406 * Generate data for a constant vector constructor w/a single scalar parameter
407 *
408 * Vector constructors in GLSL can be passed a single scalar of the
409 * approriate type. In these cases, the resulting vector contains the specified
410 * value in all components. This function generates data for that vector.
411 *
412 * \param type Type of the desired vector.
413 * \param initializer Scalar value used to initialize the vector.
414 * \param data Location to store the resulting vector data.
415 */
416 void
417 generate_constructor_vector(const glsl_type *type, ir_constant *initializer,
418 ir_constant_data *data)
419 {
420 switch (type->base_type) {
421 case GLSL_TYPE_UINT:
422 case GLSL_TYPE_INT:
423 for (unsigned i = 0; i < type->components(); i++)
424 data->u[i] = initializer->value.u[0];
425
426 break;
427
428 case GLSL_TYPE_FLOAT:
429 for (unsigned i = 0; i < type->components(); i++)
430 data->f[i] = initializer->value.f[0];
431
432 break;
433
434 case GLSL_TYPE_BOOL:
435 for (unsigned i = 0; i < type->components(); i++)
436 data->b[i] = initializer->value.b[0];
437
438 break;
439
440 default:
441 assert(!"Should not get here.");
442 break;
443 }
444 }
445
446
447 ir_rvalue *
448 ast_function_expression::hir(exec_list *instructions,
449 struct _mesa_glsl_parse_state *state)
450 {
451 void *ctx = talloc_parent(state);
452 /* There are three sorts of function calls.
453 *
454 * 1. contstructors - The first subexpression is an ast_type_specifier.
455 * 2. methods - Only the .length() method of array types.
456 * 3. functions - Calls to regular old functions.
457 *
458 * Method calls are actually detected when the ast_field_selection
459 * expression is handled.
460 */
461 if (is_constructor()) {
462 const ast_type_specifier *type = (ast_type_specifier *) subexpressions[0];
463 YYLTYPE loc = type->get_location();
464 const char *name;
465
466 const glsl_type *const constructor_type = type->glsl_type(& name, state);
467
468
469 /* Constructors for samplers are illegal.
470 */
471 if (constructor_type->is_sampler()) {
472 _mesa_glsl_error(& loc, state, "cannot construct sampler type `%s'",
473 constructor_type->name);
474 return ir_call::get_error_instruction(ctx);
475 }
476
477 if (constructor_type->is_array()) {
478 if (state->language_version <= 110) {
479 _mesa_glsl_error(& loc, state,
480 "array constructors forbidden in GLSL 1.10");
481 return ir_call::get_error_instruction(ctx);
482 }
483
484 return process_array_constructor(instructions, constructor_type,
485 & loc, &this->expressions, state);
486 }
487
488 /* There are two kinds of constructor call. Constructors for built-in
489 * language types, such as mat4 and vec2, are free form. The only
490 * requirement is that the parameters must provide enough values of the
491 * correct scalar type. Constructors for arrays and structures must
492 * have the exact number of parameters with matching types in the
493 * correct order. These constructors follow essentially the same type
494 * matching rules as functions.
495 */
496 if (constructor_type->is_numeric() || constructor_type->is_boolean()) {
497 /* Constructing a numeric type has a couple steps. First all values
498 * passed to the constructor are broken into individual parameters
499 * and type converted to the base type of the thing being constructed.
500 *
501 * At that point we have some number of values that match the base
502 * type of the thing being constructed. Now the constructor can be
503 * treated like a function call. Each numeric type has a small set
504 * of constructor functions. The set of new parameters will either
505 * match one of those functions or the original constructor is
506 * invalid.
507 */
508 const glsl_type *const base_type = constructor_type->get_base_type();
509
510 /* Total number of components of the type being constructed.
511 */
512 const unsigned type_components = constructor_type->components();
513
514 /* Number of components from parameters that have actually been
515 * consumed. This is used to perform several kinds of error checking.
516 */
517 unsigned components_used = 0;
518
519 unsigned matrix_parameters = 0;
520 unsigned nonmatrix_parameters = 0;
521 exec_list actual_parameters;
522
523 bool all_parameters_are_constant = true;
524
525 /* This handles invalid constructor calls such as 'vec4 v = vec4();'
526 */
527 if (this->expressions.is_empty()) {
528 _mesa_glsl_error(& loc, state, "too few components to construct "
529 "`%s'",
530 constructor_type->name);
531 return ir_call::get_error_instruction(ctx);
532 }
533
534 foreach_list (n, &this->expressions) {
535 ast_node *ast = exec_node_data(ast_node, n, link);
536 ir_rvalue *result =
537 ast->hir(instructions, state)->as_rvalue();
538 ir_variable *result_var = NULL;
539
540 /* Attempt to convert the parameter to a constant valued expression.
541 * After doing so, track whether or not all the parameters to the
542 * constructor are trivially constant valued expressions.
543 */
544 ir_rvalue *const constant =
545 result->constant_expression_value();
546
547 if (constant != NULL)
548 result = constant;
549 else
550 all_parameters_are_constant = false;
551
552 /* From page 50 (page 56 of the PDF) of the GLSL 1.50 spec:
553 *
554 * "It is an error to provide extra arguments beyond this
555 * last used argument."
556 */
557 if (components_used >= type_components) {
558 _mesa_glsl_error(& loc, state, "too many parameters to `%s' "
559 "constructor",
560 constructor_type->name);
561 return ir_call::get_error_instruction(ctx);
562 }
563
564 if (!result->type->is_numeric() && !result->type->is_boolean()) {
565 _mesa_glsl_error(& loc, state, "cannot construct `%s' from a "
566 "non-numeric data type",
567 constructor_type->name);
568 return ir_call::get_error_instruction(ctx);
569 }
570
571 /* Count the number of matrix and nonmatrix parameters. This
572 * is used below to enforce some of the constructor rules.
573 */
574 if (result->type->is_matrix())
575 matrix_parameters++;
576 else
577 nonmatrix_parameters++;
578
579 /* We can't use the same instruction node in the multiple
580 * swizzle dereferences that happen, so assign it to a
581 * variable and deref that. Plus it saves computation for
582 * complicated expressions and handles
583 * glsl-vs-constructor-call.shader_test.
584 */
585 if (result->type->components() >= 1 && !result->as_constant()) {
586 result_var = new(ctx) ir_variable(result->type,
587 "constructor_tmp");
588 ir_dereference_variable *lhs;
589
590 lhs = new(ctx) ir_dereference_variable(result_var);
591 instructions->push_tail(new(ctx) ir_assignment(lhs,
592 result, NULL));
593 }
594
595 /* Process each of the components of the parameter. Dereference
596 * each component individually, perform any type conversions, and
597 * add it to the parameter list for the constructor.
598 */
599 for (unsigned i = 0; i < result->type->components(); i++) {
600 if (components_used >= type_components)
601 break;
602
603 ir_rvalue *component;
604
605 if (result_var) {
606 ir_dereference *d = new(ctx) ir_dereference_variable(result_var);
607 component = dereference_component(d, i);
608 } else {
609 component = dereference_component(result, i);
610 }
611 component = convert_component(component, base_type);
612
613 /* All cases that could result in component->type being the
614 * error type should have already been caught above.
615 */
616 assert(component->type == base_type);
617
618 if (component->as_constant() == NULL)
619 all_parameters_are_constant = false;
620
621 /* Don't actually generate constructor calls for scalars.
622 * Instead, do the usual component selection and conversion,
623 * and return the single component.
624 */
625 if (constructor_type->is_scalar())
626 return component;
627
628 actual_parameters.push_tail(component);
629 components_used++;
630 }
631 }
632
633 /* From page 28 (page 34 of the PDF) of the GLSL 1.10 spec:
634 *
635 * "It is an error to construct matrices from other matrices. This
636 * is reserved for future use."
637 */
638 if ((state->language_version <= 110) && (matrix_parameters > 0)
639 && constructor_type->is_matrix()) {
640 _mesa_glsl_error(& loc, state, "cannot construct `%s' from a "
641 "matrix in GLSL 1.10",
642 constructor_type->name);
643 return ir_call::get_error_instruction(ctx);
644 }
645
646 /* From page 50 (page 56 of the PDF) of the GLSL 1.50 spec:
647 *
648 * "If a matrix argument is given to a matrix constructor, it is
649 * an error to have any other arguments."
650 */
651 if ((matrix_parameters > 0)
652 && ((matrix_parameters + nonmatrix_parameters) > 1)
653 && constructor_type->is_matrix()) {
654 _mesa_glsl_error(& loc, state, "for matrix `%s' constructor, "
655 "matrix must be only parameter",
656 constructor_type->name);
657 return ir_call::get_error_instruction(ctx);
658 }
659
660 /* From page 28 (page 34 of the PDF) of the GLSL 1.10 spec:
661 *
662 * "In these cases, there must be enough components provided in the
663 * arguments to provide an initializer for every component in the
664 * constructed value."
665 */
666 if ((components_used < type_components) && (components_used != 1)) {
667 _mesa_glsl_error(& loc, state, "too few components to construct "
668 "`%s'",
669 constructor_type->name);
670 return ir_call::get_error_instruction(ctx);
671 }
672
673 ir_function *f = state->symbols->get_function(constructor_type->name);
674 if (f == NULL) {
675 _mesa_glsl_error(& loc, state, "no constructor for type `%s'",
676 constructor_type->name);
677 return ir_call::get_error_instruction(ctx);
678 }
679
680 const ir_function_signature *sig =
681 f->matching_signature(& actual_parameters);
682 if (sig != NULL) {
683 /* If all of the parameters are trivially constant, create a
684 * constant representing the complete collection of parameters.
685 */
686 if (all_parameters_are_constant) {
687 if (components_used >= type_components)
688 return new(ctx) ir_constant(sig->return_type,
689 & actual_parameters);
690
691 assert(sig->return_type->is_vector()
692 || sig->return_type->is_matrix());
693
694 /* Constructors with exactly one component are special for
695 * vectors and matrices. For vectors it causes all elements of
696 * the vector to be filled with the value. For matrices it
697 * causes the matrix to be filled with 0 and the diagonal to be
698 * filled with the value.
699 */
700 ir_constant_data data;
701 ir_constant *const initializer =
702 (ir_constant *) actual_parameters.head;
703 if (sig->return_type->is_matrix())
704 generate_constructor_matrix(sig->return_type, initializer,
705 &data);
706 else
707 generate_constructor_vector(sig->return_type, initializer,
708 &data);
709
710 return new(ctx) ir_constant(sig->return_type, &data);
711 } else
712 return new(ctx) ir_call(sig, & actual_parameters);
713 } else {
714 /* FINISHME: Log a better error message here. G++ will show the
715 * FINSIHME: types of the actual parameters and the set of
716 * FINSIHME: candidate functions. A different error should also be
717 * FINSIHME: logged when multiple functions match.
718 */
719 _mesa_glsl_error(& loc, state, "no matching constructor for `%s'",
720 constructor_type->name);
721 return ir_call::get_error_instruction(ctx);
722 }
723 }
724
725 return ir_call::get_error_instruction(ctx);
726 } else {
727 const ast_expression *id = subexpressions[0];
728 YYLTYPE loc = id->get_location();
729 exec_list actual_parameters;
730
731 process_parameters(instructions, &actual_parameters, &this->expressions,
732 state);
733
734 const glsl_type *const type =
735 state->symbols->get_type(id->primary_expression.identifier);
736
737 if ((type != NULL) && type->is_record()) {
738 ir_constant *constant =
739 constant_record_constructor(type, &loc, &actual_parameters, state);
740
741 if (constant != NULL)
742 return constant;
743 }
744
745 return match_function_by_name(instructions,
746 id->primary_expression.identifier, & loc,
747 &actual_parameters, state);
748 }
749
750 return ir_call::get_error_instruction(ctx);
751 }