Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2014 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 DEALINGS
  21.  * IN THE SOFTWARE.
  22.  *
  23.  * Authors:
  24.  *    Connor Abbott (cwabbott0@gmail.com)
  25.  *
  26.  */
  27.  
  28. #include "nir_types.h"
  29. #include "ir.h"
  30.  
  31. void
  32. glsl_print_type(const glsl_type *type, FILE *fp)
  33. {
  34.    if (type->base_type == GLSL_TYPE_ARRAY) {
  35.       glsl_print_type(type->fields.array, fp);
  36.       fprintf(fp, "[%u]", type->length);
  37.    } else if ((type->base_type == GLSL_TYPE_STRUCT)
  38.               && !is_gl_identifier(type->name)) {
  39.       fprintf(fp, "%s@%p", type->name, (void *) type);
  40.    } else {
  41.       fprintf(fp, "%s", type->name);
  42.    }
  43. }
  44.  
  45. void
  46. glsl_print_struct(const glsl_type *type, FILE *fp)
  47. {
  48.    assert(type->base_type == GLSL_TYPE_STRUCT);
  49.  
  50.    fprintf(fp, "struct {\n");
  51.    for (unsigned i = 0; i < type->length; i++) {
  52.       fprintf(fp, "\t");
  53.       glsl_print_type(type->fields.structure[i].type, fp);
  54.       fprintf(fp, " %s;\n", type->fields.structure[i].name);
  55.    }
  56.    fprintf(fp, "}\n");
  57. }
  58.  
  59. const glsl_type *
  60. glsl_get_array_element(const glsl_type* type)
  61. {
  62.    if (type->is_matrix())
  63.       return type->column_type();
  64.    return type->fields.array;
  65. }
  66.  
  67. const glsl_type *
  68. glsl_get_struct_field(const glsl_type *type, unsigned index)
  69. {
  70.    return type->fields.structure[index].type;
  71. }
  72.  
  73. const struct glsl_type *
  74. glsl_get_column_type(const struct glsl_type *type)
  75. {
  76.    return type->column_type();
  77. }
  78.  
  79. enum glsl_base_type
  80. glsl_get_base_type(const struct glsl_type *type)
  81. {
  82.    return type->base_type;
  83. }
  84.  
  85. unsigned
  86. glsl_get_vector_elements(const struct glsl_type *type)
  87. {
  88.    return type->vector_elements;
  89. }
  90.  
  91. unsigned
  92. glsl_get_components(const struct glsl_type *type)
  93. {
  94.    return type->components();
  95. }
  96.  
  97. unsigned
  98. glsl_get_matrix_columns(const struct glsl_type *type)
  99. {
  100.    return type->matrix_columns;
  101. }
  102.  
  103. unsigned
  104. glsl_get_length(const struct glsl_type *type)
  105. {
  106.    return type->is_matrix() ? type->matrix_columns : type->length;
  107. }
  108.  
  109. const char *
  110. glsl_get_struct_elem_name(const struct glsl_type *type, unsigned index)
  111. {
  112.    return type->fields.structure[index].name;
  113. }
  114.  
  115. bool
  116. glsl_type_is_void(const glsl_type *type)
  117. {
  118.    return type->is_void();
  119. }
  120.  
  121. bool
  122. glsl_type_is_vector(const struct glsl_type *type)
  123. {
  124.    return type->is_vector();
  125. }
  126.  
  127. bool
  128. glsl_type_is_scalar(const struct glsl_type *type)
  129. {
  130.    return type->is_scalar();
  131. }
  132.  
  133. bool
  134. glsl_type_is_matrix(const struct glsl_type *type)
  135. {
  136.    return type->is_matrix();
  137. }
  138.  
  139. const glsl_type *
  140. glsl_void_type(void)
  141. {
  142.    return glsl_type::void_type;
  143. }
  144.  
  145. const glsl_type *
  146. glsl_float_type(void)
  147. {
  148.    return glsl_type::float_type;
  149. }
  150.  
  151. const glsl_type *
  152. glsl_vec4_type(void)
  153. {
  154.    return glsl_type::vec4_type;
  155. }
  156.  
  157. const glsl_type *
  158. glsl_array_type(const glsl_type *base, unsigned elements)
  159. {
  160.    return glsl_type::get_array_instance(base, elements);
  161. }
  162.