blob: 65ccfa6bac78ac657eef62e2d928b1ee4925fbff [file] [log] [blame]
daniel@transgaming.comb5875982010-04-15 20:44:53 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7#include "UnfoldSelect.h"
8
9#include "OutputHLSL.h"
10#include "common/debug.h"
11#include "InfoSink.h"
12
13namespace sh
14{
15UnfoldSelect::UnfoldSelect(TParseContext &context, OutputHLSL *outputHLSL) : mContext(context), mOutputHLSL(outputHLSL)
16{
17 mTemporaryIndex = 0;
18}
19
20void UnfoldSelect::traverse(TIntermNode *node)
21{
22 mTemporaryIndex++;
23 node->traverse(this);
24}
25
26bool UnfoldSelect::visitSelection(Visit visit, TIntermSelection *node)
27{
28 TInfoSinkBase &out = mOutputHLSL->getBodyStream();
29
30 if (node->usesTernaryOperator())
31 {
32 int i = mTemporaryIndex++;
33
34 out << OutputHLSL::typeString(node->getType()) << " t" << i << ";\n";
35
36 node->getCondition()->traverse(this);
37 out << "if(";
38 node->getCondition()->traverse(mOutputHLSL);
39 out << ")\n"
40 "{\n";
41 node->getTrueBlock()->traverse(this);
42 out << " t" << i << " = ";
43 node->getTrueBlock()->traverse(mOutputHLSL);
44 out << ";\n"
45 "}\n"
46 "else\n"
47 "{\n";
48 node->getCondition()->traverse(this);
49 out << " t" << i << " = ";
50 node->getFalseBlock()->traverse(mOutputHLSL);
51 out << ";\n"
52 "}\n";
53
54 mTemporaryIndex--;
55 }
56
57 return false;
58}
59
60int UnfoldSelect::getTemporaryIndex()
61{
62 return mTemporaryIndex;
63}
64}