ir_constant_expression: Add support for ir_unop_ceil.
[mesa.git] / src / glsl / ir.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 #include <string.h>
24 #include "main/imports.h"
25 #include "ir.h"
26 #include "ir_visitor.h"
27 #include "glsl_types.h"
28
29 ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs,
30 ir_rvalue *condition)
31 {
32 this->lhs = lhs;
33 this->rhs = rhs;
34 this->condition = condition;
35 }
36
37
38 ir_expression::ir_expression(int op, const struct glsl_type *type,
39 ir_rvalue *op0, ir_rvalue *op1)
40 {
41 this->type = type;
42 this->operation = ir_expression_operation(op);
43 this->operands[0] = op0;
44 this->operands[1] = op1;
45 }
46
47 unsigned int
48 ir_expression::get_num_operands(ir_expression_operation op)
49 {
50 /* Update ir_print_visitor.cpp when updating this list. */
51 const int num_operands[] = {
52 1, /* ir_unop_bit_not */
53 1, /* ir_unop_logic_not */
54 1, /* ir_unop_neg */
55 1, /* ir_unop_abs */
56 1, /* ir_unop_sign */
57 1, /* ir_unop_rcp */
58 1, /* ir_unop_rsq */
59 1, /* ir_unop_sqrt */
60 1, /* ir_unop_exp */
61 1, /* ir_unop_log */
62 1, /* ir_unop_exp2 */
63 1, /* ir_unop_log2 */
64 1, /* ir_unop_f2i */
65 1, /* ir_unop_i2f */
66 1, /* ir_unop_f2b */
67 1, /* ir_unop_b2f */
68 1, /* ir_unop_i2b */
69 1, /* ir_unop_b2i */
70 1, /* ir_unop_u2f */
71
72 1, /* ir_unop_trunc */
73 1, /* ir_unop_ceil */
74 1, /* ir_unop_floor */
75 1, /* ir_unop_fract */
76
77 1, /* ir_unop_sin */
78 1, /* ir_unop_cos */
79
80 1, /* ir_unop_dFdx */
81 1, /* ir_unop_dFdy */
82
83 2, /* ir_binop_add */
84 2, /* ir_binop_sub */
85 2, /* ir_binop_mul */
86 2, /* ir_binop_div */
87 2, /* ir_binop_mod */
88
89 2, /* ir_binop_less */
90 2, /* ir_binop_greater */
91 2, /* ir_binop_lequal */
92 2, /* ir_binop_gequal */
93 2, /* ir_binop_equal */
94 2, /* ir_binop_nequal */
95
96 2, /* ir_binop_lshift */
97 2, /* ir_binop_rshift */
98 2, /* ir_binop_bit_and */
99 2, /* ir_binop_bit_xor */
100 2, /* ir_binop_bit_or */
101
102 2, /* ir_binop_logic_and */
103 2, /* ir_binop_logic_xor */
104 2, /* ir_binop_logic_or */
105
106 2, /* ir_binop_dot */
107 2, /* ir_binop_min */
108 2, /* ir_binop_max */
109
110 2, /* ir_binop_pow */
111 };
112
113 assert(sizeof(num_operands) / sizeof(num_operands[0]) == ir_binop_pow + 1);
114
115 return num_operands[op];
116 }
117
118 static const char *const operator_strs[] = {
119 "~",
120 "!",
121 "neg",
122 "abs",
123 "sign",
124 "rcp",
125 "rsq",
126 "sqrt",
127 "exp",
128 "log",
129 "exp2",
130 "log2",
131 "f2i",
132 "i2f",
133 "f2b",
134 "b2f",
135 "i2b",
136 "b2i",
137 "u2f",
138 "trunc",
139 "ceil",
140 "floor",
141 "fract",
142 "sin",
143 "cos",
144 "dFdx",
145 "dFdy",
146 "+",
147 "-",
148 "*",
149 "/",
150 "%",
151 "<",
152 ">",
153 "<=",
154 ">=",
155 "==",
156 "!=",
157 "<<",
158 ">>",
159 "&",
160 "^",
161 "|",
162 "&&",
163 "^^",
164 "||",
165 "dot",
166 "min",
167 "max",
168 "pow",
169 };
170
171 const char *ir_expression::operator_string()
172 {
173 assert((unsigned int) operation <=
174 sizeof(operator_strs) / sizeof(operator_strs[0]));
175 return operator_strs[operation];
176 }
177
178 ir_expression_operation
179 ir_expression::get_operator(const char *str)
180 {
181 const int operator_count = sizeof(operator_strs) / sizeof(operator_strs[0]);
182 for (int op = 0; op < operator_count; op++) {
183 if (strcmp(str, operator_strs[op]) == 0)
184 return (ir_expression_operation) op;
185 }
186 return (ir_expression_operation) -1;
187 }
188
189 ir_constant::ir_constant()
190 {
191 /* empty */
192 }
193
194 ir_constant::ir_constant(const struct glsl_type *type,
195 const ir_constant_data *data)
196 {
197 assert((type->base_type >= GLSL_TYPE_UINT)
198 && (type->base_type <= GLSL_TYPE_BOOL));
199
200 this->type = type;
201 memcpy(& this->value, data, sizeof(this->value));
202 }
203
204 ir_constant::ir_constant(float f)
205 {
206 this->type = glsl_type::float_type;
207 this->value.f[0] = f;
208 }
209
210 ir_constant::ir_constant(unsigned int u)
211 {
212 this->type = glsl_type::uint_type;
213 this->value.u[0] = u;
214 }
215
216 ir_constant::ir_constant(int i)
217 {
218 this->type = glsl_type::int_type;
219 this->value.i[0] = i;
220 }
221
222 ir_constant::ir_constant(bool b)
223 {
224 this->type = glsl_type::bool_type;
225 this->value.b[0] = b;
226 }
227
228 ir_constant::ir_constant(const ir_constant *c, unsigned i)
229 {
230 this->type = c->type->get_base_type();
231
232 switch (this->type->base_type) {
233 case GLSL_TYPE_UINT: this->value.u[0] = c->value.u[i]; break;
234 case GLSL_TYPE_INT: this->value.i[0] = c->value.i[i]; break;
235 case GLSL_TYPE_FLOAT: this->value.f[0] = c->value.f[i]; break;
236 case GLSL_TYPE_BOOL: this->value.b[0] = c->value.b[i]; break;
237 default: assert(!"Should not get here."); break;
238 }
239 }
240
241 ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
242 {
243 this->type = type;
244
245 /* FINISHME: Support array types. */
246 assert(type->is_scalar() || type->is_vector() || type->is_matrix()
247 || type->is_record());
248
249 /* If the constant is a record, the types of each of the entries in
250 * value_list must be a 1-for-1 match with the structure components. Each
251 * entry must also be a constant. Just move the nodes from the value_list
252 * to the list in the ir_constant.
253 */
254 /* FINISHME: Should there be some type checking and / or assertions here? */
255 /* FINISHME: Should the new constant take ownership of the nodes from
256 * FINISHME: value_list, or should it make copies?
257 */
258 if (type->is_record()) {
259 value_list->move_nodes_to(& this->components);
260 return;
261 }
262
263
264 ir_constant *value = (ir_constant *) (value_list->head);
265
266 /* Use each component from each entry in the value_list to initialize one
267 * component of the constant being constructed.
268 */
269 for (unsigned i = 0; i < type->components(); /* empty */) {
270 assert(value->as_constant() != NULL);
271 assert(!value->is_tail_sentinal());
272
273 for (unsigned j = 0; j < value->type->components(); j++) {
274 switch (type->base_type) {
275 case GLSL_TYPE_UINT:
276 this->value.u[i] = value->get_uint_component(j);
277 break;
278 case GLSL_TYPE_INT:
279 this->value.i[i] = value->get_int_component(j);
280 break;
281 case GLSL_TYPE_FLOAT:
282 this->value.f[i] = value->get_float_component(j);
283 break;
284 case GLSL_TYPE_BOOL:
285 this->value.b[i] = value->get_bool_component(j);
286 break;
287 default:
288 /* FINISHME: What to do? Exceptions are not the answer.
289 */
290 break;
291 }
292
293 i++;
294 if (i >= type->components())
295 break;
296 }
297
298 value = (ir_constant *) value->next;
299 }
300 }
301
302 bool
303 ir_constant::get_bool_component(unsigned i) const
304 {
305 switch (this->type->base_type) {
306 case GLSL_TYPE_UINT: return this->value.u[i] != 0;
307 case GLSL_TYPE_INT: return this->value.i[i] != 0;
308 case GLSL_TYPE_FLOAT: return ((int)this->value.f[i]) != 0;
309 case GLSL_TYPE_BOOL: return this->value.b[i];
310 default: assert(!"Should not get here."); break;
311 }
312
313 /* Must return something to make the compiler happy. This is clearly an
314 * error case.
315 */
316 return false;
317 }
318
319 float
320 ir_constant::get_float_component(unsigned i) const
321 {
322 switch (this->type->base_type) {
323 case GLSL_TYPE_UINT: return (float) this->value.u[i];
324 case GLSL_TYPE_INT: return (float) this->value.i[i];
325 case GLSL_TYPE_FLOAT: return this->value.f[i];
326 case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0 : 0.0;
327 default: assert(!"Should not get here."); break;
328 }
329
330 /* Must return something to make the compiler happy. This is clearly an
331 * error case.
332 */
333 return 0.0;
334 }
335
336 int
337 ir_constant::get_int_component(unsigned i) const
338 {
339 switch (this->type->base_type) {
340 case GLSL_TYPE_UINT: return this->value.u[i];
341 case GLSL_TYPE_INT: return this->value.i[i];
342 case GLSL_TYPE_FLOAT: return (int) this->value.f[i];
343 case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
344 default: assert(!"Should not get here."); break;
345 }
346
347 /* Must return something to make the compiler happy. This is clearly an
348 * error case.
349 */
350 return 0;
351 }
352
353 unsigned
354 ir_constant::get_uint_component(unsigned i) const
355 {
356 switch (this->type->base_type) {
357 case GLSL_TYPE_UINT: return this->value.u[i];
358 case GLSL_TYPE_INT: return this->value.i[i];
359 case GLSL_TYPE_FLOAT: return (unsigned) this->value.f[i];
360 case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
361 default: assert(!"Should not get here."); break;
362 }
363
364 /* Must return something to make the compiler happy. This is clearly an
365 * error case.
366 */
367 return 0;
368 }
369
370
371 ir_constant *
372 ir_constant::get_record_field(const char *name)
373 {
374 int idx = this->type->field_index(name);
375
376 if (idx < 0)
377 return NULL;
378
379 if (this->components.is_empty())
380 return NULL;
381
382 exec_node *node = this->components.head;
383 for (int i = 0; i < idx; i++) {
384 node = node->next;
385
386 /* If the end of the list is encountered before the element matching the
387 * requested field is found, return NULL.
388 */
389 if (node->is_tail_sentinal())
390 return NULL;
391 }
392
393 return (ir_constant *) node;
394 }
395
396
397 bool
398 ir_constant::has_value(const ir_constant *c) const
399 {
400 if (this->type != c->type)
401 return false;
402
403 /* FINISHME: This will probably also handle constant arrays as soon as those
404 * FINISHME: are supported.
405 */
406 if (this->type->base_type == GLSL_TYPE_STRUCT) {
407 const exec_node *a_node = this->components.head;
408 const exec_node *b_node = c->components.head;
409
410 while (!a_node->is_tail_sentinal()) {
411 assert(!b_node->is_tail_sentinal());
412
413 const ir_constant *const a_field = (ir_constant *) a_node;
414 const ir_constant *const b_field = (ir_constant *) b_node;
415
416 if (!a_field->has_value(b_field))
417 return false;
418
419 a_node = a_node->next;
420 b_node = b_node->next;
421 }
422
423 return true;
424 }
425
426 for (unsigned i = 0; i < this->type->components(); i++) {
427 switch (this->type->base_type) {
428 case GLSL_TYPE_UINT:
429 if (this->value.u[i] != c->value.u[i])
430 return false;
431 break;
432 case GLSL_TYPE_INT:
433 if (this->value.i[i] != c->value.i[i])
434 return false;
435 break;
436 case GLSL_TYPE_FLOAT:
437 if (this->value.f[i] != c->value.f[i])
438 return false;
439 break;
440 case GLSL_TYPE_BOOL:
441 if (this->value.b[i] != c->value.b[i])
442 return false;
443 break;
444 default:
445 assert(!"Should not get here.");
446 return false;
447 }
448 }
449
450 return true;
451 }
452
453 ir_dereference_variable::ir_dereference_variable(ir_variable *var)
454 {
455 this->var = var;
456 this->type = (var != NULL) ? var->type : glsl_type::error_type;
457 }
458
459
460 ir_dereference_array::ir_dereference_array(ir_rvalue *value,
461 ir_rvalue *array_index)
462 {
463 this->array_index = array_index;
464 this->set_array(value);
465 }
466
467
468 ir_dereference_array::ir_dereference_array(ir_variable *var,
469 ir_rvalue *array_index)
470 {
471 void *ctx = talloc_parent(var);
472
473 this->array_index = array_index;
474 this->set_array(new(ctx) ir_dereference_variable(var));
475 }
476
477
478 void
479 ir_dereference_array::set_array(ir_rvalue *value)
480 {
481 this->array = value;
482 this->type = glsl_type::error_type;
483
484 if (this->array != NULL) {
485 const glsl_type *const vt = this->array->type;
486
487 if (vt->is_array()) {
488 type = vt->element_type();
489 } else if (vt->is_matrix()) {
490 type = vt->column_type();
491 } else if (vt->is_vector()) {
492 type = vt->get_base_type();
493 }
494 }
495 }
496
497
498 ir_dereference_record::ir_dereference_record(ir_rvalue *value,
499 const char *field)
500 {
501 this->record = value;
502 this->field = field;
503 this->type = (this->record != NULL)
504 ? this->record->type->field_type(field) : glsl_type::error_type;
505 }
506
507
508 ir_dereference_record::ir_dereference_record(ir_variable *var,
509 const char *field)
510 {
511 void *ctx = talloc_parent(var);
512
513 this->record = new(ctx) ir_dereference_variable(var);
514 this->field = field;
515 this->type = (this->record != NULL)
516 ? this->record->type->field_type(field) : glsl_type::error_type;
517 }
518
519
520 bool
521 ir_dereference::is_lvalue()
522 {
523 ir_variable *var = this->variable_referenced();
524
525 /* Every l-value derference chain eventually ends in a variable.
526 */
527 if ((var == NULL) || var->read_only)
528 return false;
529
530 if (this->type->is_array() && !var->array_lvalue)
531 return false;
532
533 return true;
534 }
535
536
537 const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf" };
538
539 const char *ir_texture::opcode_string()
540 {
541 assert((unsigned int) op <=
542 sizeof(tex_opcode_strs) / sizeof(tex_opcode_strs[0]));
543 return tex_opcode_strs[op];
544 }
545
546 ir_texture_opcode
547 ir_texture::get_opcode(const char *str)
548 {
549 const int count = sizeof(tex_opcode_strs) / sizeof(tex_opcode_strs[0]);
550 for (int op = 0; op < count; op++) {
551 if (strcmp(str, tex_opcode_strs[op]) == 0)
552 return (ir_texture_opcode) op;
553 }
554 return (ir_texture_opcode) -1;
555 }
556
557
558 void
559 ir_texture::set_sampler(ir_dereference *sampler)
560 {
561 assert(sampler != NULL);
562 this->sampler = sampler;
563
564 switch (sampler->type->sampler_type) {
565 case GLSL_TYPE_FLOAT:
566 this->type = glsl_type::vec4_type;
567 break;
568 case GLSL_TYPE_INT:
569 this->type = glsl_type::ivec4_type;
570 break;
571 case GLSL_TYPE_UINT:
572 this->type = glsl_type::uvec4_type;
573 break;
574 }
575 }
576
577
578 void
579 ir_swizzle::init_mask(const unsigned *comp, unsigned count)
580 {
581 assert((count >= 1) && (count <= 4));
582
583 memset(&this->mask, 0, sizeof(this->mask));
584 this->mask.num_components = count;
585
586 unsigned dup_mask = 0;
587 switch (count) {
588 case 4:
589 assert(comp[3] <= 3);
590 dup_mask |= (1U << comp[3])
591 & ((1U << comp[0]) | (1U << comp[1]) | (1U << comp[2]));
592 this->mask.w = comp[3];
593
594 case 3:
595 assert(comp[2] <= 3);
596 dup_mask |= (1U << comp[2])
597 & ((1U << comp[0]) | (1U << comp[1]));
598 this->mask.z = comp[2];
599
600 case 2:
601 assert(comp[1] <= 3);
602 dup_mask |= (1U << comp[1])
603 & ((1U << comp[0]));
604 this->mask.y = comp[1];
605
606 case 1:
607 assert(comp[0] <= 3);
608 this->mask.x = comp[0];
609 }
610
611 this->mask.has_duplicates = dup_mask != 0;
612
613 /* Based on the number of elements in the swizzle and the base type
614 * (i.e., float, int, unsigned, or bool) of the vector being swizzled,
615 * generate the type of the resulting value.
616 */
617 type = glsl_type::get_instance(val->type->base_type, mask.num_components, 1);
618 }
619
620 ir_swizzle::ir_swizzle(ir_rvalue *val, unsigned x, unsigned y, unsigned z,
621 unsigned w, unsigned count)
622 : val(val)
623 {
624 const unsigned components[4] = { x, y, z, w };
625 this->init_mask(components, count);
626 }
627
628 ir_swizzle::ir_swizzle(ir_rvalue *val, const unsigned *comp,
629 unsigned count)
630 : val(val)
631 {
632 this->init_mask(comp, count);
633 }
634
635 ir_swizzle::ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask)
636 {
637 this->val = val;
638 this->mask = mask;
639 this->type = glsl_type::get_instance(val->type->base_type,
640 mask.num_components, 1);
641 }
642
643 #define X 1
644 #define R 5
645 #define S 9
646 #define I 13
647
648 ir_swizzle *
649 ir_swizzle::create(ir_rvalue *val, const char *str, unsigned vector_length)
650 {
651 void *ctx = talloc_parent(val);
652
653 /* For each possible swizzle character, this table encodes the value in
654 * \c idx_map that represents the 0th element of the vector. For invalid
655 * swizzle characters (e.g., 'k'), a special value is used that will allow
656 * detection of errors.
657 */
658 static const unsigned char base_idx[26] = {
659 /* a b c d e f g h i j k l m */
660 R, R, I, I, I, I, R, I, I, I, I, I, I,
661 /* n o p q r s t u v w x y z */
662 I, I, S, S, R, S, S, I, I, X, X, X, X
663 };
664
665 /* Each valid swizzle character has an entry in the previous table. This
666 * table encodes the base index encoded in the previous table plus the actual
667 * index of the swizzle character. When processing swizzles, the first
668 * character in the string is indexed in the previous table. Each character
669 * in the string is indexed in this table, and the value found there has the
670 * value form the first table subtracted. The result must be on the range
671 * [0,3].
672 *
673 * For example, the string "wzyx" will get X from the first table. Each of
674 * the charcaters will get X+3, X+2, X+1, and X+0 from this table. After
675 * subtraction, the swizzle values are { 3, 2, 1, 0 }.
676 *
677 * The string "wzrg" will get X from the first table. Each of the characters
678 * will get X+3, X+2, R+0, and R+1 from this table. After subtraction, the
679 * swizzle values are { 3, 2, 4, 5 }. Since 4 and 5 are outside the range
680 * [0,3], the error is detected.
681 */
682 static const unsigned char idx_map[26] = {
683 /* a b c d e f g h i j k l m */
684 R+3, R+2, 0, 0, 0, 0, R+1, 0, 0, 0, 0, 0, 0,
685 /* n o p q r s t u v w x y z */
686 0, 0, S+2, S+3, R+0, S+0, S+1, 0, 0, X+3, X+0, X+1, X+2
687 };
688
689 int swiz_idx[4] = { 0, 0, 0, 0 };
690 unsigned i;
691
692
693 /* Validate the first character in the swizzle string and look up the base
694 * index value as described above.
695 */
696 if ((str[0] < 'a') || (str[0] > 'z'))
697 return NULL;
698
699 const unsigned base = base_idx[str[0] - 'a'];
700
701
702 for (i = 0; (i < 4) && (str[i] != '\0'); i++) {
703 /* Validate the next character, and, as described above, convert it to a
704 * swizzle index.
705 */
706 if ((str[i] < 'a') || (str[i] > 'z'))
707 return NULL;
708
709 swiz_idx[i] = idx_map[str[i] - 'a'] - base;
710 if ((swiz_idx[i] < 0) || (swiz_idx[i] >= (int) vector_length))
711 return NULL;
712 }
713
714 if (str[i] != '\0')
715 return NULL;
716
717 return new(ctx) ir_swizzle(val, swiz_idx[0], swiz_idx[1], swiz_idx[2],
718 swiz_idx[3], i);
719 }
720
721 #undef X
722 #undef R
723 #undef S
724 #undef I
725
726 ir_variable *
727 ir_swizzle::variable_referenced()
728 {
729 return this->val->variable_referenced();
730 }
731
732 ir_variable::ir_variable(const struct glsl_type *type, const char *name)
733 : max_array_access(0), read_only(false), centroid(false), invariant(false),
734 shader_in(false), shader_out(false),
735 mode(ir_var_auto), interpolation(ir_var_smooth), array_lvalue(false)
736 {
737 this->type = type;
738 this->name = talloc_strdup(this, name);
739 this->location = -1;
740 this->warn_extension = NULL;
741 this->constant_value = NULL;
742
743 if (type && type->base_type == GLSL_TYPE_SAMPLER)
744 this->read_only = true;
745 }
746
747
748 const char *
749 ir_variable::interpolation_string() const
750 {
751 if (!this->shader_in && !this->shader_out)
752 return "";
753
754 switch (this->interpolation) {
755 case ir_var_smooth: return "smooth";
756 case ir_var_flat: return "flat";
757 case ir_var_noperspective: return "noperspective";
758 }
759
760 assert(!"Should not get here.");
761 return "";
762 }
763
764
765 unsigned
766 ir_variable::component_slots() const
767 {
768 /* FINISHME: Sparsely accessed arrays require fewer slots. */
769 return this->type->component_slots();
770 }
771
772
773 ir_function_signature::ir_function_signature(const glsl_type *return_type)
774 : return_type(return_type), is_defined(false), _function(NULL)
775 {
776 /* empty */
777 }
778
779
780 const char *
781 ir_function_signature::qualifiers_match(exec_list *params)
782 {
783 exec_list_iterator iter_a = parameters.iterator();
784 exec_list_iterator iter_b = params->iterator();
785
786 /* check that the qualifiers match. */
787 while (iter_a.has_next()) {
788 ir_variable *a = (ir_variable *)iter_a.get();
789 ir_variable *b = (ir_variable *)iter_b.get();
790
791 if (a->read_only != b->read_only ||
792 a->mode != b->mode ||
793 a->interpolation != b->interpolation ||
794 a->centroid != b->centroid) {
795
796 /* parameter a's qualifiers don't match */
797 return a->name;
798 }
799
800 iter_a.next();
801 iter_b.next();
802 }
803 return NULL;
804 }
805
806
807 void
808 ir_function_signature::replace_parameters(exec_list *new_params)
809 {
810 /* Destroy all of the previous parameter information. If the previous
811 * parameter information comes from the function prototype, it may either
812 * specify incorrect parameter names or not have names at all.
813 */
814 foreach_iter(exec_list_iterator, iter, parameters) {
815 assert(((ir_instruction *) iter.get())->as_variable() != NULL);
816
817 iter.remove();
818 }
819
820 new_params->move_nodes_to(&parameters);
821 }
822
823
824 ir_function::ir_function(const char *name)
825 {
826 this->name = talloc_strdup(this, name);
827 }
828
829
830 ir_call *
831 ir_call::get_error_instruction(void *ctx)
832 {
833 ir_call *call = new(ctx) ir_call;
834
835 call->type = glsl_type::error_type;
836 return call;
837 }
838
839 void
840 ir_call::set_callee(const ir_function_signature *sig)
841 {
842 assert((this->type == NULL) || (this->type == sig->return_type));
843
844 this->callee = sig;
845 }
846
847 void
848 visit_exec_list(exec_list *list, ir_visitor *visitor)
849 {
850 foreach_iter(exec_list_iterator, iter, *list) {
851 ((ir_instruction *)iter.get())->accept(visitor);
852 }
853 }
854