glsl2: Insert global declarations at the top of the instruction stream.
authorEric Anholt <eric@anholt.net>
Thu, 5 Aug 2010 21:41:09 +0000 (14:41 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 5 Aug 2010 21:41:09 +0000 (14:41 -0700)
Fixes use-before-decl in glslparsertest shaders.

Fixes:
CorrectFull.frag
CorrectModule.frag

src/glsl/ast_to_hir.cpp

index 292c7be6217ddf8d4ba170e1a9e098d5d3df44ee..f14341c8f724e476951d30e219b683e3b15a851a 100644 (file)
@@ -1951,7 +1951,14 @@ ast_declarator_list::hir(exec_list *instructions,
                          decl->identifier);
       }
 
-      instructions->push_tail(var);
+      /* Push the variable declaration to the top.  It means that all
+       * the variable declarations will appear in a funny
+       * last-to-first order, but otherwise we run into trouble if a
+       * function is prototyped, a global var is decled, then the
+       * function is defined with usage of the global var.  See
+       * glslparsertest's CorrectModule.frag.
+       */
+      instructions->push_head(var);
       instructions->append_list(&initializer_instructions);
 
       /* Add the variable to the symbol table after processing the initializer.