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_instruction::ir_instruction(int mode
)
32 make_empty_list(this);
36 ir_assignment::ir_assignment(ir_instruction
*lhs
, ir_instruction
*rhs
,
37 ir_expression
*condition
)
38 : ir_instruction(ir_op_assign
)
40 this->lhs
= (ir_dereference
*) lhs
;
42 this->condition
= condition
;
46 ir_expression::ir_expression(int op
, const struct glsl_type
*type
,
47 ir_instruction
*op0
, ir_instruction
*op1
)
48 : ir_instruction(ir_op_expression
)
51 this->operation
= ir_expression_operation(op
);
52 this->operands
[0] = op0
;
53 this->operands
[1] = op1
;
57 ir_label::ir_label(const char *label
)
58 : ir_instruction(ir_op_label
), label(label
)
64 ir_constant::ir_constant(const struct glsl_type
*type
, const void *data
)
65 : ir_instruction(ir_op_constant
)
67 const unsigned elements
=
68 ((type
->vector_elements
== 0) ? 1 : type
->vector_elements
)
69 * ((type
->matrix_rows
== 0) ? 1 : type
->matrix_rows
);
73 switch (type
->base_type
) {
74 case GLSL_TYPE_UINT
: size
= sizeof(this->value
.u
[0]); break;
75 case GLSL_TYPE_INT
: size
= sizeof(this->value
.i
[0]); break;
76 case GLSL_TYPE_FLOAT
: size
= sizeof(this->value
.f
[0]); break;
77 case GLSL_TYPE_BOOL
: size
= sizeof(this->value
.b
[0]); break;
79 /* FINISHME: What to do? Exceptions are not the answer.
84 memcpy(& this->value
, data
, size
* elements
);
88 ir_dereference::ir_dereference(ir_instruction
*var
)
89 : ir_instruction(ir_op_dereference
)
91 this->mode
= ir_reference_variable
;
93 this->type
= (var
!= NULL
) ? var
->type
: glsl_error_type
;
97 ir_variable::ir_variable(const struct glsl_type
*type
, const char *name
)
98 : ir_instruction(ir_op_var_decl
)
105 ir_function_signature::ir_function_signature(void)
106 : ir_instruction(ir_op_func_sig
)
112 ir_function::ir_function(void)
113 : ir_instruction(ir_op_func
)