blob: 52a6f5135ee046e44a8758dc5e1ea48758729ee5 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens16004fc2014-06-11 11:29:11 -04002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Jamie Madillb1a85f42014-08-19 15:23:24 -04007#include "compiler/translator/Intermediate.h"
Geoff Lang17732822013-08-29 13:46:49 -04008#include "compiler/translator/SymbolTable.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009
Zhenyao Moe40d1e92014-07-16 17:40:36 -070010namespace
11{
12
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000013//
14// Two purposes:
15// 1. Show an example of how to iterate tree. Functions can
16// also directly call Traverse() on children themselves to
17// have finer grained control over the process than shown here.
18// See the last function for how to get started.
19// 2. Print out a text based description of the tree.
20//
21
22//
23// Use this class to carry along data from node to node in
24// the traversal
25//
Zhenyao Moe40d1e92014-07-16 17:40:36 -070026class TOutputTraverser : public TIntermTraverser
27{
28 public:
29 TOutputTraverser(TInfoSinkBase &i)
30 : sink(i) { }
alokp@chromium.org7beea402010-09-15 21:18:34 +000031 TInfoSinkBase& sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000032
Zhenyao Moe40d1e92014-07-16 17:40:36 -070033 protected:
34 void visitSymbol(TIntermSymbol *);
35 void visitConstantUnion(TIntermConstantUnion *);
36 bool visitBinary(Visit visit, TIntermBinary *);
37 bool visitUnary(Visit visit, TIntermUnary *);
38 bool visitSelection(Visit visit, TIntermSelection *);
39 bool visitAggregate(Visit visit, TIntermAggregate *);
40 bool visitLoop(Visit visit, TIntermLoop *);
41 bool visitBranch(Visit visit, TIntermBranch *);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000042};
43
Zhenyao Moe40d1e92014-07-16 17:40:36 -070044//
45// Helper functions for printing, not part of traversing.
46//
47void OutputTreeText(TInfoSinkBase &sink, TIntermNode *node, const int depth)
48{
49 int i;
50
51 sink.location(node->getLine());
52
53 for (i = 0; i < depth; ++i)
54 sink << " ";
55}
56
57} // namespace anonymous
58
59
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000060TString TType::getCompleteString() const
61{
alokp@chromium.org4e4facd2010-06-02 15:21:22 +000062 TStringStream stream;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000063
alokp@chromium.org76b82082010-03-24 17:59:39 +000064 if (qualifier != EvqTemporary && qualifier != EvqGlobal)
alokp@chromium.org4e4facd2010-06-02 15:21:22 +000065 stream << getQualifierString() << " " << getPrecisionString() << " ";
alokp@chromium.org76b82082010-03-24 17:59:39 +000066 if (array)
daniel@transgaming.com4167cc92013-01-11 04:11:53 +000067 stream << "array[" << getArraySize() << "] of ";
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +000068 if (isMatrix())
69 stream << getCols() << "X" << getRows() << " matrix of ";
70 else if (isVector())
71 stream << getNominalSize() << "-component vector of ";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072
alokp@chromium.org4e4facd2010-06-02 15:21:22 +000073 stream << getBasicString();
74 return stream.str();
75}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000076
77//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000078// The rest of the file are the traversal functions. The last one
79// is the one that starts the traversal.
80//
81// Return true from interior nodes to have the external traversal
82// continue on to children. If you process children yourself,
83// return false.
84//
85
Zhenyao Moe40d1e92014-07-16 17:40:36 -070086void TOutputTraverser::visitSymbol(TIntermSymbol *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000087{
Zhenyao Moe40d1e92014-07-16 17:40:36 -070088 OutputTreeText(sink, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000089
alokp@chromium.org7beea402010-09-15 21:18:34 +000090 sink << "'" << node->getSymbol() << "' ";
91 sink << "(" << node->getCompleteString() << ")\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000092}
93
Zhenyao Moe40d1e92014-07-16 17:40:36 -070094bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095{
alokp@chromium.org7beea402010-09-15 21:18:34 +000096 TInfoSinkBase& out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000097
Zhenyao Moe40d1e92014-07-16 17:40:36 -070098 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700100 switch (node->getOp())
101 {
102 case EOpAssign:
103 out << "move second child to first child";
104 break;
105 case EOpInitialize:
106 out << "initialize first child with second child";
107 break;
108 case EOpAddAssign:
109 out << "add second child into first child";
110 break;
111 case EOpSubAssign:
112 out << "subtract second child into first child";
113 break;
114 case EOpMulAssign:
115 out << "multiply second child into first child";
116 break;
117 case EOpVectorTimesMatrixAssign:
118 out << "matrix mult second child into first child";
119 break;
120 case EOpVectorTimesScalarAssign:
121 out << "vector scale second child into first child";
122 break;
123 case EOpMatrixTimesScalarAssign:
124 out << "matrix scale second child into first child";
125 break;
126 case EOpMatrixTimesMatrixAssign:
127 out << "matrix mult second child into first child";
128 break;
129 case EOpDivAssign:
130 out << "divide second child into first child";
131 break;
132 case EOpIndexDirect:
133 out << "direct index";
134 break;
135 case EOpIndexIndirect:
136 out << "indirect index";
137 break;
138 case EOpIndexDirectStruct:
139 out << "direct index for structure";
140 break;
141 case EOpIndexDirectInterfaceBlock:
142 out << "direct index for interface block";
143 break;
144 case EOpVectorSwizzle:
145 out << "vector swizzle";
146 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000147
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700148 case EOpAdd:
149 out << "add";
150 break;
151 case EOpSub:
152 out << "subtract";
153 break;
154 case EOpMul:
155 out << "component-wise multiply";
156 break;
157 case EOpDiv:
158 out << "divide";
159 break;
160 case EOpEqual:
161 out << "Compare Equal";
162 break;
163 case EOpNotEqual:
164 out << "Compare Not Equal";
165 break;
166 case EOpLessThan:
167 out << "Compare Less Than";
168 break;
169 case EOpGreaterThan:
170 out << "Compare Greater Than";
171 break;
172 case EOpLessThanEqual:
173 out << "Compare Less Than or Equal";
174 break;
175 case EOpGreaterThanEqual:
176 out << "Compare Greater Than or Equal";
177 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000178
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700179 case EOpVectorTimesScalar:
180 out << "vector-scale";
181 break;
182 case EOpVectorTimesMatrix:
183 out << "vector-times-matrix";
184 break;
185 case EOpMatrixTimesVector:
186 out << "matrix-times-vector";
187 break;
188 case EOpMatrixTimesScalar:
189 out << "matrix-scale";
190 break;
191 case EOpMatrixTimesMatrix:
192 out << "matrix-multiply";
193 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000194
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700195 case EOpLogicalOr:
196 out << "logical-or";
197 break;
198 case EOpLogicalXor:
199 out << "logical-xor";
200 break;
201 case EOpLogicalAnd:
202 out << "logical-and";
203 break;
204 default:
205 out << "<unknown op>";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000206 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000207
alokp@chromium.org7beea402010-09-15 21:18:34 +0000208 out << " (" << node->getCompleteString() << ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000209
alokp@chromium.org7beea402010-09-15 21:18:34 +0000210 out << "\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000211
alokp@chromium.org76b82082010-03-24 17:59:39 +0000212 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000213}
214
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700215bool TOutputTraverser::visitUnary(Visit visit, TIntermUnary *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000216{
alokp@chromium.org7beea402010-09-15 21:18:34 +0000217 TInfoSinkBase& out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000218
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700219 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000220
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700221 switch (node->getOp())
222 {
223 case EOpNegative: out << "Negate value"; break;
224 case EOpVectorLogicalNot:
225 case EOpLogicalNot: out << "Negate conditional"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000226
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700227 case EOpPostIncrement: out << "Post-Increment"; break;
228 case EOpPostDecrement: out << "Post-Decrement"; break;
229 case EOpPreIncrement: out << "Pre-Increment"; break;
230 case EOpPreDecrement: out << "Pre-Decrement"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000231
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700232 case EOpRadians: out << "radians"; break;
233 case EOpDegrees: out << "degrees"; break;
234 case EOpSin: out << "sine"; break;
235 case EOpCos: out << "cosine"; break;
236 case EOpTan: out << "tangent"; break;
237 case EOpAsin: out << "arc sine"; break;
238 case EOpAcos: out << "arc cosine"; break;
239 case EOpAtan: out << "arc tangent"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000240
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700241 case EOpExp: out << "exp"; break;
242 case EOpLog: out << "log"; break;
243 case EOpExp2: out << "exp2"; break;
244 case EOpLog2: out << "log2"; break;
245 case EOpSqrt: out << "sqrt"; break;
246 case EOpInverseSqrt: out << "inverse sqrt"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000247
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700248 case EOpAbs: out << "Absolute value"; break;
249 case EOpSign: out << "Sign"; break;
250 case EOpFloor: out << "Floor"; break;
251 case EOpCeil: out << "Ceiling"; break;
252 case EOpFract: out << "Fraction"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000253
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700254 case EOpLength: out << "length"; break;
255 case EOpNormalize: out << "normalize"; break;
256 // case EOpDPdx: out << "dPdx"; break;
257 // case EOpDPdy: out << "dPdy"; break;
258 // case EOpFwidth: out << "fwidth"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000259
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700260 case EOpAny: out << "any"; break;
261 case EOpAll: out << "all"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000262
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700263 default:
264 out.prefix(EPrefixError);
265 out << "Bad unary op";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000266 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000267
alokp@chromium.org7beea402010-09-15 21:18:34 +0000268 out << " (" << node->getCompleteString() << ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000269
alokp@chromium.org7beea402010-09-15 21:18:34 +0000270 out << "\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000271
alokp@chromium.org76b82082010-03-24 17:59:39 +0000272 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000273}
274
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700275bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700277 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000278
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700279 if (node->getOp() == EOpNull)
280 {
Jamie Madill075edd82013-07-08 13:30:19 -0400281 out.prefix(EPrefixError);
282 out << "node is still EOpNull!";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000283 return true;
284 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000285
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700286 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700288 switch (node->getOp())
289 {
290 case EOpSequence: out << "Sequence\n"; return true;
291 case EOpComma: out << "Comma\n"; return true;
292 case EOpFunction: out << "Function Definition: " << node->getName(); break;
293 case EOpFunctionCall: out << "Function Call: " << node->getName(); break;
294 case EOpParameters: out << "Function Parameters: "; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000295
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700296 case EOpConstructFloat: out << "Construct float"; break;
297 case EOpConstructVec2: out << "Construct vec2"; break;
298 case EOpConstructVec3: out << "Construct vec3"; break;
299 case EOpConstructVec4: out << "Construct vec4"; break;
300 case EOpConstructBool: out << "Construct bool"; break;
301 case EOpConstructBVec2: out << "Construct bvec2"; break;
302 case EOpConstructBVec3: out << "Construct bvec3"; break;
303 case EOpConstructBVec4: out << "Construct bvec4"; break;
304 case EOpConstructInt: out << "Construct int"; break;
305 case EOpConstructIVec2: out << "Construct ivec2"; break;
306 case EOpConstructIVec3: out << "Construct ivec3"; break;
307 case EOpConstructIVec4: out << "Construct ivec4"; break;
308 case EOpConstructUInt: out << "Construct uint"; break;
309 case EOpConstructUVec2: out << "Construct uvec2"; break;
310 case EOpConstructUVec3: out << "Construct uvec3"; break;
311 case EOpConstructUVec4: out << "Construct uvec4"; break;
312 case EOpConstructMat2: out << "Construct mat2"; break;
313 case EOpConstructMat3: out << "Construct mat3"; break;
314 case EOpConstructMat4: out << "Construct mat4"; break;
315 case EOpConstructStruct: out << "Construct structure"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000316
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700317 case EOpLessThan: out << "Compare Less Than"; break;
318 case EOpGreaterThan: out << "Compare Greater Than"; break;
319 case EOpLessThanEqual: out << "Compare Less Than or Equal"; break;
320 case EOpGreaterThanEqual: out << "Compare Greater Than or Equal"; break;
321 case EOpVectorEqual: out << "Equal"; break;
322 case EOpVectorNotEqual: out << "NotEqual"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000323
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700324 case EOpMod: out << "mod"; break;
325 case EOpPow: out << "pow"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000326
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700327 case EOpAtan: out << "arc tangent"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000328
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700329 case EOpMin: out << "min"; break;
330 case EOpMax: out << "max"; break;
331 case EOpClamp: out << "clamp"; break;
332 case EOpMix: out << "mix"; break;
333 case EOpStep: out << "step"; break;
334 case EOpSmoothStep: out << "smoothstep"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000335
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700336 case EOpDistance: out << "distance"; break;
337 case EOpDot: out << "dot-product"; break;
338 case EOpCross: out << "cross-product"; break;
339 case EOpFaceForward: out << "face-forward"; break;
340 case EOpReflect: out << "reflect"; break;
341 case EOpRefract: out << "refract"; break;
342 case EOpMul: out << "component-wise multiply"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000343
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700344 case EOpDeclaration: out << "Declaration: "; break;
daniel@transgaming.coma9ae4aa2011-10-19 13:29:27 +0000345
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700346 default:
347 out.prefix(EPrefixError);
348 out << "Bad aggregation op";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000349 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000350
alokp@chromium.org76b82082010-03-24 17:59:39 +0000351 if (node->getOp() != EOpSequence && node->getOp() != EOpParameters)
alokp@chromium.org7beea402010-09-15 21:18:34 +0000352 out << " (" << node->getCompleteString() << ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000353
alokp@chromium.org7beea402010-09-15 21:18:34 +0000354 out << "\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000355
alokp@chromium.org76b82082010-03-24 17:59:39 +0000356 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000357}
358
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700359bool TOutputTraverser::visitSelection(Visit visit, TIntermSelection *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000360{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700361 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000362
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700363 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000364
alokp@chromium.org7beea402010-09-15 21:18:34 +0000365 out << "Test condition and select";
366 out << " (" << node->getCompleteString() << ")\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000367
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700368 ++mDepth;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000369
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700370 OutputTreeText(sink, node, mDepth);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000371 out << "Condition\n";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000372 node->getCondition()->traverse(this);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000373
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700374 OutputTreeText(sink, node, mDepth);
375 if (node->getTrueBlock())
376 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000377 out << "true case\n";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000378 node->getTrueBlock()->traverse(this);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700379 }
380 else
381 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000382 out << "true case is null\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700383 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000384
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700385 if (node->getFalseBlock())
386 {
387 OutputTreeText(sink, node, mDepth);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000388 out << "false case\n";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000389 node->getFalseBlock()->traverse(this);
390 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000391
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700392 --mDepth;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000393
alokp@chromium.org76b82082010-03-24 17:59:39 +0000394 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000395}
396
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700397void TOutputTraverser::visitConstantUnion(TIntermConstantUnion *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000398{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700399 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000400
Jamie Madill94bf7f22013-07-08 13:31:15 -0400401 size_t size = node->getType().getObjectSize();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000402
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700403 for (size_t i = 0; i < size; i++)
404 {
405 OutputTreeText(out, node, mDepth);
406 switch (node->getUnionArrayPointer()[i].getType())
407 {
408 case EbtBool:
409 if (node->getUnionArrayPointer()[i].getBConst())
410 out << "true";
411 else
412 out << "false";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000413
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700414 out << " (" << "const bool" << ")";
415 out << "\n";
416 break;
417 case EbtFloat:
418 out << node->getUnionArrayPointer()[i].getFConst();
419 out << " (const float)\n";
420 break;
421 case EbtInt:
422 out << node->getUnionArrayPointer()[i].getIConst();
423 out << " (const int)\n";
424 break;
425 case EbtUInt:
426 out << node->getUnionArrayPointer()[i].getUConst();
427 out << " (const uint)\n";
428 break;
429 default:
430 out.message(EPrefixInternalError, node->getLine(), "Unknown constant");
431 break;
alokp@chromium.org76b82082010-03-24 17:59:39 +0000432 }
433 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000434}
435
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700436bool TOutputTraverser::visitLoop(Visit visit, TIntermLoop *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000437{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700438 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000439
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700440 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000441
alokp@chromium.org7beea402010-09-15 21:18:34 +0000442 out << "Loop with condition ";
alokp@chromium.org52813552010-11-16 18:36:09 +0000443 if (node->getType() == ELoopDoWhile)
alokp@chromium.org7beea402010-09-15 21:18:34 +0000444 out << "not ";
445 out << "tested first\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000446
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700447 ++mDepth;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000448
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700449 OutputTreeText(sink, node, mDepth);
450 if (node->getCondition())
451 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000452 out << "Loop Condition\n";
alokp@chromium.org52813552010-11-16 18:36:09 +0000453 node->getCondition()->traverse(this);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700454 }
455 else
456 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000457 out << "No loop condition\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700458 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000459
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700460 OutputTreeText(sink, node, mDepth);
461 if (node->getBody())
462 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000463 out << "Loop Body\n";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000464 node->getBody()->traverse(this);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700465 }
466 else
467 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000468 out << "No loop body\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700469 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000470
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700471 if (node->getExpression())
472 {
473 OutputTreeText(sink, node, mDepth);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000474 out << "Loop Terminal Expression\n";
alokp@chromium.org52813552010-11-16 18:36:09 +0000475 node->getExpression()->traverse(this);
alokp@chromium.org76b82082010-03-24 17:59:39 +0000476 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000477
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700478 --mDepth;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000479
alokp@chromium.org76b82082010-03-24 17:59:39 +0000480 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000481}
482
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700483bool TOutputTraverser::visitBranch(Visit visit, TIntermBranch *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000484{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700485 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000486
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700487 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000488
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700489 switch (node->getFlowOp())
490 {
491 case EOpKill: out << "Branch: Kill"; break;
492 case EOpBreak: out << "Branch: Break"; break;
493 case EOpContinue: out << "Branch: Continue"; break;
494 case EOpReturn: out << "Branch: Return"; break;
495 default: out << "Branch: Unknown Branch"; break;
alokp@chromium.org76b82082010-03-24 17:59:39 +0000496 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000497
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700498 if (node->getExpression())
499 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000500 out << " with expression\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700501 ++mDepth;
alokp@chromium.org76b82082010-03-24 17:59:39 +0000502 node->getExpression()->traverse(this);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700503 --mDepth;
504 }
505 else
506 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000507 out << "\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700508 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000509
alokp@chromium.org76b82082010-03-24 17:59:39 +0000510 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000511}
512
513//
514// This function is the one to call externally to start the traversal.
515// Individual functions can be initialized to 0 to skip processing of that
516// type of node. It's children will still be processed.
517//
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700518void TIntermediate::outputTree(TIntermNode *root)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000519{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700520 if (root == NULL)
alokp@chromium.org76b82082010-03-24 17:59:39 +0000521 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000522
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700523 TOutputTraverser it(mInfoSink.info);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000524
alokp@chromium.org76b82082010-03-24 17:59:39 +0000525 root->traverse(&it);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000526}