2 * Copyright © 2010 Intel Corporation
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:
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
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.
24 #include "main/imports.h"
25 #include "main/simple_list.h"
27 #include "glsl_types.h"
29 ir_assignment::ir_assignment(ir_instruction
*lhs
, ir_instruction
*rhs
,
30 ir_expression
*condition
)
31 : ir_instruction(ir_op_assign
)
33 this->lhs
= (ir_dereference
*) lhs
;
35 this->condition
= condition
;
39 ir_expression::ir_expression(int op
, const struct glsl_type
*type
,
40 ir_instruction
*op0
, ir_instruction
*op1
)
41 : ir_instruction(ir_op_expression
)
44 this->operation
= ir_expression_operation(op
);
45 this->operands
[0] = op0
;
46 this->operands
[1] = op1
;
50 ir_label::ir_label(const char *label
)
51 : ir_instruction(ir_op_label
), label(label
)
57 ir_constant::ir_constant(const struct glsl_type
*type
, const void *data
)
58 : ir_instruction(ir_op_constant
)
60 const unsigned elements
=
61 ((type
->vector_elements
== 0) ? 1 : type
->vector_elements
)
62 * ((type
->matrix_rows
== 0) ? 1 : type
->matrix_rows
);
66 switch (type
->base_type
) {
67 case GLSL_TYPE_UINT
: size
= sizeof(this->value
.u
[0]); break;
68 case GLSL_TYPE_INT
: size
= sizeof(this->value
.i
[0]); break;
69 case GLSL_TYPE_FLOAT
: size
= sizeof(this->value
.f
[0]); break;
70 case GLSL_TYPE_BOOL
: size
= sizeof(this->value
.b
[0]); break;
72 /* FINISHME: What to do? Exceptions are not the answer.
77 memcpy(& this->value
, data
, size
* elements
);
81 ir_dereference::ir_dereference(ir_instruction
*var
)
82 : ir_instruction(ir_op_dereference
)
84 this->mode
= ir_reference_variable
;
86 this->type
= (var
!= NULL
) ? var
->type
: glsl_error_type
;
91 ir_dereference::set_swizzle(unsigned x
, unsigned y
, unsigned z
, unsigned w
,
94 assert((count
>= 1) && (count
<= 4));
96 const unsigned dup_mask
= 0
97 | ((count
> 1) ? ((1U << y
) & ((1U << x
) )) : 0)
98 | ((count
> 2) ? ((1U << z
) & ((1U << x
) | (1U << y
) )) : 0)
99 | ((count
> 3) ? ((1U << w
) & ((1U << x
) | (1U << y
) | (1U << z
))) : 0);
106 selector
.swizzle
.x
= x
;
107 selector
.swizzle
.y
= y
;
108 selector
.swizzle
.z
= z
;
109 selector
.swizzle
.w
= w
;
110 selector
.swizzle
.num_components
= count
;
111 selector
.swizzle
.has_duplicates
= dup_mask
!= 0;
116 ir_variable::ir_variable(const struct glsl_type
*type
, const char *name
)
117 : ir_instruction(ir_op_var_decl
), read_only(false), centroid(false),
118 invariant(false), mode(ir_var_auto
), interpolation(ir_var_smooth
)
125 ir_function_signature::ir_function_signature(const glsl_type
*return_type
)
126 : ir_instruction(ir_op_func_sig
), return_type(return_type
), definition(NULL
)
132 ir_function::ir_function(const char *name
)
133 : ir_instruction(ir_op_func
), name(name
)
140 ir_call::get_error_instruction()
142 ir_call
*call
= new ir_call
;
144 call
->type
= glsl_error_type
;