Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ir.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. ir_instruction::ir_instruction(int mode)
  29. {
  30. this->mode = mode;
  31. make_empty_list(this);
  32. }
  33. ir_assignment::ir_assignment(ir_instruction *lhs, ir_instruction *rhs,
  34. ir_expression *condition)
  35. : ir_instruction(ir_op_assign)
  36. {
  37. this->lhs = (ir_dereference *) lhs;
  38. this->rhs = rhs;
  39. this->condition = condition;
  40. }
  41. ir_expression::ir_expression(int op, const struct glsl_type *type,
  42. ir_instruction *op0, ir_instruction *op1)
  43. : ir_instruction(ir_op_expression)
  44. {
  45. this->type = type;
  46. this->operation = ir_expression_operation(op);
  47. this->operands[0] = op0;
  48. this->operands[1] = op1;
  49. }
  50. ir_label::ir_label(const char *label)
  51. : ir_instruction(ir_op_label), label(label)
  52. {
  53. /* empty */
  54. }
  55. ir_constant::ir_constant(const struct glsl_type *type, const void *data)
  56. : ir_instruction(ir_op_constant)
  57. {
  58. const unsigned elements =
  59. ((type->vector_elements == 0) ? 1 : type->vector_elements)
  60. * ((type->matrix_rows == 0) ? 1 : type->matrix_rows);
  61. unsigned size = 0;
  62. this->type = type;
  63. switch (type->base_type) {
  64. case GLSL_TYPE_UINT: size = sizeof(this->value.u[0]); break;
  65. case GLSL_TYPE_INT: size = sizeof(this->value.i[0]); break;
  66. case GLSL_TYPE_FLOAT: size = sizeof(this->value.f[0]); break;
  67. case GLSL_TYPE_BOOL: size = sizeof(this->value.b[0]); break;
  68. default:
  69. /* FINISHME: What to do? Exceptions are not the answer.
  70. */
  71. break;
  72. }
  73. memcpy(& this->value, data, size * elements);
  74. }
  75. ir_dereference::ir_dereference(ir_instruction *var)
  76. : ir_instruction(ir_op_dereference)
  77. {
  78. this->mode = ir_reference_variable;
  79. this->var = var;
  80. this->type = (var != NULL) ? var->type : glsl_error_type;
  81. }
  82. ir_variable::ir_variable(const struct glsl_type *type, const char *name)
  83. : ir_instruction(ir_op_var_decl), read_only(false), centroid(false),
  84. invariant(false), mode(ir_var_auto), interpolation(ir_var_smooth)
  85. {
  86. this->type = type;
  87. this->name = name;
  88. }
  89. ir_function_signature::ir_function_signature(void)
  90. : ir_instruction(ir_op_func_sig)
  91. {
  92. /* empty */
  93. }
  94. ir_function::ir_function(void)
  95. : ir_instruction(ir_op_func)
  96. {
  97. /* empty */
  98. }