tgsi: replace tgsi_file_names tgsi_file_names[] with tgsi_file_name() function
authorBrian Paul <brianp@vmware.com>
Thu, 6 Jun 2013 15:46:40 +0000 (09:46 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 7 Jun 2013 15:23:24 +0000 (09:23 -0600)
This change came from the discovery that the STATIC_ASSERT to check that
the number of register file strings didn't actually work.

Similar changes could be made for the other string arrays in tgsi_string.c

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
src/gallium/auxiliary/tgsi/tgsi_dump.c
src/gallium/auxiliary/tgsi/tgsi_strings.c
src/gallium/auxiliary/tgsi/tgsi_strings.h
src/gallium/auxiliary/tgsi/tgsi_text.c
src/gallium/drivers/freedreno/freedreno_compiler.c
src/gallium/drivers/ilo/shader/toy_tgsi.c

index b00aa094d38a445fb22fa5a5233b250fdc8cb138..184790b702f05c4351adcde244975646f88dac29 100644 (file)
@@ -433,7 +433,7 @@ dump_info(const struct tgsi_token *tokens,
                &tex_info->coord[chan];
          if (chan_info->file != TGSI_FILE_NULL) {
             debug_printf(" %s[%u].%c",
-                         tgsi_file_names[chan_info->file],
+                         tgsi_file_name(chan_info->file),
                          chan_info->u.index,
                          "xyzw01"[chan_info->swizzle]);
          } else {
index 77b75b1e0bf452872755c40fcb696ee9d24b8641..7f6a3d8ad8f300abe20e54c3913e2a43f238f0fb 100644 (file)
@@ -99,11 +99,11 @@ _dump_register_src(
    struct dump_ctx *ctx,
    const struct tgsi_full_src_register *src )
 {
-   ENM(src->Register.File, tgsi_file_names);
+   TXT(tgsi_file_name(src->Register.File));
    if (src->Register.Dimension) {
       if (src->Dimension.Indirect) {
          CHR( '[' );
-         ENM( src->DimIndirect.File, tgsi_file_names );
+         TXT(tgsi_file_name(src->DimIndirect.File));
          CHR( '[' );
          SID( src->DimIndirect.Index );
          TXT( "]." );
@@ -127,7 +127,7 @@ _dump_register_src(
    }
    if (src->Register.Indirect) {
       CHR( '[' );
-      ENM( src->Indirect.File, tgsi_file_names );
+      TXT(tgsi_file_name(src->Indirect.File));
       CHR( '[' );
       SID( src->Indirect.Index );
       TXT( "]." );
@@ -156,11 +156,11 @@ _dump_register_dst(
    struct dump_ctx *ctx,
    const struct tgsi_full_dst_register *dst )
 {
-   ENM(dst->Register.File, tgsi_file_names);
+   TXT(tgsi_file_name(dst->Register.File));
    if (dst->Register.Dimension) {
       if (dst->Dimension.Indirect) {
          CHR( '[' );
-         ENM( dst->DimIndirect.File, tgsi_file_names );
+         TXT(tgsi_file_name(dst->DimIndirect.File));
          CHR( '[' );
          SID( dst->DimIndirect.Index );
          TXT( "]." );
@@ -184,7 +184,7 @@ _dump_register_dst(
    }
    if (dst->Register.Indirect) {
       CHR( '[' );
-      ENM( dst->Indirect.File, tgsi_file_names );
+      TXT(tgsi_file_name(dst->Indirect.File));
       CHR( '[' );
       SID( dst->Indirect.Index );
       TXT( "]." );
@@ -266,7 +266,7 @@ iter_declaration(
 
    TXT( "DCL " );
 
-   ENM(decl->Declaration.File, tgsi_file_names);
+   TXT(tgsi_file_name(decl->Declaration.File));
 
    /* all geometry shader inputs are two dimensional */
    if (decl->Declaration.File == TGSI_FILE_INPUT &&
@@ -576,7 +576,7 @@ iter_instruction(
       ENM( inst->Texture.Texture, tgsi_texture_names );
       for (i = 0; i < inst->Texture.NumOffsets; i++) {
          TXT( ", " );
-         ENM( inst->TexOffsets[i].File, tgsi_file_names);
+         TXT(tgsi_file_name(inst->TexOffsets[i].File));
          CHR( '[' );
          SID( inst->TexOffsets[i].Index );
          CHR( ']' );
index d8caae5a6063ba94658e0e1049e7421e2a4c6a61..27856767877e268ec6e3bce6f7e9150502e87074 100644 (file)
@@ -40,7 +40,7 @@ const char *tgsi_processor_type_names[4] =
    "COMP"
 };
 
-const char *tgsi_file_names[TGSI_FILE_COUNT] =
+static const char *tgsi_file_names[] =
 {
    "NULL",
    "CONST",
@@ -176,7 +176,6 @@ const char *tgsi_immediate_type_names[3] =
 static INLINE void
 tgsi_strings_check(void)
 {
-   STATIC_ASSERT(Elements(tgsi_file_names) == TGSI_FILE_COUNT);
    STATIC_ASSERT(Elements(tgsi_semantic_names) == TGSI_SEMANTIC_COUNT);
    STATIC_ASSERT(Elements(tgsi_texture_names) == TGSI_TEXTURE_COUNT);
    STATIC_ASSERT(Elements(tgsi_property_names) == TGSI_PROPERTY_COUNT);
@@ -188,3 +187,14 @@ tgsi_strings_check(void)
    (void) tgsi_fs_coord_origin_names;
    (void) tgsi_fs_coord_pixel_center_names;
 }
+
+
+const char *
+tgsi_file_name(unsigned file)
+{
+   STATIC_ASSERT(Elements(tgsi_file_names) == TGSI_FILE_COUNT);
+   if (file < Elements(tgsi_file_names))
+      return tgsi_file_names[file];
+   else
+      return "invalid file";
+}
index 5c57e229c28e4b8a9583f8b7fc4c910228fde1da..43576465790d9a57525d43ef2f17158dfd4b7c12 100644 (file)
@@ -40,8 +40,6 @@ extern "C" {
 
 extern const char *tgsi_processor_type_names[4];
 
-extern const char *tgsi_file_names[TGSI_FILE_COUNT];
-
 extern const char *tgsi_semantic_names[TGSI_SEMANTIC_COUNT];
 
 extern const char *tgsi_texture_names[TGSI_TEXTURE_COUNT];
@@ -61,6 +59,10 @@ extern const char *tgsi_fs_coord_pixel_center_names[2];
 extern const char *tgsi_immediate_type_names[3];
 
 
+const char *
+tgsi_file_name(unsigned file);
+
+
 #if defined __cplusplus
 }
 #endif
index 187e23ede2676a358387c5cf1503a78cf735c671..688c5bc9d8d4999c560362e7df7f646a17b22225 100644 (file)
@@ -322,7 +322,7 @@ parse_file( const char **pcur, uint *file )
    for (i = 0; i < TGSI_FILE_COUNT; i++) {
       const char *cur = *pcur;
 
-      if (str_match_nocase_whole( &cur, tgsi_file_names[i] )) {
+      if (str_match_nocase_whole( &cur, tgsi_file_name(i) )) {
          *pcur = cur;
          *file = i;
          return TRUE;
index 1a596f50f6b345f6bac86ca38abc345248ea3d9e..8d1e266d46a78c397702f0f5d921456783ea2d25 100644 (file)
@@ -339,7 +339,7 @@ add_dst_reg(struct fd_compile_context *ctx, struct ir2_instruction *alu,
                break;
        default:
                DBG("unsupported dst register file: %s",
-                               tgsi_file_names[dst->File]);
+                       tgsi_file_name(dst->File));
                assert(0);
                break;
        }
@@ -385,7 +385,7 @@ add_src_reg(struct fd_compile_context *ctx, struct ir2_instruction *alu,
                break;
        default:
                DBG("unsupported src register file: %s",
-                               tgsi_file_names[src->File]);
+                       tgsi_file_name(src->File));
                assert(0);
                break;
        }
index 045d279ef8c29812144ca95b72dd411d279ecb8a..ad6161d5894bce440730a8ebfd6c55c57148c73d 100644 (file)
@@ -2565,11 +2565,11 @@ dump_reg_mapping(void *key, void *val, void *data)
 
    if (tgsi_dim) {
       ilo_printf("  v%d:\t%s[%d][%d]\n", vrf,
-            tgsi_file_names[tgsi_file], tgsi_dim, tgsi_index);
+                 tgsi_file_name(tgsi_file), tgsi_dim, tgsi_index);
    }
    else {
       ilo_printf("  v%d:\t%s[%d]\n", vrf,
-            tgsi_file_names[tgsi_file], tgsi_index);
+                 tgsi_file_name(tgsi_file), tgsi_index);
    }
 
    return PIPE_OK;