John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1 | // |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 7 | #include "localintermediate.h" |
| 8 | #include "SymbolTable.h" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 9 | |
| 10 | // |
| 11 | // Two purposes: |
| 12 | // 1. Show an example of how to iterate tree. Functions can |
| 13 | // also directly call Traverse() on children themselves to |
| 14 | // have finer grained control over the process than shown here. |
| 15 | // See the last function for how to get started. |
| 16 | // 2. Print out a text based description of the tree. |
| 17 | // |
| 18 | |
| 19 | // |
| 20 | // Use this class to carry along data from node to node in |
| 21 | // the traversal |
| 22 | // |
| 23 | class TOutputTraverser : public TIntermTraverser { |
| 24 | public: |
| 25 | TOutputTraverser(TInfoSinkBase& i) : sink(i) { } |
| 26 | TInfoSinkBase& sink; |
| 27 | |
| 28 | protected: |
| 29 | void visitSymbol(TIntermSymbol*); |
| 30 | void visitConstantUnion(TIntermConstantUnion*); |
| 31 | bool visitBinary(Visit visit, TIntermBinary*); |
| 32 | bool visitUnary(Visit visit, TIntermUnary*); |
| 33 | bool visitSelection(Visit visit, TIntermSelection*); |
| 34 | bool visitAggregate(Visit visit, TIntermAggregate*); |
| 35 | bool visitLoop(Visit visit, TIntermLoop*); |
| 36 | bool visitBranch(Visit visit, TIntermBranch*); |
| 37 | }; |
| 38 | |
| 39 | TString TType::getCompleteString() const |
| 40 | { |
| 41 | TStringStream stream; |
| 42 | |
| 43 | if (qualifier != EvqTemporary && qualifier != EvqGlobal) |
| 44 | stream << getQualifierString() << " " << getPrecisionString() << " "; |
| 45 | if (array) |
| 46 | stream << "array of "; |
Alexis Hetu | b14178b | 2015-04-13 13:23:20 -0400 | [diff] [blame] | 47 | if (isMatrix()) |
Alexis Hetu | f78e963 | 2015-05-11 16:42:43 -0400 | [diff] [blame] | 48 | stream << static_cast<int>(primarySize) << "X" << static_cast<int>(secondarySize) << " matrix of "; |
Alexis Hetu | b14178b | 2015-04-13 13:23:20 -0400 | [diff] [blame] | 49 | else if(primarySize > 1) |
Alexis Hetu | f78e963 | 2015-05-11 16:42:43 -0400 | [diff] [blame] | 50 | stream << static_cast<int>(primarySize) << "-component vector of "; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 51 | |
| 52 | stream << getBasicString(); |
| 53 | return stream.str(); |
| 54 | } |
| 55 | |
| 56 | // |
| 57 | // Helper functions for printing, not part of traversing. |
| 58 | // |
| 59 | |
| 60 | void OutputTreeText(TInfoSinkBase& sink, TIntermNode* node, const int depth) |
| 61 | { |
| 62 | int i; |
| 63 | |
| 64 | sink.location(node->getLine()); |
| 65 | |
| 66 | for (i = 0; i < depth; ++i) |
| 67 | sink << " "; |
| 68 | } |
| 69 | |
| 70 | // |
| 71 | // The rest of the file are the traversal functions. The last one |
| 72 | // is the one that starts the traversal. |
| 73 | // |
| 74 | // Return true from interior nodes to have the external traversal |
| 75 | // continue on to children. If you process children yourself, |
| 76 | // return false. |
| 77 | // |
| 78 | |
| 79 | void TOutputTraverser::visitSymbol(TIntermSymbol* node) |
| 80 | { |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 81 | OutputTreeText(sink, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 82 | |
| 83 | sink << "'" << node->getSymbol() << "' "; |
| 84 | sink << "(" << node->getCompleteString() << ")\n"; |
| 85 | } |
| 86 | |
| 87 | bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary* node) |
| 88 | { |
| 89 | TInfoSinkBase& out = sink; |
| 90 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 91 | OutputTreeText(out, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 92 | |
| 93 | switch (node->getOp()) { |
| 94 | case EOpAssign: out << "move second child to first child"; break; |
| 95 | case EOpInitialize: out << "initialize first child with second child"; break; |
| 96 | case EOpAddAssign: out << "add second child into first child"; break; |
| 97 | case EOpSubAssign: out << "subtract second child into first child"; break; |
| 98 | case EOpMulAssign: out << "multiply second child into first child"; break; |
| 99 | case EOpVectorTimesMatrixAssign: out << "matrix mult second child into first child"; break; |
| 100 | case EOpVectorTimesScalarAssign: out << "vector scale second child into first child"; break; |
| 101 | case EOpMatrixTimesScalarAssign: out << "matrix scale second child into first child"; break; |
Alexis Hetu | 1780905 | 2015-05-13 11:28:22 -0400 | [diff] [blame] | 102 | case EOpMatrixTimesMatrixAssign: out << "matrix mult second child into first child"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 103 | case EOpDivAssign: out << "divide second child into first child"; break; |
Alexis Hetu | 1780905 | 2015-05-13 11:28:22 -0400 | [diff] [blame] | 104 | case EOpIModAssign: out << "modulo second child into first child"; break; |
| 105 | case EOpBitShiftLeftAssign: out << "bit-wise shift first child left by second child"; break; |
| 106 | case EOpBitShiftRightAssign: out << "bit-wise shift first child right by second child"; break; |
| 107 | case EOpBitwiseAndAssign: out << "bit-wise and second child into first child"; break; |
| 108 | case EOpBitwiseXorAssign: out << "bit-wise xor second child into first child"; break; |
| 109 | case EOpBitwiseOrAssign: out << "bit-wise or second child into first child"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 110 | case EOpIndexDirect: out << "direct index"; break; |
| 111 | case EOpIndexIndirect: out << "indirect index"; break; |
| 112 | case EOpIndexDirectStruct: out << "direct index for structure"; break; |
| 113 | case EOpVectorSwizzle: out << "vector swizzle"; break; |
| 114 | |
| 115 | case EOpAdd: out << "add"; break; |
| 116 | case EOpSub: out << "subtract"; break; |
| 117 | case EOpMul: out << "component-wise multiply"; break; |
| 118 | case EOpDiv: out << "divide"; break; |
Alexis Hetu | 1780905 | 2015-05-13 11:28:22 -0400 | [diff] [blame] | 119 | case EOpIMod: out << "modulo"; break; |
| 120 | case EOpBitShiftLeft: out << "bit-wise shift left"; break; |
| 121 | case EOpBitShiftRight: out << "bit-wise shift right"; break; |
| 122 | case EOpBitwiseAnd: out << "bit-wise and"; break; |
| 123 | case EOpBitwiseXor: out << "bit-wise xor"; break; |
| 124 | case EOpBitwiseOr: out << "bit-wise or"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 125 | case EOpEqual: out << "Compare Equal"; break; |
| 126 | case EOpNotEqual: out << "Compare Not Equal"; break; |
| 127 | case EOpLessThan: out << "Compare Less Than"; break; |
| 128 | case EOpGreaterThan: out << "Compare Greater Than"; break; |
| 129 | case EOpLessThanEqual: out << "Compare Less Than or Equal"; break; |
| 130 | case EOpGreaterThanEqual: out << "Compare Greater Than or Equal"; break; |
| 131 | |
| 132 | case EOpVectorTimesScalar: out << "vector-scale"; break; |
| 133 | case EOpVectorTimesMatrix: out << "vector-times-matrix"; break; |
| 134 | case EOpMatrixTimesVector: out << "matrix-times-vector"; break; |
| 135 | case EOpMatrixTimesScalar: out << "matrix-scale"; break; |
| 136 | case EOpMatrixTimesMatrix: out << "matrix-multiply"; break; |
| 137 | |
| 138 | case EOpLogicalOr: out << "logical-or"; break; |
| 139 | case EOpLogicalXor: out << "logical-xor"; break; |
| 140 | case EOpLogicalAnd: out << "logical-and"; break; |
| 141 | default: out << "<unknown op>"; |
| 142 | } |
| 143 | |
| 144 | out << " (" << node->getCompleteString() << ")"; |
| 145 | |
| 146 | out << "\n"; |
| 147 | |
| 148 | return true; |
| 149 | } |
| 150 | |
| 151 | bool TOutputTraverser::visitUnary(Visit visit, TIntermUnary* node) |
| 152 | { |
| 153 | TInfoSinkBase& out = sink; |
| 154 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 155 | OutputTreeText(out, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 156 | |
| 157 | switch (node->getOp()) { |
| 158 | case EOpNegative: out << "Negate value"; break; |
| 159 | case EOpVectorLogicalNot: |
| 160 | case EOpLogicalNot: out << "Negate conditional"; break; |
Alexis Hetu | 1780905 | 2015-05-13 11:28:22 -0400 | [diff] [blame] | 161 | case EOpBitwiseNot: out << "bit-wise not"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 162 | |
| 163 | case EOpPostIncrement: out << "Post-Increment"; break; |
| 164 | case EOpPostDecrement: out << "Post-Decrement"; break; |
| 165 | case EOpPreIncrement: out << "Pre-Increment"; break; |
| 166 | case EOpPreDecrement: out << "Pre-Decrement"; break; |
| 167 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 168 | case EOpRadians: out << "radians"; break; |
| 169 | case EOpDegrees: out << "degrees"; break; |
| 170 | case EOpSin: out << "sine"; break; |
| 171 | case EOpCos: out << "cosine"; break; |
| 172 | case EOpTan: out << "tangent"; break; |
| 173 | case EOpAsin: out << "arc sine"; break; |
| 174 | case EOpAcos: out << "arc cosine"; break; |
| 175 | case EOpAtan: out << "arc tangent"; break; |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 176 | case EOpSinh: out << "hyperbolic sine"; break; |
| 177 | case EOpCosh: out << "hyperbolic cosine"; break; |
| 178 | case EOpTanh: out << "hyperbolic tangent"; break; |
| 179 | case EOpAsinh: out << "arc hyperbolic sine"; break; |
| 180 | case EOpAcosh: out << "arc hyperbolic cosine"; break; |
| 181 | case EOpAtanh: out << "arc hyperbolic tangent"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 182 | |
| 183 | case EOpExp: out << "exp"; break; |
| 184 | case EOpLog: out << "log"; break; |
| 185 | case EOpExp2: out << "exp2"; break; |
| 186 | case EOpLog2: out << "log2"; break; |
| 187 | case EOpSqrt: out << "sqrt"; break; |
| 188 | case EOpInverseSqrt: out << "inverse sqrt"; break; |
| 189 | |
| 190 | case EOpAbs: out << "Absolute value"; break; |
| 191 | case EOpSign: out << "Sign"; break; |
| 192 | case EOpFloor: out << "Floor"; break; |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 193 | case EOpTrunc: out << "Trunc"; break; |
| 194 | case EOpRound: out << "Round"; break; |
| 195 | case EOpRoundEven: out << "RoundEven"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 196 | case EOpCeil: out << "Ceiling"; break; |
| 197 | case EOpFract: out << "Fraction"; break; |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 198 | case EOpIsNan: out << "Is not a number"; break; |
| 199 | case EOpIsInf: out << "Is infinity"; break; |
| 200 | |
| 201 | case EOpFloatBitsToInt: out << "float bits to int"; break; |
| 202 | case EOpFloatBitsToUint: out << "float bits to uint"; break; |
| 203 | case EOpIntBitsToFloat: out << "int bits to float"; break; |
| 204 | case EOpUintBitsToFloat: out << "uint bits to float"; break; |
| 205 | |
| 206 | case EOpPackSnorm2x16: out << "pack Snorm 2x16"; break; |
| 207 | case EOpPackUnorm2x16: out << "pack Unorm 2x16"; break; |
| 208 | case EOpPackHalf2x16: out << "pack half 2x16"; break; |
| 209 | |
| 210 | case EOpUnpackSnorm2x16: out << "unpack Snorm 2x16"; break; |
| 211 | case EOpUnpackUnorm2x16: out << "unpack Unorm 2x16"; break; |
| 212 | case EOpUnpackHalf2x16: out << "unpack half 2x16"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 213 | |
| 214 | case EOpLength: out << "length"; break; |
| 215 | case EOpNormalize: out << "normalize"; break; |
| 216 | // case EOpDPdx: out << "dPdx"; break; |
| 217 | // case EOpDPdy: out << "dPdy"; break; |
| 218 | // case EOpFwidth: out << "fwidth"; break; |
| 219 | |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 220 | case EOpDeterminant: out << "determinant"; break; |
| 221 | case EOpTranspose: out << "transpose"; break; |
| 222 | case EOpInverse: out << "inverse"; break; |
| 223 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 224 | case EOpAny: out << "any"; break; |
| 225 | case EOpAll: out << "all"; break; |
| 226 | |
| 227 | default: out.message(EPrefixError, "Bad unary op"); |
| 228 | } |
| 229 | |
| 230 | out << " (" << node->getCompleteString() << ")"; |
| 231 | |
| 232 | out << "\n"; |
| 233 | |
| 234 | return true; |
| 235 | } |
| 236 | |
| 237 | bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate* node) |
| 238 | { |
| 239 | TInfoSinkBase& out = sink; |
| 240 | |
| 241 | if (node->getOp() == EOpNull) { |
| 242 | out.message(EPrefixError, "node is still EOpNull!"); |
| 243 | return true; |
| 244 | } |
| 245 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 246 | OutputTreeText(out, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 247 | |
| 248 | switch (node->getOp()) { |
| 249 | case EOpSequence: out << "Sequence\n"; return true; |
| 250 | case EOpComma: out << "Comma\n"; return true; |
| 251 | case EOpFunction: out << "Function Definition: " << node->getName(); break; |
| 252 | case EOpFunctionCall: out << "Function Call: " << node->getName(); break; |
| 253 | case EOpParameters: out << "Function Parameters: "; break; |
| 254 | |
| 255 | case EOpConstructFloat: out << "Construct float"; break; |
| 256 | case EOpConstructVec2: out << "Construct vec2"; break; |
| 257 | case EOpConstructVec3: out << "Construct vec3"; break; |
| 258 | case EOpConstructVec4: out << "Construct vec4"; break; |
| 259 | case EOpConstructBool: out << "Construct bool"; break; |
| 260 | case EOpConstructBVec2: out << "Construct bvec2"; break; |
| 261 | case EOpConstructBVec3: out << "Construct bvec3"; break; |
| 262 | case EOpConstructBVec4: out << "Construct bvec4"; break; |
| 263 | case EOpConstructInt: out << "Construct int"; break; |
| 264 | case EOpConstructIVec2: out << "Construct ivec2"; break; |
| 265 | case EOpConstructIVec3: out << "Construct ivec3"; break; |
| 266 | case EOpConstructIVec4: out << "Construct ivec4"; break; |
Nicolas Capens | e4b1b1d | 2015-02-17 17:26:01 -0500 | [diff] [blame] | 267 | case EOpConstructUInt: out << "Construct uint"; break; |
| 268 | case EOpConstructUVec2: out << "Construct uvec2"; break; |
| 269 | case EOpConstructUVec3: out << "Construct uvec3"; break; |
| 270 | case EOpConstructUVec4: out << "Construct uvec4"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 271 | case EOpConstructMat2: out << "Construct mat2"; break; |
| 272 | case EOpConstructMat3: out << "Construct mat3"; break; |
| 273 | case EOpConstructMat4: out << "Construct mat4"; break; |
| 274 | case EOpConstructStruct: out << "Construct structure"; break; |
| 275 | |
| 276 | case EOpLessThan: out << "Compare Less Than"; break; |
| 277 | case EOpGreaterThan: out << "Compare Greater Than"; break; |
| 278 | case EOpLessThanEqual: out << "Compare Less Than or Equal"; break; |
| 279 | case EOpGreaterThanEqual: out << "Compare Greater Than or Equal"; break; |
| 280 | case EOpVectorEqual: out << "Equal"; break; |
| 281 | case EOpVectorNotEqual: out << "NotEqual"; break; |
| 282 | |
| 283 | case EOpMod: out << "mod"; break; |
Alexis Hetu | 7d6b34d | 2016-05-03 11:30:57 -0400 | [diff] [blame] | 284 | case EOpModf: out << "modf"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 285 | case EOpPow: out << "pow"; break; |
| 286 | |
| 287 | case EOpAtan: out << "arc tangent"; break; |
| 288 | |
| 289 | case EOpMin: out << "min"; break; |
| 290 | case EOpMax: out << "max"; break; |
| 291 | case EOpClamp: out << "clamp"; break; |
| 292 | case EOpMix: out << "mix"; break; |
| 293 | case EOpStep: out << "step"; break; |
| 294 | case EOpSmoothStep: out << "smoothstep"; break; |
| 295 | |
| 296 | case EOpDistance: out << "distance"; break; |
| 297 | case EOpDot: out << "dot-product"; break; |
| 298 | case EOpCross: out << "cross-product"; break; |
| 299 | case EOpFaceForward: out << "face-forward"; break; |
| 300 | case EOpReflect: out << "reflect"; break; |
| 301 | case EOpRefract: out << "refract"; break; |
| 302 | case EOpMul: out << "component-wise multiply"; break; |
Alexis Hetu | af1970c | 2015-04-17 14:26:07 -0400 | [diff] [blame] | 303 | case EOpOuterProduct: out << "outer product"; break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 304 | |
| 305 | default: out.message(EPrefixError, "Bad aggregation op"); |
| 306 | } |
| 307 | |
| 308 | if (node->getOp() != EOpSequence && node->getOp() != EOpParameters) |
| 309 | out << " (" << node->getCompleteString() << ")"; |
| 310 | |
| 311 | out << "\n"; |
| 312 | |
| 313 | return true; |
| 314 | } |
| 315 | |
| 316 | bool TOutputTraverser::visitSelection(Visit visit, TIntermSelection* node) |
| 317 | { |
| 318 | TInfoSinkBase& out = sink; |
| 319 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 320 | OutputTreeText(out, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 321 | |
| 322 | out << "Test condition and select"; |
| 323 | out << " (" << node->getCompleteString() << ")\n"; |
| 324 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 325 | ++mDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 326 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 327 | OutputTreeText(sink, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 328 | out << "Condition\n"; |
| 329 | node->getCondition()->traverse(this); |
| 330 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 331 | OutputTreeText(sink, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 332 | if (node->getTrueBlock()) { |
| 333 | out << "true case\n"; |
| 334 | node->getTrueBlock()->traverse(this); |
| 335 | } else |
| 336 | out << "true case is null\n"; |
| 337 | |
| 338 | if (node->getFalseBlock()) { |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 339 | OutputTreeText(sink, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 340 | out << "false case\n"; |
| 341 | node->getFalseBlock()->traverse(this); |
| 342 | } |
| 343 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 344 | --mDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 345 | |
| 346 | return false; |
| 347 | } |
| 348 | |
| 349 | void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node) |
| 350 | { |
| 351 | TInfoSinkBase& out = sink; |
| 352 | |
Alexis Hetu | ab75279 | 2016-04-21 16:11:31 -0400 | [diff] [blame] | 353 | size_t size = node->getType().getObjectSize(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 354 | |
Alexis Hetu | ab75279 | 2016-04-21 16:11:31 -0400 | [diff] [blame] | 355 | for(size_t i = 0; i < size; i++) { |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 356 | OutputTreeText(out, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 357 | switch (node->getUnionArrayPointer()[i].getType()) { |
| 358 | case EbtBool: |
| 359 | if (node->getUnionArrayPointer()[i].getBConst()) |
| 360 | out << "true"; |
| 361 | else |
| 362 | out << "false"; |
| 363 | |
| 364 | out << " (" << "const bool" << ")"; |
| 365 | out << "\n"; |
| 366 | break; |
| 367 | case EbtFloat: |
| 368 | out << node->getUnionArrayPointer()[i].getFConst(); |
| 369 | out << " (const float)\n"; |
| 370 | break; |
| 371 | case EbtInt: |
| 372 | out << node->getUnionArrayPointer()[i].getIConst(); |
| 373 | out << " (const int)\n"; |
| 374 | break; |
Nicolas Capens | 3c20f80 | 2015-02-17 17:17:20 -0500 | [diff] [blame] | 375 | case EbtUInt: |
| 376 | out << node->getUnionArrayPointer()[i].getUConst(); |
| 377 | out << " (const uint)\n"; |
| 378 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 379 | default: |
| 380 | out.message(EPrefixInternalError, "Unknown constant", node->getLine()); |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | bool TOutputTraverser::visitLoop(Visit visit, TIntermLoop* node) |
| 387 | { |
| 388 | TInfoSinkBase& out = sink; |
| 389 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 390 | OutputTreeText(out, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 391 | |
| 392 | out << "Loop with condition "; |
| 393 | if (node->getType() == ELoopDoWhile) |
| 394 | out << "not "; |
| 395 | out << "tested first\n"; |
| 396 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 397 | ++mDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 398 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 399 | OutputTreeText(sink, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 400 | if (node->getCondition()) { |
| 401 | out << "Loop Condition\n"; |
| 402 | node->getCondition()->traverse(this); |
| 403 | } else |
| 404 | out << "No loop condition\n"; |
| 405 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 406 | OutputTreeText(sink, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 407 | if (node->getBody()) { |
| 408 | out << "Loop Body\n"; |
| 409 | node->getBody()->traverse(this); |
| 410 | } else |
| 411 | out << "No loop body\n"; |
| 412 | |
| 413 | if (node->getExpression()) { |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 414 | OutputTreeText(sink, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 415 | out << "Loop Terminal Expression\n"; |
| 416 | node->getExpression()->traverse(this); |
| 417 | } |
| 418 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 419 | --mDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 420 | |
| 421 | return false; |
| 422 | } |
| 423 | |
| 424 | bool TOutputTraverser::visitBranch(Visit visit, TIntermBranch* node) |
| 425 | { |
| 426 | TInfoSinkBase& out = sink; |
| 427 | |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 428 | OutputTreeText(out, node, mDepth); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 429 | |
| 430 | switch (node->getFlowOp()) { |
| 431 | case EOpKill: out << "Branch: Kill"; break; |
| 432 | case EOpBreak: out << "Branch: Break"; break; |
| 433 | case EOpContinue: out << "Branch: Continue"; break; |
| 434 | case EOpReturn: out << "Branch: Return"; break; |
| 435 | default: out << "Branch: Unknown Branch"; break; |
| 436 | } |
| 437 | |
| 438 | if (node->getExpression()) { |
| 439 | out << " with expression\n"; |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 440 | ++mDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 441 | node->getExpression()->traverse(this); |
Alexis Hetu | 76a343a | 2015-06-04 17:21:22 -0400 | [diff] [blame] | 442 | --mDepth; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 443 | } else |
| 444 | out << "\n"; |
| 445 | |
| 446 | return false; |
| 447 | } |
| 448 | |
| 449 | // |
| 450 | // This function is the one to call externally to start the traversal. |
| 451 | // Individual functions can be initialized to 0 to skip processing of that |
| 452 | // type of node. It's children will still be processed. |
| 453 | // |
| 454 | void TIntermediate::outputTree(TIntermNode* root) |
| 455 | { |
| 456 | if (root == 0) |
| 457 | return; |
| 458 | |
| 459 | TOutputTraverser it(infoSink.info); |
| 460 | |
| 461 | root->traverse(&it); |
| 462 | } |