blob: 71116e00ed842c40bb1cab2390f39c8f25c2a3f4 [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
daniel@transgaming.combbf56f72010-04-20 18:52:13 +00007#include "compiler/UnfoldSelect.h"
daniel@transgaming.comb5875982010-04-15 20:44:53 +00008
daniel@transgaming.comb5875982010-04-15 20:44:53 +00009#include "common/debug.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000010
11#include "compiler/InfoSink.h"
12#include "compiler/OutputHLSL.h"
daniel@transgaming.comb5875982010-04-15 20:44:53 +000013
14namespace sh
15{
16UnfoldSelect::UnfoldSelect(TParseContext &context, OutputHLSL *outputHLSL) : mContext(context), mOutputHLSL(outputHLSL)
17{
18 mTemporaryIndex = 0;
19}
20
21void UnfoldSelect::traverse(TIntermNode *node)
22{
23 mTemporaryIndex++;
24 node->traverse(this);
25}
26
27bool UnfoldSelect::visitSelection(Visit visit, TIntermSelection *node)
28{
29 TInfoSinkBase &out = mOutputHLSL->getBodyStream();
30
31 if (node->usesTernaryOperator())
32 {
33 int i = mTemporaryIndex++;
34
daniel@transgaming.coma2a95e72010-05-20 19:17:55 +000035 out << mOutputHLSL->typeString(node->getType()) << " t" << i << ";\n";
daniel@transgaming.comb5875982010-04-15 20:44:53 +000036
37 node->getCondition()->traverse(this);
38 out << "if(";
39 node->getCondition()->traverse(mOutputHLSL);
40 out << ")\n"
41 "{\n";
42 node->getTrueBlock()->traverse(this);
43 out << " t" << i << " = ";
44 node->getTrueBlock()->traverse(mOutputHLSL);
45 out << ";\n"
46 "}\n"
47 "else\n"
48 "{\n";
49 node->getCondition()->traverse(this);
50 out << " t" << i << " = ";
51 node->getFalseBlock()->traverse(mOutputHLSL);
52 out << ";\n"
53 "}\n";
54
55 mTemporaryIndex--;
56 }
57
58 return false;
59}
60
61int UnfoldSelect::getTemporaryIndex()
62{
63 return mTemporaryIndex;
64}
65}