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 | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 19 | #include "compiler/Common.h" |
| 20 | #include "compiler/Types.h" |
| 21 | #include "compiler/ConstantUnion.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 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; |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 195 | class TIntermLoop; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 196 | class TInfoSink; |
| 197 | |
| 198 | // |
| 199 | // Base class for the tree nodes |
| 200 | // |
| 201 | class TIntermNode { |
| 202 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 203 | POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 204 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 205 | TIntermNode() : line(0) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 206 | |
| 207 | TSourceLoc getLine() const { return line; } |
| 208 | void setLine(TSourceLoc l) { line = l; } |
| 209 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 210 | virtual void traverse(TIntermTraverser*) = 0; |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 211 | virtual TIntermTyped* getAsTyped() { return 0; } |
| 212 | virtual TIntermConstantUnion* getAsConstantUnion() { return 0; } |
| 213 | virtual TIntermAggregate* getAsAggregate() { return 0; } |
| 214 | virtual TIntermBinary* getAsBinaryNode() { return 0; } |
| 215 | virtual TIntermUnary* getAsUnaryNode() { return 0; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 216 | virtual TIntermSelection* getAsSelectionNode() { return 0; } |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 217 | virtual TIntermSymbol* getAsSymbolNode() { return 0; } |
| 218 | virtual TIntermLoop* getAsLoopNode() { return 0; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 219 | virtual ~TIntermNode() { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 220 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 221 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 222 | TSourceLoc line; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 223 | }; |
| 224 | |
| 225 | // |
| 226 | // This is just to help yacc. |
| 227 | // |
| 228 | struct TIntermNodePair { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 229 | TIntermNode* node1; |
| 230 | TIntermNode* node2; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 231 | }; |
| 232 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 233 | // |
| 234 | // Intermediate class for nodes that have a type. |
| 235 | // |
| 236 | class TIntermTyped : public TIntermNode { |
| 237 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 238 | TIntermTyped(const TType& t) : type(t) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 239 | virtual TIntermTyped* getAsTyped() { return this; } |
alokp@chromium.org | dd037b2 | 2010-03-30 18:47:20 +0000 | [diff] [blame] | 240 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 241 | void setType(const TType& t) { type = t; } |
| 242 | const TType& getType() const { return type; } |
| 243 | TType* getTypePointer() { return &type; } |
| 244 | |
| 245 | TBasicType getBasicType() const { return type.getBasicType(); } |
| 246 | TQualifier getQualifier() const { return type.getQualifier(); } |
| 247 | TPrecision getPrecision() const { return type.getPrecision(); } |
| 248 | int getNominalSize() const { return type.getNominalSize(); } |
| 249 | |
| 250 | bool isMatrix() const { return type.isMatrix(); } |
| 251 | bool isArray() const { return type.isArray(); } |
| 252 | bool isVector() const { return type.isVector(); } |
| 253 | bool isScalar() const { return type.isScalar(); } |
| 254 | const char* getBasicString() const { return type.getBasicString(); } |
| 255 | const char* getQualifierString() const { return type.getQualifierString(); } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 256 | TString getCompleteString() const { return type.getCompleteString(); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 257 | |
| 258 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 259 | TType type; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | // |
| 263 | // Handle for, do-while, and while loops. |
| 264 | // |
| 265 | class TIntermLoop : public TIntermNode { |
| 266 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 267 | TIntermLoop(TIntermNode *init, TIntermNode* aBody, TIntermTyped* aTest, TIntermTyped* aTerminal, bool testFirst) : |
| 268 | init(init), |
| 269 | body(aBody), |
| 270 | test(aTest), |
| 271 | terminal(aTerminal), |
| 272 | first(testFirst) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 273 | |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 274 | virtual TIntermLoop* getAsLoopNode() { return this; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 275 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 276 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 277 | TIntermNode *getInit() { return init; } |
| 278 | TIntermNode *getBody() { return body; } |
| 279 | TIntermTyped *getTest() { return test; } |
| 280 | TIntermTyped *getTerminal() { return terminal; } |
| 281 | bool testFirst() { return first; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 282 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 283 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 284 | TIntermNode *init; |
| 285 | TIntermNode *body; // code to loop over |
| 286 | TIntermTyped *test; // exit condition associated with loop, could be 0 for 'for' loops |
| 287 | TIntermTyped *terminal; // exists for for-loops |
| 288 | bool first; // true for while and for, not for do-while |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | // |
| 292 | // Handle break, continue, return, and kill. |
| 293 | // |
| 294 | class TIntermBranch : public TIntermNode { |
| 295 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 296 | TIntermBranch(TOperator op, TIntermTyped* e) : |
| 297 | flowOp(op), |
| 298 | expression(e) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 299 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 300 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 301 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 302 | TOperator getFlowOp() { return flowOp; } |
| 303 | TIntermTyped* getExpression() { return expression; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 304 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 305 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 306 | TOperator flowOp; |
| 307 | TIntermTyped* expression; // non-zero except for "return exp;" statements |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | // |
| 311 | // Nodes that correspond to symbols or constants in the source code. |
| 312 | // |
| 313 | class TIntermSymbol : public TIntermTyped { |
| 314 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 315 | // if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from |
| 316 | // per process globalpoolallocator, then it causes increased memory usage per compile |
| 317 | // it is essential to use "symbol = sym" to assign to symbol |
| 318 | TIntermSymbol(int i, const TString& sym, const TType& t) : |
| 319 | TIntermTyped(t), id(i) { symbol = sym;} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 320 | |
| 321 | int getId() const { return id; } |
| 322 | const TString& getSymbol() const { return symbol; } |
| 323 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 324 | virtual void traverse(TIntermTraverser*); |
| 325 | virtual TIntermSymbol* getAsSymbolNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 326 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 327 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 328 | int id; |
| 329 | TString symbol; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
| 332 | class TIntermConstantUnion : public TIntermTyped { |
| 333 | public: |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 334 | TIntermConstantUnion(ConstantUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 335 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 336 | ConstantUnion* getUnionArrayPointer() const { return unionArrayPointer; } |
| 337 | void setUnionArrayPointer(ConstantUnion *c) { unionArrayPointer = c; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 338 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 339 | virtual TIntermConstantUnion* getAsConstantUnion() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 340 | virtual void traverse(TIntermTraverser*); |
| 341 | |
| 342 | TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&); |
| 343 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 344 | protected: |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 345 | ConstantUnion *unionArrayPointer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 346 | }; |
| 347 | |
| 348 | // |
| 349 | // Intermediate class for node types that hold operators. |
| 350 | // |
| 351 | class TIntermOperator : public TIntermTyped { |
| 352 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 353 | TOperator getOp() const { return op; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 354 | void setOp(TOperator o) { op = o; } |
| 355 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 356 | bool modifiesState() const; |
| 357 | bool isConstructor() const; |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 358 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 359 | protected: |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 360 | TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat, EbpUndefined)), op(o) {} |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 361 | TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o) {} |
| 362 | TOperator op; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | // |
| 366 | // Nodes for all the basic binary math operators. |
| 367 | // |
| 368 | class TIntermBinary : public TIntermOperator { |
| 369 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 370 | TIntermBinary(TOperator o) : TIntermOperator(o) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 371 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 372 | virtual TIntermBinary* getAsBinaryNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 373 | virtual void traverse(TIntermTraverser*); |
| 374 | |
| 375 | void setLeft(TIntermTyped* n) { left = n; } |
| 376 | void setRight(TIntermTyped* n) { right = n; } |
| 377 | TIntermTyped* getLeft() const { return left; } |
| 378 | TIntermTyped* getRight() const { return right; } |
| 379 | bool promote(TInfoSink&); |
| 380 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 381 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 382 | TIntermTyped* left; |
| 383 | TIntermTyped* right; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 384 | }; |
| 385 | |
| 386 | // |
| 387 | // Nodes for unary math operators. |
| 388 | // |
| 389 | class TIntermUnary : public TIntermOperator { |
| 390 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 391 | TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(0) {} |
| 392 | TIntermUnary(TOperator o) : TIntermOperator(o), operand(0) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 393 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 394 | virtual void traverse(TIntermTraverser*); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 395 | virtual TIntermUnary* getAsUnaryNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 396 | |
| 397 | void setOperand(TIntermTyped* o) { operand = o; } |
| 398 | TIntermTyped* getOperand() { return operand; } |
| 399 | bool promote(TInfoSink&); |
| 400 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 401 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 402 | TIntermTyped* operand; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 403 | }; |
| 404 | |
| 405 | typedef TVector<TIntermNode*> TIntermSequence; |
| 406 | typedef TVector<int> TQualifierList; |
| 407 | // |
| 408 | // Nodes that operate on an arbitrary sized set of children. |
| 409 | // |
| 410 | class TIntermAggregate : public TIntermOperator { |
| 411 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 412 | TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(0) { } |
| 413 | TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(0) { } |
| 414 | ~TIntermAggregate() { delete pragmaTable; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 415 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 416 | virtual TIntermAggregate* getAsAggregate() { return this; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 417 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 418 | |
| 419 | TIntermSequence& getSequence() { return sequence; } |
| 420 | void setName(const TString& n) { name = n; } |
| 421 | const TString& getName() const { return name; } |
| 422 | |
| 423 | void setUserDefined() { userDefined = true; } |
| 424 | bool isUserDefined() { return userDefined; } |
| 425 | TQualifierList& getQualifier() { return qualifier; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 426 | void setOptimize(bool o) { optimize = o; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 427 | bool getOptimize() { return optimize; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 428 | void setDebug(bool d) { debug = d; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 429 | bool getDebug() { return debug; } |
| 430 | void addToPragmaTable(const TPragmaTable& pTable); |
| 431 | const TPragmaTable& getPragmaTable() const { return *pragmaTable; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 432 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 433 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 434 | TIntermAggregate(const TIntermAggregate&); // disallow copy constructor |
| 435 | TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator |
| 436 | TIntermSequence sequence; |
| 437 | TQualifierList qualifier; |
| 438 | TString name; |
| 439 | bool userDefined; // used for user defined function names |
| 440 | bool optimize; |
| 441 | bool debug; |
| 442 | TPragmaTable *pragmaTable; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 443 | }; |
| 444 | |
| 445 | // |
| 446 | // For if tests. Simplified since there is no switch statement. |
| 447 | // |
| 448 | class TIntermSelection : public TIntermTyped { |
| 449 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 450 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) : |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 451 | TIntermTyped(TType(EbtVoid, EbpUndefined)), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 452 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) : |
| 453 | TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 454 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 455 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 456 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 457 | bool usesTernaryOperator() const { return getBasicType() != EbtVoid; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame^] | 458 | TIntermNode* getCondition() const { return condition; } |
| 459 | TIntermNode* getTrueBlock() const { return trueBlock; } |
| 460 | TIntermNode* getFalseBlock() const { return falseBlock; } |
| 461 | TIntermSelection* getAsSelectionNode() { return this; } |
| 462 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 463 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 464 | TIntermTyped* condition; |
| 465 | TIntermNode* trueBlock; |
| 466 | TIntermNode* falseBlock; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 467 | }; |
| 468 | |
| 469 | enum Visit |
| 470 | { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 471 | PreVisit, |
| 472 | InVisit, |
| 473 | PostVisit |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 474 | }; |
| 475 | |
| 476 | // |
| 477 | // For traversing the tree. User should derive from this, |
| 478 | // put their traversal specific data in it, and then pass |
| 479 | // it to a Traverse method. |
| 480 | // |
| 481 | // When using this, just fill in the methods for nodes you want visited. |
| 482 | // Return false from a pre-visit to skip visiting that node's subtree. |
| 483 | // |
| 484 | class TIntermTraverser |
| 485 | { |
| 486 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 487 | POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 488 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 489 | TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, bool rightToLeft = false) : |
| 490 | preVisit(preVisit), |
| 491 | inVisit(inVisit), |
| 492 | postVisit(postVisit), |
| 493 | rightToLeft(rightToLeft), |
| 494 | depth(0) {} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 495 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 496 | virtual void visitSymbol(TIntermSymbol*) {} |
| 497 | virtual void visitConstantUnion(TIntermConstantUnion*) {} |
| 498 | virtual bool visitBinary(Visit visit, TIntermBinary*) {return true;} |
| 499 | virtual bool visitUnary(Visit visit, TIntermUnary*) {return true;} |
| 500 | virtual bool visitSelection(Visit visit, TIntermSelection*) {return true;} |
| 501 | virtual bool visitAggregate(Visit visit, TIntermAggregate*) {return true;} |
| 502 | virtual bool visitLoop(Visit visit, TIntermLoop*) {return true;} |
| 503 | virtual bool visitBranch(Visit visit, TIntermBranch*) {return true;} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 504 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 505 | void incrementDepth() {depth++;} |
| 506 | void decrementDepth() {depth--;} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 507 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 508 | const bool preVisit; |
| 509 | const bool inVisit; |
| 510 | const bool postVisit; |
| 511 | const bool rightToLeft; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 512 | |
| 513 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 514 | int depth; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 515 | }; |
| 516 | |
| 517 | #endif // __INTERMEDIATE_H |