michael@0: // michael@0: // Copyright (c) 2010 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #include "GLSLANG/ShaderLang.h" michael@0: #include "compiler/intermediate.h" michael@0: michael@0: class TInfoSinkBase; michael@0: michael@0: struct TLoopInfo { michael@0: struct TIndex { michael@0: int id; // symbol id. michael@0: } index; michael@0: TIntermLoop* loop; michael@0: }; michael@0: typedef TVector TLoopStack; michael@0: michael@0: // Traverses intermediate tree to ensure that the shader does not exceed the michael@0: // minimum functionality mandated in GLSL 1.0 spec, Appendix A. michael@0: class ValidateLimitations : public TIntermTraverser { michael@0: public: michael@0: ValidateLimitations(ShShaderType shaderType, TInfoSinkBase& sink); michael@0: michael@0: int numErrors() const { return mNumErrors; } michael@0: michael@0: virtual bool visitBinary(Visit, TIntermBinary*); michael@0: virtual bool visitUnary(Visit, TIntermUnary*); michael@0: virtual bool visitAggregate(Visit, TIntermAggregate*); michael@0: virtual bool visitLoop(Visit, TIntermLoop*); michael@0: michael@0: private: michael@0: void error(TSourceLoc loc, const char *reason, const char* token); michael@0: michael@0: bool withinLoopBody() const; michael@0: bool isLoopIndex(const TIntermSymbol* symbol) const; michael@0: bool validateLoopType(TIntermLoop* node); michael@0: bool validateForLoopHeader(TIntermLoop* node, TLoopInfo* info); michael@0: bool validateForLoopInit(TIntermLoop* node, TLoopInfo* info); michael@0: bool validateForLoopCond(TIntermLoop* node, TLoopInfo* info); michael@0: bool validateForLoopExpr(TIntermLoop* node, TLoopInfo* info); michael@0: // Returns true if none of the loop indices is used as the argument to michael@0: // the given function out or inout parameter. michael@0: bool validateFunctionCall(TIntermAggregate* node); michael@0: bool validateOperation(TIntermOperator* node, TIntermNode* operand); michael@0: michael@0: // Returns true if indexing does not exceed the minimum functionality michael@0: // mandated in GLSL 1.0 spec, Appendix A, Section 5. michael@0: bool isConstExpr(TIntermNode* node); michael@0: bool isConstIndexExpr(TIntermNode* node); michael@0: bool validateIndexing(TIntermBinary* node); michael@0: michael@0: ShShaderType mShaderType; michael@0: TInfoSinkBase& mSink; michael@0: int mNumErrors; michael@0: TLoopStack mLoopStack; michael@0: }; michael@0: