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.
7 #include "GLSLANG/ShaderLang.h"
8 #include "compiler/intermediate.h"
18 typedef TVector<TLoopInfo> TLoopStack;
20 // Traverses intermediate tree to ensure that the shader does not exceed the
21 // minimum functionality mandated in GLSL 1.0 spec, Appendix A.
22 class ValidateLimitations : public TIntermTraverser {
24 ValidateLimitations(ShShaderType shaderType, TInfoSinkBase& sink);
26 int numErrors() const { return mNumErrors; }
28 virtual void visitSymbol(TIntermSymbol*);
29 virtual void visitConstantUnion(TIntermConstantUnion*);
30 virtual bool visitBinary(Visit, TIntermBinary*);
31 virtual bool visitUnary(Visit, TIntermUnary*);
32 virtual bool visitSelection(Visit, TIntermSelection*);
33 virtual bool visitAggregate(Visit, TIntermAggregate*);
34 virtual bool visitLoop(Visit, TIntermLoop*);
35 virtual bool visitBranch(Visit, TIntermBranch*);
38 void error(TSourceLoc loc, const char *reason, const char* token);
40 bool withinLoopBody() const;
41 bool isLoopIndex(const TIntermSymbol* symbol) const;
42 bool validateLoopType(TIntermLoop* node);
43 bool validateForLoopHeader(TIntermLoop* node, TLoopInfo* info);
44 bool validateForLoopInit(TIntermLoop* node, TLoopInfo* info);
45 bool validateForLoopCond(TIntermLoop* node, TLoopInfo* info);
46 bool validateForLoopExpr(TIntermLoop* node, TLoopInfo* info);
47 // Returns true if none of the loop indices is used as the argument to
48 // the given function out or inout parameter.
49 bool validateFunctionCall(TIntermAggregate* node);
50 bool validateOperation(TIntermOperator* node, TIntermNode* operand);
52 // Returns true if indexing does not exceed the minimum functionality
53 // mandated in GLSL 1.0 spec, Appendix A, Section 5.
54 bool isConstExpr(TIntermNode* node);
55 bool isConstIndexExpr(TIntermNode* node);
56 bool validateIndexing(TIntermBinary* node);
58 ShShaderType mShaderType;
61 TLoopStack mLoopStack;