Edit

kc3-lang/angle/src/compiler/UnfoldSelect.cpp

Branch :

  • Show log

    Commit

  • Author : alokp@chromium.org
    Date : 2010-06-02 15:50:56
    Hash : 91b72320
    Message : Removed the dependency of compiler on common. This is done to make compiler self-sufficient so that it is easier to consume by external developers. I tried to replace all instances of assert by simply redefining assert(x) to ASSERT(x), but was getting a lot of compile errors. I still need to investigate that. Review URL: http://codereview.appspot.com/1461041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@323 736b8ea6-26fd-11df-bfd4-992fa37f6226

  • src/compiler/UnfoldSelect.cpp
  • //
    // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    #include "compiler/UnfoldSelect.h"
    
    #include "compiler/InfoSink.h"
    #include "compiler/OutputHLSL.h"
    
    namespace sh
    {
    UnfoldSelect::UnfoldSelect(TParseContext &context, OutputHLSL *outputHLSL) : mContext(context), mOutputHLSL(outputHLSL)
    {
        mTemporaryIndex = 0;
    }
    
    void UnfoldSelect::traverse(TIntermNode *node)
    {
        mTemporaryIndex++;
        node->traverse(this);
    }
    
    bool UnfoldSelect::visitSelection(Visit visit, TIntermSelection *node)
    {
        TInfoSinkBase &out = mOutputHLSL->getBodyStream();
    
        if (node->usesTernaryOperator())
        {
            int i = mTemporaryIndex++;
    
            out << mOutputHLSL->typeString(node->getType()) << " t" << i << ";\n";
    
            node->getCondition()->traverse(this);
            out << "if(";
            node->getCondition()->traverse(mOutputHLSL);
            out << ")\n"
                   "{\n";
            node->getTrueBlock()->traverse(this);
            out << "    t" << i << " = ";
            node->getTrueBlock()->traverse(mOutputHLSL);
            out << ";\n"
                   "}\n"
                   "else\n"
                   "{\n";
            node->getCondition()->traverse(this);
            out << "    t" << i << " = ";
            node->getFalseBlock()->traverse(mOutputHLSL);
            out << ";\n"
                   "}\n";
    
            mTemporaryIndex--;
        }
    
        return false;
    }
    
    int UnfoldSelect::getTemporaryIndex()
    {
        return mTemporaryIndex;
    }
    }