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