daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 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 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 21 | #include "compiler/Common.h" |
| 22 | #include "compiler/Types.h" |
| 23 | #include "compiler/ConstantUnion.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 24 | |
| 25 | // |
| 26 | // Operators used by the high-level (parse tree) representation. |
| 27 | // |
| 28 | enum TOperator { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 29 | EOpNull, // if in a node, should only mean a node is still being built |
| 30 | EOpSequence, // denotes a list of statements, or parameters, etc. |
| 31 | EOpFunctionCall, |
| 32 | EOpFunction, // For function definition |
| 33 | EOpParameters, // an aggregate listing the parameters to a function |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 34 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 35 | EOpDeclaration, |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 36 | EOpPrototype, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 37 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 38 | // |
| 39 | // Unary operators |
| 40 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 41 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 42 | EOpNegative, |
| 43 | EOpLogicalNot, |
| 44 | EOpVectorLogicalNot, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 45 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 46 | EOpPostIncrement, |
| 47 | EOpPostDecrement, |
| 48 | EOpPreIncrement, |
| 49 | EOpPreDecrement, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 50 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 51 | EOpConvIntToBool, |
| 52 | EOpConvFloatToBool, |
| 53 | EOpConvBoolToFloat, |
| 54 | EOpConvIntToFloat, |
| 55 | EOpConvFloatToInt, |
| 56 | EOpConvBoolToInt, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 57 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 58 | // |
| 59 | // binary operations |
| 60 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 61 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 62 | EOpAdd, |
| 63 | EOpSub, |
| 64 | EOpMul, |
| 65 | EOpDiv, |
| 66 | EOpEqual, |
| 67 | EOpNotEqual, |
| 68 | EOpVectorEqual, |
| 69 | EOpVectorNotEqual, |
| 70 | EOpLessThan, |
| 71 | EOpGreaterThan, |
| 72 | EOpLessThanEqual, |
| 73 | EOpGreaterThanEqual, |
| 74 | EOpComma, |
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 | EOpVectorTimesScalar, |
| 77 | EOpVectorTimesMatrix, |
| 78 | EOpMatrixTimesVector, |
| 79 | EOpMatrixTimesScalar, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 80 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 81 | EOpLogicalOr, |
| 82 | EOpLogicalXor, |
| 83 | EOpLogicalAnd, |
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 | EOpIndexDirect, |
| 86 | EOpIndexIndirect, |
| 87 | EOpIndexDirectStruct, |
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 | EOpVectorSwizzle, |
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 | // |
| 92 | // Built-in functions potentially mapped to operators |
| 93 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 94 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 95 | EOpRadians, |
| 96 | EOpDegrees, |
| 97 | EOpSin, |
| 98 | EOpCos, |
| 99 | EOpTan, |
| 100 | EOpAsin, |
| 101 | EOpAcos, |
| 102 | EOpAtan, |
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 | EOpPow, |
| 105 | EOpExp, |
| 106 | EOpLog, |
| 107 | EOpExp2, |
| 108 | EOpLog2, |
| 109 | EOpSqrt, |
| 110 | EOpInverseSqrt, |
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 | EOpAbs, |
| 113 | EOpSign, |
| 114 | EOpFloor, |
| 115 | EOpCeil, |
| 116 | EOpFract, |
| 117 | EOpMod, |
| 118 | EOpMin, |
| 119 | EOpMax, |
| 120 | EOpClamp, |
| 121 | EOpMix, |
| 122 | EOpStep, |
| 123 | EOpSmoothStep, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 124 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 125 | EOpLength, |
| 126 | EOpDistance, |
| 127 | EOpDot, |
| 128 | EOpCross, |
| 129 | EOpNormalize, |
| 130 | EOpFaceForward, |
| 131 | EOpReflect, |
| 132 | EOpRefract, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 133 | |
alokp@chromium.org | 0609889 | 2010-08-26 19:36:42 +0000 | [diff] [blame] | 134 | EOpDFdx, // Fragment only, OES_standard_derivatives extension |
| 135 | EOpDFdy, // Fragment only, OES_standard_derivatives extension |
| 136 | EOpFwidth, // Fragment only, OES_standard_derivatives extension |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 137 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 138 | EOpMatrixTimesMatrix, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 139 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 140 | EOpAny, |
| 141 | EOpAll, |
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 | // |
| 144 | // Branch |
| 145 | // |
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 | EOpKill, // Fragment only |
| 148 | EOpReturn, |
| 149 | EOpBreak, |
| 150 | EOpContinue, |
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 | // Constructors |
| 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 | EOpConstructInt, |
| 157 | EOpConstructBool, |
| 158 | EOpConstructFloat, |
| 159 | EOpConstructVec2, |
| 160 | EOpConstructVec3, |
| 161 | EOpConstructVec4, |
| 162 | EOpConstructBVec2, |
| 163 | EOpConstructBVec3, |
| 164 | EOpConstructBVec4, |
| 165 | EOpConstructIVec2, |
| 166 | EOpConstructIVec3, |
| 167 | EOpConstructIVec4, |
| 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, |
| 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: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 207 | POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 208 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 209 | TIntermNode() : line(0) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 210 | |
| 211 | TSourceLoc getLine() const { return line; } |
| 212 | void setLine(TSourceLoc l) { line = l; } |
| 213 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 214 | virtual void traverse(TIntermTraverser*) = 0; |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 215 | virtual TIntermTyped* getAsTyped() { return 0; } |
| 216 | virtual TIntermConstantUnion* getAsConstantUnion() { return 0; } |
| 217 | virtual TIntermAggregate* getAsAggregate() { return 0; } |
| 218 | virtual TIntermBinary* getAsBinaryNode() { return 0; } |
| 219 | virtual TIntermUnary* getAsUnaryNode() { return 0; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 220 | virtual TIntermSelection* getAsSelectionNode() { return 0; } |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 221 | virtual TIntermSymbol* getAsSymbolNode() { return 0; } |
| 222 | virtual TIntermLoop* getAsLoopNode() { return 0; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 223 | virtual ~TIntermNode() { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 224 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 225 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 226 | TSourceLoc line; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | // |
| 230 | // This is just to help yacc. |
| 231 | // |
| 232 | struct TIntermNodePair { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 233 | TIntermNode* node1; |
| 234 | TIntermNode* node2; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 235 | }; |
| 236 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 237 | // |
| 238 | // Intermediate class for nodes that have a type. |
| 239 | // |
| 240 | class TIntermTyped : public TIntermNode { |
| 241 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 242 | TIntermTyped(const TType& t) : type(t) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 243 | virtual TIntermTyped* getAsTyped() { return this; } |
alokp@chromium.org | dd037b2 | 2010-03-30 18:47:20 +0000 | [diff] [blame] | 244 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 245 | void setType(const TType& t) { type = t; } |
| 246 | const TType& getType() const { return type; } |
| 247 | TType* getTypePointer() { return &type; } |
| 248 | |
| 249 | TBasicType getBasicType() const { return type.getBasicType(); } |
| 250 | TQualifier getQualifier() const { return type.getQualifier(); } |
| 251 | TPrecision getPrecision() const { return type.getPrecision(); } |
| 252 | int getNominalSize() const { return type.getNominalSize(); } |
| 253 | |
| 254 | bool isMatrix() const { return type.isMatrix(); } |
| 255 | bool isArray() const { return type.isArray(); } |
| 256 | bool isVector() const { return type.isVector(); } |
| 257 | bool isScalar() const { return type.isScalar(); } |
| 258 | const char* getBasicString() const { return type.getBasicString(); } |
| 259 | const char* getQualifierString() const { return type.getQualifierString(); } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 260 | TString getCompleteString() const { return type.getCompleteString(); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 261 | |
| 262 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 263 | TType type; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | // |
| 267 | // Handle for, do-while, and while loops. |
| 268 | // |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 269 | enum TLoopType { |
| 270 | ELoopFor, |
| 271 | ELoopWhile, |
| 272 | ELoopDoWhile, |
| 273 | }; |
| 274 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 275 | class TIntermLoop : public TIntermNode { |
| 276 | public: |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 277 | TIntermLoop(TLoopType aType, |
| 278 | TIntermNode *aInit, TIntermTyped* aCond, TIntermTyped* aExpr, |
| 279 | TIntermNode* aBody) : |
| 280 | type(aType), |
| 281 | init(aInit), |
| 282 | cond(aCond), |
| 283 | expr(aExpr), |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 284 | body(aBody), |
| 285 | unrollFlag(false) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 286 | |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 287 | virtual TIntermLoop* getAsLoopNode() { return this; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 288 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 289 | |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 290 | TLoopType getType() const { return type; } |
| 291 | TIntermNode* getInit() { return init; } |
| 292 | TIntermTyped* getCondition() { return cond; } |
| 293 | TIntermTyped* getExpression() { return expr; } |
| 294 | TIntermNode* getBody() { return body; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 295 | |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 296 | void setUnrollFlag(bool flag) { unrollFlag = flag; } |
| 297 | bool getUnrollFlag() { return unrollFlag; } |
| 298 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 299 | protected: |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 300 | TLoopType type; |
| 301 | TIntermNode* init; // for-loop initialization |
| 302 | TIntermTyped* cond; // loop exit condition |
| 303 | TIntermTyped* expr; // for-loop expression |
| 304 | TIntermNode* body; // loop body |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 305 | |
| 306 | bool unrollFlag; // Whether the loop should be unrolled or not. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 307 | }; |
| 308 | |
| 309 | // |
| 310 | // Handle break, continue, return, and kill. |
| 311 | // |
| 312 | class TIntermBranch : public TIntermNode { |
| 313 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 314 | TIntermBranch(TOperator op, TIntermTyped* e) : |
| 315 | flowOp(op), |
| 316 | expression(e) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 317 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 318 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 319 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 320 | TOperator getFlowOp() { return flowOp; } |
| 321 | TIntermTyped* getExpression() { return expression; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 322 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 323 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 324 | TOperator flowOp; |
| 325 | TIntermTyped* expression; // non-zero except for "return exp;" statements |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 326 | }; |
| 327 | |
| 328 | // |
| 329 | // Nodes that correspond to symbols or constants in the source code. |
| 330 | // |
| 331 | class TIntermSymbol : public TIntermTyped { |
| 332 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 333 | // if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from |
| 334 | // per process globalpoolallocator, then it causes increased memory usage per compile |
| 335 | // it is essential to use "symbol = sym" to assign to symbol |
| 336 | TIntermSymbol(int i, const TString& sym, const TType& t) : |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 337 | TIntermTyped(t), id(i) { symbol = sym; originalSymbol = sym; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 338 | |
| 339 | int getId() const { return id; } |
| 340 | const TString& getSymbol() const { return symbol; } |
| 341 | |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 342 | void setId(int newId) { id = newId; } |
| 343 | void setSymbol(const TString& sym) { symbol = sym; } |
| 344 | |
| 345 | const TString& getOriginalSymbol() const { return originalSymbol; } |
| 346 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 347 | virtual void traverse(TIntermTraverser*); |
| 348 | virtual TIntermSymbol* getAsSymbolNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 349 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 350 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 351 | int id; |
| 352 | TString symbol; |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 353 | TString originalSymbol; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | class TIntermConstantUnion : public TIntermTyped { |
| 357 | public: |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 358 | TIntermConstantUnion(ConstantUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 359 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 360 | ConstantUnion* getUnionArrayPointer() const { return unionArrayPointer; } |
| 361 | void setUnionArrayPointer(ConstantUnion *c) { unionArrayPointer = c; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 362 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 363 | virtual TIntermConstantUnion* getAsConstantUnion() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 364 | virtual void traverse(TIntermTraverser*); |
| 365 | |
| 366 | TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&); |
| 367 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 368 | protected: |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 369 | ConstantUnion *unionArrayPointer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | // |
| 373 | // Intermediate class for node types that hold operators. |
| 374 | // |
| 375 | class TIntermOperator : public TIntermTyped { |
| 376 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 377 | TOperator getOp() const { return op; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 378 | void setOp(TOperator o) { op = o; } |
| 379 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 380 | bool modifiesState() const; |
| 381 | bool isConstructor() const; |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 382 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 383 | protected: |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 384 | TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat, EbpUndefined)), op(o) {} |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 385 | TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o) {} |
| 386 | TOperator op; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | // |
| 390 | // Nodes for all the basic binary math operators. |
| 391 | // |
| 392 | class TIntermBinary : public TIntermOperator { |
| 393 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 394 | TIntermBinary(TOperator o) : TIntermOperator(o) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 395 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 396 | virtual TIntermBinary* getAsBinaryNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 397 | virtual void traverse(TIntermTraverser*); |
| 398 | |
| 399 | void setLeft(TIntermTyped* n) { left = n; } |
| 400 | void setRight(TIntermTyped* n) { right = n; } |
| 401 | TIntermTyped* getLeft() const { return left; } |
| 402 | TIntermTyped* getRight() const { return right; } |
| 403 | bool promote(TInfoSink&); |
| 404 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 405 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 406 | TIntermTyped* left; |
| 407 | TIntermTyped* right; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 408 | }; |
| 409 | |
| 410 | // |
| 411 | // Nodes for unary math operators. |
| 412 | // |
| 413 | class TIntermUnary : public TIntermOperator { |
| 414 | public: |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 415 | TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(0), useEmulatedFunction(false) {} |
zmo@google.com | e4eb991 | 2011-08-29 21:13:12 +0000 | [diff] [blame] | 416 | TIntermUnary(TOperator o) : TIntermOperator(o), operand(0), useEmulatedFunction(false) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 417 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 418 | virtual void traverse(TIntermTraverser*); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 419 | virtual TIntermUnary* getAsUnaryNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 420 | |
| 421 | void setOperand(TIntermTyped* o) { operand = o; } |
| 422 | TIntermTyped* getOperand() { return operand; } |
| 423 | bool promote(TInfoSink&); |
| 424 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 425 | void setUseEmulatedFunction() { useEmulatedFunction = true; } |
| 426 | bool getUseEmulatedFunction() { return useEmulatedFunction; } |
| 427 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 428 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 429 | TIntermTyped* operand; |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 430 | |
| 431 | // If set to true, replace the built-in function call with an emulated one |
| 432 | // to work around driver bugs. |
| 433 | bool useEmulatedFunction; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 434 | }; |
| 435 | |
| 436 | typedef TVector<TIntermNode*> TIntermSequence; |
| 437 | typedef TVector<int> TQualifierList; |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 438 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 439 | // |
| 440 | // Nodes that operate on an arbitrary sized set of children. |
| 441 | // |
| 442 | class TIntermAggregate : public TIntermOperator { |
| 443 | public: |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 444 | TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), endLine(0), useEmulatedFunction(false) { } |
| 445 | TIntermAggregate(TOperator o) : TIntermOperator(o), useEmulatedFunction(false) { } |
| 446 | ~TIntermAggregate() { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 447 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 448 | virtual TIntermAggregate* getAsAggregate() { return this; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 449 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 450 | |
| 451 | TIntermSequence& getSequence() { return sequence; } |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 452 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 453 | void setName(const TString& n) { name = n; } |
| 454 | const TString& getName() const { return name; } |
| 455 | |
| 456 | void setUserDefined() { userDefined = true; } |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 457 | bool isUserDefined() const { return userDefined; } |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 458 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 459 | void setOptimize(bool o) { optimize = o; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 460 | bool getOptimize() { return optimize; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 461 | void setDebug(bool d) { debug = d; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 462 | bool getDebug() { return debug; } |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 463 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 464 | void setEndLine(TSourceLoc line) { endLine = line; } |
| 465 | TSourceLoc getEndLine() const { return endLine; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 466 | |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 467 | void setUseEmulatedFunction() { useEmulatedFunction = true; } |
| 468 | bool getUseEmulatedFunction() { return useEmulatedFunction; } |
| 469 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 470 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 471 | TIntermAggregate(const TIntermAggregate&); // disallow copy constructor |
| 472 | TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator |
| 473 | TIntermSequence sequence; |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 474 | TString name; |
| 475 | bool userDefined; // used for user defined function names |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 476 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 477 | bool optimize; |
| 478 | bool debug; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 479 | TSourceLoc endLine; |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 480 | |
| 481 | // If set to true, replace the built-in function call with an emulated one |
| 482 | // to work around driver bugs. |
| 483 | bool useEmulatedFunction; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 484 | }; |
| 485 | |
| 486 | // |
| 487 | // For if tests. Simplified since there is no switch statement. |
| 488 | // |
| 489 | class TIntermSelection : public TIntermTyped { |
| 490 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 491 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) : |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 492 | TIntermTyped(TType(EbtVoid, EbpUndefined)), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 493 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) : |
| 494 | TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 495 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 496 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 497 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 498 | bool usesTernaryOperator() const { return getBasicType() != EbtVoid; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 499 | TIntermNode* getCondition() const { return condition; } |
| 500 | TIntermNode* getTrueBlock() const { return trueBlock; } |
| 501 | TIntermNode* getFalseBlock() const { return falseBlock; } |
| 502 | TIntermSelection* getAsSelectionNode() { return this; } |
| 503 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 504 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 505 | TIntermTyped* condition; |
| 506 | TIntermNode* trueBlock; |
| 507 | TIntermNode* falseBlock; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 508 | }; |
| 509 | |
| 510 | enum Visit |
| 511 | { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 512 | PreVisit, |
| 513 | InVisit, |
| 514 | PostVisit |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 515 | }; |
| 516 | |
| 517 | // |
| 518 | // For traversing the tree. User should derive from this, |
| 519 | // put their traversal specific data in it, and then pass |
| 520 | // it to a Traverse method. |
| 521 | // |
| 522 | // When using this, just fill in the methods for nodes you want visited. |
| 523 | // Return false from a pre-visit to skip visiting that node's subtree. |
| 524 | // |
| 525 | class TIntermTraverser |
| 526 | { |
| 527 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 528 | POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 529 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 530 | TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, bool rightToLeft = false) : |
| 531 | preVisit(preVisit), |
| 532 | inVisit(inVisit), |
| 533 | postVisit(postVisit), |
| 534 | rightToLeft(rightToLeft), |
| 535 | depth(0) {} |
maxvujovic@gmail.com | c6b3b3c | 2012-06-27 22:49:39 +0000 | [diff] [blame] | 536 | virtual ~TIntermTraverser() {}; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 537 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 538 | virtual void visitSymbol(TIntermSymbol*) {} |
| 539 | virtual void visitConstantUnion(TIntermConstantUnion*) {} |
| 540 | virtual bool visitBinary(Visit visit, TIntermBinary*) {return true;} |
| 541 | virtual bool visitUnary(Visit visit, TIntermUnary*) {return true;} |
| 542 | virtual bool visitSelection(Visit visit, TIntermSelection*) {return true;} |
| 543 | virtual bool visitAggregate(Visit visit, TIntermAggregate*) {return true;} |
| 544 | virtual bool visitLoop(Visit visit, TIntermLoop*) {return true;} |
| 545 | virtual bool visitBranch(Visit visit, TIntermBranch*) {return true;} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 546 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 547 | void incrementDepth() {depth++;} |
| 548 | void decrementDepth() {depth--;} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 549 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame^] | 550 | // Return the original name if hash function pointer is NULL; |
| 551 | // otherwise return the hashed name. |
| 552 | static TString hash(const TString& name, ShHashFunction64 hashFunction); |
| 553 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 554 | const bool preVisit; |
| 555 | const bool inVisit; |
| 556 | const bool postVisit; |
| 557 | const bool rightToLeft; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 558 | |
| 559 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 560 | int depth; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 561 | }; |
| 562 | |
| 563 | #endif // __INTERMEDIATE_H |