alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 1 | // |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 7 | #include "compiler/translator/BuiltInFunctionEmulator.h" |
| 8 | #include "compiler/translator/DetectCallDepth.h" |
| 9 | #include "compiler/translator/ForLoopUnroll.h" |
| 10 | #include "compiler/translator/Initialize.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 11 | #include "compiler/translator/InitializeParseContext.h" |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 12 | #include "compiler/translator/InitializeVariables.h" |
Jamie Madill | 6b9cb25 | 2013-10-17 10:45:47 -0400 | [diff] [blame] | 13 | #include "compiler/translator/ParseContext.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 14 | #include "compiler/translator/RenameFunction.h" |
| 15 | #include "compiler/translator/ShHandle.h" |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 16 | #include "compiler/translator/UnfoldShortCircuitAST.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 17 | #include "compiler/translator/ValidateLimitations.h" |
| 18 | #include "compiler/translator/ValidateOutputs.h" |
| 19 | #include "compiler/translator/VariablePacker.h" |
| 20 | #include "compiler/translator/depgraph/DependencyGraph.h" |
| 21 | #include "compiler/translator/depgraph/DependencyGraphOutput.h" |
| 22 | #include "compiler/translator/timing/RestrictFragmentShaderTiming.h" |
| 23 | #include "compiler/translator/timing/RestrictVertexShaderTiming.h" |
shannon.woods@transgaming.com | da1ed36 | 2013-01-25 21:54:57 +0000 | [diff] [blame] | 24 | #include "third_party/compiler/ArrayBoundsClamper.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 25 | |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 26 | bool IsWebGLBasedSpec(ShShaderSpec spec) |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 27 | { |
| 28 | return spec == SH_WEBGL_SPEC || spec == SH_CSS_SHADERS_SPEC; |
| 29 | } |
| 30 | |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 31 | size_t GetGlobalMaxTokenSize(ShShaderSpec spec) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 32 | { |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 33 | // WebGL defines a max token legnth of 256, while ES2 leaves max token |
| 34 | // size undefined. ES3 defines a max size of 1024 characters. |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 35 | if (IsWebGLBasedSpec(spec)) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 36 | { |
| 37 | return 256; |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | return 1024; |
| 42 | } |
| 43 | } |
| 44 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 45 | namespace { |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 46 | class TScopedPoolAllocator |
| 47 | { |
| 48 | public: |
| 49 | TScopedPoolAllocator(TPoolAllocator* allocator) : mAllocator(allocator) |
| 50 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 51 | mAllocator->push(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 52 | SetGlobalPoolAllocator(mAllocator); |
| 53 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 54 | ~TScopedPoolAllocator() |
| 55 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 56 | SetGlobalPoolAllocator(NULL); |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 57 | mAllocator->pop(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 60 | private: |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 61 | TPoolAllocator* mAllocator; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 62 | }; |
| 63 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 64 | class TScopedSymbolTableLevel |
| 65 | { |
| 66 | public: |
| 67 | TScopedSymbolTableLevel(TSymbolTable* table) : mTable(table) |
| 68 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 69 | ASSERT(mTable->atBuiltInLevel()); |
| 70 | mTable->push(); |
| 71 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 72 | ~TScopedSymbolTableLevel() |
| 73 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 74 | while (!mTable->atBuiltInLevel()) |
| 75 | mTable->pop(); |
| 76 | } |
| 77 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 78 | private: |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 79 | TSymbolTable* mTable; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 80 | }; |
| 81 | } // namespace |
| 82 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 83 | TShHandleBase::TShHandleBase() |
| 84 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 85 | allocator.push(); |
| 86 | SetGlobalPoolAllocator(&allocator); |
| 87 | } |
| 88 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 89 | TShHandleBase::~TShHandleBase() |
| 90 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 91 | SetGlobalPoolAllocator(NULL); |
| 92 | allocator.popAll(); |
| 93 | } |
| 94 | |
Jamie Madill | 68fe74a | 2014-05-27 12:56:01 -0400 | [diff] [blame^] | 95 | TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output) |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 96 | : shaderType(type), |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 97 | shaderSpec(spec), |
Jamie Madill | 68fe74a | 2014-05-27 12:56:01 -0400 | [diff] [blame^] | 98 | outputType(output), |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 99 | maxUniformVectors(0), |
| 100 | maxExpressionComplexity(0), |
| 101 | maxCallStackDepth(0), |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 102 | fragmentPrecisionHigh(false), |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 103 | clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC), |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame] | 104 | builtInFunctionEmulator(type) |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 105 | { |
| 106 | } |
| 107 | |
| 108 | TCompiler::~TCompiler() |
| 109 | { |
| 110 | } |
| 111 | |
| 112 | bool TCompiler::Init(const ShBuiltInResources& resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 113 | { |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 114 | shaderVersion = 100; |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 115 | maxUniformVectors = (shaderType == SH_VERTEX_SHADER) ? |
| 116 | resources.MaxVertexUniformVectors : |
| 117 | resources.MaxFragmentUniformVectors; |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 118 | maxExpressionComplexity = resources.MaxExpressionComplexity; |
| 119 | maxCallStackDepth = resources.MaxCallStackDepth; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 120 | |
| 121 | SetGlobalPoolAllocator(&allocator); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 122 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 123 | // Generate built-in symbol table. |
| 124 | if (!InitBuiltInSymbolTable(resources)) |
| 125 | return false; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 126 | InitExtensionBehavior(resources, extensionBehavior); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 127 | fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 128 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 129 | arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy); |
| 130 | clampingStrategy = resources.ArrayIndexClampingStrategy; |
| 131 | |
daniel@transgaming.com | c23f461 | 2012-11-28 19:42:57 +0000 | [diff] [blame] | 132 | hashFunction = resources.HashFunction; |
| 133 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 134 | return true; |
| 135 | } |
| 136 | |
| 137 | bool TCompiler::compile(const char* const shaderStrings[], |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 138 | size_t numStrings, |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 139 | int compileOptions) |
| 140 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 141 | TScopedPoolAllocator scopedAlloc(&allocator); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 142 | clearResults(); |
| 143 | |
| 144 | if (numStrings == 0) |
| 145 | return true; |
| 146 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 147 | // If compiling for WebGL, validate loop and indexing as well. |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 148 | if (IsWebGLBasedSpec(shaderSpec)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 149 | compileOptions |= SH_VALIDATE_LOOP_INDEXING; |
alokp@chromium.org | 1f29954 | 2010-11-12 15:50:23 +0000 | [diff] [blame] | 150 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 151 | // First string is path of source file if flag is set. The actual source follows. |
| 152 | const char* sourcePath = NULL; |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 153 | size_t firstSource = 0; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 154 | if (compileOptions & SH_SOURCE_PATH) |
| 155 | { |
| 156 | sourcePath = shaderStrings[0]; |
| 157 | ++firstSource; |
| 158 | } |
| 159 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 160 | TIntermediate intermediate(infoSink); |
| 161 | TParseContext parseContext(symbolTable, extensionBehavior, intermediate, |
zmo@google.com | dc4b4f8 | 2011-06-17 00:42:53 +0000 | [diff] [blame] | 162 | shaderType, shaderSpec, compileOptions, true, |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 163 | sourcePath, infoSink); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 164 | parseContext.fragmentPrecisionHigh = fragmentPrecisionHigh; |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 165 | SetGlobalParseContext(&parseContext); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 166 | |
| 167 | // We preserve symbols at the built-in level from compile-to-compile. |
| 168 | // Start pushing the user-defined symbols at global level. |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 169 | TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 170 | |
| 171 | // Parse shader. |
| 172 | bool success = |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 173 | (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) && |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 174 | (parseContext.treeRoot != NULL); |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 175 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 176 | shaderVersion = parseContext.getShaderVersion(); |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 177 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 178 | if (success) |
| 179 | { |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 180 | TIntermNode* root = parseContext.treeRoot; |
| 181 | success = intermediate.postProcess(root); |
| 182 | |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 183 | // Disallow expressions deemed too complex. |
| 184 | if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY)) |
| 185 | success = limitExpressionComplexity(root); |
| 186 | |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 187 | if (success) |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 188 | success = detectCallDepth(root, infoSink, (compileOptions & SH_LIMIT_CALL_STACK_DEPTH) != 0); |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 189 | |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 190 | if (success && shaderVersion == 300 && shaderType == SH_FRAGMENT_SHADER) |
| 191 | success = validateOutputs(root); |
| 192 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 193 | if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING)) |
| 194 | success = validateLimitations(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 195 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 196 | if (success && (compileOptions & SH_TIMING_RESTRICTIONS)) |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 197 | success = enforceTimingRestrictions(root, (compileOptions & SH_DEPENDENCY_GRAPH) != 0); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 198 | |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 199 | if (success && shaderSpec == SH_CSS_SHADERS_SPEC) |
| 200 | rewriteCSSShader(root); |
| 201 | |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 202 | // Unroll for-loop markup needs to happen after validateLimitations pass. |
| 203 | if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX)) |
Zhenyao Mo | 3cdfcce | 2014-03-07 13:00:08 -0800 | [diff] [blame] | 204 | { |
| 205 | ForLoopUnrollMarker marker(ForLoopUnrollMarker::kIntegerIndex); |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 206 | root->traverse(&marker); |
| 207 | } |
| 208 | if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX)) |
Zhenyao Mo | 3cdfcce | 2014-03-07 13:00:08 -0800 | [diff] [blame] | 209 | { |
| 210 | ForLoopUnrollMarker marker(ForLoopUnrollMarker::kSamplerArrayIndex); |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 211 | root->traverse(&marker); |
| 212 | if (marker.samplerArrayIndexIsFloatLoopIndex()) |
| 213 | { |
| 214 | infoSink.info.prefix(EPrefixError); |
| 215 | infoSink.info << "sampler array index is float loop index"; |
| 216 | success = false; |
| 217 | } |
| 218 | } |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 219 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 220 | // Built-in function emulation needs to happen after validateLimitations pass. |
| 221 | if (success && (compileOptions & SH_EMULATE_BUILT_IN_FUNCTIONS)) |
| 222 | builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(root); |
| 223 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 224 | // Clamping uniform array bounds needs to happen after validateLimitations pass. |
| 225 | if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS)) |
| 226 | arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root); |
| 227 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 228 | if (success && shaderType == SH_VERTEX_SHADER && (compileOptions & SH_INIT_GL_POSITION)) |
| 229 | initializeGLPosition(root); |
Zhenyao Mo | ac44cd2 | 2013-09-23 14:57:09 -0400 | [diff] [blame] | 230 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 231 | if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT)) |
| 232 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 233 | UnfoldShortCircuitAST unfoldShortCircuit; |
| 234 | root->traverse(&unfoldShortCircuit); |
| 235 | unfoldShortCircuit.updateTree(); |
| 236 | } |
| 237 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 238 | if (success && (compileOptions & SH_VARIABLES)) |
| 239 | { |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 240 | collectVariables(root); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 241 | if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) |
| 242 | { |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 243 | success = enforcePackingRestrictions(); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 244 | if (!success) |
| 245 | { |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 246 | infoSink.info.prefix(EPrefixError); |
| 247 | infoSink.info << "too many uniforms"; |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 250 | if (success && shaderType == SH_VERTEX_SHADER && |
| 251 | (compileOptions & SH_INIT_VARYINGS_WITHOUT_STATIC_USE)) |
| 252 | initializeVaryingsWithoutStaticUse(root); |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 253 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 254 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 255 | if (success && (compileOptions & SH_INTERMEDIATE_TREE)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 256 | intermediate.outputTree(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 257 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 258 | if (success && (compileOptions & SH_OBJECT_CODE)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 259 | translate(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // Cleanup memory. |
| 263 | intermediate.remove(parseContext.treeRoot); |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 264 | SetGlobalParseContext(NULL); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 265 | return success; |
| 266 | } |
| 267 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 268 | bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 269 | { |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 270 | compileResources = resources; |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 271 | setResourceString(); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 272 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 273 | assert(symbolTable.isEmpty()); |
| 274 | symbolTable.push(); // COMMON_BUILTINS |
| 275 | symbolTable.push(); // ESSL1_BUILTINS |
| 276 | symbolTable.push(); // ESSL3_BUILTINS |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 277 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 278 | TPublicType integer; |
| 279 | integer.type = EbtInt; |
| 280 | integer.primarySize = 1; |
| 281 | integer.secondarySize = 1; |
| 282 | integer.array = false; |
| 283 | |
| 284 | TPublicType floatingPoint; |
| 285 | floatingPoint.type = EbtFloat; |
| 286 | floatingPoint.primarySize = 1; |
| 287 | floatingPoint.secondarySize = 1; |
| 288 | floatingPoint.array = false; |
| 289 | |
Zhenyao Mo | a5a1dfc | 2013-09-23 14:57:03 -0400 | [diff] [blame] | 290 | TPublicType sampler; |
| 291 | sampler.primarySize = 1; |
| 292 | sampler.secondarySize = 1; |
| 293 | sampler.array = false; |
| 294 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 295 | switch(shaderType) |
| 296 | { |
| 297 | case SH_FRAGMENT_SHADER: |
| 298 | symbolTable.setDefaultPrecision(integer, EbpMedium); |
| 299 | break; |
| 300 | case SH_VERTEX_SHADER: |
| 301 | symbolTable.setDefaultPrecision(integer, EbpHigh); |
| 302 | symbolTable.setDefaultPrecision(floatingPoint, EbpHigh); |
| 303 | break; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 304 | default: |
| 305 | assert(false && "Language not supported"); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 306 | } |
Zhenyao Mo | a5a1dfc | 2013-09-23 14:57:03 -0400 | [diff] [blame] | 307 | // We set defaults for all the sampler types, even those that are |
| 308 | // only available if an extension exists. |
| 309 | for (int samplerType = EbtGuardSamplerBegin + 1; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 310 | samplerType < EbtGuardSamplerEnd; ++samplerType) |
| 311 | { |
Zhenyao Mo | a5a1dfc | 2013-09-23 14:57:03 -0400 | [diff] [blame] | 312 | sampler.type = static_cast<TBasicType>(samplerType); |
| 313 | symbolTable.setDefaultPrecision(sampler, EbpLow); |
| 314 | } |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 315 | |
Jamie Madill | 1b45214 | 2013-07-12 14:51:11 -0400 | [diff] [blame] | 316 | InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 317 | |
| 318 | IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable); |
| 319 | |
| 320 | return true; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 323 | void TCompiler::setResourceString() |
| 324 | { |
| 325 | std::ostringstream strstream; |
| 326 | strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs |
| 327 | << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors |
| 328 | << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors |
| 329 | << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits |
| 330 | << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits |
| 331 | << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits |
| 332 | << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors |
| 333 | << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers |
| 334 | << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives |
| 335 | << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external |
| 336 | << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle |
| 337 | << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers |
| 338 | << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh |
| 339 | << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity |
| 340 | << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth |
| 341 | << ":EXT_frag_depth:" << compileResources.EXT_frag_depth |
| 342 | << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod |
| 343 | << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors |
| 344 | << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors |
| 345 | << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset |
| 346 | << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset; |
| 347 | |
| 348 | builtInResourcesString = strstream.str(); |
| 349 | } |
| 350 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 351 | void TCompiler::clearResults() |
| 352 | { |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 353 | arrayBoundsClamper.Cleanup(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 354 | infoSink.info.erase(); |
| 355 | infoSink.obj.erase(); |
| 356 | infoSink.debug.erase(); |
| 357 | |
| 358 | attribs.clear(); |
| 359 | uniforms.clear(); |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 360 | varyings.clear(); |
zmo@google.com | a3b4ab4 | 2011-09-16 00:53:26 +0000 | [diff] [blame] | 361 | |
| 362 | builtInFunctionEmulator.Cleanup(); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 363 | |
| 364 | nameMap.clear(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 367 | bool TCompiler::detectCallDepth(TIntermNode* root, TInfoSink& infoSink, bool limitCallStackDepth) |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 368 | { |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 369 | DetectCallDepth detect(infoSink, limitCallStackDepth, maxCallStackDepth); |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 370 | root->traverse(&detect); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 371 | switch (detect.detectCallDepth()) |
| 372 | { |
| 373 | case DetectCallDepth::kErrorNone: |
| 374 | return true; |
| 375 | case DetectCallDepth::kErrorMissingMain: |
| 376 | infoSink.info.prefix(EPrefixError); |
| 377 | infoSink.info << "Missing main()"; |
| 378 | return false; |
| 379 | case DetectCallDepth::kErrorRecursion: |
| 380 | infoSink.info.prefix(EPrefixError); |
| 381 | infoSink.info << "Function recursion detected"; |
| 382 | return false; |
| 383 | case DetectCallDepth::kErrorMaxDepthExceeded: |
| 384 | infoSink.info.prefix(EPrefixError); |
| 385 | infoSink.info << "Function call stack too deep"; |
| 386 | return false; |
| 387 | default: |
| 388 | UNREACHABLE(); |
| 389 | return false; |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 393 | bool TCompiler::validateOutputs(TIntermNode* root) |
| 394 | { |
| 395 | ValidateOutputs validateOutputs(infoSink.info, compileResources.MaxDrawBuffers); |
| 396 | root->traverse(&validateOutputs); |
| 397 | return (validateOutputs.numErrors() == 0); |
| 398 | } |
| 399 | |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 400 | void TCompiler::rewriteCSSShader(TIntermNode* root) |
| 401 | { |
| 402 | RenameFunction renamer("main(", "css_main("); |
| 403 | root->traverse(&renamer); |
| 404 | } |
| 405 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 406 | bool TCompiler::validateLimitations(TIntermNode* root) |
| 407 | { |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 408 | ValidateLimitations validate(shaderType, infoSink.info); |
| 409 | root->traverse(&validate); |
| 410 | return validate.numErrors() == 0; |
| 411 | } |
| 412 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 413 | bool TCompiler::enforceTimingRestrictions(TIntermNode* root, bool outputGraph) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 414 | { |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 415 | if (shaderSpec != SH_WEBGL_SPEC) |
| 416 | { |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 417 | infoSink.info << "Timing restrictions must be enforced under the WebGL spec."; |
| 418 | return false; |
| 419 | } |
| 420 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 421 | if (shaderType == SH_FRAGMENT_SHADER) |
| 422 | { |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 423 | TDependencyGraph graph(root); |
| 424 | |
| 425 | // Output any errors first. |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 426 | bool success = enforceFragmentShaderTimingRestrictions(graph); |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 427 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 428 | // Then, output the dependency graph. |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 429 | if (outputGraph) |
| 430 | { |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 431 | TDependencyGraphOutput output(infoSink.info); |
| 432 | output.outputAllSpanningTrees(graph); |
| 433 | } |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 434 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 435 | return success; |
| 436 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 437 | else |
| 438 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 439 | return enforceVertexShaderTimingRestrictions(root); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 443 | bool TCompiler::limitExpressionComplexity(TIntermNode* root) |
| 444 | { |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 445 | TMaxDepthTraverser traverser(maxExpressionComplexity+1); |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 446 | root->traverse(&traverser); |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 447 | |
| 448 | if (traverser.getMaxDepth() > maxExpressionComplexity) |
| 449 | { |
| 450 | infoSink.info << "Expression too complex."; |
| 451 | return false; |
| 452 | } |
| 453 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 454 | TDependencyGraph graph(root); |
| 455 | |
| 456 | for (TFunctionCallVector::const_iterator iter = graph.beginUserDefinedFunctionCalls(); |
| 457 | iter != graph.endUserDefinedFunctionCalls(); |
| 458 | ++iter) |
| 459 | { |
| 460 | TGraphFunctionCall* samplerSymbol = *iter; |
| 461 | TDependencyGraphTraverser graphTraverser; |
| 462 | samplerSymbol->traverse(&graphTraverser); |
| 463 | } |
| 464 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 465 | return true; |
| 466 | } |
| 467 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 468 | bool TCompiler::enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 469 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 470 | RestrictFragmentShaderTiming restrictor(infoSink.info); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 471 | restrictor.enforceRestrictions(graph); |
| 472 | return restrictor.numErrors() == 0; |
| 473 | } |
| 474 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 475 | bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 476 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 477 | RestrictVertexShaderTiming restrictor(infoSink.info); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 478 | restrictor.enforceRestrictions(root); |
| 479 | return restrictor.numErrors() == 0; |
| 480 | } |
| 481 | |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 482 | void TCompiler::collectVariables(TIntermNode* root) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 483 | { |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 484 | CollectVariables collect(attribs, uniforms, varyings, hashFunction); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 485 | root->traverse(&collect); |
| 486 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 487 | |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 488 | bool TCompiler::enforcePackingRestrictions() |
| 489 | { |
| 490 | VariablePacker packer; |
| 491 | return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, uniforms); |
| 492 | } |
| 493 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 494 | void TCompiler::initializeGLPosition(TIntermNode* root) |
| 495 | { |
| 496 | InitializeVariables::InitVariableInfoList variables; |
| 497 | InitializeVariables::InitVariableInfo var( |
| 498 | "gl_Position", TType(EbtFloat, EbpUndefined, EvqPosition, 4)); |
| 499 | variables.push_back(var); |
| 500 | InitializeVariables initializer(variables); |
| 501 | root->traverse(&initializer); |
| 502 | } |
| 503 | |
| 504 | void TCompiler::initializeVaryingsWithoutStaticUse(TIntermNode* root) |
| 505 | { |
| 506 | InitializeVariables::InitVariableInfoList variables; |
| 507 | for (size_t ii = 0; ii < varyings.size(); ++ii) |
| 508 | { |
| 509 | const TVariableInfo& varying = varyings[ii]; |
| 510 | if (varying.staticUse) |
| 511 | continue; |
Zhenyao Mo | 66e5dda | 2014-04-28 11:13:25 -0700 | [diff] [blame] | 512 | unsigned char primarySize = 1, secondarySize = 1; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 513 | switch (varying.type) |
| 514 | { |
| 515 | case SH_FLOAT: |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 516 | break; |
| 517 | case SH_FLOAT_VEC2: |
Zhenyao Mo | 66e5dda | 2014-04-28 11:13:25 -0700 | [diff] [blame] | 518 | primarySize = 2; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 519 | break; |
| 520 | case SH_FLOAT_VEC3: |
Zhenyao Mo | 66e5dda | 2014-04-28 11:13:25 -0700 | [diff] [blame] | 521 | primarySize = 3; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 522 | break; |
| 523 | case SH_FLOAT_VEC4: |
Zhenyao Mo | 66e5dda | 2014-04-28 11:13:25 -0700 | [diff] [blame] | 524 | primarySize = 4; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 525 | break; |
| 526 | case SH_FLOAT_MAT2: |
Zhenyao Mo | 66e5dda | 2014-04-28 11:13:25 -0700 | [diff] [blame] | 527 | primarySize = 2; |
| 528 | secondarySize = 2; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 529 | break; |
| 530 | case SH_FLOAT_MAT3: |
Zhenyao Mo | 66e5dda | 2014-04-28 11:13:25 -0700 | [diff] [blame] | 531 | primarySize = 3; |
| 532 | secondarySize = 3; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 533 | break; |
| 534 | case SH_FLOAT_MAT4: |
Zhenyao Mo | 66e5dda | 2014-04-28 11:13:25 -0700 | [diff] [blame] | 535 | primarySize = 4; |
| 536 | secondarySize = 4; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 537 | break; |
| 538 | default: |
| 539 | ASSERT(false); |
| 540 | } |
Zhenyao Mo | 66e5dda | 2014-04-28 11:13:25 -0700 | [diff] [blame] | 541 | TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 542 | TString name = varying.name.c_str(); |
| 543 | if (varying.isArray) |
| 544 | { |
| 545 | type.setArraySize(varying.size); |
| 546 | name = name.substr(0, name.find_first_of('[')); |
| 547 | } |
| 548 | |
| 549 | InitializeVariables::InitVariableInfo var(name, type); |
| 550 | variables.push_back(var); |
| 551 | } |
| 552 | InitializeVariables initializer(variables); |
| 553 | root->traverse(&initializer); |
| 554 | } |
| 555 | |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 556 | const TExtensionBehavior& TCompiler::getExtensionBehavior() const |
| 557 | { |
| 558 | return extensionBehavior; |
| 559 | } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 560 | |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 561 | const ShBuiltInResources& TCompiler::getResources() const |
| 562 | { |
| 563 | return compileResources; |
| 564 | } |
| 565 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 566 | const ArrayBoundsClamper& TCompiler::getArrayBoundsClamper() const |
| 567 | { |
| 568 | return arrayBoundsClamper; |
| 569 | } |
| 570 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 571 | ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const |
| 572 | { |
| 573 | return clampingStrategy; |
| 574 | } |
| 575 | |
| 576 | const BuiltInFunctionEmulator& TCompiler::getBuiltInFunctionEmulator() const |
| 577 | { |
| 578 | return builtInFunctionEmulator; |
| 579 | } |