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 | |
| 19 | #include "Common.h" |
| 20 | #include "Types.h" |
| 21 | #include "ConstantUnion.h" |
| 22 | |
| 23 | // |
| 24 | // Operators used by the high-level (parse tree) representation. |
| 25 | // |
| 26 | enum TOperator { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 27 | EOpNull, // if in a node, should only mean a node is still being built |
| 28 | EOpSequence, // denotes a list of statements, or parameters, etc. |
| 29 | EOpFunctionCall, |
| 30 | EOpFunction, // For function definition |
| 31 | EOpParameters, // an aggregate listing the parameters to a function |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 32 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 33 | EOpDeclaration, |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 34 | EOpPrototype, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 35 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 36 | // |
| 37 | // Unary operators |
| 38 | // |
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 | EOpNegative, |
| 41 | EOpLogicalNot, |
| 42 | EOpVectorLogicalNot, |
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 | EOpPostIncrement, |
| 45 | EOpPostDecrement, |
| 46 | EOpPreIncrement, |
| 47 | EOpPreDecrement, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 48 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 49 | EOpConvIntToBool, |
| 50 | EOpConvFloatToBool, |
| 51 | EOpConvBoolToFloat, |
| 52 | EOpConvIntToFloat, |
| 53 | EOpConvFloatToInt, |
| 54 | EOpConvBoolToInt, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 55 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 56 | // |
| 57 | // binary operations |
| 58 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 59 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 60 | EOpAdd, |
| 61 | EOpSub, |
| 62 | EOpMul, |
| 63 | EOpDiv, |
| 64 | EOpEqual, |
| 65 | EOpNotEqual, |
| 66 | EOpVectorEqual, |
| 67 | EOpVectorNotEqual, |
| 68 | EOpLessThan, |
| 69 | EOpGreaterThan, |
| 70 | EOpLessThanEqual, |
| 71 | EOpGreaterThanEqual, |
| 72 | EOpComma, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 73 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 74 | EOpVectorTimesScalar, |
| 75 | EOpVectorTimesMatrix, |
| 76 | EOpMatrixTimesVector, |
| 77 | EOpMatrixTimesScalar, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 78 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 79 | EOpLogicalOr, |
| 80 | EOpLogicalXor, |
| 81 | EOpLogicalAnd, |
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 | EOpIndexDirect, |
| 84 | EOpIndexIndirect, |
| 85 | EOpIndexDirectStruct, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 86 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 87 | EOpVectorSwizzle, |
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 | // |
| 90 | // Built-in functions potentially mapped to operators |
| 91 | // |
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 | EOpRadians, |
| 94 | EOpDegrees, |
| 95 | EOpSin, |
| 96 | EOpCos, |
| 97 | EOpTan, |
| 98 | EOpAsin, |
| 99 | EOpAcos, |
| 100 | EOpAtan, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 101 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 102 | EOpPow, |
| 103 | EOpExp, |
| 104 | EOpLog, |
| 105 | EOpExp2, |
| 106 | EOpLog2, |
| 107 | EOpSqrt, |
| 108 | EOpInverseSqrt, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 109 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 110 | EOpAbs, |
| 111 | EOpSign, |
| 112 | EOpFloor, |
| 113 | EOpCeil, |
| 114 | EOpFract, |
| 115 | EOpMod, |
| 116 | EOpMin, |
| 117 | EOpMax, |
| 118 | EOpClamp, |
| 119 | EOpMix, |
| 120 | EOpStep, |
| 121 | EOpSmoothStep, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 122 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 123 | EOpLength, |
| 124 | EOpDistance, |
| 125 | EOpDot, |
| 126 | EOpCross, |
| 127 | EOpNormalize, |
| 128 | EOpFaceForward, |
| 129 | EOpReflect, |
| 130 | EOpRefract, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 131 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 132 | //EOpDPdx, // Fragment only, OES_standard_derivatives extension |
| 133 | //EOpDPdy, // Fragment only, OES_standard_derivatives extension |
| 134 | //EOpFwidth, // Fragment only, OES_standard_derivatives extension |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 135 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 136 | EOpMatrixTimesMatrix, |
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 | EOpAny, |
| 139 | EOpAll, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 140 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 141 | // |
| 142 | // Branch |
| 143 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 144 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 145 | EOpKill, // Fragment only |
| 146 | EOpReturn, |
| 147 | EOpBreak, |
| 148 | EOpContinue, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 149 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 150 | // |
| 151 | // Constructors |
| 152 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 153 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 154 | EOpConstructInt, |
| 155 | EOpConstructBool, |
| 156 | EOpConstructFloat, |
| 157 | EOpConstructVec2, |
| 158 | EOpConstructVec3, |
| 159 | EOpConstructVec4, |
| 160 | EOpConstructBVec2, |
| 161 | EOpConstructBVec3, |
| 162 | EOpConstructBVec4, |
| 163 | EOpConstructIVec2, |
| 164 | EOpConstructIVec3, |
| 165 | EOpConstructIVec4, |
| 166 | EOpConstructMat2, |
| 167 | EOpConstructMat3, |
| 168 | EOpConstructMat4, |
| 169 | EOpConstructStruct, |
| 170 | |
| 171 | // |
| 172 | // moves |
| 173 | // |
| 174 | |
| 175 | EOpAssign, |
| 176 | EOpInitialize, |
| 177 | EOpAddAssign, |
| 178 | EOpSubAssign, |
| 179 | EOpMulAssign, |
| 180 | EOpVectorTimesMatrixAssign, |
| 181 | EOpVectorTimesScalarAssign, |
| 182 | EOpMatrixTimesScalarAssign, |
| 183 | EOpMatrixTimesMatrixAssign, |
| 184 | EOpDivAssign, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | class TIntermTraverser; |
| 188 | class TIntermAggregate; |
| 189 | class TIntermBinary; |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 190 | class TIntermUnary; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 191 | class TIntermConstantUnion; |
| 192 | class TIntermSelection; |
| 193 | class TIntermTyped; |
| 194 | class TIntermSymbol; |
| 195 | class TInfoSink; |
| 196 | |
| 197 | // |
| 198 | // Base class for the tree nodes |
| 199 | // |
| 200 | class TIntermNode { |
| 201 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 202 | POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 203 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 204 | TIntermNode() : line(0) {} |
| 205 | virtual TSourceLoc getLine() const { return line; } |
| 206 | virtual void setLine(TSourceLoc l) { line = l; } |
| 207 | virtual void traverse(TIntermTraverser*) = 0; |
| 208 | virtual TIntermTyped* getAsTyped() { return 0; } |
| 209 | virtual TIntermConstantUnion* getAsConstantUnion() { return 0; } |
| 210 | virtual TIntermAggregate* getAsAggregate() { return 0; } |
| 211 | virtual TIntermBinary* getAsBinaryNode() { return 0; } |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 212 | virtual TIntermUnary* getAsUnaryNode() { return 0; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 213 | virtual TIntermSelection* getAsSelectionNode() { return 0; } |
| 214 | virtual TIntermSymbol* getAsSymbolNode() { return 0; } |
| 215 | virtual ~TIntermNode() { } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 216 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 217 | TSourceLoc line; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | // |
| 221 | // This is just to help yacc. |
| 222 | // |
| 223 | struct TIntermNodePair { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 224 | TIntermNode* node1; |
| 225 | TIntermNode* node2; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 226 | }; |
| 227 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 228 | // |
| 229 | // Intermediate class for nodes that have a type. |
| 230 | // |
| 231 | class TIntermTyped : public TIntermNode { |
| 232 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 233 | TIntermTyped(const TType& t) : type(t) { } |
| 234 | virtual TIntermTyped* getAsTyped() { return this; } |
| 235 | virtual void setType(const TType& t) { type = t; } |
| 236 | virtual const TType& getType() const { return type; } |
| 237 | virtual TType* getTypePointer() { return &type; } |
alokp@chromium.org | dd037b2 | 2010-03-30 18:47:20 +0000 | [diff] [blame] | 238 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 239 | virtual TBasicType getBasicType() const { return type.getBasicType(); } |
| 240 | virtual TQualifier getQualifier() const { return type.getQualifier(); } |
| 241 | virtual int getNominalSize() const { return type.getNominalSize(); } |
| 242 | virtual int getSize() const { return type.getInstanceSize(); } |
| 243 | virtual bool isMatrix() const { return type.isMatrix(); } |
| 244 | virtual bool isArray() const { return type.isArray(); } |
| 245 | virtual bool isVector() const { return type.isVector(); } |
| 246 | const char* getBasicString() const { return type.getBasicString(); } |
| 247 | const char* getQualifierString() const { return type.getQualifierString(); } |
| 248 | TString getCompleteString() const { return type.getCompleteString(); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 249 | |
| 250 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 251 | TType type; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 252 | }; |
| 253 | |
| 254 | // |
| 255 | // Handle for, do-while, and while loops. |
| 256 | // |
| 257 | class TIntermLoop : public TIntermNode { |
| 258 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 259 | TIntermLoop(TIntermNode *init, TIntermNode* aBody, TIntermTyped* aTest, TIntermTyped* aTerminal, bool testFirst) : |
| 260 | init(init), |
| 261 | body(aBody), |
| 262 | test(aTest), |
| 263 | terminal(aTerminal), |
| 264 | first(testFirst) { } |
| 265 | virtual void traverse(TIntermTraverser*); |
| 266 | TIntermNode *getInit() { return init; } |
| 267 | TIntermNode *getBody() { return body; } |
| 268 | TIntermTyped *getTest() { return test; } |
| 269 | TIntermTyped *getTerminal() { return terminal; } |
| 270 | bool testFirst() { return first; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 271 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 272 | TIntermNode *init; |
| 273 | TIntermNode *body; // code to loop over |
| 274 | TIntermTyped *test; // exit condition associated with loop, could be 0 for 'for' loops |
| 275 | TIntermTyped *terminal; // exists for for-loops |
| 276 | bool first; // true for while and for, not for do-while |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | // |
| 280 | // Handle break, continue, return, and kill. |
| 281 | // |
| 282 | class TIntermBranch : public TIntermNode { |
| 283 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 284 | TIntermBranch(TOperator op, TIntermTyped* e) : |
| 285 | flowOp(op), |
| 286 | expression(e) { } |
| 287 | virtual void traverse(TIntermTraverser*); |
| 288 | TOperator getFlowOp() { return flowOp; } |
| 289 | TIntermTyped* getExpression() { return expression; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 290 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 291 | TOperator flowOp; |
| 292 | TIntermTyped* expression; // non-zero except for "return exp;" statements |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | // |
| 296 | // Nodes that correspond to symbols or constants in the source code. |
| 297 | // |
| 298 | class TIntermSymbol : public TIntermTyped { |
| 299 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 300 | // if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from |
| 301 | // per process globalpoolallocator, then it causes increased memory usage per compile |
| 302 | // it is essential to use "symbol = sym" to assign to symbol |
| 303 | TIntermSymbol(int i, const TString& sym, const TType& t) : |
| 304 | TIntermTyped(t), id(i) { symbol = sym;} |
| 305 | virtual int getId() const { return id; } |
| 306 | virtual const TString& getSymbol() const { return symbol; } |
| 307 | virtual void traverse(TIntermTraverser*); |
| 308 | virtual TIntermSymbol* getAsSymbolNode() { return this; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 309 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 310 | int id; |
| 311 | TString symbol; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | class TIntermConstantUnion : public TIntermTyped { |
| 315 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 316 | TIntermConstantUnion(constUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { } |
| 317 | constUnion* getUnionArrayPointer() const { return unionArrayPointer; } |
| 318 | void setUnionArrayPointer(constUnion *c) { unionArrayPointer = c; } |
| 319 | virtual TIntermConstantUnion* getAsConstantUnion() { return this; } |
| 320 | virtual void traverse(TIntermTraverser* ); |
| 321 | virtual TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 322 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 323 | constUnion *unionArrayPointer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | // |
| 327 | // Intermediate class for node types that hold operators. |
| 328 | // |
| 329 | class TIntermOperator : public TIntermTyped { |
| 330 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 331 | TOperator getOp() const { return op; } |
| 332 | bool modifiesState() const; |
| 333 | bool isConstructor() const; |
| 334 | virtual bool promote(TInfoSink&) { return true; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 335 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 336 | TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat)), op(o) {} |
| 337 | TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o) {} |
| 338 | TOperator op; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | // |
| 342 | // Nodes for all the basic binary math operators. |
| 343 | // |
| 344 | class TIntermBinary : public TIntermOperator { |
| 345 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 346 | TIntermBinary(TOperator o) : TIntermOperator(o) {} |
| 347 | virtual void traverse(TIntermTraverser*); |
| 348 | virtual void setLeft(TIntermTyped* n) { left = n; } |
| 349 | virtual void setRight(TIntermTyped* n) { right = n; } |
| 350 | virtual TIntermTyped* getLeft() const { return left; } |
| 351 | virtual TIntermTyped* getRight() const { return right; } |
| 352 | virtual TIntermBinary* getAsBinaryNode() { return this; } |
| 353 | virtual bool promote(TInfoSink&); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 354 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 355 | TIntermTyped* left; |
| 356 | TIntermTyped* right; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | // |
| 360 | // Nodes for unary math operators. |
| 361 | // |
| 362 | class TIntermUnary : public TIntermOperator { |
| 363 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 364 | TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(0) {} |
| 365 | TIntermUnary(TOperator o) : TIntermOperator(o), operand(0) {} |
| 366 | virtual void traverse(TIntermTraverser*); |
| 367 | virtual void setOperand(TIntermTyped* o) { operand = o; } |
| 368 | virtual TIntermTyped* getOperand() { return operand; } |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 369 | virtual TIntermUnary* getAsUnaryNode() { return this; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 370 | virtual bool promote(TInfoSink&); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 371 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 372 | TIntermTyped* operand; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | typedef TVector<TIntermNode*> TIntermSequence; |
| 376 | typedef TVector<int> TQualifierList; |
| 377 | // |
| 378 | // Nodes that operate on an arbitrary sized set of children. |
| 379 | // |
| 380 | class TIntermAggregate : public TIntermOperator { |
| 381 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 382 | TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(0) { } |
| 383 | TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(0) { } |
| 384 | ~TIntermAggregate() { delete pragmaTable; } |
| 385 | virtual TIntermAggregate* getAsAggregate() { return this; } |
| 386 | virtual void setOperator(TOperator o) { op = o; } |
| 387 | virtual TIntermSequence& getSequence() { return sequence; } |
| 388 | virtual void setName(const TString& n) { name = n; } |
| 389 | virtual const TString& getName() const { return name; } |
| 390 | virtual void traverse(TIntermTraverser*); |
| 391 | virtual void setUserDefined() { userDefined = true; } |
| 392 | virtual bool isUserDefined() { return userDefined; } |
| 393 | virtual TQualifierList& getQualifier() { return qualifier; } |
| 394 | void setOptimize(bool o) { optimize = o; } |
| 395 | void setDebug(bool d) { debug = d; } |
| 396 | bool getOptimize() { return optimize; } |
| 397 | bool getDebug() { return debug; } |
| 398 | void addToPragmaTable(const TPragmaTable& pTable); |
| 399 | const TPragmaTable& getPragmaTable() const { return *pragmaTable; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 400 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 401 | TIntermAggregate(const TIntermAggregate&); // disallow copy constructor |
| 402 | TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator |
| 403 | TIntermSequence sequence; |
| 404 | TQualifierList qualifier; |
| 405 | TString name; |
| 406 | bool userDefined; // used for user defined function names |
| 407 | bool optimize; |
| 408 | bool debug; |
| 409 | TPragmaTable *pragmaTable; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 410 | }; |
| 411 | |
| 412 | // |
| 413 | // For if tests. Simplified since there is no switch statement. |
| 414 | // |
| 415 | class TIntermSelection : public TIntermTyped { |
| 416 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 417 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) : |
| 418 | TIntermTyped(TType(EbtVoid)), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
| 419 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) : |
| 420 | TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
| 421 | virtual void traverse(TIntermTraverser*); |
| 422 | bool usesTernaryOperator() const { return getBasicType() != EbtVoid; } |
| 423 | virtual TIntermNode* getCondition() const { return condition; } |
| 424 | virtual TIntermNode* getTrueBlock() const { return trueBlock; } |
| 425 | virtual TIntermNode* getFalseBlock() const { return falseBlock; } |
| 426 | virtual TIntermSelection* getAsSelectionNode() { return this; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 427 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 428 | TIntermTyped* condition; |
| 429 | TIntermNode* trueBlock; |
| 430 | TIntermNode* falseBlock; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | enum Visit |
| 434 | { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 435 | PreVisit, |
| 436 | InVisit, |
| 437 | PostVisit |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 438 | }; |
| 439 | |
| 440 | // |
| 441 | // For traversing the tree. User should derive from this, |
| 442 | // put their traversal specific data in it, and then pass |
| 443 | // it to a Traverse method. |
| 444 | // |
| 445 | // When using this, just fill in the methods for nodes you want visited. |
| 446 | // Return false from a pre-visit to skip visiting that node's subtree. |
| 447 | // |
| 448 | class TIntermTraverser |
| 449 | { |
| 450 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 451 | POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 452 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 453 | TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, bool rightToLeft = false) : |
| 454 | preVisit(preVisit), |
| 455 | inVisit(inVisit), |
| 456 | postVisit(postVisit), |
| 457 | rightToLeft(rightToLeft), |
| 458 | depth(0) {} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 459 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 460 | virtual void visitSymbol(TIntermSymbol*) {} |
| 461 | virtual void visitConstantUnion(TIntermConstantUnion*) {} |
| 462 | virtual bool visitBinary(Visit visit, TIntermBinary*) {return true;} |
| 463 | virtual bool visitUnary(Visit visit, TIntermUnary*) {return true;} |
| 464 | virtual bool visitSelection(Visit visit, TIntermSelection*) {return true;} |
| 465 | virtual bool visitAggregate(Visit visit, TIntermAggregate*) {return true;} |
| 466 | virtual bool visitLoop(Visit visit, TIntermLoop*) {return true;} |
| 467 | virtual bool visitBranch(Visit visit, TIntermBranch*) {return true;} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 468 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 469 | void incrementDepth() {depth++;} |
| 470 | void decrementDepth() {depth--;} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 471 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 472 | const bool preVisit; |
| 473 | const bool inVisit; |
| 474 | const bool postVisit; |
| 475 | const bool rightToLeft; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 476 | |
| 477 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 478 | int depth; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 479 | }; |
| 480 | |
| 481 | #endif // __INTERMEDIATE_H |