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 | |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 7 | #include "compiler/translator/Cache.h" |
Jamie Madill | d4a3a31 | 2014-06-25 16:04:56 -0400 | [diff] [blame] | 8 | #include "compiler/translator/Compiler.h" |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 9 | #include "compiler/translator/CallDAG.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 10 | #include "compiler/translator/ForLoopUnroll.h" |
| 11 | #include "compiler/translator/Initialize.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 12 | #include "compiler/translator/InitializeParseContext.h" |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 13 | #include "compiler/translator/InitializeVariables.h" |
Jamie Madill | 6b9cb25 | 2013-10-17 10:45:47 -0400 | [diff] [blame] | 14 | #include "compiler/translator/ParseContext.h" |
Olli Etuaho | c683311 | 2015-04-22 15:15:54 +0300 | [diff] [blame] | 15 | #include "compiler/translator/PruneEmptyDeclarations.h" |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 16 | #include "compiler/translator/RegenerateStructNames.h" |
Olli Etuaho | 5c407bb | 2015-06-01 12:20:39 +0300 | [diff] [blame] | 17 | #include "compiler/translator/RemovePow.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 18 | #include "compiler/translator/RenameFunction.h" |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 19 | #include "compiler/translator/RewriteDoWhile.h" |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 20 | #include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h" |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 21 | #include "compiler/translator/UnfoldShortCircuitAST.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 22 | #include "compiler/translator/ValidateLimitations.h" |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 23 | #include "compiler/translator/ValidateMaxParameters.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 24 | #include "compiler/translator/ValidateOutputs.h" |
| 25 | #include "compiler/translator/VariablePacker.h" |
| 26 | #include "compiler/translator/depgraph/DependencyGraph.h" |
| 27 | #include "compiler/translator/depgraph/DependencyGraphOutput.h" |
| 28 | #include "compiler/translator/timing/RestrictFragmentShaderTiming.h" |
| 29 | #include "compiler/translator/timing/RestrictVertexShaderTiming.h" |
shannon.woods@transgaming.com | da1ed36 | 2013-01-25 21:54:57 +0000 | [diff] [blame] | 30 | #include "third_party/compiler/ArrayBoundsClamper.h" |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 31 | #include "angle_gl.h" |
Jamie Madill | aa72d78 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 32 | #include "common/utilities.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 33 | |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 34 | bool IsWebGLBasedSpec(ShShaderSpec spec) |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 35 | { |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 36 | return (spec == SH_WEBGL_SPEC || |
| 37 | spec == SH_CSS_SHADERS_SPEC || |
| 38 | spec == SH_WEBGL2_SPEC); |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 41 | bool IsGLSL130OrNewer(ShShaderOutput output) |
| 42 | { |
| 43 | return (output == SH_GLSL_130_OUTPUT || |
Geoff Lang | 8273e00 | 2015-06-15 13:40:19 -0700 | [diff] [blame] | 44 | output == SH_GLSL_140_OUTPUT || |
| 45 | output == SH_GLSL_150_CORE_OUTPUT || |
| 46 | output == SH_GLSL_330_CORE_OUTPUT || |
| 47 | output == SH_GLSL_400_CORE_OUTPUT || |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 48 | output == SH_GLSL_410_CORE_OUTPUT || |
Geoff Lang | 8273e00 | 2015-06-15 13:40:19 -0700 | [diff] [blame] | 49 | output == SH_GLSL_420_CORE_OUTPUT || |
| 50 | output == SH_GLSL_430_CORE_OUTPUT || |
| 51 | output == SH_GLSL_440_CORE_OUTPUT || |
| 52 | output == SH_GLSL_450_CORE_OUTPUT); |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 55 | size_t GetGlobalMaxTokenSize(ShShaderSpec spec) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 56 | { |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 57 | // WebGL defines a max token legnth of 256, while ES2 leaves max token |
| 58 | // size undefined. ES3 defines a max size of 1024 characters. |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 59 | switch (spec) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 60 | { |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 61 | case SH_WEBGL_SPEC: |
| 62 | case SH_CSS_SHADERS_SPEC: |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 63 | return 256; |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 64 | default: |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 65 | return 1024; |
| 66 | } |
| 67 | } |
| 68 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 69 | namespace { |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 70 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 71 | class TScopedPoolAllocator |
| 72 | { |
| 73 | public: |
| 74 | TScopedPoolAllocator(TPoolAllocator* allocator) : mAllocator(allocator) |
| 75 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 76 | mAllocator->push(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 77 | SetGlobalPoolAllocator(mAllocator); |
| 78 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 79 | ~TScopedPoolAllocator() |
| 80 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 81 | SetGlobalPoolAllocator(NULL); |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 82 | mAllocator->pop(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 85 | private: |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 86 | TPoolAllocator* mAllocator; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 87 | }; |
| 88 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 89 | class TScopedSymbolTableLevel |
| 90 | { |
| 91 | public: |
| 92 | TScopedSymbolTableLevel(TSymbolTable* table) : mTable(table) |
| 93 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 94 | ASSERT(mTable->atBuiltInLevel()); |
| 95 | mTable->push(); |
| 96 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 97 | ~TScopedSymbolTableLevel() |
| 98 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 99 | while (!mTable->atBuiltInLevel()) |
| 100 | mTable->pop(); |
| 101 | } |
| 102 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 103 | private: |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 104 | TSymbolTable* mTable; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 105 | }; |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 106 | |
| 107 | int MapSpecToShaderVersion(ShShaderSpec spec) |
| 108 | { |
| 109 | switch (spec) |
| 110 | { |
| 111 | case SH_GLES2_SPEC: |
| 112 | case SH_WEBGL_SPEC: |
| 113 | case SH_CSS_SHADERS_SPEC: |
| 114 | return 100; |
| 115 | case SH_GLES3_SPEC: |
| 116 | case SH_WEBGL2_SPEC: |
| 117 | return 300; |
| 118 | default: |
| 119 | UNREACHABLE(); |
| 120 | return 0; |
| 121 | } |
| 122 | } |
| 123 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 124 | } // namespace |
| 125 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 126 | TShHandleBase::TShHandleBase() |
| 127 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 128 | allocator.push(); |
| 129 | SetGlobalPoolAllocator(&allocator); |
| 130 | } |
| 131 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 132 | TShHandleBase::~TShHandleBase() |
| 133 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 134 | SetGlobalPoolAllocator(NULL); |
| 135 | allocator.popAll(); |
| 136 | } |
| 137 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 138 | TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output) |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 139 | : shaderType(type), |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 140 | shaderSpec(spec), |
Jamie Madill | 68fe74a | 2014-05-27 12:56:01 -0400 | [diff] [blame] | 141 | outputType(output), |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 142 | maxUniformVectors(0), |
| 143 | maxExpressionComplexity(0), |
| 144 | maxCallStackDepth(0), |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 145 | maxFunctionParameters(0), |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 146 | fragmentPrecisionHigh(false), |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 147 | clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC), |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 148 | builtInFunctionEmulator(), |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 149 | mSourcePath(NULL), |
| 150 | mTemporaryIndex(0) |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 151 | { |
| 152 | } |
| 153 | |
| 154 | TCompiler::~TCompiler() |
| 155 | { |
| 156 | } |
| 157 | |
Olli Etuaho | 5d91dda | 2015-06-18 15:47:46 +0300 | [diff] [blame] | 158 | bool TCompiler::shouldRunLoopAndIndexingValidation(int compileOptions) const |
| 159 | { |
| 160 | // If compiling an ESSL 1.00 shader for WebGL, or if its been requested through the API, |
| 161 | // validate loop and indexing as well (to verify that the shader only uses minimal functionality |
| 162 | // of ESSL 1.00 as in Appendix A of the spec). |
| 163 | return (IsWebGLBasedSpec(shaderSpec) && shaderVersion == 100) || |
| 164 | (compileOptions & SH_VALIDATE_LOOP_INDEXING); |
| 165 | } |
| 166 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 167 | bool TCompiler::Init(const ShBuiltInResources& resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 168 | { |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 169 | shaderVersion = 100; |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 170 | maxUniformVectors = (shaderType == GL_VERTEX_SHADER) ? |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 171 | resources.MaxVertexUniformVectors : |
| 172 | resources.MaxFragmentUniformVectors; |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 173 | maxExpressionComplexity = resources.MaxExpressionComplexity; |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 174 | maxCallStackDepth = resources.MaxCallStackDepth; |
| 175 | maxFunctionParameters = resources.MaxFunctionParameters; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 176 | |
| 177 | SetGlobalPoolAllocator(&allocator); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 178 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 179 | // Generate built-in symbol table. |
| 180 | if (!InitBuiltInSymbolTable(resources)) |
| 181 | return false; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 182 | InitExtensionBehavior(resources, extensionBehavior); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 183 | fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 184 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 185 | arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy); |
| 186 | clampingStrategy = resources.ArrayIndexClampingStrategy; |
| 187 | |
daniel@transgaming.com | c23f461 | 2012-11-28 19:42:57 +0000 | [diff] [blame] | 188 | hashFunction = resources.HashFunction; |
| 189 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 190 | return true; |
| 191 | } |
| 192 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 193 | TIntermNode *TCompiler::compileTreeForTesting(const char* const shaderStrings[], |
| 194 | size_t numStrings, int compileOptions) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 195 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 196 | return compileTreeImpl(shaderStrings, numStrings, compileOptions); |
| 197 | } |
| 198 | |
Olli Etuaho | a7b6db7 | 2015-08-19 14:26:30 +0300 | [diff] [blame] | 199 | TIntermNode *TCompiler::compileTreeImpl(const char *const shaderStrings[], |
| 200 | size_t numStrings, |
| 201 | const int compileOptions) |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 202 | { |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 203 | clearResults(); |
| 204 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 205 | ASSERT(numStrings > 0); |
| 206 | ASSERT(GetGlobalPoolAllocator()); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 207 | |
David Yen | 0fbd128 | 2015-02-02 14:46:09 -0800 | [diff] [blame] | 208 | // Reset the extension behavior for each compilation unit. |
| 209 | ResetExtensionBehavior(extensionBehavior); |
| 210 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 211 | // First string is path of source file if flag is set. The actual source follows. |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 212 | size_t firstSource = 0; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 213 | if (compileOptions & SH_SOURCE_PATH) |
| 214 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 215 | mSourcePath = shaderStrings[0]; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 216 | ++firstSource; |
| 217 | } |
| 218 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 219 | TIntermediate intermediate(infoSink); |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 220 | TParseContext parseContext(symbolTable, extensionBehavior, intermediate, shaderType, shaderSpec, |
| 221 | compileOptions, true, infoSink, getResources()); |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 222 | |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 223 | parseContext.setFragmentPrecisionHighOnESSL1(fragmentPrecisionHigh); |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 224 | SetGlobalParseContext(&parseContext); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 225 | |
| 226 | // We preserve symbols at the built-in level from compile-to-compile. |
| 227 | // Start pushing the user-defined symbols at global level. |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 228 | TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 229 | |
| 230 | // Parse shader. |
| 231 | bool success = |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 232 | (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr, &parseContext) == 0) && |
| 233 | (parseContext.getTreeRoot() != nullptr); |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 234 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 235 | shaderVersion = parseContext.getShaderVersion(); |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 236 | if (success && MapSpecToShaderVersion(shaderSpec) < shaderVersion) |
| 237 | { |
| 238 | infoSink.info.prefix(EPrefixError); |
| 239 | infoSink.info << "unsupported shader version"; |
| 240 | success = false; |
| 241 | } |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 242 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 243 | TIntermNode *root = nullptr; |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 244 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 245 | if (success) |
| 246 | { |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 247 | mPragma = parseContext.pragma(); |
| 248 | if (mPragma.stdgl.invariantAll) |
| 249 | { |
| 250 | symbolTable.setGlobalInvariant(); |
| 251 | } |
| 252 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 253 | root = parseContext.getTreeRoot(); |
Olli Etuaho | 43613b0 | 2015-08-04 11:02:21 +0300 | [diff] [blame] | 254 | root = intermediate.postProcess(root); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 255 | |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 256 | // Highp might have been auto-enabled based on shader version |
| 257 | fragmentPrecisionHigh = parseContext.getFragmentPrecisionHigh(); |
| 258 | |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 259 | // Disallow expressions deemed too complex. |
| 260 | if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY)) |
| 261 | success = limitExpressionComplexity(root); |
| 262 | |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 263 | // Create the function DAG and check there is no recursion |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 264 | if (success) |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 265 | success = initCallDag(root); |
| 266 | |
| 267 | if (success && (compileOptions & SH_LIMIT_CALL_STACK_DEPTH)) |
| 268 | success = checkCallDepth(); |
| 269 | |
| 270 | // Checks which functions are used and if "main" exists |
| 271 | if (success) |
| 272 | { |
| 273 | functionMetadata.clear(); |
| 274 | functionMetadata.resize(mCallDag.size()); |
| 275 | success = tagUsedFunctions(); |
| 276 | } |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 277 | |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 278 | if (success && !(compileOptions & SH_DONT_PRUNE_UNUSED_FUNCTIONS)) |
| 279 | success = pruneUnusedFunctions(root); |
| 280 | |
Olli Etuaho | c683311 | 2015-04-22 15:15:54 +0300 | [diff] [blame] | 281 | // Prune empty declarations to work around driver bugs and to keep declaration output simple. |
| 282 | if (success) |
| 283 | PruneEmptyDeclarations(root); |
| 284 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 285 | if (success && shaderVersion == 300 && shaderType == GL_FRAGMENT_SHADER) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 286 | success = validateOutputs(root); |
| 287 | |
Olli Etuaho | 5d91dda | 2015-06-18 15:47:46 +0300 | [diff] [blame] | 288 | if (success && shouldRunLoopAndIndexingValidation(compileOptions)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 289 | success = validateLimitations(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 290 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 291 | if (success && (compileOptions & SH_TIMING_RESTRICTIONS)) |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 292 | success = enforceTimingRestrictions(root, (compileOptions & SH_DEPENDENCY_GRAPH) != 0); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 293 | |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 294 | if (success && shaderSpec == SH_CSS_SHADERS_SPEC) |
| 295 | rewriteCSSShader(root); |
| 296 | |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 297 | // Unroll for-loop markup needs to happen after validateLimitations pass. |
| 298 | if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX)) |
Zhenyao Mo | 3cdfcce | 2014-03-07 13:00:08 -0800 | [diff] [blame] | 299 | { |
Olli Etuaho | 8a76dcc | 2015-12-10 20:25:12 +0200 | [diff] [blame] | 300 | ForLoopUnrollMarker marker(ForLoopUnrollMarker::kIntegerIndex, |
| 301 | shouldRunLoopAndIndexingValidation(compileOptions)); |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 302 | root->traverse(&marker); |
| 303 | } |
| 304 | if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX)) |
Zhenyao Mo | 3cdfcce | 2014-03-07 13:00:08 -0800 | [diff] [blame] | 305 | { |
Olli Etuaho | 8a76dcc | 2015-12-10 20:25:12 +0200 | [diff] [blame] | 306 | ForLoopUnrollMarker marker(ForLoopUnrollMarker::kSamplerArrayIndex, |
| 307 | shouldRunLoopAndIndexingValidation(compileOptions)); |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 308 | root->traverse(&marker); |
| 309 | if (marker.samplerArrayIndexIsFloatLoopIndex()) |
| 310 | { |
| 311 | infoSink.info.prefix(EPrefixError); |
| 312 | infoSink.info << "sampler array index is float loop index"; |
| 313 | success = false; |
| 314 | } |
| 315 | } |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 316 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 317 | // Built-in function emulation needs to happen after validateLimitations pass. |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 318 | if (success) |
| 319 | { |
| 320 | initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions); |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 321 | builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(root); |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 322 | } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 323 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 324 | // Clamping uniform array bounds needs to happen after validateLimitations pass. |
| 325 | if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS)) |
| 326 | arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root); |
| 327 | |
Ian Ewell | 924b7de | 2016-01-21 13:54:28 -0500 | [diff] [blame] | 328 | // gl_Position is always written in compatibility output mode |
| 329 | if (success && shaderType == GL_VERTEX_SHADER && |
| 330 | ((compileOptions & SH_INIT_GL_POSITION) || |
| 331 | (outputType == SH_GLSL_COMPATIBILITY_OUTPUT))) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 332 | initializeGLPosition(root); |
Zhenyao Mo | ac44cd2 | 2013-09-23 14:57:09 -0400 | [diff] [blame] | 333 | |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 334 | // This pass might emit short circuits so keep it before the short circuit unfolding |
| 335 | if (success && (compileOptions & SH_REWRITE_DO_WHILE_LOOPS)) |
| 336 | RewriteDoWhile(root, getTemporaryIndex()); |
| 337 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 338 | if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT)) |
| 339 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 340 | UnfoldShortCircuitAST unfoldShortCircuit; |
| 341 | root->traverse(&unfoldShortCircuit); |
| 342 | unfoldShortCircuit.updateTree(); |
| 343 | } |
| 344 | |
Olli Etuaho | 5c407bb | 2015-06-01 12:20:39 +0300 | [diff] [blame] | 345 | if (success && (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT)) |
| 346 | { |
| 347 | RemovePow(root); |
| 348 | } |
| 349 | |
Olli Etuaho | 4dfe809 | 2015-08-21 17:44:35 +0300 | [diff] [blame] | 350 | if (success && shouldCollectVariables(compileOptions)) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 351 | { |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 352 | collectVariables(root); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 353 | if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) |
| 354 | { |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 355 | success = enforcePackingRestrictions(); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 356 | if (!success) |
| 357 | { |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 358 | infoSink.info.prefix(EPrefixError); |
| 359 | infoSink.info << "too many uniforms"; |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 362 | if (success && shaderType == GL_VERTEX_SHADER && |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 363 | (compileOptions & SH_INIT_VARYINGS_WITHOUT_STATIC_USE)) |
| 364 | initializeVaryingsWithoutStaticUse(root); |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 365 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 366 | |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 367 | if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS)) |
| 368 | { |
Zhenyao Mo | daf5657 | 2014-08-06 16:18:30 -0700 | [diff] [blame] | 369 | ScalarizeVecAndMatConstructorArgs scalarizer( |
| 370 | shaderType, fragmentPrecisionHigh); |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 371 | root->traverse(&scalarizer); |
| 372 | } |
| 373 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 374 | if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES)) |
| 375 | { |
| 376 | RegenerateStructNames gen(symbolTable, shaderVersion); |
| 377 | root->traverse(&gen); |
| 378 | } |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 381 | SetGlobalParseContext(NULL); |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 382 | if (success) |
| 383 | return root; |
| 384 | |
| 385 | return NULL; |
| 386 | } |
| 387 | |
| 388 | bool TCompiler::compile(const char* const shaderStrings[], |
| 389 | size_t numStrings, int compileOptions) |
| 390 | { |
| 391 | if (numStrings == 0) |
| 392 | return true; |
| 393 | |
| 394 | TScopedPoolAllocator scopedAlloc(&allocator); |
| 395 | TIntermNode *root = compileTreeImpl(shaderStrings, numStrings, compileOptions); |
| 396 | |
| 397 | if (root) |
| 398 | { |
| 399 | if (compileOptions & SH_INTERMEDIATE_TREE) |
| 400 | TIntermediate::outputTree(root, infoSink.info); |
| 401 | |
| 402 | if (compileOptions & SH_OBJECT_CODE) |
| 403 | translate(root, compileOptions); |
| 404 | |
| 405 | // The IntermNode tree doesn't need to be deleted here, since the |
| 406 | // memory will be freed in a big chunk by the PoolAllocator. |
| 407 | return true; |
| 408 | } |
| 409 | return false; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 412 | bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 413 | { |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 414 | compileResources = resources; |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 415 | setResourceString(); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 416 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 417 | assert(symbolTable.isEmpty()); |
| 418 | symbolTable.push(); // COMMON_BUILTINS |
| 419 | symbolTable.push(); // ESSL1_BUILTINS |
| 420 | symbolTable.push(); // ESSL3_BUILTINS |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 421 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 422 | TPublicType integer; |
| 423 | integer.type = EbtInt; |
| 424 | integer.primarySize = 1; |
| 425 | integer.secondarySize = 1; |
| 426 | integer.array = false; |
| 427 | |
| 428 | TPublicType floatingPoint; |
| 429 | floatingPoint.type = EbtFloat; |
| 430 | floatingPoint.primarySize = 1; |
| 431 | floatingPoint.secondarySize = 1; |
| 432 | floatingPoint.array = false; |
| 433 | |
| 434 | switch(shaderType) |
| 435 | { |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 436 | case GL_FRAGMENT_SHADER: |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 437 | symbolTable.setDefaultPrecision(integer, EbpMedium); |
| 438 | break; |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 439 | case GL_VERTEX_SHADER: |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 440 | symbolTable.setDefaultPrecision(integer, EbpHigh); |
| 441 | symbolTable.setDefaultPrecision(floatingPoint, EbpHigh); |
| 442 | break; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 443 | default: |
| 444 | assert(false && "Language not supported"); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 445 | } |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 446 | // Set defaults for sampler types that have default precision, even those that are |
Zhenyao Mo | a5a1dfc | 2013-09-23 14:57:03 -0400 | [diff] [blame] | 447 | // only available if an extension exists. |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 448 | // New sampler types in ESSL3 don't have default precision. ESSL1 types do. |
| 449 | initSamplerDefaultPrecision(EbtSampler2D); |
| 450 | initSamplerDefaultPrecision(EbtSamplerCube); |
| 451 | // SamplerExternalOES is specified in the extension to have default precision. |
| 452 | initSamplerDefaultPrecision(EbtSamplerExternalOES); |
| 453 | // It isn't specified whether Sampler2DRect has default precision. |
| 454 | initSamplerDefaultPrecision(EbtSampler2DRect); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 455 | |
Jamie Madill | 1b45214 | 2013-07-12 14:51:11 -0400 | [diff] [blame] | 456 | InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 457 | |
| 458 | IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable); |
| 459 | |
| 460 | return true; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 463 | void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType) |
| 464 | { |
| 465 | ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd); |
| 466 | TPublicType sampler; |
| 467 | sampler.primarySize = 1; |
| 468 | sampler.secondarySize = 1; |
| 469 | sampler.array = false; |
| 470 | sampler.type = samplerType; |
| 471 | symbolTable.setDefaultPrecision(sampler, EbpLow); |
| 472 | } |
| 473 | |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 474 | void TCompiler::setResourceString() |
| 475 | { |
| 476 | std::ostringstream strstream; |
| 477 | strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs |
| 478 | << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors |
| 479 | << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors |
| 480 | << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits |
| 481 | << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits |
| 482 | << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits |
| 483 | << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors |
| 484 | << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers |
| 485 | << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives |
| 486 | << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external |
| 487 | << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle |
| 488 | << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers |
| 489 | << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh |
| 490 | << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity |
| 491 | << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 492 | << ":MaxFunctionParameters:" << compileResources.MaxFunctionParameters |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 493 | << ":EXT_blend_func_extended:" << compileResources.EXT_blend_func_extended |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 494 | << ":EXT_frag_depth:" << compileResources.EXT_frag_depth |
| 495 | << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod |
Erik Dahlström | ea7a212 | 2014-11-17 16:15:57 +0100 | [diff] [blame] | 496 | << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch |
| 497 | << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch |
| 498 | << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 499 | << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors |
| 500 | << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors |
| 501 | << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset |
Olli Etuaho | e61209a | 2014-09-26 12:01:17 +0300 | [diff] [blame] | 502 | << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 503 | << ":MaxDualSourceDrawBuffers:" << compileResources.MaxDualSourceDrawBuffers |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 504 | << ":NV_draw_buffers:" << compileResources.NV_draw_buffers |
| 505 | << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision; |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 506 | |
| 507 | builtInResourcesString = strstream.str(); |
| 508 | } |
| 509 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 510 | void TCompiler::clearResults() |
| 511 | { |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 512 | arrayBoundsClamper.Cleanup(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 513 | infoSink.info.erase(); |
| 514 | infoSink.obj.erase(); |
| 515 | infoSink.debug.erase(); |
| 516 | |
Jamie Madill | ed27c72 | 2014-07-02 15:31:23 -0400 | [diff] [blame] | 517 | attributes.clear(); |
| 518 | outputVariables.clear(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 519 | uniforms.clear(); |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 520 | expandedUniforms.clear(); |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 521 | varyings.clear(); |
Jamie Madill | ed27c72 | 2014-07-02 15:31:23 -0400 | [diff] [blame] | 522 | interfaceBlocks.clear(); |
zmo@google.com | a3b4ab4 | 2011-09-16 00:53:26 +0000 | [diff] [blame] | 523 | |
| 524 | builtInFunctionEmulator.Cleanup(); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 525 | |
| 526 | nameMap.clear(); |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 527 | |
| 528 | mSourcePath = NULL; |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 529 | mTemporaryIndex = 0; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 532 | bool TCompiler::initCallDag(TIntermNode *root) |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 533 | { |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 534 | mCallDag.clear(); |
| 535 | |
| 536 | switch (mCallDag.init(root, &infoSink.info)) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 537 | { |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 538 | case CallDAG::INITDAG_SUCCESS: |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 539 | return true; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 540 | case CallDAG::INITDAG_RECURSION: |
| 541 | infoSink.info.prefix(EPrefixError); |
| 542 | infoSink.info << "Function recursion detected"; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 543 | return false; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 544 | case CallDAG::INITDAG_UNDEFINED: |
| 545 | infoSink.info.prefix(EPrefixError); |
| 546 | infoSink.info << "Unimplemented function detected"; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 547 | return false; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | UNREACHABLE(); |
| 551 | return true; |
| 552 | } |
| 553 | |
| 554 | bool TCompiler::checkCallDepth() |
| 555 | { |
| 556 | std::vector<int> depths(mCallDag.size()); |
| 557 | |
| 558 | for (size_t i = 0; i < mCallDag.size(); i++) |
| 559 | { |
| 560 | int depth = 0; |
| 561 | auto &record = mCallDag.getRecordFromIndex(i); |
| 562 | |
| 563 | for (auto &calleeIndex : record.callees) |
| 564 | { |
| 565 | depth = std::max(depth, depths[calleeIndex] + 1); |
| 566 | } |
| 567 | |
| 568 | depths[i] = depth; |
| 569 | |
| 570 | if (depth >= maxCallStackDepth) |
| 571 | { |
| 572 | // Trace back the function chain to have a meaningful info log. |
| 573 | infoSink.info.prefix(EPrefixError); |
| 574 | infoSink.info << "Call stack too deep (larger than " << maxCallStackDepth |
| 575 | << ") with the following call chain: " << record.name; |
| 576 | |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 577 | int currentFunction = static_cast<int>(i); |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 578 | int currentDepth = depth; |
| 579 | |
| 580 | while (currentFunction != -1) |
| 581 | { |
| 582 | infoSink.info << " -> " << mCallDag.getRecordFromIndex(currentFunction).name; |
| 583 | |
| 584 | int nextFunction = -1; |
| 585 | for (auto& calleeIndex : mCallDag.getRecordFromIndex(currentFunction).callees) |
| 586 | { |
| 587 | if (depths[calleeIndex] == currentDepth - 1) |
| 588 | { |
| 589 | currentDepth--; |
| 590 | nextFunction = calleeIndex; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | currentFunction = nextFunction; |
| 595 | } |
| 596 | |
| 597 | return false; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | return true; |
| 602 | } |
| 603 | |
| 604 | bool TCompiler::tagUsedFunctions() |
| 605 | { |
| 606 | // Search from main, starting from the end of the DAG as it usually is the root. |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 607 | for (size_t i = mCallDag.size(); i-- > 0;) |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 608 | { |
| 609 | if (mCallDag.getRecordFromIndex(i).name == "main(") |
| 610 | { |
| 611 | internalTagUsedFunction(i); |
| 612 | return true; |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | infoSink.info.prefix(EPrefixError); |
Olli Etuaho | 792a41d | 2015-12-15 12:39:16 +0200 | [diff] [blame] | 617 | infoSink.info << "Missing main()\n"; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 618 | return false; |
| 619 | } |
| 620 | |
| 621 | void TCompiler::internalTagUsedFunction(size_t index) |
| 622 | { |
| 623 | if (functionMetadata[index].used) |
| 624 | { |
| 625 | return; |
| 626 | } |
| 627 | |
| 628 | functionMetadata[index].used = true; |
| 629 | |
| 630 | for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees) |
| 631 | { |
| 632 | internalTagUsedFunction(calleeIndex); |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 636 | // A predicate for the stl that returns if a top-level node is unused |
| 637 | class TCompiler::UnusedPredicate |
| 638 | { |
| 639 | public: |
| 640 | UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas) |
| 641 | : mCallDag(callDag), |
| 642 | mMetadatas(metadatas) |
| 643 | { |
| 644 | } |
| 645 | |
| 646 | bool operator ()(TIntermNode *node) |
| 647 | { |
| 648 | const TIntermAggregate *asAggregate = node->getAsAggregate(); |
| 649 | |
| 650 | if (asAggregate == nullptr) |
| 651 | { |
| 652 | return false; |
| 653 | } |
| 654 | |
| 655 | if (!(asAggregate->getOp() == EOpFunction || asAggregate->getOp() == EOpPrototype)) |
| 656 | { |
| 657 | return false; |
| 658 | } |
| 659 | |
| 660 | size_t callDagIndex = mCallDag->findIndex(asAggregate); |
| 661 | if (callDagIndex == CallDAG::InvalidIndex) |
| 662 | { |
| 663 | // This happens only for unimplemented prototypes which are thus unused |
| 664 | ASSERT(asAggregate->getOp() == EOpPrototype); |
| 665 | return true; |
| 666 | } |
| 667 | |
| 668 | ASSERT(callDagIndex < mMetadatas->size()); |
| 669 | return !(*mMetadatas)[callDagIndex].used; |
| 670 | } |
| 671 | |
| 672 | private: |
| 673 | const CallDAG *mCallDag; |
| 674 | const std::vector<FunctionMetadata> *mMetadatas; |
| 675 | }; |
| 676 | |
| 677 | bool TCompiler::pruneUnusedFunctions(TIntermNode *root) |
| 678 | { |
| 679 | TIntermAggregate *rootNode = root->getAsAggregate(); |
| 680 | ASSERT(rootNode != nullptr); |
| 681 | |
| 682 | UnusedPredicate isUnused(&mCallDag, &functionMetadata); |
| 683 | TIntermSequence *sequence = rootNode->getSequence(); |
Corentin Wallez | b081e78 | 2015-07-20 05:40:04 -0700 | [diff] [blame] | 684 | |
| 685 | if (!sequence->empty()) |
| 686 | { |
| 687 | sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused), sequence->end()); |
| 688 | } |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 689 | |
| 690 | return true; |
| 691 | } |
| 692 | |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 693 | bool TCompiler::validateOutputs(TIntermNode* root) |
| 694 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 695 | ValidateOutputs validateOutputs(getExtensionBehavior(), compileResources.MaxDrawBuffers); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 696 | root->traverse(&validateOutputs); |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 697 | return (validateOutputs.validateAndCountErrors(infoSink.info) == 0); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 698 | } |
| 699 | |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 700 | void TCompiler::rewriteCSSShader(TIntermNode* root) |
| 701 | { |
| 702 | RenameFunction renamer("main(", "css_main("); |
| 703 | root->traverse(&renamer); |
| 704 | } |
| 705 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 706 | bool TCompiler::validateLimitations(TIntermNode* root) |
| 707 | { |
Olli Etuaho | 8a76dcc | 2015-12-10 20:25:12 +0200 | [diff] [blame] | 708 | ValidateLimitations validate(shaderType, &infoSink.info); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 709 | root->traverse(&validate); |
| 710 | return validate.numErrors() == 0; |
| 711 | } |
| 712 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 713 | bool TCompiler::enforceTimingRestrictions(TIntermNode* root, bool outputGraph) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 714 | { |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 715 | if (shaderSpec != SH_WEBGL_SPEC) |
| 716 | { |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 717 | infoSink.info << "Timing restrictions must be enforced under the WebGL spec."; |
| 718 | return false; |
| 719 | } |
| 720 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 721 | if (shaderType == GL_FRAGMENT_SHADER) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 722 | { |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 723 | TDependencyGraph graph(root); |
| 724 | |
| 725 | // Output any errors first. |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 726 | bool success = enforceFragmentShaderTimingRestrictions(graph); |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 727 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 728 | // Then, output the dependency graph. |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 729 | if (outputGraph) |
| 730 | { |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 731 | TDependencyGraphOutput output(infoSink.info); |
| 732 | output.outputAllSpanningTrees(graph); |
| 733 | } |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 734 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 735 | return success; |
| 736 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 737 | else |
| 738 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 739 | return enforceVertexShaderTimingRestrictions(root); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 743 | bool TCompiler::limitExpressionComplexity(TIntermNode* root) |
| 744 | { |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 745 | TMaxDepthTraverser traverser(maxExpressionComplexity+1); |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 746 | root->traverse(&traverser); |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 747 | |
| 748 | if (traverser.getMaxDepth() > maxExpressionComplexity) |
| 749 | { |
| 750 | infoSink.info << "Expression too complex."; |
| 751 | return false; |
| 752 | } |
| 753 | |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 754 | if (!ValidateMaxParameters::validate(root, maxFunctionParameters)) |
| 755 | { |
| 756 | infoSink.info << "Function has too many parameters."; |
| 757 | return false; |
| 758 | } |
| 759 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 760 | return true; |
| 761 | } |
| 762 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 763 | bool TCompiler::enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 764 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 765 | RestrictFragmentShaderTiming restrictor(infoSink.info); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 766 | restrictor.enforceRestrictions(graph); |
| 767 | return restrictor.numErrors() == 0; |
| 768 | } |
| 769 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 770 | bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 771 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 772 | RestrictVertexShaderTiming restrictor(infoSink.info); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 773 | restrictor.enforceRestrictions(root); |
| 774 | return restrictor.numErrors() == 0; |
| 775 | } |
| 776 | |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 777 | void TCompiler::collectVariables(TIntermNode* root) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 778 | { |
Jamie Madill | a2fbb84 | 2014-09-03 09:40:47 -0400 | [diff] [blame] | 779 | sh::CollectVariables collect(&attributes, |
| 780 | &outputVariables, |
| 781 | &uniforms, |
| 782 | &varyings, |
| 783 | &interfaceBlocks, |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 784 | hashFunction, |
| 785 | symbolTable); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 786 | root->traverse(&collect); |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 787 | |
Zhenyao Mo | 409078f | 2014-10-28 13:23:18 -0700 | [diff] [blame] | 788 | // This is for enforcePackingRestriction(). |
| 789 | sh::ExpandUniforms(uniforms, &expandedUniforms); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 790 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 791 | |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 792 | bool TCompiler::enforcePackingRestrictions() |
| 793 | { |
| 794 | VariablePacker packer; |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 795 | return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms); |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 798 | void TCompiler::initializeGLPosition(TIntermNode* root) |
| 799 | { |
| 800 | InitializeVariables::InitVariableInfoList variables; |
| 801 | InitializeVariables::InitVariableInfo var( |
| 802 | "gl_Position", TType(EbtFloat, EbpUndefined, EvqPosition, 4)); |
| 803 | variables.push_back(var); |
| 804 | InitializeVariables initializer(variables); |
| 805 | root->traverse(&initializer); |
| 806 | } |
| 807 | |
| 808 | void TCompiler::initializeVaryingsWithoutStaticUse(TIntermNode* root) |
| 809 | { |
| 810 | InitializeVariables::InitVariableInfoList variables; |
| 811 | for (size_t ii = 0; ii < varyings.size(); ++ii) |
| 812 | { |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 813 | const sh::Varying& varying = varyings[ii]; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 814 | if (varying.staticUse) |
| 815 | continue; |
Jamie Madill | aa72d78 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 816 | unsigned char primarySize = static_cast<unsigned char>(gl::VariableColumnCount(varying.type)); |
| 817 | unsigned char secondarySize = static_cast<unsigned char>(gl::VariableRowCount(varying.type)); |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 818 | TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray()); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 819 | TString name = varying.name.c_str(); |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 820 | if (varying.isArray()) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 821 | { |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 822 | type.setArraySize(varying.arraySize); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 823 | name = name.substr(0, name.find_first_of('[')); |
| 824 | } |
| 825 | |
| 826 | InitializeVariables::InitVariableInfo var(name, type); |
| 827 | variables.push_back(var); |
| 828 | } |
| 829 | InitializeVariables initializer(variables); |
| 830 | root->traverse(&initializer); |
| 831 | } |
| 832 | |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 833 | const TExtensionBehavior& TCompiler::getExtensionBehavior() const |
| 834 | { |
| 835 | return extensionBehavior; |
| 836 | } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 837 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 838 | const char *TCompiler::getSourcePath() const |
| 839 | { |
| 840 | return mSourcePath; |
| 841 | } |
| 842 | |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 843 | const ShBuiltInResources& TCompiler::getResources() const |
| 844 | { |
| 845 | return compileResources; |
| 846 | } |
| 847 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 848 | const ArrayBoundsClamper& TCompiler::getArrayBoundsClamper() const |
| 849 | { |
| 850 | return arrayBoundsClamper; |
| 851 | } |
| 852 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 853 | ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const |
| 854 | { |
| 855 | return clampingStrategy; |
| 856 | } |
| 857 | |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 858 | const BuiltInFunctionEmulator& TCompiler::getBuiltInFunctionEmulator() const |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 859 | { |
| 860 | return builtInFunctionEmulator; |
| 861 | } |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 862 | |
| 863 | void TCompiler::writePragma() |
| 864 | { |
| 865 | TInfoSinkBase &sink = infoSink.obj; |
| 866 | if (mPragma.stdgl.invariantAll) |
| 867 | sink << "#pragma STDGL invariant(all)\n"; |
| 868 | } |