blob: cd571f820de03ead0595a05af869d743fdd8eb91 [file] [log] [blame]
alokp@chromium.org07620a52010-09-23 17:53:56 +00001//
Jamie Madill88f6e942014-02-19 10:27:53 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
alokp@chromium.org07620a52010-09-23 17:53:56 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Dmitry Skiba01971112015-07-10 14:54:00 -04007#include "compiler/translator/Cache.h"
Jamie Madilld4a3a312014-06-25 16:04:56 -04008#include "compiler/translator/Compiler.h"
Corentin Wallez71d147f2015-02-11 11:15:24 -08009#include "compiler/translator/CallDAG.h"
Geoff Lang17732822013-08-29 13:46:49 -040010#include "compiler/translator/ForLoopUnroll.h"
11#include "compiler/translator/Initialize.h"
Geoff Lang17732822013-08-29 13:46:49 -040012#include "compiler/translator/InitializeParseContext.h"
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080013#include "compiler/translator/InitializeVariables.h"
Jamie Madill6b9cb252013-10-17 10:45:47 -040014#include "compiler/translator/ParseContext.h"
Olli Etuahoc6833112015-04-22 15:15:54 +030015#include "compiler/translator/PruneEmptyDeclarations.h"
Zhenyao Moe740add2014-07-18 17:01:01 -070016#include "compiler/translator/RegenerateStructNames.h"
Olli Etuaho5c407bb2015-06-01 12:20:39 +030017#include "compiler/translator/RemovePow.h"
Geoff Lang17732822013-08-29 13:46:49 -040018#include "compiler/translator/RenameFunction.h"
Zhenyao Mocd68fe72014-07-11 10:45:44 -070019#include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h"
Zhenyao Mo7cab38b2013-10-15 12:59:30 -070020#include "compiler/translator/UnfoldShortCircuitAST.h"
Geoff Lang17732822013-08-29 13:46:49 -040021#include "compiler/translator/ValidateLimitations.h"
22#include "compiler/translator/ValidateOutputs.h"
23#include "compiler/translator/VariablePacker.h"
24#include "compiler/translator/depgraph/DependencyGraph.h"
25#include "compiler/translator/depgraph/DependencyGraphOutput.h"
26#include "compiler/translator/timing/RestrictFragmentShaderTiming.h"
27#include "compiler/translator/timing/RestrictVertexShaderTiming.h"
shannon.woods@transgaming.comda1ed362013-01-25 21:54:57 +000028#include "third_party/compiler/ArrayBoundsClamper.h"
Jamie Madill183bde52014-07-02 15:31:19 -040029#include "angle_gl.h"
Jamie Madillaa72d782014-07-02 15:31:19 -040030#include "common/utilities.h"
alokp@chromium.org07620a52010-09-23 17:53:56 +000031
Jamie Madill5508f392014-02-20 13:31:36 -050032bool IsWebGLBasedSpec(ShShaderSpec spec)
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000033{
Zhenyao Modb9b40b2014-10-29 15:00:04 -070034 return (spec == SH_WEBGL_SPEC ||
35 spec == SH_CSS_SHADERS_SPEC ||
36 spec == SH_WEBGL2_SPEC);
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000037}
38
Qingqing Dengad0d0792015-04-08 14:25:06 -070039bool IsGLSL130OrNewer(ShShaderOutput output)
40{
41 return (output == SH_GLSL_130_OUTPUT ||
Geoff Lang8273e002015-06-15 13:40:19 -070042 output == SH_GLSL_140_OUTPUT ||
43 output == SH_GLSL_150_CORE_OUTPUT ||
44 output == SH_GLSL_330_CORE_OUTPUT ||
45 output == SH_GLSL_400_CORE_OUTPUT ||
Qingqing Dengad0d0792015-04-08 14:25:06 -070046 output == SH_GLSL_410_CORE_OUTPUT ||
Geoff Lang8273e002015-06-15 13:40:19 -070047 output == SH_GLSL_420_CORE_OUTPUT ||
48 output == SH_GLSL_430_CORE_OUTPUT ||
49 output == SH_GLSL_440_CORE_OUTPUT ||
50 output == SH_GLSL_450_CORE_OUTPUT);
Qingqing Dengad0d0792015-04-08 14:25:06 -070051}
52
Zhenyao Mo7faf1a12014-04-25 18:03:56 -070053size_t GetGlobalMaxTokenSize(ShShaderSpec spec)
Jamie Madill88f6e942014-02-19 10:27:53 -050054{
Jamie Madill88f6e942014-02-19 10:27:53 -050055 // WebGL defines a max token legnth of 256, while ES2 leaves max token
56 // size undefined. ES3 defines a max size of 1024 characters.
Zhenyao Modb9b40b2014-10-29 15:00:04 -070057 switch (spec)
Jamie Madill88f6e942014-02-19 10:27:53 -050058 {
Zhenyao Modb9b40b2014-10-29 15:00:04 -070059 case SH_WEBGL_SPEC:
60 case SH_CSS_SHADERS_SPEC:
Jamie Madill88f6e942014-02-19 10:27:53 -050061 return 256;
Zhenyao Modb9b40b2014-10-29 15:00:04 -070062 default:
Jamie Madill88f6e942014-02-19 10:27:53 -050063 return 1024;
64 }
65}
66
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000067namespace {
Zhenyao Modb9b40b2014-10-29 15:00:04 -070068
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080069class TScopedPoolAllocator
70{
71 public:
72 TScopedPoolAllocator(TPoolAllocator* allocator) : mAllocator(allocator)
73 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040074 mAllocator->push();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000075 SetGlobalPoolAllocator(mAllocator);
76 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080077 ~TScopedPoolAllocator()
78 {
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000079 SetGlobalPoolAllocator(NULL);
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040080 mAllocator->pop();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000081 }
82
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080083 private:
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000084 TPoolAllocator* mAllocator;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040085};
86
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080087class TScopedSymbolTableLevel
88{
89 public:
90 TScopedSymbolTableLevel(TSymbolTable* table) : mTable(table)
91 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040092 ASSERT(mTable->atBuiltInLevel());
93 mTable->push();
94 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080095 ~TScopedSymbolTableLevel()
96 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040097 while (!mTable->atBuiltInLevel())
98 mTable->pop();
99 }
100
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800101 private:
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400102 TSymbolTable* mTable;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000103};
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700104
105int MapSpecToShaderVersion(ShShaderSpec spec)
106{
107 switch (spec)
108 {
109 case SH_GLES2_SPEC:
110 case SH_WEBGL_SPEC:
111 case SH_CSS_SHADERS_SPEC:
112 return 100;
113 case SH_GLES3_SPEC:
114 case SH_WEBGL2_SPEC:
115 return 300;
116 default:
117 UNREACHABLE();
118 return 0;
119 }
120}
121
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000122} // namespace
123
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800124TShHandleBase::TShHandleBase()
125{
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000126 allocator.push();
127 SetGlobalPoolAllocator(&allocator);
128}
129
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800130TShHandleBase::~TShHandleBase()
131{
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000132 SetGlobalPoolAllocator(NULL);
133 allocator.popAll();
134}
135
Jamie Madill183bde52014-07-02 15:31:19 -0400136TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000137 : shaderType(type),
zmo@google.comf420c422011-09-12 18:27:59 +0000138 shaderSpec(spec),
Jamie Madill68fe74a2014-05-27 12:56:01 -0400139 outputType(output),
Jamie Madilleb1a0102013-07-08 13:31:38 -0400140 maxUniformVectors(0),
141 maxExpressionComplexity(0),
142 maxCallStackDepth(0),
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000143 fragmentPrecisionHigh(false),
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000144 clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC),
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200145 builtInFunctionEmulator(),
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200146 mSourcePath(NULL)
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000147{
148}
149
150TCompiler::~TCompiler()
151{
152}
153
154bool TCompiler::Init(const ShBuiltInResources& resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000155{
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000156 shaderVersion = 100;
Jamie Madill183bde52014-07-02 15:31:19 -0400157 maxUniformVectors = (shaderType == GL_VERTEX_SHADER) ?
gman@chromium.org8d804792012-10-17 21:33:48 +0000158 resources.MaxVertexUniformVectors :
159 resources.MaxFragmentUniformVectors;
Jamie Madilleb1a0102013-07-08 13:31:38 -0400160 maxExpressionComplexity = resources.MaxExpressionComplexity;
161 maxCallStackDepth = resources.MaxCallStackDepth;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400162
163 SetGlobalPoolAllocator(&allocator);
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000164
alokp@chromium.org07620a52010-09-23 17:53:56 +0000165 // Generate built-in symbol table.
166 if (!InitBuiltInSymbolTable(resources))
167 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000168 InitExtensionBehavior(resources, extensionBehavior);
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000169 fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000170
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000171 arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy);
172 clampingStrategy = resources.ArrayIndexClampingStrategy;
173
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000174 hashFunction = resources.HashFunction;
175
alokp@chromium.org07620a52010-09-23 17:53:56 +0000176 return true;
177}
178
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200179TIntermNode *TCompiler::compileTreeForTesting(const char* const shaderStrings[],
180 size_t numStrings, int compileOptions)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000181{
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200182 return compileTreeImpl(shaderStrings, numStrings, compileOptions);
183}
184
185TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[],
186 size_t numStrings, int compileOptions)
187{
alokp@chromium.org07620a52010-09-23 17:53:56 +0000188 clearResults();
189
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200190 ASSERT(numStrings > 0);
191 ASSERT(GetGlobalPoolAllocator());
alokp@chromium.org07620a52010-09-23 17:53:56 +0000192
David Yen0fbd1282015-02-02 14:46:09 -0800193 // Reset the extension behavior for each compilation unit.
194 ResetExtensionBehavior(extensionBehavior);
195
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000196 // If compiling for WebGL, validate loop and indexing as well.
Jamie Madill5508f392014-02-20 13:31:36 -0500197 if (IsWebGLBasedSpec(shaderSpec))
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000198 compileOptions |= SH_VALIDATE_LOOP_INDEXING;
alokp@chromium.org1f299542010-11-12 15:50:23 +0000199
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000200 // First string is path of source file if flag is set. The actual source follows.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000201 size_t firstSource = 0;
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000202 if (compileOptions & SH_SOURCE_PATH)
203 {
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200204 mSourcePath = shaderStrings[0];
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000205 ++firstSource;
206 }
207
Olli Etuaho853dc1a2014-11-06 17:25:48 +0200208 bool debugShaderPrecision = getResources().WEBGL_debug_shader_precision == 1;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000209 TIntermediate intermediate(infoSink);
210 TParseContext parseContext(symbolTable, extensionBehavior, intermediate,
zmo@google.comdc4b4f82011-06-17 00:42:53 +0000211 shaderType, shaderSpec, compileOptions, true,
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200212 infoSink, debugShaderPrecision);
Olli Etuaho853dc1a2014-11-06 17:25:48 +0200213
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400214 parseContext.setFragmentPrecisionHigh(fragmentPrecisionHigh);
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -0400215 SetGlobalParseContext(&parseContext);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000216
217 // We preserve symbols at the built-in level from compile-to-compile.
218 // Start pushing the user-defined symbols at global level.
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400219 TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000220
221 // Parse shader.
222 bool success =
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400223 (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr, &parseContext) == 0) &&
224 (parseContext.getTreeRoot() != nullptr);
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000225
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000226 shaderVersion = parseContext.getShaderVersion();
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700227 if (success && MapSpecToShaderVersion(shaderSpec) < shaderVersion)
228 {
229 infoSink.info.prefix(EPrefixError);
230 infoSink.info << "unsupported shader version";
231 success = false;
232 }
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000233
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400234 TIntermNode *root = nullptr;
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200235
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800236 if (success)
237 {
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700238 mPragma = parseContext.pragma();
239 if (mPragma.stdgl.invariantAll)
240 {
241 symbolTable.setGlobalInvariant();
242 }
243
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400244 root = parseContext.getTreeRoot();
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000245 success = intermediate.postProcess(root);
246
Jamie Madill6654bc92014-03-26 14:01:57 -0400247 // Disallow expressions deemed too complex.
248 if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY))
249 success = limitExpressionComplexity(root);
250
Corentin Wallez71d147f2015-02-11 11:15:24 -0800251 // Create the function DAG and check there is no recursion
zmo@google.comb1762df2011-07-30 02:04:23 +0000252 if (success)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800253 success = initCallDag(root);
254
255 if (success && (compileOptions & SH_LIMIT_CALL_STACK_DEPTH))
256 success = checkCallDepth();
257
258 // Checks which functions are used and if "main" exists
259 if (success)
260 {
261 functionMetadata.clear();
262 functionMetadata.resize(mCallDag.size());
263 success = tagUsedFunctions();
264 }
zmo@google.comb1762df2011-07-30 02:04:23 +0000265
Corentin Walleza094a8a2015-04-07 11:53:06 -0700266 if (success && !(compileOptions & SH_DONT_PRUNE_UNUSED_FUNCTIONS))
267 success = pruneUnusedFunctions(root);
268
Olli Etuahoc6833112015-04-22 15:15:54 +0300269 // Prune empty declarations to work around driver bugs and to keep declaration output simple.
270 if (success)
271 PruneEmptyDeclarations(root);
272
Jamie Madill183bde52014-07-02 15:31:19 -0400273 if (success && shaderVersion == 300 && shaderType == GL_FRAGMENT_SHADER)
Jamie Madill05a80ce2013-06-20 11:55:49 -0400274 success = validateOutputs(root);
275
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000276 if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING))
277 success = validateLimitations(root);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000278
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000279 if (success && (compileOptions & SH_TIMING_RESTRICTIONS))
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000280 success = enforceTimingRestrictions(root, (compileOptions & SH_DEPENDENCY_GRAPH) != 0);
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000281
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000282 if (success && shaderSpec == SH_CSS_SHADERS_SPEC)
283 rewriteCSSShader(root);
284
zmo@google.com0c6bb7a2011-08-17 19:39:58 +0000285 // Unroll for-loop markup needs to happen after validateLimitations pass.
286 if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX))
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800287 {
288 ForLoopUnrollMarker marker(ForLoopUnrollMarker::kIntegerIndex);
Zhenyao Mo550c6002014-02-26 15:40:48 -0800289 root->traverse(&marker);
290 }
291 if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX))
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800292 {
293 ForLoopUnrollMarker marker(ForLoopUnrollMarker::kSamplerArrayIndex);
Zhenyao Mo550c6002014-02-26 15:40:48 -0800294 root->traverse(&marker);
295 if (marker.samplerArrayIndexIsFloatLoopIndex())
296 {
297 infoSink.info.prefix(EPrefixError);
298 infoSink.info << "sampler array index is float loop index";
299 success = false;
300 }
301 }
zmo@google.com0c6bb7a2011-08-17 19:39:58 +0000302
zmo@google.com32e97312011-08-24 01:03:11 +0000303 // Built-in function emulation needs to happen after validateLimitations pass.
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200304 if (success)
305 {
306 initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions);
zmo@google.com32e97312011-08-24 01:03:11 +0000307 builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(root);
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200308 }
zmo@google.com32e97312011-08-24 01:03:11 +0000309
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000310 // Clamping uniform array bounds needs to happen after validateLimitations pass.
311 if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS))
312 arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root);
313
Jamie Madill183bde52014-07-02 15:31:19 -0400314 if (success && shaderType == GL_VERTEX_SHADER && (compileOptions & SH_INIT_GL_POSITION))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800315 initializeGLPosition(root);
Zhenyao Moac44cd22013-09-23 14:57:09 -0400316
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800317 if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT))
318 {
Zhenyao Mo7cab38b2013-10-15 12:59:30 -0700319 UnfoldShortCircuitAST unfoldShortCircuit;
320 root->traverse(&unfoldShortCircuit);
321 unfoldShortCircuit.updateTree();
322 }
323
Olli Etuaho5c407bb2015-06-01 12:20:39 +0300324 if (success && (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT))
325 {
326 RemovePow(root);
327 }
328
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800329 if (success && (compileOptions & SH_VARIABLES))
330 {
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400331 collectVariables(root);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800332 if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS)
333 {
gman@chromium.org8d804792012-10-17 21:33:48 +0000334 success = enforcePackingRestrictions();
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800335 if (!success)
336 {
Jamie Madill075edd82013-07-08 13:30:19 -0400337 infoSink.info.prefix(EPrefixError);
338 infoSink.info << "too many uniforms";
gman@chromium.org8d804792012-10-17 21:33:48 +0000339 }
340 }
Jamie Madill183bde52014-07-02 15:31:19 -0400341 if (success && shaderType == GL_VERTEX_SHADER &&
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800342 (compileOptions & SH_INIT_VARYINGS_WITHOUT_STATIC_USE))
343 initializeVaryingsWithoutStaticUse(root);
gman@chromium.org8d804792012-10-17 21:33:48 +0000344 }
zmo@google.comfd747b82011-04-23 01:30:07 +0000345
Zhenyao Mocd68fe72014-07-11 10:45:44 -0700346 if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS))
347 {
Zhenyao Modaf56572014-08-06 16:18:30 -0700348 ScalarizeVecAndMatConstructorArgs scalarizer(
349 shaderType, fragmentPrecisionHigh);
Zhenyao Mocd68fe72014-07-11 10:45:44 -0700350 root->traverse(&scalarizer);
351 }
352
Zhenyao Moe740add2014-07-18 17:01:01 -0700353 if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES))
354 {
355 RegenerateStructNames gen(symbolTable, shaderVersion);
356 root->traverse(&gen);
357 }
alokp@chromium.org07620a52010-09-23 17:53:56 +0000358 }
359
Zhenyao Mo7faf1a12014-04-25 18:03:56 -0700360 SetGlobalParseContext(NULL);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200361 if (success)
362 return root;
363
364 return NULL;
365}
366
367bool TCompiler::compile(const char* const shaderStrings[],
368 size_t numStrings, int compileOptions)
369{
370 if (numStrings == 0)
371 return true;
372
373 TScopedPoolAllocator scopedAlloc(&allocator);
374 TIntermNode *root = compileTreeImpl(shaderStrings, numStrings, compileOptions);
375
376 if (root)
377 {
378 if (compileOptions & SH_INTERMEDIATE_TREE)
379 TIntermediate::outputTree(root, infoSink.info);
380
381 if (compileOptions & SH_OBJECT_CODE)
382 translate(root, compileOptions);
383
384 // The IntermNode tree doesn't need to be deleted here, since the
385 // memory will be freed in a big chunk by the PoolAllocator.
386 return true;
387 }
388 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000389}
390
Nicolas Capens49a88872013-06-20 09:54:03 -0400391bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000392{
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +0000393 compileResources = resources;
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400394 setResourceString();
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000395
Nicolas Capens49a88872013-06-20 09:54:03 -0400396 assert(symbolTable.isEmpty());
397 symbolTable.push(); // COMMON_BUILTINS
398 symbolTable.push(); // ESSL1_BUILTINS
399 symbolTable.push(); // ESSL3_BUILTINS
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000400
Nicolas Capens49a88872013-06-20 09:54:03 -0400401 TPublicType integer;
402 integer.type = EbtInt;
403 integer.primarySize = 1;
404 integer.secondarySize = 1;
405 integer.array = false;
406
407 TPublicType floatingPoint;
408 floatingPoint.type = EbtFloat;
409 floatingPoint.primarySize = 1;
410 floatingPoint.secondarySize = 1;
411 floatingPoint.array = false;
412
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400413 TPublicType sampler;
414 sampler.primarySize = 1;
415 sampler.secondarySize = 1;
416 sampler.array = false;
417
Nicolas Capens49a88872013-06-20 09:54:03 -0400418 switch(shaderType)
419 {
Jamie Madill183bde52014-07-02 15:31:19 -0400420 case GL_FRAGMENT_SHADER:
Nicolas Capens49a88872013-06-20 09:54:03 -0400421 symbolTable.setDefaultPrecision(integer, EbpMedium);
422 break;
Jamie Madill183bde52014-07-02 15:31:19 -0400423 case GL_VERTEX_SHADER:
Nicolas Capens49a88872013-06-20 09:54:03 -0400424 symbolTable.setDefaultPrecision(integer, EbpHigh);
425 symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
426 break;
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800427 default:
428 assert(false && "Language not supported");
Nicolas Capens49a88872013-06-20 09:54:03 -0400429 }
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400430 // We set defaults for all the sampler types, even those that are
431 // only available if an extension exists.
432 for (int samplerType = EbtGuardSamplerBegin + 1;
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800433 samplerType < EbtGuardSamplerEnd; ++samplerType)
434 {
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400435 sampler.type = static_cast<TBasicType>(samplerType);
436 symbolTable.setDefaultPrecision(sampler, EbpLow);
437 }
Nicolas Capens49a88872013-06-20 09:54:03 -0400438
Jamie Madill1b452142013-07-12 14:51:11 -0400439 InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
Nicolas Capens49a88872013-06-20 09:54:03 -0400440
441 IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
442
443 return true;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000444}
445
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400446void TCompiler::setResourceString()
447{
448 std::ostringstream strstream;
449 strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs
450 << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors
451 << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors
452 << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits
453 << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits
454 << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits
455 << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors
456 << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers
457 << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives
458 << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external
459 << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle
460 << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers
461 << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh
462 << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity
463 << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth
464 << ":EXT_frag_depth:" << compileResources.EXT_frag_depth
465 << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100466 << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch
467 << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch
468 << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400469 << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors
470 << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors
471 << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset
Olli Etuahoe61209a2014-09-26 12:01:17 +0300472 << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset
Olli Etuaho853dc1a2014-11-06 17:25:48 +0200473 << ":NV_draw_buffers:" << compileResources.NV_draw_buffers
474 << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision;
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400475
476 builtInResourcesString = strstream.str();
477}
478
alokp@chromium.org07620a52010-09-23 17:53:56 +0000479void TCompiler::clearResults()
480{
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000481 arrayBoundsClamper.Cleanup();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000482 infoSink.info.erase();
483 infoSink.obj.erase();
484 infoSink.debug.erase();
485
Jamie Madilled27c722014-07-02 15:31:23 -0400486 attributes.clear();
487 outputVariables.clear();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000488 uniforms.clear();
Jamie Madill23a8a432014-07-09 13:27:42 -0400489 expandedUniforms.clear();
Zhenyao Mod2d340b2013-09-23 14:57:05 -0400490 varyings.clear();
Jamie Madilled27c722014-07-02 15:31:23 -0400491 interfaceBlocks.clear();
zmo@google.coma3b4ab42011-09-16 00:53:26 +0000492
493 builtInFunctionEmulator.Cleanup();
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +0000494
495 nameMap.clear();
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200496
497 mSourcePath = NULL;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000498}
499
Corentin Wallez71d147f2015-02-11 11:15:24 -0800500bool TCompiler::initCallDag(TIntermNode *root)
zmo@google.comb1762df2011-07-30 02:04:23 +0000501{
Corentin Wallez71d147f2015-02-11 11:15:24 -0800502 mCallDag.clear();
503
504 switch (mCallDag.init(root, &infoSink.info))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800505 {
Corentin Wallez71d147f2015-02-11 11:15:24 -0800506 case CallDAG::INITDAG_SUCCESS:
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800507 return true;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800508 case CallDAG::INITDAG_RECURSION:
509 infoSink.info.prefix(EPrefixError);
510 infoSink.info << "Function recursion detected";
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800511 return false;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800512 case CallDAG::INITDAG_UNDEFINED:
513 infoSink.info.prefix(EPrefixError);
514 infoSink.info << "Unimplemented function detected";
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800515 return false;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800516 }
517
518 UNREACHABLE();
519 return true;
520}
521
522bool TCompiler::checkCallDepth()
523{
524 std::vector<int> depths(mCallDag.size());
525
526 for (size_t i = 0; i < mCallDag.size(); i++)
527 {
528 int depth = 0;
529 auto &record = mCallDag.getRecordFromIndex(i);
530
531 for (auto &calleeIndex : record.callees)
532 {
533 depth = std::max(depth, depths[calleeIndex] + 1);
534 }
535
536 depths[i] = depth;
537
538 if (depth >= maxCallStackDepth)
539 {
540 // Trace back the function chain to have a meaningful info log.
541 infoSink.info.prefix(EPrefixError);
542 infoSink.info << "Call stack too deep (larger than " << maxCallStackDepth
543 << ") with the following call chain: " << record.name;
544
545 int currentFunction = i;
546 int currentDepth = depth;
547
548 while (currentFunction != -1)
549 {
550 infoSink.info << " -> " << mCallDag.getRecordFromIndex(currentFunction).name;
551
552 int nextFunction = -1;
553 for (auto& calleeIndex : mCallDag.getRecordFromIndex(currentFunction).callees)
554 {
555 if (depths[calleeIndex] == currentDepth - 1)
556 {
557 currentDepth--;
558 nextFunction = calleeIndex;
559 }
560 }
561
562 currentFunction = nextFunction;
563 }
564
565 return false;
566 }
567 }
568
569 return true;
570}
571
572bool TCompiler::tagUsedFunctions()
573{
574 // Search from main, starting from the end of the DAG as it usually is the root.
575 for (int i = mCallDag.size(); i-- > 0;)
576 {
577 if (mCallDag.getRecordFromIndex(i).name == "main(")
578 {
579 internalTagUsedFunction(i);
580 return true;
581 }
582 }
583
584 infoSink.info.prefix(EPrefixError);
585 infoSink.info << "Missing main()";
586 return false;
587}
588
589void TCompiler::internalTagUsedFunction(size_t index)
590{
591 if (functionMetadata[index].used)
592 {
593 return;
594 }
595
596 functionMetadata[index].used = true;
597
598 for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees)
599 {
600 internalTagUsedFunction(calleeIndex);
zmo@google.comb1762df2011-07-30 02:04:23 +0000601 }
602}
603
Corentin Walleza094a8a2015-04-07 11:53:06 -0700604// A predicate for the stl that returns if a top-level node is unused
605class TCompiler::UnusedPredicate
606{
607 public:
608 UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas)
609 : mCallDag(callDag),
610 mMetadatas(metadatas)
611 {
612 }
613
614 bool operator ()(TIntermNode *node)
615 {
616 const TIntermAggregate *asAggregate = node->getAsAggregate();
617
618 if (asAggregate == nullptr)
619 {
620 return false;
621 }
622
623 if (!(asAggregate->getOp() == EOpFunction || asAggregate->getOp() == EOpPrototype))
624 {
625 return false;
626 }
627
628 size_t callDagIndex = mCallDag->findIndex(asAggregate);
629 if (callDagIndex == CallDAG::InvalidIndex)
630 {
631 // This happens only for unimplemented prototypes which are thus unused
632 ASSERT(asAggregate->getOp() == EOpPrototype);
633 return true;
634 }
635
636 ASSERT(callDagIndex < mMetadatas->size());
637 return !(*mMetadatas)[callDagIndex].used;
638 }
639
640 private:
641 const CallDAG *mCallDag;
642 const std::vector<FunctionMetadata> *mMetadatas;
643};
644
645bool TCompiler::pruneUnusedFunctions(TIntermNode *root)
646{
647 TIntermAggregate *rootNode = root->getAsAggregate();
648 ASSERT(rootNode != nullptr);
649
650 UnusedPredicate isUnused(&mCallDag, &functionMetadata);
651 TIntermSequence *sequence = rootNode->getSequence();
652 sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused), sequence->end());
653
654 return true;
655}
656
Jamie Madill05a80ce2013-06-20 11:55:49 -0400657bool TCompiler::validateOutputs(TIntermNode* root)
658{
659 ValidateOutputs validateOutputs(infoSink.info, compileResources.MaxDrawBuffers);
660 root->traverse(&validateOutputs);
661 return (validateOutputs.numErrors() == 0);
662}
663
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000664void TCompiler::rewriteCSSShader(TIntermNode* root)
665{
666 RenameFunction renamer("main(", "css_main(");
667 root->traverse(&renamer);
668}
669
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800670bool TCompiler::validateLimitations(TIntermNode* root)
671{
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000672 ValidateLimitations validate(shaderType, infoSink.info);
673 root->traverse(&validate);
674 return validate.numErrors() == 0;
675}
676
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000677bool TCompiler::enforceTimingRestrictions(TIntermNode* root, bool outputGraph)
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000678{
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800679 if (shaderSpec != SH_WEBGL_SPEC)
680 {
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000681 infoSink.info << "Timing restrictions must be enforced under the WebGL spec.";
682 return false;
683 }
684
Jamie Madill183bde52014-07-02 15:31:19 -0400685 if (shaderType == GL_FRAGMENT_SHADER)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800686 {
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000687 TDependencyGraph graph(root);
688
689 // Output any errors first.
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000690 bool success = enforceFragmentShaderTimingRestrictions(graph);
Jamie Madill5508f392014-02-20 13:31:36 -0500691
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000692 // Then, output the dependency graph.
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800693 if (outputGraph)
694 {
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000695 TDependencyGraphOutput output(infoSink.info);
696 output.outputAllSpanningTrees(graph);
697 }
Jamie Madill5508f392014-02-20 13:31:36 -0500698
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000699 return success;
700 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800701 else
702 {
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000703 return enforceVertexShaderTimingRestrictions(root);
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000704 }
705}
706
Jamie Madilleb1a0102013-07-08 13:31:38 -0400707bool TCompiler::limitExpressionComplexity(TIntermNode* root)
708{
Jamie Madill6654bc92014-03-26 14:01:57 -0400709 TMaxDepthTraverser traverser(maxExpressionComplexity+1);
Jamie Madilleb1a0102013-07-08 13:31:38 -0400710 root->traverse(&traverser);
Jamie Madill6654bc92014-03-26 14:01:57 -0400711
712 if (traverser.getMaxDepth() > maxExpressionComplexity)
713 {
714 infoSink.info << "Expression too complex.";
715 return false;
716 }
717
Jamie Madilleb1a0102013-07-08 13:31:38 -0400718 TDependencyGraph graph(root);
719
720 for (TFunctionCallVector::const_iterator iter = graph.beginUserDefinedFunctionCalls();
721 iter != graph.endUserDefinedFunctionCalls();
722 ++iter)
723 {
724 TGraphFunctionCall* samplerSymbol = *iter;
725 TDependencyGraphTraverser graphTraverser;
726 samplerSymbol->traverse(&graphTraverser);
727 }
728
Jamie Madilleb1a0102013-07-08 13:31:38 -0400729 return true;
730}
731
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000732bool TCompiler::enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph)
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000733{
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000734 RestrictFragmentShaderTiming restrictor(infoSink.info);
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000735 restrictor.enforceRestrictions(graph);
736 return restrictor.numErrors() == 0;
737}
738
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000739bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root)
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000740{
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000741 RestrictVertexShaderTiming restrictor(infoSink.info);
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000742 restrictor.enforceRestrictions(root);
743 return restrictor.numErrors() == 0;
744}
745
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400746void TCompiler::collectVariables(TIntermNode* root)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000747{
Jamie Madilla2fbb842014-09-03 09:40:47 -0400748 sh::CollectVariables collect(&attributes,
749 &outputVariables,
750 &uniforms,
751 &varyings,
752 &interfaceBlocks,
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700753 hashFunction,
754 symbolTable);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000755 root->traverse(&collect);
Jamie Madill23a8a432014-07-09 13:27:42 -0400756
Zhenyao Mo409078f2014-10-28 13:23:18 -0700757 // This is for enforcePackingRestriction().
758 sh::ExpandUniforms(uniforms, &expandedUniforms);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000759}
zmo@google.comfd747b82011-04-23 01:30:07 +0000760
gman@chromium.org8d804792012-10-17 21:33:48 +0000761bool TCompiler::enforcePackingRestrictions()
762{
763 VariablePacker packer;
Jamie Madill23a8a432014-07-09 13:27:42 -0400764 return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms);
gman@chromium.org8d804792012-10-17 21:33:48 +0000765}
766
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800767void TCompiler::initializeGLPosition(TIntermNode* root)
768{
769 InitializeVariables::InitVariableInfoList variables;
770 InitializeVariables::InitVariableInfo var(
771 "gl_Position", TType(EbtFloat, EbpUndefined, EvqPosition, 4));
772 variables.push_back(var);
773 InitializeVariables initializer(variables);
774 root->traverse(&initializer);
775}
776
777void TCompiler::initializeVaryingsWithoutStaticUse(TIntermNode* root)
778{
779 InitializeVariables::InitVariableInfoList variables;
780 for (size_t ii = 0; ii < varyings.size(); ++ii)
781 {
Jamie Madilla718c1e2014-07-02 15:31:22 -0400782 const sh::Varying& varying = varyings[ii];
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800783 if (varying.staticUse)
784 continue;
Jamie Madillaa72d782014-07-02 15:31:19 -0400785 unsigned char primarySize = static_cast<unsigned char>(gl::VariableColumnCount(varying.type));
786 unsigned char secondarySize = static_cast<unsigned char>(gl::VariableRowCount(varying.type));
Jamie Madilla718c1e2014-07-02 15:31:22 -0400787 TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray());
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800788 TString name = varying.name.c_str();
Jamie Madilla718c1e2014-07-02 15:31:22 -0400789 if (varying.isArray())
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800790 {
Jamie Madilla718c1e2014-07-02 15:31:22 -0400791 type.setArraySize(varying.arraySize);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800792 name = name.substr(0, name.find_first_of('['));
793 }
794
795 InitializeVariables::InitVariableInfo var(name, type);
796 variables.push_back(var);
797 }
798 InitializeVariables initializer(variables);
799 root->traverse(&initializer);
800}
801
zmo@google.com5601ea02011-06-10 18:23:25 +0000802const TExtensionBehavior& TCompiler::getExtensionBehavior() const
803{
804 return extensionBehavior;
805}
zmo@google.com32e97312011-08-24 01:03:11 +0000806
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200807const char *TCompiler::getSourcePath() const
808{
809 return mSourcePath;
810}
811
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +0000812const ShBuiltInResources& TCompiler::getResources() const
813{
814 return compileResources;
815}
816
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000817const ArrayBoundsClamper& TCompiler::getArrayBoundsClamper() const
818{
819 return arrayBoundsClamper;
820}
821
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000822ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const
823{
824 return clampingStrategy;
825}
826
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200827const BuiltInFunctionEmulator& TCompiler::getBuiltInFunctionEmulator() const
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000828{
829 return builtInFunctionEmulator;
830}
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700831
832void TCompiler::writePragma()
833{
834 TInfoSinkBase &sink = infoSink.obj;
835 if (mPragma.stdgl.invariantAll)
836 sink << "#pragma STDGL invariant(all)\n";
837}