Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 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 "main/simple_list.h" |
| 26 | #include "ir.h" |
| 27 | #include "glsl_types.h" |
| 28 | |
| 29 | ir_instruction::ir_instruction(int mode) |
| 30 | { |
| 31 | this->mode = mode; |
| 32 | make_empty_list(this); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | ir_assignment::ir_assignment(ir_instruction *lhs, ir_instruction *rhs, |
| 37 | ir_expression *condition) |
| 38 | : ir_instruction(ir_op_assign) |
| 39 | { |
| 40 | this->lhs = (ir_dereference *) lhs; |
| 41 | this->rhs = rhs; |
| 42 | this->condition = condition; |
| 43 | } |
| 44 | |
| 45 | |
| 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) |
| 49 | { |
| 50 | this->type = type; |
| 51 | this->operation = ir_expression_operation(op); |
| 52 | this->operands[0] = op0; |
| 53 | this->operands[1] = op1; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | ir_label::ir_label(const char *label) |
| 58 | : ir_instruction(ir_op_label), label(label) |
| 59 | { |
| 60 | /* empty */ |
| 61 | } |
| 62 | |
| 63 | |
| 64 | ir_constant::ir_constant(const struct glsl_type *type, const void *data) |
| 65 | : ir_instruction(ir_op_constant) |
| 66 | { |
| 67 | const unsigned elements = |
| 68 | ((type->vector_elements == 0) ? 1 : type->vector_elements) |
| 69 | * ((type->matrix_rows == 0) ? 1 : type->matrix_rows); |
| 70 | unsigned size = 0; |
| 71 | |
| 72 | this->type = type; |
| 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; |
| 78 | default: |
| 79 | /* FINISHME: What to do? Exceptions are not the answer. |
| 80 | */ |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | memcpy(& this->value, data, size * elements); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | ir_dereference::ir_dereference(ir_instruction *var) |
| 89 | : ir_instruction(ir_op_dereference) |
| 90 | { |
| 91 | this->mode = ir_reference_variable; |
| 92 | this->var = var; |
| 93 | this->type = (var != NULL) ? var->type : glsl_error_type; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | ir_variable::ir_variable(const struct glsl_type *type, const char *name) |
| 98 | : ir_instruction(ir_op_var_decl) |
| 99 | { |
| 100 | this->type = type; |
| 101 | this->name = name; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | ir_function_signature::ir_function_signature(void) |
| 106 | : ir_instruction(ir_op_func_sig) |
| 107 | { |
| 108 | make_empty_list(& parameters); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | ir_function::ir_function(void) |
| 113 | : ir_instruction(ir_op_func) |
| 114 | { |
| 115 | make_empty_list(& signatures); |
| 116 | } |