aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_print.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2015-12-26 10:26:29 -0800
committerJason Ekstrand <[email protected]>2016-03-12 15:48:36 -0800
commit13969565f91a65c490f8362363b73b207df5c7e0 (patch)
treede54a5ef227cf9f77b0d8b02baa8134fa50e72bb /src/compiler/nir/nir_print.c
parente4bebe8a0255dcd8c9910f2cf89894313286df4d (diff)
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. Reviewed-by: Jordan Justen <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_print.c')
-rw-r--r--src/compiler/nir/nir_print.c66
1 files changed, 36 insertions, 30 deletions
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index 8ccaf8a0edb..85799d64ec8 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -219,6 +219,40 @@ 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;
+ if (var->name == NULL) {
+ name = ralloc_asprintf(state->syms, "@%u", state->index++);
+ } else {
+ 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_constant(nir_constant *c, const struct glsl_type *type, print_state *state)
{
@@ -286,20 +320,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 ||
@@ -349,28 +370,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