[Mesa-dev] [PATCH] glsl: Generate readable unique names at print time.
Eric Anholt
eric at anholt.net
Fri Mar 25 13:22:02 PDT 2011
On Fri, 25 Mar 2011 12:24:09 -0700, Kenneth Graunke <kenneth at whitecape.org> wrote:
> Since GLSL IR allows multiple ir_variables to share the same name, we
> need to generate unique names when printing the IR. Previously, we
> always used %s@%p, appending the ir_variable's memory address.
>
> While this worked, it had two drawbacks:
> - When there aren't duplicates, the extra "@0x669a3e88" is useless
> and makes the code harder to read.
> - Real duplicates were hard to tell apart:
> channel_expressions at 0x6699e3c8 vs. channel_expressions at 0x6699ddd8
>
> We now append @2, @3, @4, and so on, but only where necessary to
> distinguish duplicates. Since we only do this at print time, any
> performance impact is irrelevant.
Nice.
> +ir_print_visitor::ir_print_visitor()
> +{
> + indentation = 0;
> + printable_names =
> + hash_table_ctor(32, hash_table_string_hash, hash_table_string_compare);
Don't you mean pointer_hash, pointer_compare here...
> +const char *
> +ir_print_visitor::unique_name(ir_variable *var)
> +{
> + /* Do we already have a name for this variable? */
> + const char *name = (const char *) hash_table_find(this->printable_names, var);
since you're passing a pointer?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110325/59ac8045/attachment.pgp>
More information about the mesa-dev
mailing list