daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 16004fc | 2014-06-11 11:29:11 -0400 | [diff] [blame^] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 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 | // |
| 8 | // Definition of the in-memory high-level intermediate representation |
| 9 | // of shaders. This is a tree that parser creates. |
| 10 | // |
| 11 | // Nodes in the tree are defined as a hierarchy of classes derived from |
| 12 | // TIntermNode. Each is a node in a tree. There is no preset branching factor; |
| 13 | // each node can have it's own type of list of children. |
| 14 | // |
| 15 | |
| 16 | #ifndef __INTERMEDIATE_H |
| 17 | #define __INTERMEDIATE_H |
| 18 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 19 | #include "GLSLANG/ShaderLang.h" |
| 20 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 21 | #include <algorithm> |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 22 | #include <queue> |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 23 | #include "compiler/translator/Common.h" |
| 24 | #include "compiler/translator/Types.h" |
| 25 | #include "compiler/translator/ConstantUnion.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 26 | |
| 27 | // |
| 28 | // Operators used by the high-level (parse tree) representation. |
| 29 | // |
| 30 | enum TOperator { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 31 | EOpNull, // if in a node, should only mean a node is still being built |
| 32 | EOpSequence, // denotes a list of statements, or parameters, etc. |
| 33 | EOpFunctionCall, |
| 34 | EOpFunction, // For function definition |
| 35 | EOpParameters, // an aggregate listing the parameters to a function |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 36 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 37 | EOpDeclaration, |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 38 | EOpPrototype, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 39 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 40 | // |
| 41 | // Unary operators |
| 42 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 43 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 44 | EOpNegative, |
| 45 | EOpLogicalNot, |
| 46 | EOpVectorLogicalNot, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 47 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 48 | EOpPostIncrement, |
| 49 | EOpPostDecrement, |
| 50 | EOpPreIncrement, |
| 51 | EOpPreDecrement, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 52 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 53 | // |
| 54 | // binary operations |
| 55 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 56 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 57 | EOpAdd, |
| 58 | EOpSub, |
| 59 | EOpMul, |
| 60 | EOpDiv, |
| 61 | EOpEqual, |
| 62 | EOpNotEqual, |
| 63 | EOpVectorEqual, |
| 64 | EOpVectorNotEqual, |
| 65 | EOpLessThan, |
| 66 | EOpGreaterThan, |
| 67 | EOpLessThanEqual, |
| 68 | EOpGreaterThanEqual, |
| 69 | EOpComma, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 70 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 71 | EOpVectorTimesScalar, |
| 72 | EOpVectorTimesMatrix, |
| 73 | EOpMatrixTimesVector, |
| 74 | EOpMatrixTimesScalar, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 75 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 76 | EOpLogicalOr, |
| 77 | EOpLogicalXor, |
| 78 | EOpLogicalAnd, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 79 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 80 | EOpIndexDirect, |
| 81 | EOpIndexIndirect, |
| 82 | EOpIndexDirectStruct, |
shannonwoods@chromium.org | 5668c5d | 2013-05-30 00:11:48 +0000 | [diff] [blame] | 83 | EOpIndexDirectInterfaceBlock, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 84 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 85 | EOpVectorSwizzle, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 86 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 87 | // |
| 88 | // Built-in functions potentially mapped to operators |
| 89 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 90 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 91 | EOpRadians, |
| 92 | EOpDegrees, |
| 93 | EOpSin, |
| 94 | EOpCos, |
| 95 | EOpTan, |
| 96 | EOpAsin, |
| 97 | EOpAcos, |
| 98 | EOpAtan, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 99 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 100 | EOpPow, |
| 101 | EOpExp, |
| 102 | EOpLog, |
| 103 | EOpExp2, |
| 104 | EOpLog2, |
| 105 | EOpSqrt, |
| 106 | EOpInverseSqrt, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 107 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 108 | EOpAbs, |
| 109 | EOpSign, |
| 110 | EOpFloor, |
| 111 | EOpCeil, |
| 112 | EOpFract, |
| 113 | EOpMod, |
| 114 | EOpMin, |
| 115 | EOpMax, |
| 116 | EOpClamp, |
| 117 | EOpMix, |
| 118 | EOpStep, |
| 119 | EOpSmoothStep, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 120 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 121 | EOpLength, |
| 122 | EOpDistance, |
| 123 | EOpDot, |
| 124 | EOpCross, |
| 125 | EOpNormalize, |
| 126 | EOpFaceForward, |
| 127 | EOpReflect, |
| 128 | EOpRefract, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 129 | |
alokp@chromium.org | 0609889 | 2010-08-26 19:36:42 +0000 | [diff] [blame] | 130 | EOpDFdx, // Fragment only, OES_standard_derivatives extension |
| 131 | EOpDFdy, // Fragment only, OES_standard_derivatives extension |
| 132 | EOpFwidth, // Fragment only, OES_standard_derivatives extension |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 133 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 134 | EOpMatrixTimesMatrix, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 135 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 136 | EOpAny, |
| 137 | EOpAll, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 138 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 139 | // |
| 140 | // Branch |
| 141 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 142 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 143 | EOpKill, // Fragment only |
| 144 | EOpReturn, |
| 145 | EOpBreak, |
| 146 | EOpContinue, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 147 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 148 | // |
| 149 | // Constructors |
| 150 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 151 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 152 | EOpConstructInt, |
Nicolas Capens | ab60b93 | 2013-06-05 10:31:21 -0400 | [diff] [blame] | 153 | EOpConstructUInt, |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 154 | EOpConstructBool, |
| 155 | EOpConstructFloat, |
| 156 | EOpConstructVec2, |
| 157 | EOpConstructVec3, |
| 158 | EOpConstructVec4, |
| 159 | EOpConstructBVec2, |
| 160 | EOpConstructBVec3, |
| 161 | EOpConstructBVec4, |
| 162 | EOpConstructIVec2, |
| 163 | EOpConstructIVec3, |
| 164 | EOpConstructIVec4, |
shannonwoods@chromium.org | 8c788e8 | 2013-05-30 00:20:21 +0000 | [diff] [blame] | 165 | EOpConstructUVec2, |
| 166 | EOpConstructUVec3, |
| 167 | EOpConstructUVec4, |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 168 | EOpConstructMat2, |
| 169 | EOpConstructMat3, |
| 170 | EOpConstructMat4, |
| 171 | EOpConstructStruct, |
| 172 | |
| 173 | // |
| 174 | // moves |
| 175 | // |
| 176 | |
| 177 | EOpAssign, |
| 178 | EOpInitialize, |
| 179 | EOpAddAssign, |
| 180 | EOpSubAssign, |
| 181 | EOpMulAssign, |
| 182 | EOpVectorTimesMatrixAssign, |
| 183 | EOpVectorTimesScalarAssign, |
| 184 | EOpMatrixTimesScalarAssign, |
| 185 | EOpMatrixTimesMatrixAssign, |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 186 | EOpDivAssign |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 189 | extern const char* getOperatorString(TOperator op); |
| 190 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 191 | class TIntermTraverser; |
| 192 | class TIntermAggregate; |
| 193 | class TIntermBinary; |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 194 | class TIntermUnary; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 195 | class TIntermConstantUnion; |
| 196 | class TIntermSelection; |
| 197 | class TIntermTyped; |
| 198 | class TIntermSymbol; |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 199 | class TIntermLoop; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 200 | class TInfoSink; |
| 201 | |
| 202 | // |
| 203 | // Base class for the tree nodes |
| 204 | // |
| 205 | class TIntermNode { |
| 206 | public: |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 207 | POOL_ALLOCATOR_NEW_DELETE(); |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 208 | TIntermNode() { |
| 209 | // TODO: Move this to TSourceLoc constructor |
| 210 | // after getting rid of TPublicType. |
| 211 | line.first_file = line.last_file = 0; |
| 212 | line.first_line = line.last_line = 0; |
| 213 | } |
| 214 | virtual ~TIntermNode() { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 215 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 216 | const TSourceLoc& getLine() const { return line; } |
| 217 | void setLine(const TSourceLoc& l) { line = l; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 218 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 219 | virtual void traverse(TIntermTraverser*) = 0; |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 220 | virtual TIntermTyped* getAsTyped() { return 0; } |
| 221 | virtual TIntermConstantUnion* getAsConstantUnion() { return 0; } |
| 222 | virtual TIntermAggregate* getAsAggregate() { return 0; } |
| 223 | virtual TIntermBinary* getAsBinaryNode() { return 0; } |
| 224 | virtual TIntermUnary* getAsUnaryNode() { return 0; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 225 | virtual TIntermSelection* getAsSelectionNode() { return 0; } |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 226 | virtual TIntermSymbol* getAsSymbolNode() { return 0; } |
| 227 | virtual TIntermLoop* getAsLoopNode() { return 0; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 228 | |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 229 | // Replace a child node. Return true if |original| is a child |
| 230 | // node and it is replaced; otherwise, return false. |
| 231 | virtual bool replaceChildNode( |
| 232 | TIntermNode *original, TIntermNode *replacement) = 0; |
| 233 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 234 | // For traversing a tree in no particular order, but using |
| 235 | // heap memory. |
| 236 | virtual void enqueueChildren(std::queue<TIntermNode*> *nodeQueue) const = 0; |
| 237 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 238 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 239 | TSourceLoc line; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | // |
| 243 | // This is just to help yacc. |
| 244 | // |
| 245 | struct TIntermNodePair { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 246 | TIntermNode* node1; |
| 247 | TIntermNode* node2; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 248 | }; |
| 249 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 250 | // |
| 251 | // Intermediate class for nodes that have a type. |
| 252 | // |
| 253 | class TIntermTyped : public TIntermNode { |
| 254 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 255 | TIntermTyped(const TType& t) : type(t) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 256 | virtual TIntermTyped* getAsTyped() { return this; } |
alokp@chromium.org | dd037b2 | 2010-03-30 18:47:20 +0000 | [diff] [blame] | 257 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 258 | virtual bool hasSideEffects() const = 0; |
| 259 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 260 | void setType(const TType& t) { type = t; } |
| 261 | const TType& getType() const { return type; } |
| 262 | TType* getTypePointer() { return &type; } |
| 263 | |
| 264 | TBasicType getBasicType() const { return type.getBasicType(); } |
| 265 | TQualifier getQualifier() const { return type.getQualifier(); } |
| 266 | TPrecision getPrecision() const { return type.getPrecision(); } |
Shannon Woods | 3841b8e | 2013-09-10 18:23:12 -0400 | [diff] [blame] | 267 | int getCols() const { return type.getCols(); } |
| 268 | int getRows() const { return type.getRows(); } |
| 269 | int getNominalSize() const { return type.getNominalSize(); } |
| 270 | int getSecondarySize() const { return type.getSecondarySize(); } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 271 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 272 | bool isInterfaceBlock() const { return type.isInterfaceBlock(); } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 273 | bool isMatrix() const { return type.isMatrix(); } |
| 274 | bool isArray() const { return type.isArray(); } |
| 275 | bool isVector() const { return type.isVector(); } |
| 276 | bool isScalar() const { return type.isScalar(); } |
shannonwoods@chromium.org | 6b70991 | 2013-05-30 00:20:04 +0000 | [diff] [blame] | 277 | bool isScalarInt() const { return type.isScalarInt(); } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 278 | const char* getBasicString() const { return type.getBasicString(); } |
| 279 | const char* getQualifierString() const { return type.getQualifierString(); } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 280 | TString getCompleteString() const { return type.getCompleteString(); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 281 | |
daniel@transgaming.com | 3ca980a | 2012-12-20 21:11:52 +0000 | [diff] [blame] | 282 | int getArraySize() const { return type.getArraySize(); } |
| 283 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 284 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 285 | TType type; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | // |
| 289 | // Handle for, do-while, and while loops. |
| 290 | // |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 291 | enum TLoopType { |
| 292 | ELoopFor, |
| 293 | ELoopWhile, |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 294 | ELoopDoWhile |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 295 | }; |
| 296 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 297 | class TIntermLoop : public TIntermNode { |
| 298 | public: |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 299 | TIntermLoop(TLoopType aType, |
| 300 | TIntermNode *aInit, TIntermTyped* aCond, TIntermTyped* aExpr, |
| 301 | TIntermNode* aBody) : |
| 302 | type(aType), |
| 303 | init(aInit), |
| 304 | cond(aCond), |
| 305 | expr(aExpr), |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 306 | body(aBody), |
| 307 | unrollFlag(false) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 308 | |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 309 | virtual TIntermLoop* getAsLoopNode() { return this; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 310 | virtual void traverse(TIntermTraverser*); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 311 | virtual bool replaceChildNode( |
| 312 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 313 | |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 314 | TLoopType getType() const { return type; } |
| 315 | TIntermNode* getInit() { return init; } |
| 316 | TIntermTyped* getCondition() { return cond; } |
| 317 | TIntermTyped* getExpression() { return expr; } |
| 318 | TIntermNode* getBody() { return body; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 319 | |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 320 | void setUnrollFlag(bool flag) { unrollFlag = flag; } |
| 321 | bool getUnrollFlag() { return unrollFlag; } |
| 322 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 323 | virtual void enqueueChildren(std::queue<TIntermNode*> *nodeQueue) const; |
| 324 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 325 | protected: |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 326 | TLoopType type; |
| 327 | TIntermNode* init; // for-loop initialization |
| 328 | TIntermTyped* cond; // loop exit condition |
| 329 | TIntermTyped* expr; // for-loop expression |
| 330 | TIntermNode* body; // loop body |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 331 | |
| 332 | bool unrollFlag; // Whether the loop should be unrolled or not. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | // |
| 336 | // Handle break, continue, return, and kill. |
| 337 | // |
| 338 | class TIntermBranch : public TIntermNode { |
| 339 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 340 | TIntermBranch(TOperator op, TIntermTyped* e) : |
| 341 | flowOp(op), |
| 342 | expression(e) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 343 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 344 | virtual void traverse(TIntermTraverser*); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 345 | virtual bool replaceChildNode( |
| 346 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 347 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 348 | TOperator getFlowOp() { return flowOp; } |
| 349 | TIntermTyped* getExpression() { return expression; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 350 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 351 | virtual void enqueueChildren(std::queue<TIntermNode*> *nodeQueue) const; |
| 352 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 353 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 354 | TOperator flowOp; |
| 355 | TIntermTyped* expression; // non-zero except for "return exp;" statements |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 356 | }; |
| 357 | |
| 358 | // |
| 359 | // Nodes that correspond to symbols or constants in the source code. |
| 360 | // |
| 361 | class TIntermSymbol : public TIntermTyped { |
| 362 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 363 | // if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from |
| 364 | // per process globalpoolallocator, then it causes increased memory usage per compile |
| 365 | // it is essential to use "symbol = sym" to assign to symbol |
| 366 | TIntermSymbol(int i, const TString& sym, const TType& t) : |
Zhenyao Mo | 3cdfcce | 2014-03-07 13:00:08 -0800 | [diff] [blame] | 367 | TIntermTyped(t), id(i) { symbol = sym; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 368 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 369 | virtual bool hasSideEffects() const { return false; } |
| 370 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 371 | int getId() const { return id; } |
| 372 | const TString& getSymbol() const { return symbol; } |
| 373 | |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 374 | void setId(int newId) { id = newId; } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 375 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 376 | virtual void traverse(TIntermTraverser*); |
| 377 | virtual TIntermSymbol* getAsSymbolNode() { return this; } |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 378 | virtual bool replaceChildNode(TIntermNode *, TIntermNode *) { return false; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 379 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 380 | virtual void enqueueChildren(std::queue<TIntermNode*> *nodeQueue) const {} |
| 381 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 382 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 383 | int id; |
| 384 | TString symbol; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 385 | }; |
| 386 | |
| 387 | class TIntermConstantUnion : public TIntermTyped { |
| 388 | public: |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 389 | TIntermConstantUnion(ConstantUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 390 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 391 | virtual bool hasSideEffects() const { return false; } |
| 392 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 393 | ConstantUnion* getUnionArrayPointer() const { return unionArrayPointer; } |
shannon.woods%transgaming.com@gtempaccount.com | c0d0c22 | 2013-04-13 03:29:36 +0000 | [diff] [blame] | 394 | |
Nicolas Capens | a621c2e | 2013-11-20 13:40:23 -0500 | [diff] [blame] | 395 | int getIConst(size_t index) const { return unionArrayPointer ? unionArrayPointer[index].getIConst() : 0; } |
| 396 | unsigned int getUConst(size_t index) const { return unionArrayPointer ? unionArrayPointer[index].getUConst() : 0; } |
| 397 | float getFConst(size_t index) const { return unionArrayPointer ? unionArrayPointer[index].getFConst() : 0.0f; } |
| 398 | bool getBConst(size_t index) const { return unionArrayPointer ? unionArrayPointer[index].getBConst() : false; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 399 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 400 | virtual TIntermConstantUnion* getAsConstantUnion() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 401 | virtual void traverse(TIntermTraverser*); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 402 | virtual bool replaceChildNode(TIntermNode *, TIntermNode *) { return false; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 403 | |
| 404 | TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&); |
| 405 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 406 | virtual void enqueueChildren(std::queue<TIntermNode*> *nodeQueue) const {} |
| 407 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 408 | protected: |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 409 | ConstantUnion *unionArrayPointer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 410 | }; |
| 411 | |
| 412 | // |
| 413 | // Intermediate class for node types that hold operators. |
| 414 | // |
| 415 | class TIntermOperator : public TIntermTyped { |
| 416 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 417 | TOperator getOp() const { return op; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 418 | void setOp(TOperator o) { op = o; } |
| 419 | |
Jamie Madill | f4b79ba | 2013-11-26 10:38:18 -0500 | [diff] [blame] | 420 | bool isAssignment() const; |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 421 | bool isConstructor() const; |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 422 | |
Jamie Madill | f4b79ba | 2013-11-26 10:38:18 -0500 | [diff] [blame] | 423 | virtual bool hasSideEffects() const { return isAssignment(); } |
| 424 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 425 | protected: |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 426 | TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat, EbpUndefined)), op(o) {} |
Jamie Madill | e53c98b | 2014-02-03 11:57:13 -0500 | [diff] [blame] | 427 | TIntermOperator(TOperator o, const TType& t) : TIntermTyped(t), op(o) {} |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 428 | TOperator op; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 429 | }; |
| 430 | |
| 431 | // |
| 432 | // Nodes for all the basic binary math operators. |
| 433 | // |
| 434 | class TIntermBinary : public TIntermOperator { |
| 435 | public: |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 436 | TIntermBinary(TOperator o) : TIntermOperator(o), addIndexClamp(false) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 437 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 438 | virtual TIntermBinary* getAsBinaryNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 439 | virtual void traverse(TIntermTraverser*); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 440 | virtual bool replaceChildNode( |
| 441 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 442 | |
Jamie Madill | f4b79ba | 2013-11-26 10:38:18 -0500 | [diff] [blame] | 443 | virtual bool hasSideEffects() const { return (isAssignment() || left->hasSideEffects() || right->hasSideEffects()); } |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 444 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 445 | void setLeft(TIntermTyped* n) { left = n; } |
| 446 | void setRight(TIntermTyped* n) { right = n; } |
| 447 | TIntermTyped* getLeft() const { return left; } |
| 448 | TIntermTyped* getRight() const { return right; } |
| 449 | bool promote(TInfoSink&); |
| 450 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 451 | void setAddIndexClamp() { addIndexClamp = true; } |
| 452 | bool getAddIndexClamp() { return addIndexClamp; } |
| 453 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 454 | virtual void enqueueChildren(std::queue<TIntermNode*> *nodeQueue) const; |
| 455 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 456 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 457 | TIntermTyped* left; |
| 458 | TIntermTyped* right; |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 459 | |
| 460 | // If set to true, wrap any EOpIndexIndirect with a clamp to bounds. |
| 461 | bool addIndexClamp; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 462 | }; |
| 463 | |
| 464 | // |
| 465 | // Nodes for unary math operators. |
| 466 | // |
| 467 | class TIntermUnary : public TIntermOperator { |
| 468 | public: |
Jamie Madill | e53c98b | 2014-02-03 11:57:13 -0500 | [diff] [blame] | 469 | TIntermUnary(TOperator o, const TType& t) : TIntermOperator(o, t), operand(0), useEmulatedFunction(false) {} |
zmo@google.com | e4eb991 | 2011-08-29 21:13:12 +0000 | [diff] [blame] | 470 | TIntermUnary(TOperator o) : TIntermOperator(o), operand(0), useEmulatedFunction(false) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 471 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 472 | virtual void traverse(TIntermTraverser*); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 473 | virtual TIntermUnary* getAsUnaryNode() { return this; } |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 474 | virtual bool replaceChildNode( |
| 475 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 476 | |
Jamie Madill | f4b79ba | 2013-11-26 10:38:18 -0500 | [diff] [blame] | 477 | virtual bool hasSideEffects() const { return (isAssignment() || operand->hasSideEffects()); } |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 478 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 479 | void setOperand(TIntermTyped* o) { operand = o; } |
| 480 | TIntermTyped* getOperand() { return operand; } |
| 481 | bool promote(TInfoSink&); |
| 482 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 483 | void setUseEmulatedFunction() { useEmulatedFunction = true; } |
| 484 | bool getUseEmulatedFunction() { return useEmulatedFunction; } |
| 485 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 486 | virtual void enqueueChildren(std::queue<TIntermNode*> *nodeQueue) const; |
| 487 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 488 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 489 | TIntermTyped* operand; |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 490 | |
| 491 | // If set to true, replace the built-in function call with an emulated one |
| 492 | // to work around driver bugs. |
| 493 | bool useEmulatedFunction; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 494 | }; |
| 495 | |
| 496 | typedef TVector<TIntermNode*> TIntermSequence; |
| 497 | typedef TVector<int> TQualifierList; |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 498 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 499 | // |
| 500 | // Nodes that operate on an arbitrary sized set of children. |
| 501 | // |
| 502 | class TIntermAggregate : public TIntermOperator { |
| 503 | public: |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 504 | TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), useEmulatedFunction(false) { } |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 505 | TIntermAggregate(TOperator o) : TIntermOperator(o), useEmulatedFunction(false) { } |
| 506 | ~TIntermAggregate() { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 507 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 508 | virtual TIntermAggregate* getAsAggregate() { return this; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 509 | virtual void traverse(TIntermTraverser*); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 510 | virtual bool replaceChildNode( |
| 511 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 512 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 513 | // Conservatively assume function calls and other aggregate operators have side-effects |
| 514 | virtual bool hasSideEffects() const { return true; } |
| 515 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 516 | TIntermSequence& getSequence() { return sequence; } |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 517 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 518 | void setName(const TString& n) { name = n; } |
| 519 | const TString& getName() const { return name; } |
| 520 | |
| 521 | void setUserDefined() { userDefined = true; } |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 522 | bool isUserDefined() const { return userDefined; } |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 523 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 524 | void setOptimize(bool o) { optimize = o; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 525 | bool getOptimize() { return optimize; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 526 | void setDebug(bool d) { debug = d; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 527 | bool getDebug() { return debug; } |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 528 | |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 529 | void setUseEmulatedFunction() { useEmulatedFunction = true; } |
| 530 | bool getUseEmulatedFunction() { return useEmulatedFunction; } |
| 531 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 532 | virtual void enqueueChildren(std::queue<TIntermNode*> *nodeQueue) const; |
| 533 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 534 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 535 | TIntermAggregate(const TIntermAggregate&); // disallow copy constructor |
| 536 | TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator |
| 537 | TIntermSequence sequence; |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 538 | TString name; |
| 539 | bool userDefined; // used for user defined function names |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 540 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 541 | bool optimize; |
| 542 | bool debug; |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 543 | |
| 544 | // If set to true, replace the built-in function call with an emulated one |
| 545 | // to work around driver bugs. |
| 546 | bool useEmulatedFunction; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 547 | }; |
| 548 | |
| 549 | // |
| 550 | // For if tests. Simplified since there is no switch statement. |
| 551 | // |
| 552 | class TIntermSelection : public TIntermTyped { |
| 553 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 554 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) : |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 555 | TIntermTyped(TType(EbtVoid, EbpUndefined)), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 556 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) : |
| 557 | TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 558 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 559 | virtual void traverse(TIntermTraverser*); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 560 | virtual bool replaceChildNode( |
| 561 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 562 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 563 | // Conservatively assume selections have side-effects |
| 564 | virtual bool hasSideEffects() const { return true; } |
| 565 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 566 | bool usesTernaryOperator() const { return getBasicType() != EbtVoid; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 567 | TIntermNode* getCondition() const { return condition; } |
| 568 | TIntermNode* getTrueBlock() const { return trueBlock; } |
| 569 | TIntermNode* getFalseBlock() const { return falseBlock; } |
| 570 | TIntermSelection* getAsSelectionNode() { return this; } |
| 571 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 572 | virtual void enqueueChildren(std::queue<TIntermNode*> *nodeQueue) const; |
| 573 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 574 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 575 | TIntermTyped* condition; |
| 576 | TIntermNode* trueBlock; |
| 577 | TIntermNode* falseBlock; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 578 | }; |
| 579 | |
| 580 | enum Visit |
| 581 | { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 582 | PreVisit, |
| 583 | InVisit, |
| 584 | PostVisit |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 585 | }; |
| 586 | |
| 587 | // |
| 588 | // For traversing the tree. User should derive from this, |
| 589 | // put their traversal specific data in it, and then pass |
| 590 | // it to a Traverse method. |
| 591 | // |
| 592 | // When using this, just fill in the methods for nodes you want visited. |
| 593 | // Return false from a pre-visit to skip visiting that node's subtree. |
| 594 | // |
| 595 | class TIntermTraverser |
| 596 | { |
| 597 | public: |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 598 | POOL_ALLOCATOR_NEW_DELETE(); |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 599 | TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, bool rightToLeft = false) : |
| 600 | preVisit(preVisit), |
| 601 | inVisit(inVisit), |
| 602 | postVisit(postVisit), |
| 603 | rightToLeft(rightToLeft), |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 604 | depth(0), |
| 605 | maxDepth(0) {} |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 606 | virtual ~TIntermTraverser() {} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 607 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 608 | virtual void visitSymbol(TIntermSymbol*) {} |
| 609 | virtual void visitConstantUnion(TIntermConstantUnion*) {} |
| 610 | virtual bool visitBinary(Visit visit, TIntermBinary*) {return true;} |
| 611 | virtual bool visitUnary(Visit visit, TIntermUnary*) {return true;} |
| 612 | virtual bool visitSelection(Visit visit, TIntermSelection*) {return true;} |
| 613 | virtual bool visitAggregate(Visit visit, TIntermAggregate*) {return true;} |
| 614 | virtual bool visitLoop(Visit visit, TIntermLoop*) {return true;} |
| 615 | virtual bool visitBranch(Visit visit, TIntermBranch*) {return true;} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 616 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 617 | int getMaxDepth() const {return maxDepth;} |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 618 | |
| 619 | void incrementDepth(TIntermNode *current) |
| 620 | { |
| 621 | depth++; |
| 622 | maxDepth = std::max(maxDepth, depth); |
| 623 | path.push_back(current); |
| 624 | } |
| 625 | |
| 626 | void decrementDepth() |
| 627 | { |
| 628 | depth--; |
| 629 | path.pop_back(); |
| 630 | } |
| 631 | |
| 632 | TIntermNode *getParentNode() |
| 633 | { |
| 634 | return path.size() == 0 ? NULL : path.back(); |
| 635 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 636 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 637 | // Return the original name if hash function pointer is NULL; |
| 638 | // otherwise return the hashed name. |
| 639 | static TString hash(const TString& name, ShHashFunction64 hashFunction); |
| 640 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 641 | const bool preVisit; |
| 642 | const bool inVisit; |
| 643 | const bool postVisit; |
| 644 | const bool rightToLeft; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 645 | |
| 646 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 647 | int depth; |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 648 | int maxDepth; |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 649 | |
| 650 | // All the nodes from root to the current node's parent during traversing. |
| 651 | TVector<TIntermNode *> path; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 652 | }; |
| 653 | |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 654 | // |
| 655 | // For traversing the tree, and computing max depth. |
| 656 | // Takes a maximum depth limit to prevent stack overflow. |
| 657 | // |
| 658 | class TMaxDepthTraverser : public TIntermTraverser |
| 659 | { |
| 660 | public: |
| 661 | POOL_ALLOCATOR_NEW_DELETE(); |
| 662 | TMaxDepthTraverser(int depthLimit) |
| 663 | : TIntermTraverser(true, true, false, false), |
| 664 | depthLimit(depthLimit) |
| 665 | {} |
| 666 | |
| 667 | virtual bool visitBinary(Visit visit, TIntermBinary*) { return depthCheck(); } |
| 668 | virtual bool visitUnary(Visit visit, TIntermUnary*) { return depthCheck(); } |
| 669 | virtual bool visitSelection(Visit visit, TIntermSelection*) { return depthCheck(); } |
| 670 | virtual bool visitAggregate(Visit visit, TIntermAggregate*) { return depthCheck(); } |
| 671 | virtual bool visitLoop(Visit visit, TIntermLoop*) { return depthCheck(); } |
| 672 | virtual bool visitBranch(Visit visit, TIntermBranch*) { return depthCheck(); } |
| 673 | |
| 674 | protected: |
| 675 | int depthLimit; |
| 676 | |
| 677 | bool depthCheck() const { return maxDepth < depthLimit; } |
| 678 | }; |
| 679 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 680 | #endif // __INTERMEDIATE_H |