[Mesa-dev] [PATCH] nir: Delete open coded type printing.

Kenneth Graunke kenneth at whitecape.org
Wed Oct 5 19:09:03 UTC 2016


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>
---
 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 c183e5c..37616f0 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 ||
@@ -459,8 +458,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
@@ -1099,14 +1098,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);
-- 
2.10.0



More information about the mesa-dev mailing list