blob: cd773189acaa5ae82f1dd8530ac02d0c24c52b51 [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
Jamie Madilld4a3a312014-06-25 16:04:56 -04007#include "compiler/translator/Compiler.h"
Corentin Wallez71d147f2015-02-11 11:15:24 -08008#include "compiler/translator/CallDAG.h"
Geoff Lang17732822013-08-29 13:46:49 -04009#include "compiler/translator/ForLoopUnroll.h"
10#include "compiler/translator/Initialize.h"
Geoff Lang17732822013-08-29 13:46:49 -040011#include "compiler/translator/InitializeParseContext.h"
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080012#include "compiler/translator/InitializeVariables.h"
Jamie Madill6b9cb252013-10-17 10:45:47 -040013#include "compiler/translator/ParseContext.h"
Olli Etuahoc6833112015-04-22 15:15:54 +030014#include "compiler/translator/PruneEmptyDeclarations.h"
Zhenyao Moe740add2014-07-18 17:01:01 -070015#include "compiler/translator/RegenerateStructNames.h"
Olli Etuaho5c407bb2015-06-01 12:20:39 +030016#include "compiler/translator/RemovePow.h"
Geoff Lang17732822013-08-29 13:46:49 -040017#include "compiler/translator/RenameFunction.h"
Zhenyao Mocd68fe72014-07-11 10:45:44 -070018#include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h"
Zhenyao Mo7cab38b2013-10-15 12:59:30 -070019#include "compiler/translator/UnfoldShortCircuitAST.h"
Geoff Lang17732822013-08-29 13:46:49 -040020#include "compiler/translator/ValidateLimitations.h"
21#include "compiler/translator/ValidateOutputs.h"
22#include "compiler/translator/VariablePacker.h"
23#include "compiler/translator/depgraph/DependencyGraph.h"
24#include "compiler/translator/depgraph/DependencyGraphOutput.h"
25#include "compiler/translator/timing/RestrictFragmentShaderTiming.h"
26#include "compiler/translator/timing/RestrictVertexShaderTiming.h"
shannon.woods@transgaming.comda1ed362013-01-25 21:54:57 +000027#include "third_party/compiler/ArrayBoundsClamper.h"
Jamie Madill183bde52014-07-02 15:31:19 -040028#include "angle_gl.h"
Jamie Madillaa72d782014-07-02 15:31:19 -040029#include "common/utilities.h"
alokp@chromium.org07620a52010-09-23 17:53:56 +000030
Jamie Madill5508f392014-02-20 13:31:36 -050031bool IsWebGLBasedSpec(ShShaderSpec spec)
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000032{
Zhenyao Modb9b40b2014-10-29 15:00:04 -070033 return (spec == SH_WEBGL_SPEC ||
34 spec == SH_CSS_SHADERS_SPEC ||
35 spec == SH_WEBGL2_SPEC);
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000036}
37
Qingqing Dengad0d0792015-04-08 14:25:06 -070038bool IsGLSL130OrNewer(ShShaderOutput output)
39{
40 return (output == SH_GLSL_130_OUTPUT ||
Geoff Lang8273e002015-06-15 13:40:19 -070041 output == SH_GLSL_140_OUTPUT ||
42 output == SH_GLSL_150_CORE_OUTPUT ||
43 output == SH_GLSL_330_CORE_OUTPUT ||
44 output == SH_GLSL_400_CORE_OUTPUT ||
Qingqing Dengad0d0792015-04-08 14:25:06 -070045 output == SH_GLSL_410_CORE_OUTPUT ||
Geoff Lang8273e002015-06-15 13:40:19 -070046 output == SH_GLSL_420_CORE_OUTPUT ||
47 output == SH_GLSL_430_CORE_OUTPUT ||
48 output == SH_GLSL_440_CORE_OUTPUT ||
49 output == SH_GLSL_450_CORE_OUTPUT);
Qingqing Dengad0d0792015-04-08 14:25:06 -070050}
51
Zhenyao Mo7faf1a12014-04-25 18:03:56 -070052size_t GetGlobalMaxTokenSize(ShShaderSpec spec)
Jamie Madill88f6e942014-02-19 10:27:53 -050053{
Jamie Madill88f6e942014-02-19 10:27:53 -050054 // WebGL defines a max token legnth of 256, while ES2 leaves max token
55 // size undefined. ES3 defines a max size of 1024 characters.
Zhenyao Modb9b40b2014-10-29 15:00:04 -070056 switch (spec)
Jamie Madill88f6e942014-02-19 10:27:53 -050057 {
Zhenyao Modb9b40b2014-10-29 15:00:04 -070058 case SH_WEBGL_SPEC:
59 case SH_CSS_SHADERS_SPEC:
Jamie Madill88f6e942014-02-19 10:27:53 -050060 return 256;
Zhenyao Modb9b40b2014-10-29 15:00:04 -070061 default:
Jamie Madill88f6e942014-02-19 10:27:53 -050062 return 1024;
63 }
64}
65
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000066namespace {
Zhenyao Modb9b40b2014-10-29 15:00:04 -070067
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080068class TScopedPoolAllocator
69{
70 public:
71 TScopedPoolAllocator(TPoolAllocator* allocator) : mAllocator(allocator)
72 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040073 mAllocator->push();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000074 SetGlobalPoolAllocator(mAllocator);
75 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080076 ~TScopedPoolAllocator()
77 {
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000078 SetGlobalPoolAllocator(NULL);
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040079 mAllocator->pop();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000080 }
81
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080082 private:
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000083 TPoolAllocator* mAllocator;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040084};
85
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080086class TScopedSymbolTableLevel
87{
88 public:
89 TScopedSymbolTableLevel(TSymbolTable* table) : mTable(table)
90 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040091 ASSERT(mTable->atBuiltInLevel());
92 mTable->push();
93 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080094 ~TScopedSymbolTableLevel()
95 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -040096 while (!mTable->atBuiltInLevel())
97 mTable->pop();
98 }
99
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800100 private:
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400101 TSymbolTable* mTable;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000102};
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700103
104int MapSpecToShaderVersion(ShShaderSpec spec)
105{
106 switch (spec)
107 {
108 case SH_GLES2_SPEC:
109 case SH_WEBGL_SPEC:
110 case SH_CSS_SHADERS_SPEC:
111 return 100;
112 case SH_GLES3_SPEC:
113 case SH_WEBGL2_SPEC:
114 return 300;
115 default:
116 UNREACHABLE();
117 return 0;
118 }
119}
120
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000121} // namespace
122
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800123TShHandleBase::TShHandleBase()
124{
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000125 allocator.push();
126 SetGlobalPoolAllocator(&allocator);
127}
128
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800129TShHandleBase::~TShHandleBase()
130{
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000131 SetGlobalPoolAllocator(NULL);
132 allocator.popAll();
133}
134
Jamie Madill183bde52014-07-02 15:31:19 -0400135TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000136 : shaderType(type),
zmo@google.comf420c422011-09-12 18:27:59 +0000137 shaderSpec(spec),
Jamie Madill68fe74a2014-05-27 12:56:01 -0400138 outputType(output),
Jamie Madilleb1a0102013-07-08 13:31:38 -0400139 maxUniformVectors(0),
140 maxExpressionComplexity(0),
141 maxCallStackDepth(0),
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000142 fragmentPrecisionHigh(false),
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000143 clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC),
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200144 builtInFunctionEmulator(),
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200145 mSourcePath(NULL)
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000146{
147}
148
149TCompiler::~TCompiler()
150{
151}
152
153bool TCompiler::Init(const ShBuiltInResources& resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000154{
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000155 shaderVersion = 100;
Jamie Madill183bde52014-07-02 15:31:19 -0400156 maxUniformVectors = (shaderType == GL_VERTEX_SHADER) ?
gman@chromium.org8d804792012-10-17 21:33:48 +0000157 resources.MaxVertexUniformVectors :
158 resources.MaxFragmentUniformVectors;
Jamie Madilleb1a0102013-07-08 13:31:38 -0400159 maxExpressionComplexity = resources.MaxExpressionComplexity;
160 maxCallStackDepth = resources.MaxCallStackDepth;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400161
162 SetGlobalPoolAllocator(&allocator);
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000163
alokp@chromium.org07620a52010-09-23 17:53:56 +0000164 // Generate built-in symbol table.
165 if (!InitBuiltInSymbolTable(resources))
166 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000167 InitExtensionBehavior(resources, extensionBehavior);
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000168 fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000169
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000170 arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy);
171 clampingStrategy = resources.ArrayIndexClampingStrategy;
172
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000173 hashFunction = resources.HashFunction;
174
alokp@chromium.org07620a52010-09-23 17:53:56 +0000175 return true;
176}
177
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200178TIntermNode *TCompiler::compileTreeForTesting(const char* const shaderStrings[],
179 size_t numStrings, int compileOptions)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000180{
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200181 return compileTreeImpl(shaderStrings, numStrings, compileOptions);
182}
183
184TIntermNode *TCompiler::compileTreeImpl(const char* const shaderStrings[],
185 size_t numStrings, int compileOptions)
186{
alokp@chromium.org07620a52010-09-23 17:53:56 +0000187 clearResults();
188
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200189 ASSERT(numStrings > 0);
190 ASSERT(GetGlobalPoolAllocator());
alokp@chromium.org07620a52010-09-23 17:53:56 +0000191
David Yen0fbd1282015-02-02 14:46:09 -0800192 // Reset the extension behavior for each compilation unit.
193 ResetExtensionBehavior(extensionBehavior);
194
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000195 // If compiling for WebGL, validate loop and indexing as well.
Jamie Madill5508f392014-02-20 13:31:36 -0500196 if (IsWebGLBasedSpec(shaderSpec))
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000197 compileOptions |= SH_VALIDATE_LOOP_INDEXING;
alokp@chromium.org1f299542010-11-12 15:50:23 +0000198
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000199 // First string is path of source file if flag is set. The actual source follows.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000200 size_t firstSource = 0;
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000201 if (compileOptions & SH_SOURCE_PATH)
202 {
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200203 mSourcePath = shaderStrings[0];
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000204 ++firstSource;
205 }
206
Olli Etuaho853dc1a2014-11-06 17:25:48 +0200207 bool debugShaderPrecision = getResources().WEBGL_debug_shader_precision == 1;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000208 TIntermediate intermediate(infoSink);
209 TParseContext parseContext(symbolTable, extensionBehavior, intermediate,
zmo@google.comdc4b4f82011-06-17 00:42:53 +0000210 shaderType, shaderSpec, compileOptions, true,
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200211 infoSink, debugShaderPrecision);
Olli Etuaho853dc1a2014-11-06 17:25:48 +0200212
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400213 parseContext.setFragmentPrecisionHigh(fragmentPrecisionHigh);
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -0400214 SetGlobalParseContext(&parseContext);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000215
216 // We preserve symbols at the built-in level from compile-to-compile.
217 // Start pushing the user-defined symbols at global level.
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400218 TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000219
220 // Parse shader.
221 bool success =
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400222 (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr, &parseContext) == 0) &&
223 (parseContext.getTreeRoot() != nullptr);
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000224
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000225 shaderVersion = parseContext.getShaderVersion();
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700226 if (success && MapSpecToShaderVersion(shaderSpec) < shaderVersion)
227 {
228 infoSink.info.prefix(EPrefixError);
229 infoSink.info << "unsupported shader version";
230 success = false;
231 }
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000232
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400233 TIntermNode *root = nullptr;
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200234
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800235 if (success)
236 {
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700237 mPragma = parseContext.pragma();
238 if (mPragma.stdgl.invariantAll)
239 {
240 symbolTable.setGlobalInvariant();
241 }
242
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400243 root = parseContext.getTreeRoot();
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000244 success = intermediate.postProcess(root);
245
Jamie Madill6654bc92014-03-26 14:01:57 -0400246 // Disallow expressions deemed too complex.
247 if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY))
248 success = limitExpressionComplexity(root);
249
Corentin Wallez71d147f2015-02-11 11:15:24 -0800250 // Create the function DAG and check there is no recursion
zmo@google.comb1762df2011-07-30 02:04:23 +0000251 if (success)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800252 success = initCallDag(root);
253
254 if (success && (compileOptions & SH_LIMIT_CALL_STACK_DEPTH))
255 success = checkCallDepth();
256
257 // Checks which functions are used and if "main" exists
258 if (success)
259 {
260 functionMetadata.clear();
261 functionMetadata.resize(mCallDag.size());
262 success = tagUsedFunctions();
263 }
zmo@google.comb1762df2011-07-30 02:04:23 +0000264
Corentin Walleza094a8a2015-04-07 11:53:06 -0700265 if (success && !(compileOptions & SH_DONT_PRUNE_UNUSED_FUNCTIONS))
266 success = pruneUnusedFunctions(root);
267
Olli Etuahoc6833112015-04-22 15:15:54 +0300268 // Prune empty declarations to work around driver bugs and to keep declaration output simple.
269 if (success)
270 PruneEmptyDeclarations(root);
271
Jamie Madill183bde52014-07-02 15:31:19 -0400272 if (success && shaderVersion == 300 && shaderType == GL_FRAGMENT_SHADER)
Jamie Madill05a80ce2013-06-20 11:55:49 -0400273 success = validateOutputs(root);
274
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000275 if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING))
276 success = validateLimitations(root);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000277
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000278 if (success && (compileOptions & SH_TIMING_RESTRICTIONS))
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000279 success = enforceTimingRestrictions(root, (compileOptions & SH_DEPENDENCY_GRAPH) != 0);
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000280
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000281 if (success && shaderSpec == SH_CSS_SHADERS_SPEC)
282 rewriteCSSShader(root);
283
zmo@google.com0c6bb7a2011-08-17 19:39:58 +0000284 // Unroll for-loop markup needs to happen after validateLimitations pass.
285 if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX))
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800286 {
287 ForLoopUnrollMarker marker(ForLoopUnrollMarker::kIntegerIndex);
Zhenyao Mo550c6002014-02-26 15:40:48 -0800288 root->traverse(&marker);
289 }
290 if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX))
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800291 {
292 ForLoopUnrollMarker marker(ForLoopUnrollMarker::kSamplerArrayIndex);
Zhenyao Mo550c6002014-02-26 15:40:48 -0800293 root->traverse(&marker);
294 if (marker.samplerArrayIndexIsFloatLoopIndex())
295 {
296 infoSink.info.prefix(EPrefixError);
297 infoSink.info << "sampler array index is float loop index";
298 success = false;
299 }
300 }
zmo@google.com0c6bb7a2011-08-17 19:39:58 +0000301
zmo@google.com32e97312011-08-24 01:03:11 +0000302 // Built-in function emulation needs to happen after validateLimitations pass.
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200303 if (success)
304 {
305 initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions);
zmo@google.com32e97312011-08-24 01:03:11 +0000306 builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(root);
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200307 }
zmo@google.com32e97312011-08-24 01:03:11 +0000308
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000309 // Clamping uniform array bounds needs to happen after validateLimitations pass.
310 if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS))
311 arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root);
312
Jamie Madill183bde52014-07-02 15:31:19 -0400313 if (success && shaderType == GL_VERTEX_SHADER && (compileOptions & SH_INIT_GL_POSITION))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800314 initializeGLPosition(root);
Zhenyao Moac44cd22013-09-23 14:57:09 -0400315
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800316 if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT))
317 {
Zhenyao Mo7cab38b2013-10-15 12:59:30 -0700318 UnfoldShortCircuitAST unfoldShortCircuit;
319 root->traverse(&unfoldShortCircuit);
320 unfoldShortCircuit.updateTree();
321 }
322
Olli Etuaho5c407bb2015-06-01 12:20:39 +0300323 if (success && (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT))
324 {
325 RemovePow(root);
326 }
327
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800328 if (success && (compileOptions & SH_VARIABLES))
329 {
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400330 collectVariables(root);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800331 if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS)
332 {
gman@chromium.org8d804792012-10-17 21:33:48 +0000333 success = enforcePackingRestrictions();
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800334 if (!success)
335 {
Jamie Madill075edd82013-07-08 13:30:19 -0400336 infoSink.info.prefix(EPrefixError);
337 infoSink.info << "too many uniforms";
gman@chromium.org8d804792012-10-17 21:33:48 +0000338 }
339 }
Jamie Madill183bde52014-07-02 15:31:19 -0400340 if (success && shaderType == GL_VERTEX_SHADER &&
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800341 (compileOptions & SH_INIT_VARYINGS_WITHOUT_STATIC_USE))
342 initializeVaryingsWithoutStaticUse(root);
gman@chromium.org8d804792012-10-17 21:33:48 +0000343 }
zmo@google.comfd747b82011-04-23 01:30:07 +0000344
Zhenyao Mocd68fe72014-07-11 10:45:44 -0700345 if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS))
346 {
Zhenyao Modaf56572014-08-06 16:18:30 -0700347 ScalarizeVecAndMatConstructorArgs scalarizer(
348 shaderType, fragmentPrecisionHigh);
Zhenyao Mocd68fe72014-07-11 10:45:44 -0700349 root->traverse(&scalarizer);
350 }
351
Zhenyao Moe740add2014-07-18 17:01:01 -0700352 if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES))
353 {
354 RegenerateStructNames gen(symbolTable, shaderVersion);
355 root->traverse(&gen);
356 }
alokp@chromium.org07620a52010-09-23 17:53:56 +0000357 }
358
Zhenyao Mo7faf1a12014-04-25 18:03:56 -0700359 SetGlobalParseContext(NULL);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200360 if (success)
361 return root;
362
363 return NULL;
364}
365
366bool TCompiler::compile(const char* const shaderStrings[],
367 size_t numStrings, int compileOptions)
368{
369 if (numStrings == 0)
370 return true;
371
372 TScopedPoolAllocator scopedAlloc(&allocator);
373 TIntermNode *root = compileTreeImpl(shaderStrings, numStrings, compileOptions);
374
375 if (root)
376 {
377 if (compileOptions & SH_INTERMEDIATE_TREE)
378 TIntermediate::outputTree(root, infoSink.info);
379
380 if (compileOptions & SH_OBJECT_CODE)
381 translate(root, compileOptions);
382
383 // The IntermNode tree doesn't need to be deleted here, since the
384 // memory will be freed in a big chunk by the PoolAllocator.
385 return true;
386 }
387 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000388}
389
Nicolas Capens49a88872013-06-20 09:54:03 -0400390bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000391{
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +0000392 compileResources = resources;
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400393 setResourceString();
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000394
Nicolas Capens49a88872013-06-20 09:54:03 -0400395 assert(symbolTable.isEmpty());
396 symbolTable.push(); // COMMON_BUILTINS
397 symbolTable.push(); // ESSL1_BUILTINS
398 symbolTable.push(); // ESSL3_BUILTINS
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000399
Nicolas Capens49a88872013-06-20 09:54:03 -0400400 TPublicType integer;
401 integer.type = EbtInt;
402 integer.primarySize = 1;
403 integer.secondarySize = 1;
404 integer.array = false;
405
406 TPublicType floatingPoint;
407 floatingPoint.type = EbtFloat;
408 floatingPoint.primarySize = 1;
409 floatingPoint.secondarySize = 1;
410 floatingPoint.array = false;
411
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400412 TPublicType sampler;
413 sampler.primarySize = 1;
414 sampler.secondarySize = 1;
415 sampler.array = false;
416
Nicolas Capens49a88872013-06-20 09:54:03 -0400417 switch(shaderType)
418 {
Jamie Madill183bde52014-07-02 15:31:19 -0400419 case GL_FRAGMENT_SHADER:
Nicolas Capens49a88872013-06-20 09:54:03 -0400420 symbolTable.setDefaultPrecision(integer, EbpMedium);
421 break;
Jamie Madill183bde52014-07-02 15:31:19 -0400422 case GL_VERTEX_SHADER:
Nicolas Capens49a88872013-06-20 09:54:03 -0400423 symbolTable.setDefaultPrecision(integer, EbpHigh);
424 symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
425 break;
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800426 default:
427 assert(false && "Language not supported");
Nicolas Capens49a88872013-06-20 09:54:03 -0400428 }
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400429 // We set defaults for all the sampler types, even those that are
430 // only available if an extension exists.
431 for (int samplerType = EbtGuardSamplerBegin + 1;
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800432 samplerType < EbtGuardSamplerEnd; ++samplerType)
433 {
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400434 sampler.type = static_cast<TBasicType>(samplerType);
435 symbolTable.setDefaultPrecision(sampler, EbpLow);
436 }
Nicolas Capens49a88872013-06-20 09:54:03 -0400437
Jamie Madill1b452142013-07-12 14:51:11 -0400438 InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
Nicolas Capens49a88872013-06-20 09:54:03 -0400439
440 IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
441
442 return true;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000443}
444
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400445void TCompiler::setResourceString()
446{
447 std::ostringstream strstream;
448 strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs
449 << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors
450 << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors
451 << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits
452 << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits
453 << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits
454 << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors
455 << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers
456 << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives
457 << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external
458 << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle
459 << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers
460 << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh
461 << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity
462 << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth
463 << ":EXT_frag_depth:" << compileResources.EXT_frag_depth
464 << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100465 << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch
466 << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch
467 << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400468 << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors
469 << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors
470 << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset
Olli Etuahoe61209a2014-09-26 12:01:17 +0300471 << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset
Olli Etuaho853dc1a2014-11-06 17:25:48 +0200472 << ":NV_draw_buffers:" << compileResources.NV_draw_buffers
473 << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision;
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400474
475 builtInResourcesString = strstream.str();
476}
477
alokp@chromium.org07620a52010-09-23 17:53:56 +0000478void TCompiler::clearResults()
479{
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000480 arrayBoundsClamper.Cleanup();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000481 infoSink.info.erase();
482 infoSink.obj.erase();
483 infoSink.debug.erase();
484
Jamie Madilled27c722014-07-02 15:31:23 -0400485 attributes.clear();
486 outputVariables.clear();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000487 uniforms.clear();
Jamie Madill23a8a432014-07-09 13:27:42 -0400488 expandedUniforms.clear();
Zhenyao Mod2d340b2013-09-23 14:57:05 -0400489 varyings.clear();
Jamie Madilled27c722014-07-02 15:31:23 -0400490 interfaceBlocks.clear();
zmo@google.coma3b4ab42011-09-16 00:53:26 +0000491
492 builtInFunctionEmulator.Cleanup();
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +0000493
494 nameMap.clear();
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200495
496 mSourcePath = NULL;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000497}
498
Corentin Wallez71d147f2015-02-11 11:15:24 -0800499bool TCompiler::initCallDag(TIntermNode *root)
zmo@google.comb1762df2011-07-30 02:04:23 +0000500{
Corentin Wallez71d147f2015-02-11 11:15:24 -0800501 mCallDag.clear();
502
503 switch (mCallDag.init(root, &infoSink.info))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800504 {
Corentin Wallez71d147f2015-02-11 11:15:24 -0800505 case CallDAG::INITDAG_SUCCESS:
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800506 return true;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800507 case CallDAG::INITDAG_RECURSION:
508 infoSink.info.prefix(EPrefixError);
509 infoSink.info << "Function recursion detected";
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800510 return false;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800511 case CallDAG::INITDAG_UNDEFINED:
512 infoSink.info.prefix(EPrefixError);
513 infoSink.info << "Unimplemented function detected";
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800514 return false;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800515 }
516
517 UNREACHABLE();
518 return true;
519}
520
521bool TCompiler::checkCallDepth()
522{
523 std::vector<int> depths(mCallDag.size());
524
525 for (size_t i = 0; i < mCallDag.size(); i++)
526 {
527 int depth = 0;
528 auto &record = mCallDag.getRecordFromIndex(i);
529
530 for (auto &calleeIndex : record.callees)
531 {
532 depth = std::max(depth, depths[calleeIndex] + 1);
533 }
534
535 depths[i] = depth;
536
537 if (depth >= maxCallStackDepth)
538 {
539 // Trace back the function chain to have a meaningful info log.
540 infoSink.info.prefix(EPrefixError);
541 infoSink.info << "Call stack too deep (larger than " << maxCallStackDepth
542 << ") with the following call chain: " << record.name;
543
544 int currentFunction = i;
545 int currentDepth = depth;
546
547 while (currentFunction != -1)
548 {
549 infoSink.info << " -> " << mCallDag.getRecordFromIndex(currentFunction).name;
550
551 int nextFunction = -1;
552 for (auto& calleeIndex : mCallDag.getRecordFromIndex(currentFunction).callees)
553 {
554 if (depths[calleeIndex] == currentDepth - 1)
555 {
556 currentDepth--;
557 nextFunction = calleeIndex;
558 }
559 }
560
561 currentFunction = nextFunction;
562 }
563
564 return false;
565 }
566 }
567
568 return true;
569}
570
571bool TCompiler::tagUsedFunctions()
572{
573 // Search from main, starting from the end of the DAG as it usually is the root.
574 for (int i = mCallDag.size(); i-- > 0;)
575 {
576 if (mCallDag.getRecordFromIndex(i).name == "main(")
577 {
578 internalTagUsedFunction(i);
579 return true;
580 }
581 }
582
583 infoSink.info.prefix(EPrefixError);
584 infoSink.info << "Missing main()";
585 return false;
586}
587
588void TCompiler::internalTagUsedFunction(size_t index)
589{
590 if (functionMetadata[index].used)
591 {
592 return;
593 }
594
595 functionMetadata[index].used = true;
596
597 for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees)
598 {
599 internalTagUsedFunction(calleeIndex);
zmo@google.comb1762df2011-07-30 02:04:23 +0000600 }
601}
602
Corentin Walleza094a8a2015-04-07 11:53:06 -0700603// A predicate for the stl that returns if a top-level node is unused
604class TCompiler::UnusedPredicate
605{
606 public:
607 UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas)
608 : mCallDag(callDag),
609 mMetadatas(metadatas)
610 {
611 }
612
613 bool operator ()(TIntermNode *node)
614 {
615 const TIntermAggregate *asAggregate = node->getAsAggregate();
616
617 if (asAggregate == nullptr)
618 {
619 return false;
620 }
621
622 if (!(asAggregate->getOp() == EOpFunction || asAggregate->getOp() == EOpPrototype))
623 {
624 return false;
625 }
626
627 size_t callDagIndex = mCallDag->findIndex(asAggregate);
628 if (callDagIndex == CallDAG::InvalidIndex)
629 {
630 // This happens only for unimplemented prototypes which are thus unused
631 ASSERT(asAggregate->getOp() == EOpPrototype);
632 return true;
633 }
634
635 ASSERT(callDagIndex < mMetadatas->size());
636 return !(*mMetadatas)[callDagIndex].used;
637 }
638
639 private:
640 const CallDAG *mCallDag;
641 const std::vector<FunctionMetadata> *mMetadatas;
642};
643
644bool TCompiler::pruneUnusedFunctions(TIntermNode *root)
645{
646 TIntermAggregate *rootNode = root->getAsAggregate();
647 ASSERT(rootNode != nullptr);
648
649 UnusedPredicate isUnused(&mCallDag, &functionMetadata);
650 TIntermSequence *sequence = rootNode->getSequence();
651 sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused), sequence->end());
652
653 return true;
654}
655
Jamie Madill05a80ce2013-06-20 11:55:49 -0400656bool TCompiler::validateOutputs(TIntermNode* root)
657{
658 ValidateOutputs validateOutputs(infoSink.info, compileResources.MaxDrawBuffers);
659 root->traverse(&validateOutputs);
660 return (validateOutputs.numErrors() == 0);
661}
662
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000663void TCompiler::rewriteCSSShader(TIntermNode* root)
664{
665 RenameFunction renamer("main(", "css_main(");
666 root->traverse(&renamer);
667}
668
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800669bool TCompiler::validateLimitations(TIntermNode* root)
670{
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000671 ValidateLimitations validate(shaderType, infoSink.info);
672 root->traverse(&validate);
673 return validate.numErrors() == 0;
674}
675
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000676bool TCompiler::enforceTimingRestrictions(TIntermNode* root, bool outputGraph)
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000677{
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800678 if (shaderSpec != SH_WEBGL_SPEC)
679 {
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000680 infoSink.info << "Timing restrictions must be enforced under the WebGL spec.";
681 return false;
682 }
683
Jamie Madill183bde52014-07-02 15:31:19 -0400684 if (shaderType == GL_FRAGMENT_SHADER)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800685 {
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000686 TDependencyGraph graph(root);
687
688 // Output any errors first.
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000689 bool success = enforceFragmentShaderTimingRestrictions(graph);
Jamie Madill5508f392014-02-20 13:31:36 -0500690
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000691 // Then, output the dependency graph.
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800692 if (outputGraph)
693 {
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000694 TDependencyGraphOutput output(infoSink.info);
695 output.outputAllSpanningTrees(graph);
696 }
Jamie Madill5508f392014-02-20 13:31:36 -0500697
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000698 return success;
699 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800700 else
701 {
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000702 return enforceVertexShaderTimingRestrictions(root);
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000703 }
704}
705
Jamie Madilleb1a0102013-07-08 13:31:38 -0400706bool TCompiler::limitExpressionComplexity(TIntermNode* root)
707{
Jamie Madill6654bc92014-03-26 14:01:57 -0400708 TMaxDepthTraverser traverser(maxExpressionComplexity+1);
Jamie Madilleb1a0102013-07-08 13:31:38 -0400709 root->traverse(&traverser);
Jamie Madill6654bc92014-03-26 14:01:57 -0400710
711 if (traverser.getMaxDepth() > maxExpressionComplexity)
712 {
713 infoSink.info << "Expression too complex.";
714 return false;
715 }
716
Jamie Madilleb1a0102013-07-08 13:31:38 -0400717 TDependencyGraph graph(root);
718
719 for (TFunctionCallVector::const_iterator iter = graph.beginUserDefinedFunctionCalls();
720 iter != graph.endUserDefinedFunctionCalls();
721 ++iter)
722 {
723 TGraphFunctionCall* samplerSymbol = *iter;
724 TDependencyGraphTraverser graphTraverser;
725 samplerSymbol->traverse(&graphTraverser);
726 }
727
Jamie Madilleb1a0102013-07-08 13:31:38 -0400728 return true;
729}
730
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000731bool TCompiler::enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph)
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000732{
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000733 RestrictFragmentShaderTiming restrictor(infoSink.info);
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000734 restrictor.enforceRestrictions(graph);
735 return restrictor.numErrors() == 0;
736}
737
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000738bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root)
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000739{
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +0000740 RestrictVertexShaderTiming restrictor(infoSink.info);
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000741 restrictor.enforceRestrictions(root);
742 return restrictor.numErrors() == 0;
743}
744
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400745void TCompiler::collectVariables(TIntermNode* root)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000746{
Jamie Madilla2fbb842014-09-03 09:40:47 -0400747 sh::CollectVariables collect(&attributes,
748 &outputVariables,
749 &uniforms,
750 &varyings,
751 &interfaceBlocks,
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700752 hashFunction,
753 symbolTable);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000754 root->traverse(&collect);
Jamie Madill23a8a432014-07-09 13:27:42 -0400755
Zhenyao Mo409078f2014-10-28 13:23:18 -0700756 // This is for enforcePackingRestriction().
757 sh::ExpandUniforms(uniforms, &expandedUniforms);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000758}
zmo@google.comfd747b82011-04-23 01:30:07 +0000759
gman@chromium.org8d804792012-10-17 21:33:48 +0000760bool TCompiler::enforcePackingRestrictions()
761{
762 VariablePacker packer;
Jamie Madill23a8a432014-07-09 13:27:42 -0400763 return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms);
gman@chromium.org8d804792012-10-17 21:33:48 +0000764}
765
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800766void TCompiler::initializeGLPosition(TIntermNode* root)
767{
768 InitializeVariables::InitVariableInfoList variables;
769 InitializeVariables::InitVariableInfo var(
770 "gl_Position", TType(EbtFloat, EbpUndefined, EvqPosition, 4));
771 variables.push_back(var);
772 InitializeVariables initializer(variables);
773 root->traverse(&initializer);
774}
775
776void TCompiler::initializeVaryingsWithoutStaticUse(TIntermNode* root)
777{
778 InitializeVariables::InitVariableInfoList variables;
779 for (size_t ii = 0; ii < varyings.size(); ++ii)
780 {
Jamie Madilla718c1e2014-07-02 15:31:22 -0400781 const sh::Varying& varying = varyings[ii];
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800782 if (varying.staticUse)
783 continue;
Jamie Madillaa72d782014-07-02 15:31:19 -0400784 unsigned char primarySize = static_cast<unsigned char>(gl::VariableColumnCount(varying.type));
785 unsigned char secondarySize = static_cast<unsigned char>(gl::VariableRowCount(varying.type));
Jamie Madilla718c1e2014-07-02 15:31:22 -0400786 TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray());
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800787 TString name = varying.name.c_str();
Jamie Madilla718c1e2014-07-02 15:31:22 -0400788 if (varying.isArray())
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800789 {
Jamie Madilla718c1e2014-07-02 15:31:22 -0400790 type.setArraySize(varying.arraySize);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800791 name = name.substr(0, name.find_first_of('['));
792 }
793
794 InitializeVariables::InitVariableInfo var(name, type);
795 variables.push_back(var);
796 }
797 InitializeVariables initializer(variables);
798 root->traverse(&initializer);
799}
800
zmo@google.com5601ea02011-06-10 18:23:25 +0000801const TExtensionBehavior& TCompiler::getExtensionBehavior() const
802{
803 return extensionBehavior;
804}
zmo@google.com32e97312011-08-24 01:03:11 +0000805
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200806const char *TCompiler::getSourcePath() const
807{
808 return mSourcePath;
809}
810
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +0000811const ShBuiltInResources& TCompiler::getResources() const
812{
813 return compileResources;
814}
815
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000816const ArrayBoundsClamper& TCompiler::getArrayBoundsClamper() const
817{
818 return arrayBoundsClamper;
819}
820
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000821ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const
822{
823 return clampingStrategy;
824}
825
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200826const BuiltInFunctionEmulator& TCompiler::getBuiltInFunctionEmulator() const
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000827{
828 return builtInFunctionEmulator;
829}
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700830
831void TCompiler::writePragma()
832{
833 TInfoSinkBase &sink = infoSink.obj;
834 if (mPragma.stdgl.invariantAll)
835 sink << "#pragma STDGL invariant(all)\n";
836}