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 | 0609889 | 2010-08-26 19:36:42 +0000 | [diff] [blame] | 132 | EOpDFdx, // Fragment only, OES_standard_derivatives extension |
| 133 | EOpDFdy, // 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 | // |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame^] | 265 | enum TLoopType { |
| 266 | ELoopFor, |
| 267 | ELoopWhile, |
| 268 | ELoopDoWhile, |
| 269 | }; |
| 270 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 271 | class TIntermLoop : public TIntermNode { |
| 272 | public: |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame^] | 273 | TIntermLoop(TLoopType aType, |
| 274 | TIntermNode *aInit, TIntermTyped* aCond, TIntermTyped* aExpr, |
| 275 | TIntermNode* aBody) : |
| 276 | type(aType), |
| 277 | init(aInit), |
| 278 | cond(aCond), |
| 279 | expr(aExpr), |
| 280 | body(aBody) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 281 | |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 282 | virtual TIntermLoop* getAsLoopNode() { return this; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 283 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 284 | |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame^] | 285 | TLoopType getType() const { return type; } |
| 286 | TIntermNode* getInit() { return init; } |
| 287 | TIntermTyped* getCondition() { return cond; } |
| 288 | TIntermTyped* getExpression() { return expr; } |
| 289 | TIntermNode* getBody() { return body; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 290 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 291 | protected: |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame^] | 292 | TLoopType type; |
| 293 | TIntermNode* init; // for-loop initialization |
| 294 | TIntermTyped* cond; // loop exit condition |
| 295 | TIntermTyped* expr; // for-loop expression |
| 296 | TIntermNode* body; // loop body |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | // |
| 300 | // Handle break, continue, return, and kill. |
| 301 | // |
| 302 | class TIntermBranch : public TIntermNode { |
| 303 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 304 | TIntermBranch(TOperator op, TIntermTyped* e) : |
| 305 | flowOp(op), |
| 306 | expression(e) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 307 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 308 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 309 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 310 | TOperator getFlowOp() { return flowOp; } |
| 311 | TIntermTyped* getExpression() { return expression; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 312 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 313 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 314 | TOperator flowOp; |
| 315 | TIntermTyped* expression; // non-zero except for "return exp;" statements |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | // |
| 319 | // Nodes that correspond to symbols or constants in the source code. |
| 320 | // |
| 321 | class TIntermSymbol : public TIntermTyped { |
| 322 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 323 | // if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from |
| 324 | // per process globalpoolallocator, then it causes increased memory usage per compile |
| 325 | // it is essential to use "symbol = sym" to assign to symbol |
| 326 | TIntermSymbol(int i, const TString& sym, const TType& t) : |
| 327 | TIntermTyped(t), id(i) { symbol = sym;} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 328 | |
| 329 | int getId() const { return id; } |
| 330 | const TString& getSymbol() const { return symbol; } |
| 331 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 332 | virtual void traverse(TIntermTraverser*); |
| 333 | virtual TIntermSymbol* getAsSymbolNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 334 | |
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 | int id; |
| 337 | TString symbol; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | class TIntermConstantUnion : public TIntermTyped { |
| 341 | public: |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 342 | TIntermConstantUnion(ConstantUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 343 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 344 | ConstantUnion* getUnionArrayPointer() const { return unionArrayPointer; } |
| 345 | void setUnionArrayPointer(ConstantUnion *c) { unionArrayPointer = c; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 346 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 347 | virtual TIntermConstantUnion* getAsConstantUnion() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 348 | virtual void traverse(TIntermTraverser*); |
| 349 | |
| 350 | TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&); |
| 351 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 352 | protected: |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 353 | ConstantUnion *unionArrayPointer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | // |
| 357 | // Intermediate class for node types that hold operators. |
| 358 | // |
| 359 | class TIntermOperator : public TIntermTyped { |
| 360 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 361 | TOperator getOp() const { return op; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 362 | void setOp(TOperator o) { op = o; } |
| 363 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 364 | bool modifiesState() const; |
| 365 | bool isConstructor() const; |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 366 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 367 | protected: |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 368 | TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat, EbpUndefined)), op(o) {} |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 369 | TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o) {} |
| 370 | TOperator op; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 371 | }; |
| 372 | |
| 373 | // |
| 374 | // Nodes for all the basic binary math operators. |
| 375 | // |
| 376 | class TIntermBinary : public TIntermOperator { |
| 377 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 378 | TIntermBinary(TOperator o) : TIntermOperator(o) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 379 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 380 | virtual TIntermBinary* getAsBinaryNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 381 | virtual void traverse(TIntermTraverser*); |
| 382 | |
| 383 | void setLeft(TIntermTyped* n) { left = n; } |
| 384 | void setRight(TIntermTyped* n) { right = n; } |
| 385 | TIntermTyped* getLeft() const { return left; } |
| 386 | TIntermTyped* getRight() const { return right; } |
| 387 | bool promote(TInfoSink&); |
| 388 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 389 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 390 | TIntermTyped* left; |
| 391 | TIntermTyped* right; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 392 | }; |
| 393 | |
| 394 | // |
| 395 | // Nodes for unary math operators. |
| 396 | // |
| 397 | class TIntermUnary : public TIntermOperator { |
| 398 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 399 | TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(0) {} |
| 400 | TIntermUnary(TOperator o) : TIntermOperator(o), operand(0) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 401 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 402 | virtual void traverse(TIntermTraverser*); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 403 | virtual TIntermUnary* getAsUnaryNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 404 | |
| 405 | void setOperand(TIntermTyped* o) { operand = o; } |
| 406 | TIntermTyped* getOperand() { return operand; } |
| 407 | bool promote(TInfoSink&); |
| 408 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 409 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 410 | TIntermTyped* operand; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 411 | }; |
| 412 | |
| 413 | typedef TVector<TIntermNode*> TIntermSequence; |
| 414 | typedef TVector<int> TQualifierList; |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 415 | typedef TMap<TString, TString> TPragmaTable; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 416 | // |
| 417 | // Nodes that operate on an arbitrary sized set of children. |
| 418 | // |
| 419 | class TIntermAggregate : public TIntermOperator { |
| 420 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 421 | TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(0) { } |
| 422 | TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(0) { } |
| 423 | ~TIntermAggregate() { delete pragmaTable; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 424 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 425 | virtual TIntermAggregate* getAsAggregate() { return this; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 426 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 427 | |
| 428 | TIntermSequence& getSequence() { return sequence; } |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 429 | |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 430 | void setName(const TString& n) { name = n; } |
| 431 | const TString& getName() const { return name; } |
| 432 | |
| 433 | void setUserDefined() { userDefined = true; } |
| 434 | bool isUserDefined() { return userDefined; } |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 435 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 436 | void setOptimize(bool o) { optimize = o; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 437 | bool getOptimize() { return optimize; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 438 | void setDebug(bool d) { debug = d; } |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 439 | bool getDebug() { return debug; } |
| 440 | void addToPragmaTable(const TPragmaTable& pTable); |
| 441 | const TPragmaTable& getPragmaTable() const { return *pragmaTable; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 442 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 443 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 444 | TIntermAggregate(const TIntermAggregate&); // disallow copy constructor |
| 445 | TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator |
| 446 | TIntermSequence sequence; |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 447 | TString name; |
| 448 | bool userDefined; // used for user defined function names |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 449 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 450 | bool optimize; |
| 451 | bool debug; |
| 452 | TPragmaTable *pragmaTable; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 453 | }; |
| 454 | |
| 455 | // |
| 456 | // For if tests. Simplified since there is no switch statement. |
| 457 | // |
| 458 | class TIntermSelection : public TIntermTyped { |
| 459 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 460 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) : |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 461 | TIntermTyped(TType(EbtVoid, EbpUndefined)), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 462 | TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) : |
| 463 | TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 464 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 465 | virtual void traverse(TIntermTraverser*); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 466 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 467 | bool usesTernaryOperator() const { return getBasicType() != EbtVoid; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 468 | TIntermNode* getCondition() const { return condition; } |
| 469 | TIntermNode* getTrueBlock() const { return trueBlock; } |
| 470 | TIntermNode* getFalseBlock() const { return falseBlock; } |
| 471 | TIntermSelection* getAsSelectionNode() { return this; } |
| 472 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 473 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 474 | TIntermTyped* condition; |
| 475 | TIntermNode* trueBlock; |
| 476 | TIntermNode* falseBlock; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 477 | }; |
| 478 | |
| 479 | enum Visit |
| 480 | { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 481 | PreVisit, |
| 482 | InVisit, |
| 483 | PostVisit |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 484 | }; |
| 485 | |
| 486 | // |
| 487 | // For traversing the tree. User should derive from this, |
| 488 | // put their traversal specific data in it, and then pass |
| 489 | // it to a Traverse method. |
| 490 | // |
| 491 | // When using this, just fill in the methods for nodes you want visited. |
| 492 | // Return false from a pre-visit to skip visiting that node's subtree. |
| 493 | // |
| 494 | class TIntermTraverser |
| 495 | { |
| 496 | public: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 497 | POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 498 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 499 | TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, bool rightToLeft = false) : |
| 500 | preVisit(preVisit), |
| 501 | inVisit(inVisit), |
| 502 | postVisit(postVisit), |
| 503 | rightToLeft(rightToLeft), |
| 504 | depth(0) {} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 505 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 506 | virtual void visitSymbol(TIntermSymbol*) {} |
| 507 | virtual void visitConstantUnion(TIntermConstantUnion*) {} |
| 508 | virtual bool visitBinary(Visit visit, TIntermBinary*) {return true;} |
| 509 | virtual bool visitUnary(Visit visit, TIntermUnary*) {return true;} |
| 510 | virtual bool visitSelection(Visit visit, TIntermSelection*) {return true;} |
| 511 | virtual bool visitAggregate(Visit visit, TIntermAggregate*) {return true;} |
| 512 | virtual bool visitLoop(Visit visit, TIntermLoop*) {return true;} |
| 513 | virtual bool visitBranch(Visit visit, TIntermBranch*) {return true;} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 514 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 515 | void incrementDepth() {depth++;} |
| 516 | void decrementDepth() {depth--;} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 517 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 518 | const bool preVisit; |
| 519 | const bool inVisit; |
| 520 | const bool postVisit; |
| 521 | const bool rightToLeft; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 522 | |
| 523 | protected: |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 524 | int depth; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 525 | }; |
| 526 | |
| 527 | #endif // __INTERMEDIATE_H |