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