blob: 8839dd8b8af3656d133241d016178837981811fb [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"
alokp@chromium.orgb59a7782010-11-24 18:38:33 +00009
10class TInfoSinkBase;
11
12struct TLoopInfo {
13 struct TIndex {
14 int id; // symbol id.
15 } index;
zmo@google.com0b8d4eb2011-04-04 19:17:11 +000016 TIntermLoop* loop;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000017};
18typedef 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.
22class ValidateLimitations : public TIntermTraverser {
23public:
24 ValidateLimitations(ShShaderType shaderType, TInfoSinkBase& sink);
25
26 int numErrors() const { return mNumErrors; }
27
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000028 virtual bool visitBinary(Visit, TIntermBinary*);
29 virtual bool visitUnary(Visit, TIntermUnary*);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000030 virtual bool visitAggregate(Visit, TIntermAggregate*);
31 virtual bool visitLoop(Visit, TIntermLoop*);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000032
33private:
34 void error(TSourceLoc loc, const char *reason, const char* token);
35
36 bool withinLoopBody() const;
37 bool isLoopIndex(const TIntermSymbol* symbol) const;
38 bool validateLoopType(TIntermLoop* node);
39 bool validateForLoopHeader(TIntermLoop* node, TLoopInfo* info);
40 bool validateForLoopInit(TIntermLoop* node, TLoopInfo* info);
41 bool validateForLoopCond(TIntermLoop* node, TLoopInfo* info);
42 bool validateForLoopExpr(TIntermLoop* node, TLoopInfo* info);
43 // Returns true if none of the loop indices is used as the argument to
44 // the given function out or inout parameter.
45 bool validateFunctionCall(TIntermAggregate* node);
46 bool validateOperation(TIntermOperator* node, TIntermNode* operand);
47
48 // Returns true if indexing does not exceed the minimum functionality
49 // mandated in GLSL 1.0 spec, Appendix A, Section 5.
50 bool isConstExpr(TIntermNode* node);
51 bool isConstIndexExpr(TIntermNode* node);
52 bool validateIndexing(TIntermBinary* node);
53
54 ShShaderType mShaderType;
55 TInfoSinkBase& mSink;
56 int mNumErrors;
57 TLoopStack mLoopStack;
58};
59