Make note of how many times a symbol is referenced.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 02 Mar 2011 23:58:16 -0800
changeset 1005 7ca34382b740
parent 1004 650ee7802725
child 1006 0f65599179f9
Make note of how many times a symbol is referenced. (Maybe for dead code stripping later on.)
mojoshader_compiler.c
--- a/mojoshader_compiler.c	Wed Mar 02 21:40:18 2011 -0800
+++ b/mojoshader_compiler.c	Wed Mar 02 23:58:16 2011 -0800
@@ -69,6 +69,7 @@
     const char *symbol;
     const MOJOSHADER_astDataType *datatype;
     int index;  // unique positive value within a function, negative if global.
+    int referenced;  // non-zero if something looked for this symbol (so we know it's used).
     struct SymbolScope *next;
 } SymbolScope;
 
@@ -351,6 +352,7 @@
     item->symbol = sym;  // cached strings, don't copy.
     item->index = index;
     item->datatype = dt;
+    item->referenced = 0;
     item->next = map->scope;
     map->scope = item;
 } // push_symbol
@@ -471,8 +473,12 @@
     const void *_item = NULL;
     hash_find(map->hash, sym, &_item);
     SymbolScope *item = (SymbolScope *) _item;
-    if (item && _index)
-        *_index = item->index;
+    if (item != NULL)
+    {
+        item->referenced++;
+        if (_index != NULL)
+            *_index = item->index;
+    } // if
     return item ? item->datatype : NULL;
 } // find_symbol