initial import
[vuplus_webkit] / Source / ThirdParty / ANGLE / src / compiler / ValidateLimitations.h
1 //
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"
8 #include "compiler/intermediate.h"
9
10 class TInfoSinkBase;
11
12 struct TLoopInfo {
13     struct TIndex {
14         int id;  // symbol id.
15     } index;
16     TIntermLoop* loop;
17 };
18 typedef TVector<TLoopInfo> TLoopStack;
19
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 {
23 public:
24     ValidateLimitations(ShShaderType shaderType, TInfoSinkBase& sink);
25
26     int numErrors() const { return mNumErrors; }
27
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*);
36
37 private:
38     void error(TSourceLoc loc, const char *reason, const char* token);
39
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);
51
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);
57
58     ShShaderType mShaderType;
59     TInfoSinkBase& mSink;
60     int mNumErrors;
61     TLoopStack mLoopStack;
62 };
63