blob: 7713acb82c75d513edc86e3524c5c89b28a30645 [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)
Olli Etuahof9004132014-10-20 18:26:48 +030065 stream << getQualifierString() << " ";
66 if (precision != EbpUndefined)
67 stream << getPrecisionString() << " ";
alokp@chromium.org76b82082010-03-24 17:59:39 +000068 if (array)
daniel@transgaming.com4167cc92013-01-11 04:11:53 +000069 stream << "array[" << getArraySize() << "] of ";
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +000070 if (isMatrix())
71 stream << getCols() << "X" << getRows() << " matrix of ";
72 else if (isVector())
73 stream << getNominalSize() << "-component vector of ";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000074
alokp@chromium.org4e4facd2010-06-02 15:21:22 +000075 stream << getBasicString();
76 return stream.str();
77}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000078
79//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000080// The rest of the file are the traversal functions. The last one
81// is the one that starts the traversal.
82//
83// Return true from interior nodes to have the external traversal
84// continue on to children. If you process children yourself,
85// return false.
86//
87
Zhenyao Moe40d1e92014-07-16 17:40:36 -070088void TOutputTraverser::visitSymbol(TIntermSymbol *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000089{
Zhenyao Moe40d1e92014-07-16 17:40:36 -070090 OutputTreeText(sink, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000091
alokp@chromium.org7beea402010-09-15 21:18:34 +000092 sink << "'" << node->getSymbol() << "' ";
93 sink << "(" << node->getCompleteString() << ")\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000094}
95
Zhenyao Moe40d1e92014-07-16 17:40:36 -070096bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000097{
alokp@chromium.org7beea402010-09-15 21:18:34 +000098 TInfoSinkBase& out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700100 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000101
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700102 switch (node->getOp())
103 {
104 case EOpAssign:
105 out << "move second child to first child";
106 break;
107 case EOpInitialize:
108 out << "initialize first child with second child";
109 break;
110 case EOpAddAssign:
111 out << "add second child into first child";
112 break;
113 case EOpSubAssign:
114 out << "subtract second child into first child";
115 break;
116 case EOpMulAssign:
117 out << "multiply second child into first child";
118 break;
119 case EOpVectorTimesMatrixAssign:
120 out << "matrix mult second child into first child";
121 break;
122 case EOpVectorTimesScalarAssign:
123 out << "vector scale second child into first child";
124 break;
125 case EOpMatrixTimesScalarAssign:
126 out << "matrix scale second child into first child";
127 break;
128 case EOpMatrixTimesMatrixAssign:
129 out << "matrix mult second child into first child";
130 break;
131 case EOpDivAssign:
132 out << "divide second child into first child";
133 break;
134 case EOpIndexDirect:
135 out << "direct index";
136 break;
137 case EOpIndexIndirect:
138 out << "indirect index";
139 break;
140 case EOpIndexDirectStruct:
141 out << "direct index for structure";
142 break;
143 case EOpIndexDirectInterfaceBlock:
144 out << "direct index for interface block";
145 break;
146 case EOpVectorSwizzle:
147 out << "vector swizzle";
148 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000149
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700150 case EOpAdd:
151 out << "add";
152 break;
153 case EOpSub:
154 out << "subtract";
155 break;
156 case EOpMul:
157 out << "component-wise multiply";
158 break;
159 case EOpDiv:
160 out << "divide";
161 break;
162 case EOpEqual:
163 out << "Compare Equal";
164 break;
165 case EOpNotEqual:
166 out << "Compare Not Equal";
167 break;
168 case EOpLessThan:
169 out << "Compare Less Than";
170 break;
171 case EOpGreaterThan:
172 out << "Compare Greater Than";
173 break;
174 case EOpLessThanEqual:
175 out << "Compare Less Than or Equal";
176 break;
177 case EOpGreaterThanEqual:
178 out << "Compare Greater Than or Equal";
179 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000180
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700181 case EOpVectorTimesScalar:
182 out << "vector-scale";
183 break;
184 case EOpVectorTimesMatrix:
185 out << "vector-times-matrix";
186 break;
187 case EOpMatrixTimesVector:
188 out << "matrix-times-vector";
189 break;
190 case EOpMatrixTimesScalar:
191 out << "matrix-scale";
192 break;
193 case EOpMatrixTimesMatrix:
194 out << "matrix-multiply";
195 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000196
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700197 case EOpLogicalOr:
198 out << "logical-or";
199 break;
200 case EOpLogicalXor:
201 out << "logical-xor";
202 break;
203 case EOpLogicalAnd:
204 out << "logical-and";
205 break;
206 default:
207 out << "<unknown op>";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000208 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000209
alokp@chromium.org7beea402010-09-15 21:18:34 +0000210 out << " (" << node->getCompleteString() << ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000211
alokp@chromium.org7beea402010-09-15 21:18:34 +0000212 out << "\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000213
alokp@chromium.org76b82082010-03-24 17:59:39 +0000214 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000215}
216
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700217bool TOutputTraverser::visitUnary(Visit visit, TIntermUnary *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000218{
alokp@chromium.org7beea402010-09-15 21:18:34 +0000219 TInfoSinkBase& out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000220
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700221 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000222
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700223 switch (node->getOp())
224 {
225 case EOpNegative: out << "Negate value"; break;
Zhenyao Mode1e00e2014-10-09 16:55:32 -0700226 case EOpPositive: out << "Positive sign"; break;
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700227 case EOpVectorLogicalNot:
228 case EOpLogicalNot: out << "Negate conditional"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000229
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700230 case EOpPostIncrement: out << "Post-Increment"; break;
231 case EOpPostDecrement: out << "Post-Decrement"; break;
232 case EOpPreIncrement: out << "Pre-Increment"; break;
233 case EOpPreDecrement: out << "Pre-Decrement"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000234
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700235 case EOpRadians: out << "radians"; break;
236 case EOpDegrees: out << "degrees"; break;
237 case EOpSin: out << "sine"; break;
238 case EOpCos: out << "cosine"; break;
239 case EOpTan: out << "tangent"; break;
240 case EOpAsin: out << "arc sine"; break;
241 case EOpAcos: out << "arc cosine"; break;
242 case EOpAtan: out << "arc tangent"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000243
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700244 case EOpExp: out << "exp"; break;
245 case EOpLog: out << "log"; break;
246 case EOpExp2: out << "exp2"; break;
247 case EOpLog2: out << "log2"; break;
248 case EOpSqrt: out << "sqrt"; break;
249 case EOpInverseSqrt: out << "inverse sqrt"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000250
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700251 case EOpAbs: out << "Absolute value"; break;
252 case EOpSign: out << "Sign"; break;
253 case EOpFloor: out << "Floor"; break;
254 case EOpCeil: out << "Ceiling"; break;
255 case EOpFract: out << "Fraction"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000256
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700257 case EOpLength: out << "length"; break;
258 case EOpNormalize: out << "normalize"; break;
259 // case EOpDPdx: out << "dPdx"; break;
260 // case EOpDPdy: out << "dPdy"; break;
261 // case EOpFwidth: out << "fwidth"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000262
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700263 case EOpAny: out << "any"; break;
264 case EOpAll: out << "all"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000265
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700266 default:
267 out.prefix(EPrefixError);
268 out << "Bad unary op";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000269 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000270
alokp@chromium.org7beea402010-09-15 21:18:34 +0000271 out << " (" << node->getCompleteString() << ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000272
alokp@chromium.org7beea402010-09-15 21:18:34 +0000273 out << "\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000274
alokp@chromium.org76b82082010-03-24 17:59:39 +0000275 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276}
277
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700278bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000279{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700280 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000281
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700282 if (node->getOp() == EOpNull)
283 {
Jamie Madill075edd82013-07-08 13:30:19 -0400284 out.prefix(EPrefixError);
285 out << "node is still EOpNull!";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000286 return true;
287 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000288
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700289 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000290
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700291 switch (node->getOp())
292 {
293 case EOpSequence: out << "Sequence\n"; return true;
294 case EOpComma: out << "Comma\n"; return true;
295 case EOpFunction: out << "Function Definition: " << node->getName(); break;
296 case EOpFunctionCall: out << "Function Call: " << node->getName(); break;
297 case EOpParameters: out << "Function Parameters: "; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000298
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700299 case EOpConstructFloat: out << "Construct float"; break;
300 case EOpConstructVec2: out << "Construct vec2"; break;
301 case EOpConstructVec3: out << "Construct vec3"; break;
302 case EOpConstructVec4: out << "Construct vec4"; break;
303 case EOpConstructBool: out << "Construct bool"; break;
304 case EOpConstructBVec2: out << "Construct bvec2"; break;
305 case EOpConstructBVec3: out << "Construct bvec3"; break;
306 case EOpConstructBVec4: out << "Construct bvec4"; break;
307 case EOpConstructInt: out << "Construct int"; break;
308 case EOpConstructIVec2: out << "Construct ivec2"; break;
309 case EOpConstructIVec3: out << "Construct ivec3"; break;
310 case EOpConstructIVec4: out << "Construct ivec4"; break;
311 case EOpConstructUInt: out << "Construct uint"; break;
312 case EOpConstructUVec2: out << "Construct uvec2"; break;
313 case EOpConstructUVec3: out << "Construct uvec3"; break;
314 case EOpConstructUVec4: out << "Construct uvec4"; break;
315 case EOpConstructMat2: out << "Construct mat2"; break;
316 case EOpConstructMat3: out << "Construct mat3"; break;
317 case EOpConstructMat4: out << "Construct mat4"; break;
318 case EOpConstructStruct: out << "Construct structure"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000319
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700320 case EOpLessThan: out << "Compare Less Than"; break;
321 case EOpGreaterThan: out << "Compare Greater Than"; break;
322 case EOpLessThanEqual: out << "Compare Less Than or Equal"; break;
323 case EOpGreaterThanEqual: out << "Compare Greater Than or Equal"; break;
324 case EOpVectorEqual: out << "Equal"; break;
325 case EOpVectorNotEqual: out << "NotEqual"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000326
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700327 case EOpMod: out << "mod"; break;
328 case EOpPow: out << "pow"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000329
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700330 case EOpAtan: out << "arc tangent"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000331
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700332 case EOpMin: out << "min"; break;
333 case EOpMax: out << "max"; break;
334 case EOpClamp: out << "clamp"; break;
335 case EOpMix: out << "mix"; break;
336 case EOpStep: out << "step"; break;
337 case EOpSmoothStep: out << "smoothstep"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000338
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700339 case EOpDistance: out << "distance"; break;
340 case EOpDot: out << "dot-product"; break;
341 case EOpCross: out << "cross-product"; break;
342 case EOpFaceForward: out << "face-forward"; break;
343 case EOpReflect: out << "reflect"; break;
344 case EOpRefract: out << "refract"; break;
345 case EOpMul: out << "component-wise multiply"; break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000346
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700347 case EOpDeclaration: out << "Declaration: "; break;
Jamie Madill3b5c2da2014-08-19 15:23:32 -0400348 case EOpInvariantDeclaration: out << "Invariant Declaration: "; break;
daniel@transgaming.coma9ae4aa2011-10-19 13:29:27 +0000349
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700350 default:
351 out.prefix(EPrefixError);
352 out << "Bad aggregation op";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000353 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000354
alokp@chromium.org76b82082010-03-24 17:59:39 +0000355 if (node->getOp() != EOpSequence && node->getOp() != EOpParameters)
alokp@chromium.org7beea402010-09-15 21:18:34 +0000356 out << " (" << node->getCompleteString() << ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000357
alokp@chromium.org7beea402010-09-15 21:18:34 +0000358 out << "\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000359
alokp@chromium.org76b82082010-03-24 17:59:39 +0000360 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000361}
362
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700363bool TOutputTraverser::visitSelection(Visit visit, TIntermSelection *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000364{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700365 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000366
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700367 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000368
alokp@chromium.org7beea402010-09-15 21:18:34 +0000369 out << "Test condition and select";
370 out << " (" << node->getCompleteString() << ")\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000371
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700372 ++mDepth;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000373
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700374 OutputTreeText(sink, node, mDepth);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000375 out << "Condition\n";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000376 node->getCondition()->traverse(this);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000377
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700378 OutputTreeText(sink, node, mDepth);
379 if (node->getTrueBlock())
380 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000381 out << "true case\n";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000382 node->getTrueBlock()->traverse(this);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700383 }
384 else
385 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000386 out << "true case is null\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700387 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000388
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700389 if (node->getFalseBlock())
390 {
391 OutputTreeText(sink, node, mDepth);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000392 out << "false case\n";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000393 node->getFalseBlock()->traverse(this);
394 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000395
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700396 --mDepth;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000397
alokp@chromium.org76b82082010-03-24 17:59:39 +0000398 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000399}
400
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700401void TOutputTraverser::visitConstantUnion(TIntermConstantUnion *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000402{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700403 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000404
Jamie Madill94bf7f22013-07-08 13:31:15 -0400405 size_t size = node->getType().getObjectSize();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000406
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700407 for (size_t i = 0; i < size; i++)
408 {
409 OutputTreeText(out, node, mDepth);
410 switch (node->getUnionArrayPointer()[i].getType())
411 {
412 case EbtBool:
413 if (node->getUnionArrayPointer()[i].getBConst())
414 out << "true";
415 else
416 out << "false";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000417
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700418 out << " (" << "const bool" << ")";
419 out << "\n";
420 break;
421 case EbtFloat:
422 out << node->getUnionArrayPointer()[i].getFConst();
423 out << " (const float)\n";
424 break;
425 case EbtInt:
426 out << node->getUnionArrayPointer()[i].getIConst();
427 out << " (const int)\n";
428 break;
429 case EbtUInt:
430 out << node->getUnionArrayPointer()[i].getUConst();
431 out << " (const uint)\n";
432 break;
433 default:
434 out.message(EPrefixInternalError, node->getLine(), "Unknown constant");
435 break;
alokp@chromium.org76b82082010-03-24 17:59:39 +0000436 }
437 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000438}
439
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700440bool TOutputTraverser::visitLoop(Visit visit, TIntermLoop *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000441{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700442 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000443
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700444 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000445
alokp@chromium.org7beea402010-09-15 21:18:34 +0000446 out << "Loop with condition ";
alokp@chromium.org52813552010-11-16 18:36:09 +0000447 if (node->getType() == ELoopDoWhile)
alokp@chromium.org7beea402010-09-15 21:18:34 +0000448 out << "not ";
449 out << "tested first\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000450
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700451 ++mDepth;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000452
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700453 OutputTreeText(sink, node, mDepth);
454 if (node->getCondition())
455 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000456 out << "Loop Condition\n";
alokp@chromium.org52813552010-11-16 18:36:09 +0000457 node->getCondition()->traverse(this);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700458 }
459 else
460 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000461 out << "No loop condition\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700462 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000463
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700464 OutputTreeText(sink, node, mDepth);
465 if (node->getBody())
466 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000467 out << "Loop Body\n";
alokp@chromium.org76b82082010-03-24 17:59:39 +0000468 node->getBody()->traverse(this);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700469 }
470 else
471 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000472 out << "No loop body\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700473 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000474
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700475 if (node->getExpression())
476 {
477 OutputTreeText(sink, node, mDepth);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000478 out << "Loop Terminal Expression\n";
alokp@chromium.org52813552010-11-16 18:36:09 +0000479 node->getExpression()->traverse(this);
alokp@chromium.org76b82082010-03-24 17:59:39 +0000480 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000481
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700482 --mDepth;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000483
alokp@chromium.org76b82082010-03-24 17:59:39 +0000484 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000485}
486
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700487bool TOutputTraverser::visitBranch(Visit visit, TIntermBranch *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000488{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700489 TInfoSinkBase &out = sink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000490
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700491 OutputTreeText(out, node, mDepth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000492
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700493 switch (node->getFlowOp())
494 {
495 case EOpKill: out << "Branch: Kill"; break;
496 case EOpBreak: out << "Branch: Break"; break;
497 case EOpContinue: out << "Branch: Continue"; break;
498 case EOpReturn: out << "Branch: Return"; break;
499 default: out << "Branch: Unknown Branch"; break;
alokp@chromium.org76b82082010-03-24 17:59:39 +0000500 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000501
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700502 if (node->getExpression())
503 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000504 out << " with expression\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700505 ++mDepth;
alokp@chromium.org76b82082010-03-24 17:59:39 +0000506 node->getExpression()->traverse(this);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700507 --mDepth;
508 }
509 else
510 {
alokp@chromium.org7beea402010-09-15 21:18:34 +0000511 out << "\n";
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700512 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000513
alokp@chromium.org76b82082010-03-24 17:59:39 +0000514 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000515}
516
517//
518// This function is the one to call externally to start the traversal.
519// Individual functions can be initialized to 0 to skip processing of that
520// type of node. It's children will still be processed.
521//
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700522void TIntermediate::outputTree(TIntermNode *root)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000523{
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700524 if (root == NULL)
alokp@chromium.org76b82082010-03-24 17:59:39 +0000525 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000526
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700527 TOutputTraverser it(mInfoSink.info);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000528
alokp@chromium.org76b82082010-03-24 17:59:39 +0000529 root->traverse(&it);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000530}