1 //
2 // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_
8 #define COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_
9 
10 #include <GLSLANG/ShaderLang.h>
11 
12 #include "compiler/translator/ExtensionBehavior.h"
13 #include "compiler/translator/IntermNode.h"
14 
15 namespace sh
16 {
17 class TSymbolTable;
18 
19 typedef std::vector<sh::ShaderVariable> InitVariableList;
20 
21 // For all of the functions below: If canUseLoopsToInitialize is set, for loops are used instead of
22 // a large number of initializers where it can make sense, such as for initializing large arrays.
23 
24 // Return a sequence of assignment operations to initialize "initializedSymbol". initializedSymbol
25 // may be an array, struct or any combination of these, as long as it contains only basic types.
26 TIntermSequence *CreateInitCode(const TIntermTyped *initializedSymbol,
27                                 bool canUseLoopsToInitialize,
28                                 TSymbolTable *symbolTable);
29 
30 // Initialize all uninitialized local variables, so that undefined behavior is avoided.
31 void InitializeUninitializedLocals(TIntermBlock *root,
32                                    int shaderVersion,
33                                    bool canUseLoopsToInitialize,
34                                    TSymbolTable *symbolTable);
35 
36 // This function can initialize all the types that CreateInitCode is able to initialize. All
37 // variables must be globals which can be found in the symbol table. For now it is used for the
38 // following two scenarios:
39 //   1. Initializing gl_Position;
40 //   2. Initializing output variables referred to in the shader source.
41 // Note: The type of each lvalue in an initializer is retrieved from the symbol table. gl_FragData
42 // requires special handling because the number of indices which can be initialized is determined by
43 // enabled extensions.
44 void InitializeVariables(TIntermBlock *root,
45                          const InitVariableList &vars,
46                          TSymbolTable *symbolTable,
47                          int shaderVersion,
48                          const TExtensionBehavior &extensionBehavior,
49                          bool canUseLoopsToInitialize);
50 
51 }  // namespace sh
52 
53 #endif  // COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_
54