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_print_visitor.cpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 <cstdio>
  24. #include "ir_print_visitor.h"
  25. #include "glsl_types.h"
  26. static void
  27. print_type(const glsl_type *t)
  28. {
  29. if (t->base_type == GLSL_TYPE_ARRAY) {
  30. printf("array\n");
  31. printf(" (");
  32. print_type(t->fields.array);
  33. printf(")\n");
  34. printf(" (%u)\n", t->length);
  35. printf(")");
  36. } else if (t->base_type == GLSL_TYPE_STRUCT) {
  37. printf("struct (%s %u\n", t->name ? t->name : "@", t->length);
  38. printf(" (FINISHME: structure fields go here)\n");
  39. printf(")");
  40. } else {
  41. printf("%s", t->name);
  42. }
  43. }
  44. void ir_print_visitor::visit(ir_variable *ir)
  45. {
  46. printf("(declare \n");
  47. const char *const cent = (ir->centroid) ? "centroid " : "";
  48. const char *const inv = (ir->invariant) ? "invariant " : "";
  49. const char *const mode[] = { "", "uniform ", "in ", "out ", "inout " };
  50. const char *const interp[] = { "", "flat", "noperspective" };
  51. printf(" (%s%s%s%s)\n",
  52. cent, inv, mode[ir->mode], interp[ir->interpolation]);
  53. printf(" (");
  54. print_type(ir->type);
  55. printf(")\n");
  56. printf(" (%s)\n", ir->name);
  57. printf(")\n");
  58. }
  59. void ir_print_visitor::visit(ir_label *ir)
  60. {
  61. printf("(label %s)\n", ir->label);
  62. }
  63. void ir_print_visitor::visit(ir_function_signature *ir)
  64. {
  65. printf("%s:%d:\n", __func__, __LINE__);
  66. (void) ir;
  67. }
  68. void ir_print_visitor::visit(ir_function *ir)
  69. {
  70. printf("(function %s\n", ir->name);
  71. printf(")\n");
  72. }
  73. void ir_print_visitor::visit(ir_expression *ir)
  74. {
  75. printf("%s:%d:\n", __func__, __LINE__);
  76. (void) ir;
  77. }
  78. void ir_print_visitor::visit(ir_dereference *ir)
  79. {
  80. printf("%s:%d:\n", __func__, __LINE__);
  81. (void) ir;
  82. }
  83. void ir_print_visitor::visit(ir_assignment *ir)
  84. {
  85. printf("(assign\n");
  86. printf(" (");
  87. if (ir->condition)
  88. ir->condition->accept(this);
  89. else
  90. printf("true");
  91. printf(")\n");
  92. printf(" (");
  93. ir->lhs->accept(this);
  94. printf(")\n");
  95. printf(" (");
  96. ir->rhs->accept(this);
  97. printf(")\n");
  98. }
  99. void ir_print_visitor::visit(ir_constant *ir)
  100. {
  101. (void) ir;
  102. printf("(constant\n");
  103. printf(" (");
  104. print_type(ir->type);
  105. printf(")\n");
  106. printf(" (FINISHME: value goes here)\n");
  107. printf(")\n");
  108. }
  109. void
  110. ir_print_visitor::visit(ir_call *ir)
  111. {
  112. (void) ir;
  113. printf("(call FINISHME: function name here\n");
  114. printf(" (FINISHME: function paramaters here))\n");
  115. }