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.

hir_field_selection.cpp 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "ir.h"
  24. #include "main/imports.h"
  25. #include "symbol_table.h"
  26. #include "glsl_parser_extras.h"
  27. #include "ast.h"
  28. #include "glsl_types.h"
  29. struct ir_rvalue *
  30. _mesa_ast_field_selection_to_hir(const ast_expression *expr,
  31. exec_list *instructions,
  32. struct _mesa_glsl_parse_state *state)
  33. {
  34. ir_rvalue *result = NULL;
  35. ir_rvalue *op;
  36. op = expr->subexpressions[0]->hir(instructions, state);
  37. /* There are two kinds of field selection. There is the selection of a
  38. * specific field from a structure, and there is the selection of a
  39. * swizzle / mask from a vector. Which is which is determined entirely
  40. * by the base type of the thing to which the field selection operator is
  41. * being applied.
  42. */
  43. YYLTYPE loc = expr->get_location();
  44. if (op->type->is_error()) {
  45. /* silently propagate the error */
  46. } else if (op->type->is_vector()) {
  47. ir_swizzle *swiz = ir_swizzle::create(op,
  48. expr->primary_expression.identifier,
  49. op->type->vector_elements);
  50. if (swiz != NULL) {
  51. result = swiz;
  52. } else {
  53. /* FINISHME: Logging of error messages should be moved into
  54. * FINISHME: ir_swizzle::create. This allows the generation of more
  55. * FINISHME: specific error messages.
  56. */
  57. _mesa_glsl_error(& loc, state, "Invalid swizzle / mask `%s'",
  58. expr->primary_expression.identifier);
  59. }
  60. } else if (op->type->base_type == GLSL_TYPE_STRUCT) {
  61. result = new ir_dereference_record(op,
  62. expr->primary_expression.identifier);
  63. if (result->type->is_error()) {
  64. _mesa_glsl_error(& loc, state, "Cannot access field `%s' of "
  65. "structure",
  66. expr->primary_expression.identifier);
  67. }
  68. } else {
  69. _mesa_glsl_error(& loc, state, "Cannot access field `%s' of "
  70. "non-structure / non-vector.",
  71. expr->primary_expression.identifier);
  72. }
  73. return result ? result : ir_call::get_error_instruction();
  74. }