From: Jason Ekstrand Date: Fri, 18 Dec 2015 22:39:02 +0000 (-0800) Subject: nir/print: Factor variable name lookup into a helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=413a9d351746a0e3ecb274a8f39dcefec7010edd;p=mesa.git nir/print: Factor variable name lookup into a helper Otherwise, we have a problem when we go to print functions with arguments because their names get added to the hash table during declaration which happens after we print the prototype. --- diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c index 10f46cef1de..26b1cbb467d 100644 --- a/src/glsl/nir/nir_print.c +++ b/src/glsl/nir/nir_print.c @@ -219,6 +219,35 @@ print_alu_instr(nir_alu_instr *instr, print_state *state) } } +static const char * +get_var_name(nir_variable *var, print_state *state) +{ + if (state->ht == NULL) + return var->name; + + assert(state->syms); + + struct hash_entry *entry = _mesa_hash_table_search(state->ht, var); + if (entry) + return entry->data; + + char *name; + + struct set_entry *set_entry = _mesa_set_search(state->syms, var->name); + if (set_entry != NULL) { + /* we have a collision with another name, append an @ + a unique index */ + name = ralloc_asprintf(state->syms, "%s@%u", var->name, state->index++); + } else { + /* Mark this one as seen */ + _mesa_set_add(state->syms, var->name); + name = var->name; + } + + _mesa_hash_table_insert(state->ht, var, name); + + return name; +} + static void print_var_decl(nir_variable *var, print_state *state) { @@ -239,20 +268,7 @@ print_var_decl(nir_variable *var, print_state *state) glsl_print_type(var->type, fp); - struct set_entry *entry = NULL; - if (state->syms) - entry = _mesa_set_search(state->syms, var->name); - - char *name; - - if (entry != NULL) { - /* we have a collision with another name, append an @ + a unique index */ - name = ralloc_asprintf(state->syms, "%s@%u", var->name, state->index++); - } else { - name = var->name; - } - - fprintf(fp, " %s", name); + fprintf(fp, " %s", get_var_name(var, state)); if (var->data.mode == nir_var_shader_in || var->data.mode == nir_var_shader_out || @@ -296,28 +312,13 @@ print_var_decl(nir_variable *var, print_state *state) } fprintf(fp, "\n"); - - if (state->syms) { - _mesa_set_add(state->syms, name); - _mesa_hash_table_insert(state->ht, var, name); - } } static void print_var(nir_variable *var, print_state *state) { FILE *fp = state->fp; - const char *name; - if (state->ht) { - struct hash_entry *entry = _mesa_hash_table_search(state->ht, var); - - assert(entry != NULL); - name = entry->data; - } else { - name = var->name; - } - - fprintf(fp, "%s", name); + fprintf(fp, "%s", get_var_name(var, state)); } static void