Renamed UnfoldSelect to UnfoldShortCircuit.

TRAC #11866 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@1062 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 8915eba8
# Copyright (c) 2010 The ANGLE Project Authors. All rights reserved. # Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -171,8 +171,8 @@ ...@@ -171,8 +171,8 @@
'compiler/OutputHLSL.h', 'compiler/OutputHLSL.h',
'compiler/TranslatorHLSL.cpp', 'compiler/TranslatorHLSL.cpp',
'compiler/TranslatorHLSL.h', 'compiler/TranslatorHLSL.h',
'compiler/UnfoldSelect.cpp', 'compiler/UnfoldShortCircuit.cpp',
'compiler/UnfoldSelect.h', 'compiler/UnfoldShortCircuit.h',
'compiler/SearchSymbol.cpp', 'compiler/SearchSymbol.cpp',
'compiler/SearchSymbol.h', 'compiler/SearchSymbol.h',
], ],
......
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1061 #define BUILD_REVISION 1062
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/debug.h" #include "compiler/debug.h"
#include "compiler/InfoSink.h" #include "compiler/InfoSink.h"
#include "compiler/UnfoldSelect.h" #include "compiler/UnfoldShortCircuit.h"
#include "compiler/SearchSymbol.h" #include "compiler/SearchSymbol.h"
#include <stdio.h> #include <stdio.h>
...@@ -27,7 +27,7 @@ TString str(int i) ...@@ -27,7 +27,7 @@ TString str(int i)
OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, true), mContext(context) OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, true), mContext(context)
{ {
mUnfoldSelect = new UnfoldSelect(context, this); mUnfoldShortCircuit = new UnfoldShortCircuit(context, this);
mInsideFunction = false; mInsideFunction = false;
mUsesTexture2D = false; mUsesTexture2D = false;
...@@ -80,7 +80,7 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr ...@@ -80,7 +80,7 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr
OutputHLSL::~OutputHLSL() OutputHLSL::~OutputHLSL()
{ {
delete mUnfoldSelect; delete mUnfoldShortCircuit;
} }
void OutputHLSL::output() void OutputHLSL::output()
...@@ -1056,14 +1056,14 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -1056,14 +1056,14 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
case EOpMatrixTimesVector: outputTriplet(visit, "mul(transpose(", "), ", ")"); break; case EOpMatrixTimesVector: outputTriplet(visit, "mul(transpose(", "), ", ")"); break;
case EOpMatrixTimesMatrix: outputTriplet(visit, "transpose(mul(transpose(", "), transpose(", ")))"); break; case EOpMatrixTimesMatrix: outputTriplet(visit, "transpose(mul(transpose(", "), transpose(", ")))"); break;
case EOpLogicalOr: case EOpLogicalOr:
out << "s" << mUnfoldSelect->getNextTemporaryIndex(); out << "s" << mUnfoldShortCircuit->getNextTemporaryIndex();
return false; return false;
case EOpLogicalXor: case EOpLogicalXor:
mUsesXor = true; mUsesXor = true;
outputTriplet(visit, "xor(", ", ", ")"); outputTriplet(visit, "xor(", ", ", ")");
break; break;
case EOpLogicalAnd: case EOpLogicalAnd:
out << "s" << mUnfoldSelect->getNextTemporaryIndex(); out << "s" << mUnfoldShortCircuit->getNextTemporaryIndex();
return false; return false;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1583,11 +1583,11 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node) ...@@ -1583,11 +1583,11 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
if (node->usesTernaryOperator()) if (node->usesTernaryOperator())
{ {
out << "s" << mUnfoldSelect->getNextTemporaryIndex(); out << "s" << mUnfoldShortCircuit->getNextTemporaryIndex();
} }
else // if/else statement else // if/else statement
{ {
mUnfoldSelect->traverse(node->getCondition()); mUnfoldShortCircuit->traverse(node->getCondition());
out << "if("; out << "if(";
...@@ -1736,7 +1736,7 @@ void OutputHLSL::traverseStatements(TIntermNode *node) ...@@ -1736,7 +1736,7 @@ void OutputHLSL::traverseStatements(TIntermNode *node)
{ {
if (isSingleStatement(node)) if (isSingleStatement(node))
{ {
mUnfoldSelect->traverse(node); mUnfoldShortCircuit->traverse(node);
} }
node->traverse(this); node->traverse(this);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace sh namespace sh
{ {
class UnfoldSelect; class UnfoldShortCircuit;
class OutputHLSL : public TIntermTraverser class OutputHLSL : public TIntermTraverser
{ {
...@@ -64,7 +64,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -64,7 +64,7 @@ class OutputHLSL : public TIntermTraverser
TString structLookup(const TString &typeName); TString structLookup(const TString &typeName);
TParseContext &mContext; TParseContext &mContext;
UnfoldSelect *mUnfoldSelect; UnfoldShortCircuit *mUnfoldShortCircuit;
bool mInsideFunction; bool mInsideFunction;
// Output streams // Output streams
......
//
// Copyright (c) 2002-2012 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.
//
// UnfoldSelect is an AST traverser to output short-circuiting operators as if-else statements.
// The results are assigned to s# temporaries, which are used by the main translator instead of
// the original expression.
//
#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)
{
int rewindIndex = mTemporaryIndex;
node->traverse(this);
mTemporaryIndex = rewindIndex;
}
bool UnfoldSelect::visitBinary(Visit visit, TIntermBinary *node)
{
TInfoSinkBase &out = mOutputHLSL->getBodyStream();
switch (node->getOp())
{
case EOpLogicalOr:
// "x || y" is equivalent to "x ? true : y", which unfolds to "bool s; if(x) s = true; else s = y;",
// and then further simplifies down to "bool s = x; if(!s) s = y;".
{
int i = mTemporaryIndex;
out << "bool s" << i << ";\n";
out << "{\n";
mTemporaryIndex = i + 1;
node->getLeft()->traverse(this);
out << "s" << i << " = ";
mTemporaryIndex = i + 1;
node->getLeft()->traverse(mOutputHLSL);
out << ";\n";
out << "if(!s" << i << ")\n"
"{\n";
mTemporaryIndex = i + 1;
node->getRight()->traverse(this);
out << " s" << i << " = ";
mTemporaryIndex = i + 1;
node->getRight()->traverse(mOutputHLSL);
out << ";\n"
"}\n";
out << "}\n";
mTemporaryIndex = i + 1;
}
return false;
case EOpLogicalAnd:
// "x && y" is equivalent to "x ? y : false", which unfolds to "bool s; if(x) s = y; else s = false;",
// and then further simplifies down to "bool s = x; if(s) s = y;".
{
int i = mTemporaryIndex;
out << "bool s" << i << ";\n";
out << "{\n";
mTemporaryIndex = i + 1;
node->getLeft()->traverse(this);
out << "s" << i << " = ";
mTemporaryIndex = i + 1;
node->getLeft()->traverse(mOutputHLSL);
out << ";\n";
out << "if(s" << i << ")\n"
"{\n";
mTemporaryIndex = i + 1;
node->getRight()->traverse(this);
out << " s" << i << " = ";
mTemporaryIndex = i + 1;
node->getRight()->traverse(mOutputHLSL);
out << ";\n"
"}\n";
out << "}\n";
mTemporaryIndex = i + 1;
}
return false;
}
return true;
}
bool UnfoldSelect::visitSelection(Visit visit, TIntermSelection *node)
{
TInfoSinkBase &out = mOutputHLSL->getBodyStream();
// Unfold "b ? x : y" into "type s; if(b) s = x; else s = y;"
if (node->usesTernaryOperator())
{
int i = mTemporaryIndex;
out << mOutputHLSL->typeString(node->getType()) << " s" << i << ";\n";
mTemporaryIndex = i + 1;
node->getCondition()->traverse(this);
out << "if(";
mTemporaryIndex = i + 1;
node->getCondition()->traverse(mOutputHLSL);
out << ")\n"
"{\n";
mTemporaryIndex = i + 1;
node->getTrueBlock()->traverse(this);
out << " s" << i << " = ";
mTemporaryIndex = i + 1;
node->getTrueBlock()->traverse(mOutputHLSL);
out << ";\n"
"}\n"
"else\n"
"{\n";
mTemporaryIndex = i + 1;
node->getFalseBlock()->traverse(this);
out << " s" << i << " = ";
mTemporaryIndex = i + 1;
node->getFalseBlock()->traverse(mOutputHLSL);
out << ";\n"
"}\n";
mTemporaryIndex = i + 1;
}
return false;
}
bool UnfoldSelect::visitLoop(Visit visit, TIntermLoop *node)
{
int rewindIndex = mTemporaryIndex;
if (node->getInit())
{
node->getInit()->traverse(this);
}
if (node->getCondition())
{
node->getCondition()->traverse(this);
}
if (node->getExpression())
{
node->getExpression()->traverse(this);
}
mTemporaryIndex = rewindIndex;
return false;
}
int UnfoldSelect::getNextTemporaryIndex()
{
return mTemporaryIndex++;
}
}
//
// Copyright (c) 2002-2012 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.
//
// UnfoldSelect is an AST traverser to output short-circuiting operators as if-else statements
//
#ifndef COMPILER_UNFOLDSELECT_H_
#define COMPILER_UNFOLDSELECT_H_
#include "compiler/intermediate.h"
#include "compiler/ParseHelper.h"
namespace sh
{
class OutputHLSL;
class UnfoldSelect : public TIntermTraverser
{
public:
UnfoldSelect(TParseContext &context, OutputHLSL *outputHLSL);
void traverse(TIntermNode *node);
bool visitBinary(Visit visit, TIntermBinary*);
bool visitSelection(Visit visit, TIntermSelection *node);
bool visitLoop(Visit visit, TIntermLoop *node);
int getNextTemporaryIndex();
protected:
TParseContext &mContext;
OutputHLSL *const mOutputHLSL;
int mTemporaryIndex;
};
}
#endif // COMPILER_UNFOLDSELECT_H_
...@@ -307,7 +307,7 @@ ...@@ -307,7 +307,7 @@
> >
</File> </File>
<File <File
RelativePath=".\UnfoldSelect.cpp" RelativePath=".\UnfoldShortCircuit.cpp"
> >
</File> </File>
</Filter> </Filter>
...@@ -329,7 +329,7 @@ ...@@ -329,7 +329,7 @@
> >
</File> </File>
<File <File
RelativePath=".\UnfoldSelect.h" RelativePath=".\UnfoldShortCircuit.h"
> >
</File> </File>
</Filter> </Filter>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment