Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ir.cpp 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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 "ir.h"
  26. #include "ir_visitor.h"
  27. #include "glsl_types.h"
  28. ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs,
  29. ir_rvalue *condition)
  30. {
  31. this->lhs = lhs;
  32. this->rhs = rhs;
  33. this->condition = condition;
  34. }
  35. ir_expression::ir_expression(int op, const struct glsl_type *type,
  36. ir_rvalue *op0, ir_rvalue *op1)
  37. {
  38. this->type = type;
  39. this->operation = ir_expression_operation(op);
  40. this->operands[0] = op0;
  41. this->operands[1] = op1;
  42. }
  43. unsigned int
  44. ir_expression::get_num_operands(ir_expression_operation op)
  45. {
  46. /* Update ir_print_visitor.cpp when updating this list. */
  47. const int num_operands[] = {
  48. 1, /* ir_unop_bit_not */
  49. 1, /* ir_unop_logic_not */
  50. 1, /* ir_unop_neg */
  51. 1, /* ir_unop_abs */
  52. 1, /* ir_unop_sign */
  53. 1, /* ir_unop_rcp */
  54. 1, /* ir_unop_rsq */
  55. 1, /* ir_unop_sqrt */
  56. 1, /* ir_unop_exp */
  57. 1, /* ir_unop_log */
  58. 1, /* ir_unop_exp2 */
  59. 1, /* ir_unop_log2 */
  60. 1, /* ir_unop_f2i */
  61. 1, /* ir_unop_i2f */
  62. 1, /* ir_unop_f2b */
  63. 1, /* ir_unop_b2f */
  64. 1, /* ir_unop_i2b */
  65. 1, /* ir_unop_b2i */
  66. 1, /* ir_unop_u2f */
  67. 1, /* ir_unop_trunc */
  68. 1, /* ir_unop_ceil */
  69. 1, /* ir_unop_floor */
  70. 1, /* ir_unop_sin */
  71. 1, /* ir_unop_cos */
  72. 1, /* ir_unop_dFdx */
  73. 1, /* ir_unop_dFdy */
  74. 2, /* ir_binop_add */
  75. 2, /* ir_binop_sub */
  76. 2, /* ir_binop_mul */
  77. 2, /* ir_binop_div */
  78. 2, /* ir_binop_mod */
  79. 2, /* ir_binop_less */
  80. 2, /* ir_binop_greater */
  81. 2, /* ir_binop_lequal */
  82. 2, /* ir_binop_gequal */
  83. 2, /* ir_binop_equal */
  84. 2, /* ir_binop_nequal */
  85. 2, /* ir_binop_lshift */
  86. 2, /* ir_binop_rshift */
  87. 2, /* ir_binop_bit_and */
  88. 2, /* ir_binop_bit_xor */
  89. 2, /* ir_binop_bit_or */
  90. 2, /* ir_binop_logic_and */
  91. 2, /* ir_binop_logic_xor */
  92. 2, /* ir_binop_logic_or */
  93. 2, /* ir_binop_dot */
  94. 2, /* ir_binop_min */
  95. 2, /* ir_binop_max */
  96. 2, /* ir_binop_pow */
  97. };
  98. assert(sizeof(num_operands) / sizeof(num_operands[0]) == ir_binop_pow + 1);
  99. return num_operands[op];
  100. }
  101. static const char *const operator_strs[] = {
  102. "~",
  103. "!",
  104. "neg",
  105. "abs",
  106. "sign",
  107. "rcp",
  108. "rsq",
  109. "sqrt",
  110. "exp",
  111. "log",
  112. "exp2",
  113. "log2",
  114. "f2i",
  115. "i2f",
  116. "f2b",
  117. "b2f",
  118. "i2b",
  119. "b2i",
  120. "u2f",
  121. "trunc",
  122. "ceil",
  123. "floor",
  124. "sin",
  125. "cos",
  126. "dFdx",
  127. "dFdy",
  128. "+",
  129. "-",
  130. "*",
  131. "/",
  132. "%",
  133. "<",
  134. ">",
  135. "<=",
  136. ">=",
  137. "==",
  138. "!=",
  139. "<<",
  140. ">>",
  141. "&",
  142. "^",
  143. "|",
  144. "&&",
  145. "^^",
  146. "||",
  147. "dot",
  148. "min",
  149. "max",
  150. "pow",
  151. };
  152. const char *ir_expression::operator_string()
  153. {
  154. assert((unsigned int) operation <=
  155. sizeof(operator_strs) / sizeof(operator_strs[0]));
  156. return operator_strs[operation];
  157. }
  158. ir_expression_operation
  159. ir_expression::get_operator(const char *str)
  160. {
  161. const int operator_count = sizeof(operator_strs) / sizeof(operator_strs[0]);
  162. for (int op = 0; op < operator_count; op++) {
  163. if (strcmp(str, operator_strs[op]) == 0)
  164. return (ir_expression_operation) op;
  165. }
  166. return (ir_expression_operation) -1;
  167. }
  168. ir_constant::ir_constant()
  169. {
  170. /* empty */
  171. }
  172. ir_constant::ir_constant(const struct glsl_type *type, const void *data)
  173. {
  174. unsigned size = 0;
  175. this->type = type;
  176. switch (type->base_type) {
  177. case GLSL_TYPE_UINT: size = sizeof(this->value.u[0]); break;
  178. case GLSL_TYPE_INT: size = sizeof(this->value.i[0]); break;
  179. case GLSL_TYPE_FLOAT: size = sizeof(this->value.f[0]); break;
  180. case GLSL_TYPE_BOOL: size = sizeof(this->value.b[0]); break;
  181. default:
  182. /* FINISHME: What to do? Exceptions are not the answer.
  183. */
  184. break;
  185. }
  186. memcpy(& this->value, data, size * type->components());
  187. }
  188. ir_constant::ir_constant(float f)
  189. {
  190. this->type = glsl_type::float_type;
  191. this->value.f[0] = f;
  192. }
  193. ir_constant::ir_constant(unsigned int u)
  194. {
  195. this->type = glsl_type::uint_type;
  196. this->value.u[0] = u;
  197. }
  198. ir_constant::ir_constant(int i)
  199. {
  200. this->type = glsl_type::int_type;
  201. this->value.i[0] = i;
  202. }
  203. ir_constant::ir_constant(bool b)
  204. {
  205. this->type = glsl_type::bool_type;
  206. this->value.b[0] = b;
  207. }
  208. ir_constant::ir_constant(const ir_constant *c, unsigned i)
  209. {
  210. this->type = c->type->get_base_type();
  211. switch (this->type->base_type) {
  212. case GLSL_TYPE_UINT: this->value.u[0] = c->value.u[i]; break;
  213. case GLSL_TYPE_INT: this->value.i[0] = c->value.i[i]; break;
  214. case GLSL_TYPE_FLOAT: this->value.f[0] = c->value.f[i]; break;
  215. case GLSL_TYPE_BOOL: this->value.b[0] = c->value.b[i]; break;
  216. default: assert(!"Should not get here."); break;
  217. }
  218. }
  219. ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
  220. {
  221. this->type = type;
  222. /* FINISHME: Support array types. */
  223. assert(type->is_scalar() || type->is_vector() || type->is_matrix()
  224. || type->is_record());
  225. /* If the constant is a record, the types of each of the entries in
  226. * value_list must be a 1-for-1 match with the structure components. Each
  227. * entry must also be a constant. Just move the nodes from the value_list
  228. * to the list in the ir_constant.
  229. */
  230. /* FINISHME: Should there be some type checking and / or assertions here? */
  231. /* FINISHME: Should the new constant take ownership of the nodes from
  232. * FINISHME: value_list, or should it make copies?
  233. */
  234. if (type->is_record()) {
  235. value_list->move_nodes_to(& this->components);
  236. return;
  237. }
  238. ir_constant *value = (ir_constant *) (value_list->head);
  239. /* Use each component from each entry in the value_list to initialize one
  240. * component of the constant being constructed.
  241. */
  242. for (unsigned i = 0; i < type->components(); /* empty */) {
  243. assert(value->as_constant() != NULL);
  244. assert(!value->is_tail_sentinal());
  245. for (unsigned j = 0; j < value->type->components(); j++) {
  246. switch (type->base_type) {
  247. case GLSL_TYPE_UINT:
  248. this->value.u[i] = value->get_uint_component(j);
  249. break;
  250. case GLSL_TYPE_INT:
  251. this->value.i[i] = value->get_int_component(j);
  252. break;
  253. case GLSL_TYPE_FLOAT:
  254. this->value.f[i] = value->get_float_component(j);
  255. break;
  256. case GLSL_TYPE_BOOL:
  257. this->value.b[i] = value->get_bool_component(j);
  258. break;
  259. default:
  260. /* FINISHME: What to do? Exceptions are not the answer.
  261. */
  262. break;
  263. }
  264. i++;
  265. if (i >= type->components())
  266. break;
  267. }
  268. value = (ir_constant *) value->next;
  269. }
  270. }
  271. ir_constant *
  272. ir_constant::clone()
  273. {
  274. switch (this->type->base_type) {
  275. case GLSL_TYPE_UINT:
  276. case GLSL_TYPE_INT:
  277. case GLSL_TYPE_FLOAT:
  278. case GLSL_TYPE_BOOL:
  279. return new ir_constant(this->type, &this->value);
  280. case GLSL_TYPE_STRUCT: {
  281. ir_constant *c = new ir_constant;
  282. c->type = this->type;
  283. for (exec_node *node = this->components.head
  284. ; !node->is_tail_sentinal()
  285. ; node = node->next) {
  286. ir_constant *const orig = (ir_constant *) node;
  287. c->components.push_tail(orig->clone());
  288. }
  289. return c;
  290. }
  291. default:
  292. assert(!"Should not get here."); break;
  293. return NULL;
  294. }
  295. }
  296. bool
  297. ir_constant::get_bool_component(unsigned i) const
  298. {
  299. switch (this->type->base_type) {
  300. case GLSL_TYPE_UINT: return this->value.u[i] != 0;
  301. case GLSL_TYPE_INT: return this->value.i[i] != 0;
  302. case GLSL_TYPE_FLOAT: return ((int)this->value.f[i]) != 0;
  303. case GLSL_TYPE_BOOL: return this->value.b[i];
  304. default: assert(!"Should not get here."); break;
  305. }
  306. /* Must return something to make the compiler happy. This is clearly an
  307. * error case.
  308. */
  309. return false;
  310. }
  311. float
  312. ir_constant::get_float_component(unsigned i) const
  313. {
  314. switch (this->type->base_type) {
  315. case GLSL_TYPE_UINT: return (float) this->value.u[i];
  316. case GLSL_TYPE_INT: return (float) this->value.i[i];
  317. case GLSL_TYPE_FLOAT: return this->value.f[i];
  318. case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0 : 0.0;
  319. default: assert(!"Should not get here."); break;
  320. }
  321. /* Must return something to make the compiler happy. This is clearly an
  322. * error case.
  323. */
  324. return 0.0;
  325. }
  326. int
  327. ir_constant::get_int_component(unsigned i) const
  328. {
  329. switch (this->type->base_type) {
  330. case GLSL_TYPE_UINT: return this->value.u[i];
  331. case GLSL_TYPE_INT: return this->value.i[i];
  332. case GLSL_TYPE_FLOAT: return (int) this->value.f[i];
  333. case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
  334. default: assert(!"Should not get here."); break;
  335. }
  336. /* Must return something to make the compiler happy. This is clearly an
  337. * error case.
  338. */
  339. return 0;
  340. }
  341. unsigned
  342. ir_constant::get_uint_component(unsigned i) const
  343. {
  344. switch (this->type->base_type) {
  345. case GLSL_TYPE_UINT: return this->value.u[i];
  346. case GLSL_TYPE_INT: return this->value.i[i];
  347. case GLSL_TYPE_FLOAT: return (unsigned) this->value.f[i];
  348. case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
  349. default: assert(!"Should not get here."); break;
  350. }
  351. /* Must return something to make the compiler happy. This is clearly an
  352. * error case.
  353. */
  354. return 0;
  355. }
  356. ir_constant *
  357. ir_constant::get_record_field(const char *name)
  358. {
  359. int idx = this->type->field_index(name);
  360. if (idx < 0)
  361. return NULL;
  362. if (this->components.is_empty())
  363. return NULL;
  364. exec_node *node = this->components.head;
  365. for (int i = 0; i < idx; i++) {
  366. node = node->next;
  367. /* If the end of the list is encountered before the element matching the
  368. * requested field is found, return NULL.
  369. */
  370. if (node->is_tail_sentinal())
  371. return NULL;
  372. }
  373. return (ir_constant *) node;
  374. }
  375. ir_dereference_variable::ir_dereference_variable(ir_variable *var)
  376. {
  377. this->var = var;
  378. this->type = (var != NULL) ? var->type : glsl_type::error_type;
  379. }
  380. ir_dereference_array::ir_dereference_array(ir_rvalue *value,
  381. ir_rvalue *array_index)
  382. {
  383. this->array_index = array_index;
  384. this->set_array(value);
  385. }
  386. ir_dereference_array::ir_dereference_array(ir_variable *var,
  387. ir_rvalue *array_index)
  388. {
  389. this->array_index = array_index;
  390. this->set_array(new ir_dereference_variable(var));
  391. }
  392. void
  393. ir_dereference_array::set_array(ir_rvalue *value)
  394. {
  395. this->array = value;
  396. this->type = glsl_type::error_type;
  397. if (this->array != NULL) {
  398. const glsl_type *const vt = this->array->type;
  399. if (vt->is_array()) {
  400. type = vt->element_type();
  401. } else if (vt->is_matrix()) {
  402. type = vt->column_type();
  403. } else if (vt->is_vector()) {
  404. type = vt->get_base_type();
  405. }
  406. }
  407. }
  408. ir_dereference_record::ir_dereference_record(ir_rvalue *value,
  409. const char *field)
  410. {
  411. this->record = value;
  412. this->field = field;
  413. this->type = (this->record != NULL)
  414. ? this->record->type->field_type(field) : glsl_type::error_type;
  415. }
  416. ir_dereference_record::ir_dereference_record(ir_variable *var,
  417. const char *field)
  418. {
  419. this->record = new ir_dereference_variable(var);
  420. this->field = field;
  421. this->type = (this->record != NULL)
  422. ? this->record->type->field_type(field) : glsl_type::error_type;
  423. }
  424. bool
  425. ir_dereference::is_lvalue()
  426. {
  427. ir_variable *var = this->variable_referenced();
  428. /* Every l-value derference chain eventually ends in a variable.
  429. */
  430. if ((var == NULL) || var->read_only)
  431. return false;
  432. if (this->type->is_array() && !var->array_lvalue)
  433. return false;
  434. return true;
  435. }
  436. const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf" };
  437. const char *ir_texture::opcode_string()
  438. {
  439. assert((unsigned int) op <=
  440. sizeof(tex_opcode_strs) / sizeof(tex_opcode_strs[0]));
  441. return tex_opcode_strs[op];
  442. }
  443. ir_texture_opcode
  444. ir_texture::get_opcode(const char *str)
  445. {
  446. const int count = sizeof(tex_opcode_strs) / sizeof(tex_opcode_strs[0]);
  447. for (int op = 0; op < count; op++) {
  448. if (strcmp(str, tex_opcode_strs[op]) == 0)
  449. return (ir_texture_opcode) op;
  450. }
  451. return (ir_texture_opcode) -1;
  452. }
  453. void
  454. ir_texture::set_sampler(ir_dereference *sampler)
  455. {
  456. assert(sampler != NULL);
  457. this->sampler = sampler;
  458. switch (sampler->type->sampler_type) {
  459. case GLSL_TYPE_FLOAT:
  460. this->type = glsl_type::vec4_type;
  461. break;
  462. case GLSL_TYPE_INT:
  463. this->type = glsl_type::ivec4_type;
  464. break;
  465. case GLSL_TYPE_UINT:
  466. this->type = glsl_type::uvec4_type;
  467. break;
  468. }
  469. }
  470. ir_swizzle::ir_swizzle(ir_rvalue *val, unsigned x, unsigned y, unsigned z,
  471. unsigned w, unsigned count)
  472. : val(val)
  473. {
  474. assert((count >= 1) && (count <= 4));
  475. const unsigned dup_mask = 0
  476. | ((count > 1) ? ((1U << y) & ((1U << x) )) : 0)
  477. | ((count > 2) ? ((1U << z) & ((1U << x) | (1U << y) )) : 0)
  478. | ((count > 3) ? ((1U << w) & ((1U << x) | (1U << y) | (1U << z))) : 0);
  479. assert(x <= 3);
  480. assert(y <= 3);
  481. assert(z <= 3);
  482. assert(w <= 3);
  483. mask.x = x;
  484. mask.y = y;
  485. mask.z = z;
  486. mask.w = w;
  487. mask.num_components = count;
  488. mask.has_duplicates = dup_mask != 0;
  489. /* Based on the number of elements in the swizzle and the base type
  490. * (i.e., float, int, unsigned, or bool) of the vector being swizzled,
  491. * generate the type of the resulting value.
  492. */
  493. type = glsl_type::get_instance(val->type->base_type, mask.num_components, 1);
  494. }
  495. ir_swizzle::ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask)
  496. {
  497. this->val = val;
  498. this->mask = mask;
  499. this->type = glsl_type::get_instance(val->type->base_type,
  500. mask.num_components, 1);
  501. }
  502. #define X 1
  503. #define R 5
  504. #define S 9
  505. #define I 13
  506. ir_swizzle *
  507. ir_swizzle::create(ir_rvalue *val, const char *str, unsigned vector_length)
  508. {
  509. /* For each possible swizzle character, this table encodes the value in
  510. * \c idx_map that represents the 0th element of the vector. For invalid
  511. * swizzle characters (e.g., 'k'), a special value is used that will allow
  512. * detection of errors.
  513. */
  514. static const unsigned char base_idx[26] = {
  515. /* a b c d e f g h i j k l m */
  516. R, R, I, I, I, I, R, I, I, I, I, I, I,
  517. /* n o p q r s t u v w x y z */
  518. I, I, S, S, R, S, S, I, I, X, X, X, X
  519. };
  520. /* Each valid swizzle character has an entry in the previous table. This
  521. * table encodes the base index encoded in the previous table plus the actual
  522. * index of the swizzle character. When processing swizzles, the first
  523. * character in the string is indexed in the previous table. Each character
  524. * in the string is indexed in this table, and the value found there has the
  525. * value form the first table subtracted. The result must be on the range
  526. * [0,3].
  527. *
  528. * For example, the string "wzyx" will get X from the first table. Each of
  529. * the charcaters will get X+3, X+2, X+1, and X+0 from this table. After
  530. * subtraction, the swizzle values are { 3, 2, 1, 0 }.
  531. *
  532. * The string "wzrg" will get X from the first table. Each of the characters
  533. * will get X+3, X+2, R+0, and R+1 from this table. After subtraction, the
  534. * swizzle values are { 3, 2, 4, 5 }. Since 4 and 5 are outside the range
  535. * [0,3], the error is detected.
  536. */
  537. static const unsigned char idx_map[26] = {
  538. /* a b c d e f g h i j k l m */
  539. R+3, R+2, 0, 0, 0, 0, R+1, 0, 0, 0, 0, 0, 0,
  540. /* n o p q r s t u v w x y z */
  541. 0, 0, S+2, S+3, R+0, S+0, S+1, 0, 0, X+3, X+0, X+1, X+2
  542. };
  543. int swiz_idx[4] = { 0, 0, 0, 0 };
  544. unsigned i;
  545. /* Validate the first character in the swizzle string and look up the base
  546. * index value as described above.
  547. */
  548. if ((str[0] < 'a') || (str[0] > 'z'))
  549. return NULL;
  550. const unsigned base = base_idx[str[0] - 'a'];
  551. for (i = 0; (i < 4) && (str[i] != '\0'); i++) {
  552. /* Validate the next character, and, as described above, convert it to a
  553. * swizzle index.
  554. */
  555. if ((str[i] < 'a') || (str[i] > 'z'))
  556. return NULL;
  557. swiz_idx[i] = idx_map[str[i] - 'a'] - base;
  558. if ((swiz_idx[i] < 0) || (swiz_idx[i] >= (int) vector_length))
  559. return NULL;
  560. }
  561. if (str[i] != '\0')
  562. return NULL;
  563. return new ir_swizzle(val, swiz_idx[0], swiz_idx[1], swiz_idx[2],
  564. swiz_idx[3], i);
  565. }
  566. #undef X
  567. #undef R
  568. #undef S
  569. #undef I
  570. ir_variable *
  571. ir_swizzle::variable_referenced()
  572. {
  573. return this->val->variable_referenced();
  574. }
  575. ir_variable::ir_variable(const struct glsl_type *type, const char *name)
  576. : max_array_access(0), read_only(false), centroid(false), invariant(false),
  577. mode(ir_var_auto), interpolation(ir_var_smooth)
  578. {
  579. this->type = type;
  580. this->name = name;
  581. this->constant_value = NULL;
  582. if (type && type->base_type == GLSL_TYPE_SAMPLER)
  583. this->read_only = true;
  584. }
  585. ir_function_signature::ir_function_signature(const glsl_type *return_type)
  586. : return_type(return_type), is_defined(false)
  587. {
  588. /* empty */
  589. }
  590. const char *
  591. ir_function_signature::qualifiers_match(exec_list *params)
  592. {
  593. exec_list_iterator iter_a = parameters.iterator();
  594. exec_list_iterator iter_b = params->iterator();
  595. /* check that the qualifiers match. */
  596. while (iter_a.has_next()) {
  597. ir_variable *a = (ir_variable *)iter_a.get();
  598. ir_variable *b = (ir_variable *)iter_b.get();
  599. if (a->read_only != b->read_only ||
  600. a->mode != b->mode ||
  601. a->interpolation != b->interpolation ||
  602. a->centroid != b->centroid) {
  603. /* parameter a's qualifiers don't match */
  604. return a->name;
  605. }
  606. iter_a.next();
  607. iter_b.next();
  608. }
  609. return NULL;
  610. }
  611. void
  612. ir_function_signature::replace_parameters(exec_list *new_params)
  613. {
  614. /* Destroy all of the previous parameter information. If the previous
  615. * parameter information comes from the function prototype, it may either
  616. * specify incorrect parameter names or not have names at all.
  617. */
  618. foreach_iter(exec_list_iterator, iter, parameters) {
  619. assert(((ir_instruction *) iter.get())->as_variable() != NULL);
  620. iter.remove();
  621. delete (ir_instruction*) iter.get();
  622. }
  623. new_params->move_nodes_to(&parameters);
  624. }
  625. ir_function::ir_function(const char *name)
  626. : name(name)
  627. {
  628. /* empty */
  629. }
  630. ir_call *
  631. ir_call::get_error_instruction()
  632. {
  633. ir_call *call = new ir_call;
  634. call->type = glsl_type::error_type;
  635. return call;
  636. }
  637. void
  638. visit_exec_list(exec_list *list, ir_visitor *visitor)
  639. {
  640. foreach_iter(exec_list_iterator, iter, *list) {
  641. ((ir_instruction *)iter.get())->accept(visitor);
  642. }
  643. }