Clone of mesa.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

slang_assemble_assignment.c 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Mesa 3-D graphics library
  3. * Version: 6.5
  4. *
  5. * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  21. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * \file slang_assemble_assignment.c
  26. * slang assignment expressions assembler
  27. * \author Michal Krol
  28. */
  29. #include "imports.h"
  30. #include "slang_assemble.h"
  31. #include "slang_storage.h"
  32. /*
  33. * _slang_assemble_assignment()
  34. *
  35. * Copies values on the stack (<component 0> to <component N-1>) to a memory
  36. * location pointed by <addr of variable>.
  37. *
  38. * in:
  39. * +------------------+
  40. * | addr of variable |
  41. * +------------------+
  42. * | component N-1 |
  43. * | ... |
  44. * | component 0 |
  45. * +------------------+
  46. *
  47. * out:
  48. * +------------------+
  49. * | addr of variable |
  50. * +------------------+
  51. */
  52. static GLboolean assign_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,
  53. GLuint *index, GLuint size)
  54. {
  55. GLuint i;
  56. for (i = 0; i < agg->count; i++)
  57. {
  58. const slang_storage_array *arr = &agg->arrays[i];
  59. GLuint j;
  60. for (j = 0; j < arr->length; j++)
  61. {
  62. if (arr->type == slang_stor_aggregate)
  63. {
  64. if (!assign_aggregate (A, arr->aggregate, index, size))
  65. return GL_FALSE;
  66. }
  67. else
  68. {
  69. GLuint dst_addr_loc, dst_offset;
  70. slang_assembly_type ty;
  71. /* calculate the distance from top of the stack to the destination address */
  72. dst_addr_loc = size - *index;
  73. /* calculate the offset within destination variable to write */
  74. if (A->swz.num_components != 0)
  75. {
  76. /* swizzle the index to get the actual offset */
  77. dst_offset = A->swz.swizzle[*index / 4] * 4;
  78. }
  79. else
  80. {
  81. /* no swizzling - write sequentially */
  82. dst_offset = *index;
  83. }
  84. switch (arr->type)
  85. {
  86. case slang_stor_bool:
  87. ty = slang_asm_bool_copy;
  88. break;
  89. case slang_stor_int:
  90. ty = slang_asm_int_copy;
  91. break;
  92. case slang_stor_float:
  93. ty = slang_asm_float_copy;
  94. break;
  95. default:
  96. break;
  97. }
  98. if (!slang_assembly_file_push_label2 (A->file, ty, dst_addr_loc, dst_offset))
  99. return GL_FALSE;
  100. *index += 4;
  101. }
  102. }
  103. }
  104. return GL_TRUE;
  105. }
  106. GLboolean _slang_assemble_assignment (slang_assemble_ctx *A, slang_operation *op)
  107. {
  108. slang_assembly_typeinfo ti;
  109. GLboolean result = GL_FALSE;
  110. slang_storage_aggregate agg;
  111. GLuint index, size;
  112. if (!slang_assembly_typeinfo_construct (&ti))
  113. return GL_FALSE;
  114. if (!_slang_typeof_operation (A, op, &ti))
  115. goto end1;
  116. if (!slang_storage_aggregate_construct (&agg))
  117. goto end1;
  118. if (!_slang_aggregate_variable (&agg, &ti.spec, 0, A->space.funcs, A->space.structs,
  119. A->space.vars, A->mach, A->file, A->atoms))
  120. goto end;
  121. index = 0;
  122. size = _slang_sizeof_aggregate (&agg);
  123. result = assign_aggregate (A, &agg, &index, size);
  124. end1:
  125. slang_storage_aggregate_destruct (&agg);
  126. end:
  127. slang_assembly_typeinfo_destruct (&ti);
  128. return result;
  129. }
  130. /*
  131. * _slang_assemble_assign()
  132. *
  133. * Performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's
  134. * children.
  135. */
  136. GLboolean _slang_assemble_assign (slang_assemble_ctx *A, slang_operation *op, const char *oper,
  137. slang_ref_type ref)
  138. {
  139. slang_swizzle swz;
  140. if (ref == slang_ref_forbid)
  141. {
  142. if (!slang_assembly_file_push_label2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
  143. return GL_FALSE;
  144. }
  145. if (slang_string_compare ("=", oper) == 0)
  146. {
  147. if (!_slang_assemble_operation (A, &op->children[0], slang_ref_force))
  148. return GL_FALSE;
  149. swz = A->swz;
  150. if (!_slang_assemble_operation (A, &op->children[1], slang_ref_forbid))
  151. return GL_FALSE;
  152. A->swz = swz;
  153. if (!_slang_assemble_assignment (A, op->children))
  154. return GL_FALSE;
  155. }
  156. else
  157. {
  158. if (!_slang_assemble_function_call_name (A, oper, op->children, op->num_children, GL_TRUE))
  159. return GL_FALSE;
  160. }
  161. if (ref == slang_ref_forbid)
  162. {
  163. if (!slang_assembly_file_push (A->file, slang_asm_addr_copy))
  164. return GL_FALSE;
  165. if (!slang_assembly_file_push_label (A->file, slang_asm_local_free, 4))
  166. return GL_FALSE;
  167. if (!_slang_dereference (A, op->children))
  168. return GL_FALSE;
  169. }
  170. return GL_TRUE;
  171. }