daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 1 | // |
| 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.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 7 | #include "compiler/UnfoldSelect.h" |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 8 | |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 9 | #include "common/debug.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 10 | |
| 11 | #include "compiler/InfoSink.h" |
| 12 | #include "compiler/OutputHLSL.h" |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 13 | |
| 14 | namespace sh |
| 15 | { |
| 16 | UnfoldSelect::UnfoldSelect(TParseContext &context, OutputHLSL *outputHLSL) : mContext(context), mOutputHLSL(outputHLSL) |
| 17 | { |
| 18 | mTemporaryIndex = 0; |
| 19 | } |
| 20 | |
| 21 | void UnfoldSelect::traverse(TIntermNode *node) |
| 22 | { |
| 23 | mTemporaryIndex++; |
| 24 | node->traverse(this); |
| 25 | } |
| 26 | |
| 27 | bool 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.com | a2a95e7 | 2010-05-20 19:17:55 +0000 | [diff] [blame^] | 35 | out << mOutputHLSL->typeString(node->getType()) << " t" << i << ";\n"; |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 36 | |
| 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 | |
| 61 | int UnfoldSelect::getTemporaryIndex() |
| 62 | { |
| 63 | return mTemporaryIndex; |
| 64 | } |
| 65 | } |