Mesa (master): nir: Delete open coded type printing.

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Oct 6 09:15:39 UTC 2016


Module: Mesa
Branch: master
Commit: f7659e02c320fa9aac82e094e01786d2a5eb91e3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f7659e02c320fa9aac82e094e01786d2a5eb91e3

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Oct  5 11:58:59 2016 -0700

nir: Delete open coded type printing.

glsl_print_type() prints arrays of arrays incorrectly.  For example,
a type with name float[3][7] would be printed as float[7][3].  (This
is an array of length 3 containing arrays of 7 floats.)  cdecl says
that the type name is correct.

glsl_print_type() doesn't really do anything above and beyond printing
type->name, and glsl_print_struct() wasn't used at all.  So, drop them.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Timothy Arceri <timothy.arceri at collabora.com>

---

 src/compiler/nir/nir_print.c | 14 ++++++--------
 src/compiler/nir_types.cpp   | 30 ++++--------------------------
 src/compiler/nir_types.h     |  3 +--
 3 files changed, 11 insertions(+), 36 deletions(-)

diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index 9fa024e..35f6468 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -391,9 +391,8 @@ print_var_decl(nir_variable *var, print_state *state)
    const char *const wonly = (var->data.image.write_only) ? "writeonly " : "";
    fprintf(fp, "%s%s%s%s%s", coher, volat, restr, ronly, wonly);
 
-   glsl_print_type(var->type, fp);
-
-   fprintf(fp, " %s", get_var_name(var, state));
+   fprintf(fp, "%s %s", glsl_get_type_name(var->type),
+           get_var_name(var, state));
 
    if (var->data.mode == nir_var_shader_in ||
        var->data.mode == nir_var_shader_out ||
@@ -457,8 +456,8 @@ static void
 print_arg(nir_variable *var, print_state *state)
 {
    FILE *fp = state->fp;
-   glsl_print_type(var->type, fp);
-   fprintf(fp, " %s", get_var_name(var, state));
+   fprintf(fp, "%s %s", glsl_get_type_name(var->type),
+           get_var_name(var, state));
 }
 
 static void
@@ -1097,14 +1096,13 @@ print_function(nir_function *function, print_state *state)
          unreachable("Invalid parameter type");
       }
 
-      glsl_print_type(function->params[i].type, fp);
+      fprintf(fp, "%s", glsl_get_type_name(function->params[i].type));
    }
 
    if (function->return_type != NULL) {
       if (function->num_params != 0)
          fprintf(fp, ", ");
-      fprintf(fp, "returning ");
-      glsl_print_type(function->return_type, fp);
+      fprintf(fp, "returning %s", glsl_get_type_name(function->return_type));
    }
 
    fprintf(fp, "\n");
diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp
index f694a84..d145813 100644
--- a/src/compiler/nir_types.cpp
+++ b/src/compiler/nir_types.cpp
@@ -28,32 +28,10 @@
 #include "nir_types.h"
 #include "compiler/glsl/ir.h"
 
-void
-glsl_print_type(const glsl_type *type, FILE *fp)
-{
-   if (type->base_type == GLSL_TYPE_ARRAY) {
-      glsl_print_type(type->fields.array, fp);
-      fprintf(fp, "[%u]", type->length);
-   } else if ((type->base_type == GLSL_TYPE_STRUCT)
-              && !is_gl_identifier(type->name)) {
-      fprintf(fp, "%s@%p", type->name, (void *) type);
-   } else {
-      fprintf(fp, "%s", type->name);
-   }
-}
-
-void
-glsl_print_struct(const glsl_type *type, FILE *fp)
-{
-   assert(type->base_type == GLSL_TYPE_STRUCT);
-
-   fprintf(fp, "struct {\n");
-   for (unsigned i = 0; i < type->length; i++) {
-      fprintf(fp, "\t");
-      glsl_print_type(type->fields.structure[i].type, fp);
-      fprintf(fp, " %s;\n", type->fields.structure[i].name);
-   }
-   fprintf(fp, "}\n");
+const char *
+glsl_get_type_name(const glsl_type *type)
+{
+   return type->name;
 }
 
 const glsl_type *
diff --git a/src/compiler/nir_types.h b/src/compiler/nir_types.h
index 6b4f646..854d64f 100644
--- a/src/compiler/nir_types.h
+++ b/src/compiler/nir_types.h
@@ -40,8 +40,7 @@ extern "C" {
 struct glsl_type;
 #endif
 
-void glsl_print_type(const struct glsl_type *type, FILE *fp);
-void glsl_print_struct(const struct glsl_type *type, FILE *fp);
+const char *glsl_get_type_name(const struct glsl_type *type);
 
 const struct glsl_type *glsl_get_struct_field(const struct glsl_type *type,
                                               unsigned index);




More information about the mesa-commit mailing list