blob: 4162203bb7539524456d99c986e86a5a2657b158 [file] [log] [blame]
alokp@chromium.orgb59a7782010-11-24 18:38:33 +00001//
2// Copyright (c) 2010 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7#include "GLSLANG/ShaderLang.h"
Geoff Lang17732822013-08-29 13:46:49 -04008#include "compiler/translator/intermediate.h"
Zhenyao Mo550c6002014-02-26 15:40:48 -08009#include "compiler/translator/LoopInfo.h"
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000010
11class TInfoSinkBase;
12
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000013// Traverses intermediate tree to ensure that the shader does not exceed the
14// minimum functionality mandated in GLSL 1.0 spec, Appendix A.
Zhenyao Mo550c6002014-02-26 15:40:48 -080015class ValidateLimitations : public TIntermTraverser
16{
17 public:
18 ValidateLimitations(ShShaderType shaderType, TInfoSinkBase &sink);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000019
20 int numErrors() const { return mNumErrors; }
21
Zhenyao Mo550c6002014-02-26 15:40:48 -080022 virtual bool visitBinary(Visit, TIntermBinary *);
23 virtual bool visitUnary(Visit, TIntermUnary *);
24 virtual bool visitAggregate(Visit, TIntermAggregate *);
25 virtual bool visitLoop(Visit, TIntermLoop *);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000026
Zhenyao Mo550c6002014-02-26 15:40:48 -080027 private:
28 void error(TSourceLoc loc, const char *reason, const char *token);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000029
30 bool withinLoopBody() const;
Zhenyao Mo550c6002014-02-26 15:40:48 -080031 bool isLoopIndex(TIntermSymbol *symbol);
32 bool validateLoopType(TIntermLoop *node);
33
34 bool validateForLoopHeader(TIntermLoop *node);
35 // If valid, return the index symbol id; Otherwise, return -1.
36 int validateForLoopInit(TIntermLoop *node);
37 bool validateForLoopCond(TIntermLoop *node, int indexSymbolId);
38 bool validateForLoopExpr(TIntermLoop *node, int indexSymbolId);
39
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000040 // Returns true if none of the loop indices is used as the argument to
41 // the given function out or inout parameter.
Zhenyao Mo550c6002014-02-26 15:40:48 -080042 bool validateFunctionCall(TIntermAggregate *node);
43 bool validateOperation(TIntermOperator *node, TIntermNode *operand);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000044
45 // Returns true if indexing does not exceed the minimum functionality
46 // mandated in GLSL 1.0 spec, Appendix A, Section 5.
Zhenyao Mo550c6002014-02-26 15:40:48 -080047 bool isConstExpr(TIntermNode *node);
48 bool isConstIndexExpr(TIntermNode *node);
49 bool validateIndexing(TIntermBinary *node);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000050
51 ShShaderType mShaderType;
Zhenyao Mo550c6002014-02-26 15:40:48 -080052 TInfoSinkBase &mSink;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000053 int mNumErrors;
54 TLoopStack mLoopStack;
55};
56