blob: e6e8a9619f8ef44c5d0ba9ad4b22cdb119730aac [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
Jamie Madillb1a85f42014-08-19 15:23:24 -04007#include "compiler/translator/IntermNode.h"
Zhenyao Mo550c6002014-02-26 15:40:48 -08008#include "compiler/translator/LoopInfo.h"
alokp@chromium.orgb59a7782010-11-24 18:38:33 +00009
10class TInfoSinkBase;
11
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000012// Traverses intermediate tree to ensure that the shader does not exceed the
13// minimum functionality mandated in GLSL 1.0 spec, Appendix A.
Zhenyao Mo550c6002014-02-26 15:40:48 -080014class ValidateLimitations : public TIntermTraverser
15{
16 public:
Jamie Madill183bde52014-07-02 15:31:19 -040017 ValidateLimitations(sh::GLenum shaderType, TInfoSinkBase &sink);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000018
19 int numErrors() const { return mNumErrors; }
20
Zhenyao Mo550c6002014-02-26 15:40:48 -080021 virtual bool visitBinary(Visit, TIntermBinary *);
22 virtual bool visitUnary(Visit, TIntermUnary *);
23 virtual bool visitAggregate(Visit, TIntermAggregate *);
24 virtual bool visitLoop(Visit, TIntermLoop *);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000025
Zhenyao Mo550c6002014-02-26 15:40:48 -080026 private:
27 void error(TSourceLoc loc, const char *reason, const char *token);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000028
29 bool withinLoopBody() const;
Zhenyao Mo550c6002014-02-26 15:40:48 -080030 bool isLoopIndex(TIntermSymbol *symbol);
31 bool validateLoopType(TIntermLoop *node);
32
33 bool validateForLoopHeader(TIntermLoop *node);
34 // If valid, return the index symbol id; Otherwise, return -1.
35 int validateForLoopInit(TIntermLoop *node);
36 bool validateForLoopCond(TIntermLoop *node, int indexSymbolId);
37 bool validateForLoopExpr(TIntermLoop *node, int indexSymbolId);
38
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000039 // Returns true if none of the loop indices is used as the argument to
40 // the given function out or inout parameter.
Zhenyao Mo550c6002014-02-26 15:40:48 -080041 bool validateFunctionCall(TIntermAggregate *node);
42 bool validateOperation(TIntermOperator *node, TIntermNode *operand);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000043
44 // Returns true if indexing does not exceed the minimum functionality
45 // mandated in GLSL 1.0 spec, Appendix A, Section 5.
Zhenyao Mo550c6002014-02-26 15:40:48 -080046 bool isConstExpr(TIntermNode *node);
47 bool isConstIndexExpr(TIntermNode *node);
48 bool validateIndexing(TIntermBinary *node);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000049
Jamie Madill183bde52014-07-02 15:31:19 -040050 sh::GLenum mShaderType;
Zhenyao Mo550c6002014-02-26 15:40:48 -080051 TInfoSinkBase &mSink;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000052 int mNumErrors;
53 TLoopStack mLoopStack;
54};
55