xref: /aosp_15_r20/external/angle/src/compiler/translator/OutputTree.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2002 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker 
7*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/SymbolTable.h"
8*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/tree_util/IntermTraverse.h"
9*8975f5c5SAndroid Build Coastguard Worker 
10*8975f5c5SAndroid Build Coastguard Worker namespace sh
11*8975f5c5SAndroid Build Coastguard Worker {
12*8975f5c5SAndroid Build Coastguard Worker 
13*8975f5c5SAndroid Build Coastguard Worker namespace
14*8975f5c5SAndroid Build Coastguard Worker {
15*8975f5c5SAndroid Build Coastguard Worker 
OutputFunction(TInfoSinkBase & out,const char * prefix,const TFunction * function)16*8975f5c5SAndroid Build Coastguard Worker void OutputFunction(TInfoSinkBase &out, const char *prefix, const TFunction *function)
17*8975f5c5SAndroid Build Coastguard Worker {
18*8975f5c5SAndroid Build Coastguard Worker     out << prefix << ": " << static_cast<const TSymbol &>(*function);
19*8975f5c5SAndroid Build Coastguard Worker }
20*8975f5c5SAndroid Build Coastguard Worker 
OutputVariable(TInfoSinkBase & out,const TVariable & variable)21*8975f5c5SAndroid Build Coastguard Worker void OutputVariable(TInfoSinkBase &out, const TVariable &variable)
22*8975f5c5SAndroid Build Coastguard Worker {
23*8975f5c5SAndroid Build Coastguard Worker     out << static_cast<const TSymbol &>(variable) << " (" << variable.getType() << ")";
24*8975f5c5SAndroid Build Coastguard Worker }
25*8975f5c5SAndroid Build Coastguard Worker 
26*8975f5c5SAndroid Build Coastguard Worker // Two purposes:
27*8975f5c5SAndroid Build Coastguard Worker // 1.  Show an example of how to iterate tree.  Functions can also directly call traverse() on
28*8975f5c5SAndroid Build Coastguard Worker //     children themselves to have finer grained control over the process than shown here, though
29*8975f5c5SAndroid Build Coastguard Worker //     that's not recommended if it can be avoided.
30*8975f5c5SAndroid Build Coastguard Worker // 2.  Print out a text based description of the tree.
31*8975f5c5SAndroid Build Coastguard Worker 
32*8975f5c5SAndroid Build Coastguard Worker // The traverser subclass is used to carry along data from node to node in the traversal.
33*8975f5c5SAndroid Build Coastguard Worker class TOutputTraverser : public TIntermTraverser
34*8975f5c5SAndroid Build Coastguard Worker {
35*8975f5c5SAndroid Build Coastguard Worker   public:
TOutputTraverser(TInfoSinkBase & out)36*8975f5c5SAndroid Build Coastguard Worker     TOutputTraverser(TInfoSinkBase &out)
37*8975f5c5SAndroid Build Coastguard Worker         : TIntermTraverser(true, false, false), mOut(out), mIndentDepth(0)
38*8975f5c5SAndroid Build Coastguard Worker     {}
39*8975f5c5SAndroid Build Coastguard Worker 
40*8975f5c5SAndroid Build Coastguard Worker   protected:
41*8975f5c5SAndroid Build Coastguard Worker     void visitSymbol(TIntermSymbol *) override;
42*8975f5c5SAndroid Build Coastguard Worker     void visitConstantUnion(TIntermConstantUnion *) override;
43*8975f5c5SAndroid Build Coastguard Worker     bool visitSwizzle(Visit visit, TIntermSwizzle *node) override;
44*8975f5c5SAndroid Build Coastguard Worker     bool visitBinary(Visit visit, TIntermBinary *) override;
45*8975f5c5SAndroid Build Coastguard Worker     bool visitUnary(Visit visit, TIntermUnary *) override;
46*8975f5c5SAndroid Build Coastguard Worker     bool visitTernary(Visit visit, TIntermTernary *node) override;
47*8975f5c5SAndroid Build Coastguard Worker     bool visitIfElse(Visit visit, TIntermIfElse *node) override;
48*8975f5c5SAndroid Build Coastguard Worker     bool visitSwitch(Visit visit, TIntermSwitch *node) override;
49*8975f5c5SAndroid Build Coastguard Worker     bool visitCase(Visit visit, TIntermCase *node) override;
50*8975f5c5SAndroid Build Coastguard Worker     void visitFunctionPrototype(TIntermFunctionPrototype *node) override;
51*8975f5c5SAndroid Build Coastguard Worker     bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override;
52*8975f5c5SAndroid Build Coastguard Worker     bool visitAggregate(Visit visit, TIntermAggregate *) override;
53*8975f5c5SAndroid Build Coastguard Worker     bool visitBlock(Visit visit, TIntermBlock *) override;
54*8975f5c5SAndroid Build Coastguard Worker     bool visitGlobalQualifierDeclaration(Visit visit,
55*8975f5c5SAndroid Build Coastguard Worker                                          TIntermGlobalQualifierDeclaration *node) override;
56*8975f5c5SAndroid Build Coastguard Worker     bool visitDeclaration(Visit visit, TIntermDeclaration *node) override;
57*8975f5c5SAndroid Build Coastguard Worker     bool visitLoop(Visit visit, TIntermLoop *) override;
58*8975f5c5SAndroid Build Coastguard Worker     bool visitBranch(Visit visit, TIntermBranch *) override;
59*8975f5c5SAndroid Build Coastguard Worker 
getCurrentIndentDepth() const60*8975f5c5SAndroid Build Coastguard Worker     int getCurrentIndentDepth() const { return mIndentDepth + getCurrentTraversalDepth(); }
61*8975f5c5SAndroid Build Coastguard Worker 
62*8975f5c5SAndroid Build Coastguard Worker     TInfoSinkBase &mOut;
63*8975f5c5SAndroid Build Coastguard Worker     int mIndentDepth;
64*8975f5c5SAndroid Build Coastguard Worker };
65*8975f5c5SAndroid Build Coastguard Worker 
66*8975f5c5SAndroid Build Coastguard Worker //
67*8975f5c5SAndroid Build Coastguard Worker // Helper functions for printing, not part of traversing.
68*8975f5c5SAndroid Build Coastguard Worker //
OutputTreeText(TInfoSinkBase & out,TIntermNode * node,const int depth)69*8975f5c5SAndroid Build Coastguard Worker void OutputTreeText(TInfoSinkBase &out, TIntermNode *node, const int depth)
70*8975f5c5SAndroid Build Coastguard Worker {
71*8975f5c5SAndroid Build Coastguard Worker     int i;
72*8975f5c5SAndroid Build Coastguard Worker 
73*8975f5c5SAndroid Build Coastguard Worker     out.location(node->getLine().first_file, node->getLine().first_line);
74*8975f5c5SAndroid Build Coastguard Worker 
75*8975f5c5SAndroid Build Coastguard Worker     for (i = 0; i < depth; ++i)
76*8975f5c5SAndroid Build Coastguard Worker         out << "  ";
77*8975f5c5SAndroid Build Coastguard Worker }
78*8975f5c5SAndroid Build Coastguard Worker 
79*8975f5c5SAndroid Build Coastguard Worker //
80*8975f5c5SAndroid Build Coastguard Worker // The rest of the file are the traversal functions.  The last one
81*8975f5c5SAndroid Build Coastguard Worker // is the one that starts the traversal.
82*8975f5c5SAndroid Build Coastguard Worker //
83*8975f5c5SAndroid Build Coastguard Worker // Return true from interior nodes to have the external traversal
84*8975f5c5SAndroid Build Coastguard Worker // continue on to children.  If you process children yourself,
85*8975f5c5SAndroid Build Coastguard Worker // return false.
86*8975f5c5SAndroid Build Coastguard Worker //
87*8975f5c5SAndroid Build Coastguard Worker 
visitSymbol(TIntermSymbol * node)88*8975f5c5SAndroid Build Coastguard Worker void TOutputTraverser::visitSymbol(TIntermSymbol *node)
89*8975f5c5SAndroid Build Coastguard Worker {
90*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
91*8975f5c5SAndroid Build Coastguard Worker     OutputVariable(mOut, node->variable());
92*8975f5c5SAndroid Build Coastguard Worker     mOut << "\n";
93*8975f5c5SAndroid Build Coastguard Worker }
94*8975f5c5SAndroid Build Coastguard Worker 
visitSwizzle(Visit visit,TIntermSwizzle * node)95*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitSwizzle(Visit visit, TIntermSwizzle *node)
96*8975f5c5SAndroid Build Coastguard Worker {
97*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
98*8975f5c5SAndroid Build Coastguard Worker     mOut << "vector swizzle (";
99*8975f5c5SAndroid Build Coastguard Worker     node->writeOffsetsAsXYZW(&mOut);
100*8975f5c5SAndroid Build Coastguard Worker     mOut << ")";
101*8975f5c5SAndroid Build Coastguard Worker 
102*8975f5c5SAndroid Build Coastguard Worker     mOut << " (" << node->getType() << ")";
103*8975f5c5SAndroid Build Coastguard Worker     mOut << "\n";
104*8975f5c5SAndroid Build Coastguard Worker     return true;
105*8975f5c5SAndroid Build Coastguard Worker }
106*8975f5c5SAndroid Build Coastguard Worker 
visitBinary(Visit visit,TIntermBinary * node)107*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node)
108*8975f5c5SAndroid Build Coastguard Worker {
109*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
110*8975f5c5SAndroid Build Coastguard Worker 
111*8975f5c5SAndroid Build Coastguard Worker     switch (node->getOp())
112*8975f5c5SAndroid Build Coastguard Worker     {
113*8975f5c5SAndroid Build Coastguard Worker         case EOpComma:
114*8975f5c5SAndroid Build Coastguard Worker             mOut << "comma";
115*8975f5c5SAndroid Build Coastguard Worker             break;
116*8975f5c5SAndroid Build Coastguard Worker         case EOpAssign:
117*8975f5c5SAndroid Build Coastguard Worker             mOut << "move second child to first child";
118*8975f5c5SAndroid Build Coastguard Worker             break;
119*8975f5c5SAndroid Build Coastguard Worker         case EOpInitialize:
120*8975f5c5SAndroid Build Coastguard Worker             mOut << "initialize first child with second child";
121*8975f5c5SAndroid Build Coastguard Worker             break;
122*8975f5c5SAndroid Build Coastguard Worker         case EOpAddAssign:
123*8975f5c5SAndroid Build Coastguard Worker             mOut << "add second child into first child";
124*8975f5c5SAndroid Build Coastguard Worker             break;
125*8975f5c5SAndroid Build Coastguard Worker         case EOpSubAssign:
126*8975f5c5SAndroid Build Coastguard Worker             mOut << "subtract second child into first child";
127*8975f5c5SAndroid Build Coastguard Worker             break;
128*8975f5c5SAndroid Build Coastguard Worker         case EOpMulAssign:
129*8975f5c5SAndroid Build Coastguard Worker             mOut << "multiply second child into first child";
130*8975f5c5SAndroid Build Coastguard Worker             break;
131*8975f5c5SAndroid Build Coastguard Worker         case EOpVectorTimesMatrixAssign:
132*8975f5c5SAndroid Build Coastguard Worker             mOut << "matrix mult second child into first child";
133*8975f5c5SAndroid Build Coastguard Worker             break;
134*8975f5c5SAndroid Build Coastguard Worker         case EOpVectorTimesScalarAssign:
135*8975f5c5SAndroid Build Coastguard Worker             mOut << "vector scale second child into first child";
136*8975f5c5SAndroid Build Coastguard Worker             break;
137*8975f5c5SAndroid Build Coastguard Worker         case EOpMatrixTimesScalarAssign:
138*8975f5c5SAndroid Build Coastguard Worker             mOut << "matrix scale second child into first child";
139*8975f5c5SAndroid Build Coastguard Worker             break;
140*8975f5c5SAndroid Build Coastguard Worker         case EOpMatrixTimesMatrixAssign:
141*8975f5c5SAndroid Build Coastguard Worker             mOut << "matrix mult second child into first child";
142*8975f5c5SAndroid Build Coastguard Worker             break;
143*8975f5c5SAndroid Build Coastguard Worker         case EOpDivAssign:
144*8975f5c5SAndroid Build Coastguard Worker             mOut << "divide second child into first child";
145*8975f5c5SAndroid Build Coastguard Worker             break;
146*8975f5c5SAndroid Build Coastguard Worker         case EOpIModAssign:
147*8975f5c5SAndroid Build Coastguard Worker             mOut << "modulo second child into first child";
148*8975f5c5SAndroid Build Coastguard Worker             break;
149*8975f5c5SAndroid Build Coastguard Worker         case EOpBitShiftLeftAssign:
150*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise shift first child left by second child";
151*8975f5c5SAndroid Build Coastguard Worker             break;
152*8975f5c5SAndroid Build Coastguard Worker         case EOpBitShiftRightAssign:
153*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise shift first child right by second child";
154*8975f5c5SAndroid Build Coastguard Worker             break;
155*8975f5c5SAndroid Build Coastguard Worker         case EOpBitwiseAndAssign:
156*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise and second child into first child";
157*8975f5c5SAndroid Build Coastguard Worker             break;
158*8975f5c5SAndroid Build Coastguard Worker         case EOpBitwiseXorAssign:
159*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise xor second child into first child";
160*8975f5c5SAndroid Build Coastguard Worker             break;
161*8975f5c5SAndroid Build Coastguard Worker         case EOpBitwiseOrAssign:
162*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise or second child into first child";
163*8975f5c5SAndroid Build Coastguard Worker             break;
164*8975f5c5SAndroid Build Coastguard Worker 
165*8975f5c5SAndroid Build Coastguard Worker         case EOpIndexDirect:
166*8975f5c5SAndroid Build Coastguard Worker             mOut << "direct index";
167*8975f5c5SAndroid Build Coastguard Worker             break;
168*8975f5c5SAndroid Build Coastguard Worker         case EOpIndexIndirect:
169*8975f5c5SAndroid Build Coastguard Worker             mOut << "indirect index";
170*8975f5c5SAndroid Build Coastguard Worker             break;
171*8975f5c5SAndroid Build Coastguard Worker         case EOpIndexDirectStruct:
172*8975f5c5SAndroid Build Coastguard Worker             mOut << "direct index for structure";
173*8975f5c5SAndroid Build Coastguard Worker             break;
174*8975f5c5SAndroid Build Coastguard Worker         case EOpIndexDirectInterfaceBlock:
175*8975f5c5SAndroid Build Coastguard Worker             mOut << "direct index for interface block";
176*8975f5c5SAndroid Build Coastguard Worker             break;
177*8975f5c5SAndroid Build Coastguard Worker 
178*8975f5c5SAndroid Build Coastguard Worker         case EOpAdd:
179*8975f5c5SAndroid Build Coastguard Worker             mOut << "add";
180*8975f5c5SAndroid Build Coastguard Worker             break;
181*8975f5c5SAndroid Build Coastguard Worker         case EOpSub:
182*8975f5c5SAndroid Build Coastguard Worker             mOut << "subtract";
183*8975f5c5SAndroid Build Coastguard Worker             break;
184*8975f5c5SAndroid Build Coastguard Worker         case EOpMul:
185*8975f5c5SAndroid Build Coastguard Worker             mOut << "component-wise multiply";
186*8975f5c5SAndroid Build Coastguard Worker             break;
187*8975f5c5SAndroid Build Coastguard Worker         case EOpDiv:
188*8975f5c5SAndroid Build Coastguard Worker             mOut << "divide";
189*8975f5c5SAndroid Build Coastguard Worker             break;
190*8975f5c5SAndroid Build Coastguard Worker         case EOpIMod:
191*8975f5c5SAndroid Build Coastguard Worker             mOut << "modulo";
192*8975f5c5SAndroid Build Coastguard Worker             break;
193*8975f5c5SAndroid Build Coastguard Worker         case EOpBitShiftLeft:
194*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise shift left";
195*8975f5c5SAndroid Build Coastguard Worker             break;
196*8975f5c5SAndroid Build Coastguard Worker         case EOpBitShiftRight:
197*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise shift right";
198*8975f5c5SAndroid Build Coastguard Worker             break;
199*8975f5c5SAndroid Build Coastguard Worker         case EOpBitwiseAnd:
200*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise and";
201*8975f5c5SAndroid Build Coastguard Worker             break;
202*8975f5c5SAndroid Build Coastguard Worker         case EOpBitwiseXor:
203*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise xor";
204*8975f5c5SAndroid Build Coastguard Worker             break;
205*8975f5c5SAndroid Build Coastguard Worker         case EOpBitwiseOr:
206*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise or";
207*8975f5c5SAndroid Build Coastguard Worker             break;
208*8975f5c5SAndroid Build Coastguard Worker 
209*8975f5c5SAndroid Build Coastguard Worker         case EOpEqual:
210*8975f5c5SAndroid Build Coastguard Worker             mOut << "Compare Equal";
211*8975f5c5SAndroid Build Coastguard Worker             break;
212*8975f5c5SAndroid Build Coastguard Worker         case EOpNotEqual:
213*8975f5c5SAndroid Build Coastguard Worker             mOut << "Compare Not Equal";
214*8975f5c5SAndroid Build Coastguard Worker             break;
215*8975f5c5SAndroid Build Coastguard Worker         case EOpLessThan:
216*8975f5c5SAndroid Build Coastguard Worker             mOut << "Compare Less Than";
217*8975f5c5SAndroid Build Coastguard Worker             break;
218*8975f5c5SAndroid Build Coastguard Worker         case EOpGreaterThan:
219*8975f5c5SAndroid Build Coastguard Worker             mOut << "Compare Greater Than";
220*8975f5c5SAndroid Build Coastguard Worker             break;
221*8975f5c5SAndroid Build Coastguard Worker         case EOpLessThanEqual:
222*8975f5c5SAndroid Build Coastguard Worker             mOut << "Compare Less Than or Equal";
223*8975f5c5SAndroid Build Coastguard Worker             break;
224*8975f5c5SAndroid Build Coastguard Worker         case EOpGreaterThanEqual:
225*8975f5c5SAndroid Build Coastguard Worker             mOut << "Compare Greater Than or Equal";
226*8975f5c5SAndroid Build Coastguard Worker             break;
227*8975f5c5SAndroid Build Coastguard Worker 
228*8975f5c5SAndroid Build Coastguard Worker         case EOpVectorTimesScalar:
229*8975f5c5SAndroid Build Coastguard Worker             mOut << "vector-scale";
230*8975f5c5SAndroid Build Coastguard Worker             break;
231*8975f5c5SAndroid Build Coastguard Worker         case EOpVectorTimesMatrix:
232*8975f5c5SAndroid Build Coastguard Worker             mOut << "vector-times-matrix";
233*8975f5c5SAndroid Build Coastguard Worker             break;
234*8975f5c5SAndroid Build Coastguard Worker         case EOpMatrixTimesVector:
235*8975f5c5SAndroid Build Coastguard Worker             mOut << "matrix-times-vector";
236*8975f5c5SAndroid Build Coastguard Worker             break;
237*8975f5c5SAndroid Build Coastguard Worker         case EOpMatrixTimesScalar:
238*8975f5c5SAndroid Build Coastguard Worker             mOut << "matrix-scale";
239*8975f5c5SAndroid Build Coastguard Worker             break;
240*8975f5c5SAndroid Build Coastguard Worker         case EOpMatrixTimesMatrix:
241*8975f5c5SAndroid Build Coastguard Worker             mOut << "matrix-multiply";
242*8975f5c5SAndroid Build Coastguard Worker             break;
243*8975f5c5SAndroid Build Coastguard Worker 
244*8975f5c5SAndroid Build Coastguard Worker         case EOpLogicalOr:
245*8975f5c5SAndroid Build Coastguard Worker             mOut << "logical-or";
246*8975f5c5SAndroid Build Coastguard Worker             break;
247*8975f5c5SAndroid Build Coastguard Worker         case EOpLogicalXor:
248*8975f5c5SAndroid Build Coastguard Worker             mOut << "logical-xor";
249*8975f5c5SAndroid Build Coastguard Worker             break;
250*8975f5c5SAndroid Build Coastguard Worker         case EOpLogicalAnd:
251*8975f5c5SAndroid Build Coastguard Worker             mOut << "logical-and";
252*8975f5c5SAndroid Build Coastguard Worker             break;
253*8975f5c5SAndroid Build Coastguard Worker         default:
254*8975f5c5SAndroid Build Coastguard Worker             mOut << "<unknown op>";
255*8975f5c5SAndroid Build Coastguard Worker     }
256*8975f5c5SAndroid Build Coastguard Worker 
257*8975f5c5SAndroid Build Coastguard Worker     mOut << " (" << node->getType() << ")";
258*8975f5c5SAndroid Build Coastguard Worker 
259*8975f5c5SAndroid Build Coastguard Worker     mOut << "\n";
260*8975f5c5SAndroid Build Coastguard Worker 
261*8975f5c5SAndroid Build Coastguard Worker     // Special handling for direct indexes. Because constant
262*8975f5c5SAndroid Build Coastguard Worker     // unions are not aware they are struct indexes, treat them
263*8975f5c5SAndroid Build Coastguard Worker     // here where we have that contextual knowledge.
264*8975f5c5SAndroid Build Coastguard Worker     if (node->getOp() == EOpIndexDirectStruct || node->getOp() == EOpIndexDirectInterfaceBlock)
265*8975f5c5SAndroid Build Coastguard Worker     {
266*8975f5c5SAndroid Build Coastguard Worker         node->getLeft()->traverse(this);
267*8975f5c5SAndroid Build Coastguard Worker 
268*8975f5c5SAndroid Build Coastguard Worker         TIntermConstantUnion *intermConstantUnion = node->getRight()->getAsConstantUnion();
269*8975f5c5SAndroid Build Coastguard Worker         ASSERT(intermConstantUnion);
270*8975f5c5SAndroid Build Coastguard Worker 
271*8975f5c5SAndroid Build Coastguard Worker         OutputTreeText(mOut, intermConstantUnion, getCurrentIndentDepth() + 1);
272*8975f5c5SAndroid Build Coastguard Worker 
273*8975f5c5SAndroid Build Coastguard Worker         // The following code finds the field name from the constant union
274*8975f5c5SAndroid Build Coastguard Worker         const TConstantUnion *constantUnion   = intermConstantUnion->getConstantValue();
275*8975f5c5SAndroid Build Coastguard Worker         const TStructure *structure           = node->getLeft()->getType().getStruct();
276*8975f5c5SAndroid Build Coastguard Worker         const TInterfaceBlock *interfaceBlock = node->getLeft()->getType().getInterfaceBlock();
277*8975f5c5SAndroid Build Coastguard Worker         ASSERT(structure || interfaceBlock);
278*8975f5c5SAndroid Build Coastguard Worker 
279*8975f5c5SAndroid Build Coastguard Worker         const TFieldList &fields = structure ? structure->fields() : interfaceBlock->fields();
280*8975f5c5SAndroid Build Coastguard Worker 
281*8975f5c5SAndroid Build Coastguard Worker         const TField *field = fields[constantUnion->getIConst()];
282*8975f5c5SAndroid Build Coastguard Worker 
283*8975f5c5SAndroid Build Coastguard Worker         mOut << constantUnion->getIConst() << " (field '" << field->name() << "')";
284*8975f5c5SAndroid Build Coastguard Worker 
285*8975f5c5SAndroid Build Coastguard Worker         mOut << "\n";
286*8975f5c5SAndroid Build Coastguard Worker 
287*8975f5c5SAndroid Build Coastguard Worker         return false;
288*8975f5c5SAndroid Build Coastguard Worker     }
289*8975f5c5SAndroid Build Coastguard Worker 
290*8975f5c5SAndroid Build Coastguard Worker     return true;
291*8975f5c5SAndroid Build Coastguard Worker }
292*8975f5c5SAndroid Build Coastguard Worker 
visitUnary(Visit visit,TIntermUnary * node)293*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitUnary(Visit visit, TIntermUnary *node)
294*8975f5c5SAndroid Build Coastguard Worker {
295*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
296*8975f5c5SAndroid Build Coastguard Worker 
297*8975f5c5SAndroid Build Coastguard Worker     const TOperator op = node->getOp();
298*8975f5c5SAndroid Build Coastguard Worker 
299*8975f5c5SAndroid Build Coastguard Worker     switch (op)
300*8975f5c5SAndroid Build Coastguard Worker     {
301*8975f5c5SAndroid Build Coastguard Worker         // Give verbose names for ops that have special syntax and some built-in functions that are
302*8975f5c5SAndroid Build Coastguard Worker         // easy to confuse with others, but mostly use GLSL names for functions.
303*8975f5c5SAndroid Build Coastguard Worker         case EOpNegative:
304*8975f5c5SAndroid Build Coastguard Worker             mOut << "Negate value";
305*8975f5c5SAndroid Build Coastguard Worker             break;
306*8975f5c5SAndroid Build Coastguard Worker         case EOpPositive:
307*8975f5c5SAndroid Build Coastguard Worker             mOut << "Positive sign";
308*8975f5c5SAndroid Build Coastguard Worker             break;
309*8975f5c5SAndroid Build Coastguard Worker         case EOpLogicalNot:
310*8975f5c5SAndroid Build Coastguard Worker             mOut << "negation";
311*8975f5c5SAndroid Build Coastguard Worker             break;
312*8975f5c5SAndroid Build Coastguard Worker         case EOpBitwiseNot:
313*8975f5c5SAndroid Build Coastguard Worker             mOut << "bit-wise not";
314*8975f5c5SAndroid Build Coastguard Worker             break;
315*8975f5c5SAndroid Build Coastguard Worker 
316*8975f5c5SAndroid Build Coastguard Worker         case EOpPostIncrement:
317*8975f5c5SAndroid Build Coastguard Worker             mOut << "Post-Increment";
318*8975f5c5SAndroid Build Coastguard Worker             break;
319*8975f5c5SAndroid Build Coastguard Worker         case EOpPostDecrement:
320*8975f5c5SAndroid Build Coastguard Worker             mOut << "Post-Decrement";
321*8975f5c5SAndroid Build Coastguard Worker             break;
322*8975f5c5SAndroid Build Coastguard Worker         case EOpPreIncrement:
323*8975f5c5SAndroid Build Coastguard Worker             mOut << "Pre-Increment";
324*8975f5c5SAndroid Build Coastguard Worker             break;
325*8975f5c5SAndroid Build Coastguard Worker         case EOpPreDecrement:
326*8975f5c5SAndroid Build Coastguard Worker             mOut << "Pre-Decrement";
327*8975f5c5SAndroid Build Coastguard Worker             break;
328*8975f5c5SAndroid Build Coastguard Worker 
329*8975f5c5SAndroid Build Coastguard Worker         case EOpArrayLength:
330*8975f5c5SAndroid Build Coastguard Worker             mOut << "Array length";
331*8975f5c5SAndroid Build Coastguard Worker             break;
332*8975f5c5SAndroid Build Coastguard Worker 
333*8975f5c5SAndroid Build Coastguard Worker         case EOpNotComponentWise:
334*8975f5c5SAndroid Build Coastguard Worker             mOut << "component-wise not";
335*8975f5c5SAndroid Build Coastguard Worker             break;
336*8975f5c5SAndroid Build Coastguard Worker 
337*8975f5c5SAndroid Build Coastguard Worker         default:
338*8975f5c5SAndroid Build Coastguard Worker             if (BuiltInGroup::IsBuiltIn(op))
339*8975f5c5SAndroid Build Coastguard Worker             {
340*8975f5c5SAndroid Build Coastguard Worker                 OutputFunction(mOut, "Call a built-in function", node->getFunction());
341*8975f5c5SAndroid Build Coastguard Worker             }
342*8975f5c5SAndroid Build Coastguard Worker             else
343*8975f5c5SAndroid Build Coastguard Worker             {
344*8975f5c5SAndroid Build Coastguard Worker                 mOut << GetOperatorString(node->getOp());
345*8975f5c5SAndroid Build Coastguard Worker             }
346*8975f5c5SAndroid Build Coastguard Worker             break;
347*8975f5c5SAndroid Build Coastguard Worker     }
348*8975f5c5SAndroid Build Coastguard Worker 
349*8975f5c5SAndroid Build Coastguard Worker     mOut << " (" << node->getType() << ")";
350*8975f5c5SAndroid Build Coastguard Worker 
351*8975f5c5SAndroid Build Coastguard Worker     mOut << "\n";
352*8975f5c5SAndroid Build Coastguard Worker 
353*8975f5c5SAndroid Build Coastguard Worker     return true;
354*8975f5c5SAndroid Build Coastguard Worker }
355*8975f5c5SAndroid Build Coastguard Worker 
visitFunctionDefinition(Visit visit,TIntermFunctionDefinition * node)356*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node)
357*8975f5c5SAndroid Build Coastguard Worker {
358*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
359*8975f5c5SAndroid Build Coastguard Worker     mOut << "Function Definition:\n";
360*8975f5c5SAndroid Build Coastguard Worker     return true;
361*8975f5c5SAndroid Build Coastguard Worker }
362*8975f5c5SAndroid Build Coastguard Worker 
visitGlobalQualifierDeclaration(Visit visit,TIntermGlobalQualifierDeclaration * node)363*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitGlobalQualifierDeclaration(Visit visit,
364*8975f5c5SAndroid Build Coastguard Worker                                                        TIntermGlobalQualifierDeclaration *node)
365*8975f5c5SAndroid Build Coastguard Worker {
366*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
367*8975f5c5SAndroid Build Coastguard Worker     if (node->isPrecise())
368*8975f5c5SAndroid Build Coastguard Worker     {
369*8975f5c5SAndroid Build Coastguard Worker         mOut << "Precise Declaration:\n";
370*8975f5c5SAndroid Build Coastguard Worker     }
371*8975f5c5SAndroid Build Coastguard Worker     else
372*8975f5c5SAndroid Build Coastguard Worker     {
373*8975f5c5SAndroid Build Coastguard Worker         mOut << "Invariant Declaration:\n";
374*8975f5c5SAndroid Build Coastguard Worker     }
375*8975f5c5SAndroid Build Coastguard Worker     return true;
376*8975f5c5SAndroid Build Coastguard Worker }
377*8975f5c5SAndroid Build Coastguard Worker 
visitFunctionPrototype(TIntermFunctionPrototype * node)378*8975f5c5SAndroid Build Coastguard Worker void TOutputTraverser::visitFunctionPrototype(TIntermFunctionPrototype *node)
379*8975f5c5SAndroid Build Coastguard Worker {
380*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
381*8975f5c5SAndroid Build Coastguard Worker     OutputFunction(mOut, "Function Prototype", node->getFunction());
382*8975f5c5SAndroid Build Coastguard Worker     mOut << " (" << node->getType() << ")";
383*8975f5c5SAndroid Build Coastguard Worker     mOut << "\n";
384*8975f5c5SAndroid Build Coastguard Worker     size_t paramCount = node->getFunction()->getParamCount();
385*8975f5c5SAndroid Build Coastguard Worker     for (size_t i = 0; i < paramCount; ++i)
386*8975f5c5SAndroid Build Coastguard Worker     {
387*8975f5c5SAndroid Build Coastguard Worker         const TVariable *param = node->getFunction()->getParam(i);
388*8975f5c5SAndroid Build Coastguard Worker         OutputTreeText(mOut, node, getCurrentIndentDepth() + 1);
389*8975f5c5SAndroid Build Coastguard Worker         mOut << "parameter: ";
390*8975f5c5SAndroid Build Coastguard Worker         OutputVariable(mOut, *param);
391*8975f5c5SAndroid Build Coastguard Worker         mOut << "\n";
392*8975f5c5SAndroid Build Coastguard Worker     }
393*8975f5c5SAndroid Build Coastguard Worker }
394*8975f5c5SAndroid Build Coastguard Worker 
visitAggregate(Visit visit,TIntermAggregate * node)395*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
396*8975f5c5SAndroid Build Coastguard Worker {
397*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
398*8975f5c5SAndroid Build Coastguard Worker 
399*8975f5c5SAndroid Build Coastguard Worker     const TOperator op = node->getOp();
400*8975f5c5SAndroid Build Coastguard Worker 
401*8975f5c5SAndroid Build Coastguard Worker     if (op == EOpNull)
402*8975f5c5SAndroid Build Coastguard Worker     {
403*8975f5c5SAndroid Build Coastguard Worker         mOut.prefix(SH_ERROR);
404*8975f5c5SAndroid Build Coastguard Worker         mOut << "node is still EOpNull!\n";
405*8975f5c5SAndroid Build Coastguard Worker         return true;
406*8975f5c5SAndroid Build Coastguard Worker     }
407*8975f5c5SAndroid Build Coastguard Worker 
408*8975f5c5SAndroid Build Coastguard Worker     // Give verbose names for some built-in functions that are easy to confuse with others, but
409*8975f5c5SAndroid Build Coastguard Worker     // mostly use GLSL names for functions.
410*8975f5c5SAndroid Build Coastguard Worker     switch (op)
411*8975f5c5SAndroid Build Coastguard Worker     {
412*8975f5c5SAndroid Build Coastguard Worker         case EOpCallFunctionInAST:
413*8975f5c5SAndroid Build Coastguard Worker             OutputFunction(mOut, "Call a function", node->getFunction());
414*8975f5c5SAndroid Build Coastguard Worker             break;
415*8975f5c5SAndroid Build Coastguard Worker         case EOpCallInternalRawFunction:
416*8975f5c5SAndroid Build Coastguard Worker             OutputFunction(mOut, "Call an internal function with raw implementation",
417*8975f5c5SAndroid Build Coastguard Worker                            node->getFunction());
418*8975f5c5SAndroid Build Coastguard Worker             break;
419*8975f5c5SAndroid Build Coastguard Worker 
420*8975f5c5SAndroid Build Coastguard Worker         case EOpConstruct:
421*8975f5c5SAndroid Build Coastguard Worker             // The type of the constructor will be printed below.
422*8975f5c5SAndroid Build Coastguard Worker             mOut << "Construct";
423*8975f5c5SAndroid Build Coastguard Worker             break;
424*8975f5c5SAndroid Build Coastguard Worker 
425*8975f5c5SAndroid Build Coastguard Worker         case EOpEqualComponentWise:
426*8975f5c5SAndroid Build Coastguard Worker             mOut << "component-wise equal";
427*8975f5c5SAndroid Build Coastguard Worker             break;
428*8975f5c5SAndroid Build Coastguard Worker         case EOpNotEqualComponentWise:
429*8975f5c5SAndroid Build Coastguard Worker             mOut << "component-wise not equal";
430*8975f5c5SAndroid Build Coastguard Worker             break;
431*8975f5c5SAndroid Build Coastguard Worker         case EOpLessThanComponentWise:
432*8975f5c5SAndroid Build Coastguard Worker             mOut << "component-wise less than";
433*8975f5c5SAndroid Build Coastguard Worker             break;
434*8975f5c5SAndroid Build Coastguard Worker         case EOpGreaterThanComponentWise:
435*8975f5c5SAndroid Build Coastguard Worker             mOut << "component-wise greater than";
436*8975f5c5SAndroid Build Coastguard Worker             break;
437*8975f5c5SAndroid Build Coastguard Worker         case EOpLessThanEqualComponentWise:
438*8975f5c5SAndroid Build Coastguard Worker             mOut << "component-wise less than or equal";
439*8975f5c5SAndroid Build Coastguard Worker             break;
440*8975f5c5SAndroid Build Coastguard Worker         case EOpGreaterThanEqualComponentWise:
441*8975f5c5SAndroid Build Coastguard Worker             mOut << "component-wise greater than or equal";
442*8975f5c5SAndroid Build Coastguard Worker             break;
443*8975f5c5SAndroid Build Coastguard Worker 
444*8975f5c5SAndroid Build Coastguard Worker         case EOpDot:
445*8975f5c5SAndroid Build Coastguard Worker             mOut << "dot product";
446*8975f5c5SAndroid Build Coastguard Worker             break;
447*8975f5c5SAndroid Build Coastguard Worker         case EOpCross:
448*8975f5c5SAndroid Build Coastguard Worker             mOut << "cross product";
449*8975f5c5SAndroid Build Coastguard Worker             break;
450*8975f5c5SAndroid Build Coastguard Worker         case EOpMatrixCompMult:
451*8975f5c5SAndroid Build Coastguard Worker             mOut << "component-wise multiply";
452*8975f5c5SAndroid Build Coastguard Worker             break;
453*8975f5c5SAndroid Build Coastguard Worker 
454*8975f5c5SAndroid Build Coastguard Worker         default:
455*8975f5c5SAndroid Build Coastguard Worker             if (BuiltInGroup::IsBuiltIn(op))
456*8975f5c5SAndroid Build Coastguard Worker             {
457*8975f5c5SAndroid Build Coastguard Worker                 OutputFunction(mOut, "Call a built-in function", node->getFunction());
458*8975f5c5SAndroid Build Coastguard Worker             }
459*8975f5c5SAndroid Build Coastguard Worker             else
460*8975f5c5SAndroid Build Coastguard Worker             {
461*8975f5c5SAndroid Build Coastguard Worker                 mOut << GetOperatorString(node->getOp());
462*8975f5c5SAndroid Build Coastguard Worker             }
463*8975f5c5SAndroid Build Coastguard Worker             break;
464*8975f5c5SAndroid Build Coastguard Worker     }
465*8975f5c5SAndroid Build Coastguard Worker 
466*8975f5c5SAndroid Build Coastguard Worker     mOut << " (" << node->getType() << ")";
467*8975f5c5SAndroid Build Coastguard Worker 
468*8975f5c5SAndroid Build Coastguard Worker     mOut << "\n";
469*8975f5c5SAndroid Build Coastguard Worker 
470*8975f5c5SAndroid Build Coastguard Worker     return true;
471*8975f5c5SAndroid Build Coastguard Worker }
472*8975f5c5SAndroid Build Coastguard Worker 
visitBlock(Visit visit,TIntermBlock * node)473*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitBlock(Visit visit, TIntermBlock *node)
474*8975f5c5SAndroid Build Coastguard Worker {
475*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
476*8975f5c5SAndroid Build Coastguard Worker     mOut << "Code block\n";
477*8975f5c5SAndroid Build Coastguard Worker 
478*8975f5c5SAndroid Build Coastguard Worker     return true;
479*8975f5c5SAndroid Build Coastguard Worker }
480*8975f5c5SAndroid Build Coastguard Worker 
visitDeclaration(Visit visit,TIntermDeclaration * node)481*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitDeclaration(Visit visit, TIntermDeclaration *node)
482*8975f5c5SAndroid Build Coastguard Worker {
483*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
484*8975f5c5SAndroid Build Coastguard Worker     mOut << "Declaration\n";
485*8975f5c5SAndroid Build Coastguard Worker 
486*8975f5c5SAndroid Build Coastguard Worker     return true;
487*8975f5c5SAndroid Build Coastguard Worker }
488*8975f5c5SAndroid Build Coastguard Worker 
visitTernary(Visit visit,TIntermTernary * node)489*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitTernary(Visit visit, TIntermTernary *node)
490*8975f5c5SAndroid Build Coastguard Worker {
491*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
492*8975f5c5SAndroid Build Coastguard Worker 
493*8975f5c5SAndroid Build Coastguard Worker     mOut << "Ternary selection";
494*8975f5c5SAndroid Build Coastguard Worker     mOut << " (" << node->getType() << ")\n";
495*8975f5c5SAndroid Build Coastguard Worker 
496*8975f5c5SAndroid Build Coastguard Worker     ++mIndentDepth;
497*8975f5c5SAndroid Build Coastguard Worker 
498*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
499*8975f5c5SAndroid Build Coastguard Worker     mOut << "Condition\n";
500*8975f5c5SAndroid Build Coastguard Worker     node->getCondition()->traverse(this);
501*8975f5c5SAndroid Build Coastguard Worker 
502*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
503*8975f5c5SAndroid Build Coastguard Worker     if (node->getTrueExpression())
504*8975f5c5SAndroid Build Coastguard Worker     {
505*8975f5c5SAndroid Build Coastguard Worker         mOut << "true case\n";
506*8975f5c5SAndroid Build Coastguard Worker         node->getTrueExpression()->traverse(this);
507*8975f5c5SAndroid Build Coastguard Worker     }
508*8975f5c5SAndroid Build Coastguard Worker     if (node->getFalseExpression())
509*8975f5c5SAndroid Build Coastguard Worker     {
510*8975f5c5SAndroid Build Coastguard Worker         OutputTreeText(mOut, node, getCurrentIndentDepth());
511*8975f5c5SAndroid Build Coastguard Worker         mOut << "false case\n";
512*8975f5c5SAndroid Build Coastguard Worker         node->getFalseExpression()->traverse(this);
513*8975f5c5SAndroid Build Coastguard Worker     }
514*8975f5c5SAndroid Build Coastguard Worker 
515*8975f5c5SAndroid Build Coastguard Worker     --mIndentDepth;
516*8975f5c5SAndroid Build Coastguard Worker 
517*8975f5c5SAndroid Build Coastguard Worker     return false;
518*8975f5c5SAndroid Build Coastguard Worker }
519*8975f5c5SAndroid Build Coastguard Worker 
visitIfElse(Visit visit,TIntermIfElse * node)520*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitIfElse(Visit visit, TIntermIfElse *node)
521*8975f5c5SAndroid Build Coastguard Worker {
522*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
523*8975f5c5SAndroid Build Coastguard Worker 
524*8975f5c5SAndroid Build Coastguard Worker     mOut << "If test\n";
525*8975f5c5SAndroid Build Coastguard Worker 
526*8975f5c5SAndroid Build Coastguard Worker     ++mIndentDepth;
527*8975f5c5SAndroid Build Coastguard Worker 
528*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
529*8975f5c5SAndroid Build Coastguard Worker     mOut << "Condition\n";
530*8975f5c5SAndroid Build Coastguard Worker     node->getCondition()->traverse(this);
531*8975f5c5SAndroid Build Coastguard Worker 
532*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
533*8975f5c5SAndroid Build Coastguard Worker     if (node->getTrueBlock())
534*8975f5c5SAndroid Build Coastguard Worker     {
535*8975f5c5SAndroid Build Coastguard Worker         mOut << "true case\n";
536*8975f5c5SAndroid Build Coastguard Worker         node->getTrueBlock()->traverse(this);
537*8975f5c5SAndroid Build Coastguard Worker     }
538*8975f5c5SAndroid Build Coastguard Worker     else
539*8975f5c5SAndroid Build Coastguard Worker     {
540*8975f5c5SAndroid Build Coastguard Worker         mOut << "true case is null\n";
541*8975f5c5SAndroid Build Coastguard Worker     }
542*8975f5c5SAndroid Build Coastguard Worker 
543*8975f5c5SAndroid Build Coastguard Worker     if (node->getFalseBlock())
544*8975f5c5SAndroid Build Coastguard Worker     {
545*8975f5c5SAndroid Build Coastguard Worker         OutputTreeText(mOut, node, getCurrentIndentDepth());
546*8975f5c5SAndroid Build Coastguard Worker         mOut << "false case\n";
547*8975f5c5SAndroid Build Coastguard Worker         node->getFalseBlock()->traverse(this);
548*8975f5c5SAndroid Build Coastguard Worker     }
549*8975f5c5SAndroid Build Coastguard Worker 
550*8975f5c5SAndroid Build Coastguard Worker     --mIndentDepth;
551*8975f5c5SAndroid Build Coastguard Worker 
552*8975f5c5SAndroid Build Coastguard Worker     return false;
553*8975f5c5SAndroid Build Coastguard Worker }
554*8975f5c5SAndroid Build Coastguard Worker 
visitSwitch(Visit visit,TIntermSwitch * node)555*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitSwitch(Visit visit, TIntermSwitch *node)
556*8975f5c5SAndroid Build Coastguard Worker {
557*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
558*8975f5c5SAndroid Build Coastguard Worker 
559*8975f5c5SAndroid Build Coastguard Worker     mOut << "Switch\n";
560*8975f5c5SAndroid Build Coastguard Worker 
561*8975f5c5SAndroid Build Coastguard Worker     return true;
562*8975f5c5SAndroid Build Coastguard Worker }
563*8975f5c5SAndroid Build Coastguard Worker 
visitCase(Visit visit,TIntermCase * node)564*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitCase(Visit visit, TIntermCase *node)
565*8975f5c5SAndroid Build Coastguard Worker {
566*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
567*8975f5c5SAndroid Build Coastguard Worker 
568*8975f5c5SAndroid Build Coastguard Worker     if (node->getCondition() == nullptr)
569*8975f5c5SAndroid Build Coastguard Worker     {
570*8975f5c5SAndroid Build Coastguard Worker         mOut << "Default\n";
571*8975f5c5SAndroid Build Coastguard Worker     }
572*8975f5c5SAndroid Build Coastguard Worker     else
573*8975f5c5SAndroid Build Coastguard Worker     {
574*8975f5c5SAndroid Build Coastguard Worker         mOut << "Case\n";
575*8975f5c5SAndroid Build Coastguard Worker     }
576*8975f5c5SAndroid Build Coastguard Worker 
577*8975f5c5SAndroid Build Coastguard Worker     return true;
578*8975f5c5SAndroid Build Coastguard Worker }
579*8975f5c5SAndroid Build Coastguard Worker 
visitConstantUnion(TIntermConstantUnion * node)580*8975f5c5SAndroid Build Coastguard Worker void TOutputTraverser::visitConstantUnion(TIntermConstantUnion *node)
581*8975f5c5SAndroid Build Coastguard Worker {
582*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
583*8975f5c5SAndroid Build Coastguard Worker     mOut << "Constant union" << " (" << node->getType() << ")" << "\n";
584*8975f5c5SAndroid Build Coastguard Worker     ++mIndentDepth;
585*8975f5c5SAndroid Build Coastguard Worker     size_t size = node->getType().getObjectSize();
586*8975f5c5SAndroid Build Coastguard Worker 
587*8975f5c5SAndroid Build Coastguard Worker     for (size_t i = 0; i < size; i++)
588*8975f5c5SAndroid Build Coastguard Worker     {
589*8975f5c5SAndroid Build Coastguard Worker         OutputTreeText(mOut, node, getCurrentIndentDepth());
590*8975f5c5SAndroid Build Coastguard Worker         switch (node->getConstantValue()[i].getType())
591*8975f5c5SAndroid Build Coastguard Worker         {
592*8975f5c5SAndroid Build Coastguard Worker             case EbtBool:
593*8975f5c5SAndroid Build Coastguard Worker                 if (node->getConstantValue()[i].getBConst())
594*8975f5c5SAndroid Build Coastguard Worker                     mOut << "true";
595*8975f5c5SAndroid Build Coastguard Worker                 else
596*8975f5c5SAndroid Build Coastguard Worker                     mOut << "false";
597*8975f5c5SAndroid Build Coastguard Worker 
598*8975f5c5SAndroid Build Coastguard Worker                 mOut << " (" << "const bool" << ")";
599*8975f5c5SAndroid Build Coastguard Worker                 mOut << "\n";
600*8975f5c5SAndroid Build Coastguard Worker                 break;
601*8975f5c5SAndroid Build Coastguard Worker             case EbtFloat:
602*8975f5c5SAndroid Build Coastguard Worker                 mOut << node->getConstantValue()[i].getFConst();
603*8975f5c5SAndroid Build Coastguard Worker                 mOut << " (const float)\n";
604*8975f5c5SAndroid Build Coastguard Worker                 break;
605*8975f5c5SAndroid Build Coastguard Worker             case EbtInt:
606*8975f5c5SAndroid Build Coastguard Worker                 mOut << node->getConstantValue()[i].getIConst();
607*8975f5c5SAndroid Build Coastguard Worker                 mOut << " (const int)\n";
608*8975f5c5SAndroid Build Coastguard Worker                 break;
609*8975f5c5SAndroid Build Coastguard Worker             case EbtUInt:
610*8975f5c5SAndroid Build Coastguard Worker                 mOut << node->getConstantValue()[i].getUConst();
611*8975f5c5SAndroid Build Coastguard Worker                 mOut << " (const uint)\n";
612*8975f5c5SAndroid Build Coastguard Worker                 break;
613*8975f5c5SAndroid Build Coastguard Worker             case EbtYuvCscStandardEXT:
614*8975f5c5SAndroid Build Coastguard Worker                 mOut << getYuvCscStandardEXTString(
615*8975f5c5SAndroid Build Coastguard Worker                     node->getConstantValue()[i].getYuvCscStandardEXTConst());
616*8975f5c5SAndroid Build Coastguard Worker                 mOut << " (const yuvCscStandardEXT)\n";
617*8975f5c5SAndroid Build Coastguard Worker                 break;
618*8975f5c5SAndroid Build Coastguard Worker             default:
619*8975f5c5SAndroid Build Coastguard Worker                 mOut.prefix(SH_ERROR);
620*8975f5c5SAndroid Build Coastguard Worker                 mOut << "Unknown constant\n";
621*8975f5c5SAndroid Build Coastguard Worker                 break;
622*8975f5c5SAndroid Build Coastguard Worker         }
623*8975f5c5SAndroid Build Coastguard Worker     }
624*8975f5c5SAndroid Build Coastguard Worker     --mIndentDepth;
625*8975f5c5SAndroid Build Coastguard Worker }
626*8975f5c5SAndroid Build Coastguard Worker 
visitLoop(Visit visit,TIntermLoop * node)627*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitLoop(Visit visit, TIntermLoop *node)
628*8975f5c5SAndroid Build Coastguard Worker {
629*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
630*8975f5c5SAndroid Build Coastguard Worker 
631*8975f5c5SAndroid Build Coastguard Worker     mOut << "Loop with condition ";
632*8975f5c5SAndroid Build Coastguard Worker     if (node->getType() == ELoopDoWhile)
633*8975f5c5SAndroid Build Coastguard Worker         mOut << "not ";
634*8975f5c5SAndroid Build Coastguard Worker     mOut << "tested first\n";
635*8975f5c5SAndroid Build Coastguard Worker 
636*8975f5c5SAndroid Build Coastguard Worker     ++mIndentDepth;
637*8975f5c5SAndroid Build Coastguard Worker 
638*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
639*8975f5c5SAndroid Build Coastguard Worker     if (node->getCondition())
640*8975f5c5SAndroid Build Coastguard Worker     {
641*8975f5c5SAndroid Build Coastguard Worker         mOut << "Loop Condition\n";
642*8975f5c5SAndroid Build Coastguard Worker         node->getCondition()->traverse(this);
643*8975f5c5SAndroid Build Coastguard Worker     }
644*8975f5c5SAndroid Build Coastguard Worker     else
645*8975f5c5SAndroid Build Coastguard Worker     {
646*8975f5c5SAndroid Build Coastguard Worker         mOut << "No loop condition\n";
647*8975f5c5SAndroid Build Coastguard Worker     }
648*8975f5c5SAndroid Build Coastguard Worker 
649*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
650*8975f5c5SAndroid Build Coastguard Worker     mOut << "Loop Body\n";
651*8975f5c5SAndroid Build Coastguard Worker     node->getBody()->traverse(this);
652*8975f5c5SAndroid Build Coastguard Worker 
653*8975f5c5SAndroid Build Coastguard Worker     if (node->getExpression())
654*8975f5c5SAndroid Build Coastguard Worker     {
655*8975f5c5SAndroid Build Coastguard Worker         OutputTreeText(mOut, node, getCurrentIndentDepth());
656*8975f5c5SAndroid Build Coastguard Worker         mOut << "Loop Terminal Expression\n";
657*8975f5c5SAndroid Build Coastguard Worker         node->getExpression()->traverse(this);
658*8975f5c5SAndroid Build Coastguard Worker     }
659*8975f5c5SAndroid Build Coastguard Worker 
660*8975f5c5SAndroid Build Coastguard Worker     --mIndentDepth;
661*8975f5c5SAndroid Build Coastguard Worker 
662*8975f5c5SAndroid Build Coastguard Worker     return false;
663*8975f5c5SAndroid Build Coastguard Worker }
664*8975f5c5SAndroid Build Coastguard Worker 
visitBranch(Visit visit,TIntermBranch * node)665*8975f5c5SAndroid Build Coastguard Worker bool TOutputTraverser::visitBranch(Visit visit, TIntermBranch *node)
666*8975f5c5SAndroid Build Coastguard Worker {
667*8975f5c5SAndroid Build Coastguard Worker     OutputTreeText(mOut, node, getCurrentIndentDepth());
668*8975f5c5SAndroid Build Coastguard Worker 
669*8975f5c5SAndroid Build Coastguard Worker     switch (node->getFlowOp())
670*8975f5c5SAndroid Build Coastguard Worker     {
671*8975f5c5SAndroid Build Coastguard Worker         case EOpKill:
672*8975f5c5SAndroid Build Coastguard Worker             mOut << "Branch: Kill";
673*8975f5c5SAndroid Build Coastguard Worker             break;
674*8975f5c5SAndroid Build Coastguard Worker         case EOpBreak:
675*8975f5c5SAndroid Build Coastguard Worker             mOut << "Branch: Break";
676*8975f5c5SAndroid Build Coastguard Worker             break;
677*8975f5c5SAndroid Build Coastguard Worker         case EOpContinue:
678*8975f5c5SAndroid Build Coastguard Worker             mOut << "Branch: Continue";
679*8975f5c5SAndroid Build Coastguard Worker             break;
680*8975f5c5SAndroid Build Coastguard Worker         case EOpReturn:
681*8975f5c5SAndroid Build Coastguard Worker             mOut << "Branch: Return";
682*8975f5c5SAndroid Build Coastguard Worker             break;
683*8975f5c5SAndroid Build Coastguard Worker         default:
684*8975f5c5SAndroid Build Coastguard Worker             mOut << "Branch: Unknown Branch";
685*8975f5c5SAndroid Build Coastguard Worker             break;
686*8975f5c5SAndroid Build Coastguard Worker     }
687*8975f5c5SAndroid Build Coastguard Worker 
688*8975f5c5SAndroid Build Coastguard Worker     if (node->getExpression())
689*8975f5c5SAndroid Build Coastguard Worker     {
690*8975f5c5SAndroid Build Coastguard Worker         mOut << " with expression\n";
691*8975f5c5SAndroid Build Coastguard Worker         ++mIndentDepth;
692*8975f5c5SAndroid Build Coastguard Worker         node->getExpression()->traverse(this);
693*8975f5c5SAndroid Build Coastguard Worker         --mIndentDepth;
694*8975f5c5SAndroid Build Coastguard Worker     }
695*8975f5c5SAndroid Build Coastguard Worker     else
696*8975f5c5SAndroid Build Coastguard Worker     {
697*8975f5c5SAndroid Build Coastguard Worker         mOut << "\n";
698*8975f5c5SAndroid Build Coastguard Worker     }
699*8975f5c5SAndroid Build Coastguard Worker 
700*8975f5c5SAndroid Build Coastguard Worker     return false;
701*8975f5c5SAndroid Build Coastguard Worker }
702*8975f5c5SAndroid Build Coastguard Worker 
703*8975f5c5SAndroid Build Coastguard Worker }  // anonymous namespace
704*8975f5c5SAndroid Build Coastguard Worker 
OutputTree(TIntermNode * root,TInfoSinkBase & out)705*8975f5c5SAndroid Build Coastguard Worker void OutputTree(TIntermNode *root, TInfoSinkBase &out)
706*8975f5c5SAndroid Build Coastguard Worker {
707*8975f5c5SAndroid Build Coastguard Worker     TOutputTraverser it(out);
708*8975f5c5SAndroid Build Coastguard Worker     ASSERT(root);
709*8975f5c5SAndroid Build Coastguard Worker     root->traverse(&it);
710*8975f5c5SAndroid Build Coastguard Worker }
711*8975f5c5SAndroid Build Coastguard Worker 
712*8975f5c5SAndroid Build Coastguard Worker }  // namespace sh
713