diff options
Diffstat (limited to 'src/3rdparty/angle/src/compiler/translator/RewriteElseBlocks.cpp')
-rw-r--r-- | src/3rdparty/angle/src/compiler/translator/RewriteElseBlocks.cpp | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/src/3rdparty/angle/src/compiler/translator/RewriteElseBlocks.cpp b/src/3rdparty/angle/src/compiler/translator/RewriteElseBlocks.cpp index b03beb5c6c..52ede17434 100644 --- a/src/3rdparty/angle/src/compiler/translator/RewriteElseBlocks.cpp +++ b/src/3rdparty/angle/src/compiler/translator/RewriteElseBlocks.cpp @@ -23,30 +23,14 @@ class ElseBlockRewriter : public TIntermTraverser ElseBlockRewriter(); protected: - bool visitAggregate(Visit visit, TIntermAggregate *aggregate); + bool visitAggregate(Visit visit, TIntermAggregate *aggregate) override; private: - int mTemporaryIndex; const TType *mFunctionType; TIntermNode *rewriteSelection(TIntermSelection *selection); }; -TIntermSymbol *MakeNewTemporary(const TString &name, TBasicType type) -{ - TType variableType(type, EbpHigh, EvqInternal); - return new TIntermSymbol(-1, name, variableType); -} - -TIntermBinary *MakeNewBinary(TOperator op, TIntermTyped *left, TIntermTyped *right, const TType &resultType) -{ - TIntermBinary *binary = new TIntermBinary(op); - binary->setLeft(left); - binary->setRight(right); - binary->setType(resultType); - return binary; -} - TIntermUnary *MakeNewUnary(TOperator op, TIntermTyped *operand) { TIntermUnary *unary = new TIntermUnary(op, operand->getType()); @@ -55,8 +39,7 @@ TIntermUnary *MakeNewUnary(TOperator op, TIntermTyped *operand) } ElseBlockRewriter::ElseBlockRewriter() - : TIntermTraverser(true, false, true, false), - mTemporaryIndex(0), + : TIntermTraverser(true, false, true), mFunctionType(NULL) {} @@ -71,7 +54,7 @@ bool ElseBlockRewriter::visitAggregate(Visit visit, TIntermAggregate *node) { TIntermNode *statement = (*node->getSequence())[statementIndex]; TIntermSelection *selection = statement->getAsSelectionNode(); - if (selection && selection->getFalseBlock() != NULL) + if (selection && selection->getFalseBlock() != nullptr) { // Check for if / else if TIntermSelection *elseIfBranch = selection->getFalseBlock()->getAsSelectionNode(); @@ -101,20 +84,20 @@ bool ElseBlockRewriter::visitAggregate(Visit visit, TIntermAggregate *node) TIntermNode *ElseBlockRewriter::rewriteSelection(TIntermSelection *selection) { - ASSERT(selection != NULL); + ASSERT(selection != nullptr); + + nextTemporaryIndex(); - TString temporaryName = "cond_" + str(mTemporaryIndex++); TIntermTyped *typedCondition = selection->getCondition()->getAsTyped(); - TType resultType(EbtBool, EbpUndefined); - TIntermSymbol *conditionSymbolInit = MakeNewTemporary(temporaryName, EbtBool); - TIntermBinary *storeCondition = MakeNewBinary(EOpInitialize, conditionSymbolInit, - typedCondition, resultType); - TIntermNode *negatedElse = NULL; + TIntermAggregate *storeCondition = createTempInitDeclaration(typedCondition); - TIntermSelection *falseBlock = NULL; + TIntermSelection *falseBlock = nullptr; + + TType boolType(EbtBool, EbpUndefined, EvqTemporary); if (selection->getFalseBlock()) { + TIntermAggregate *negatedElse = nullptr; // crbug.com/346463 // D3D generates error messages claiming a function has no return value, when rewriting // an if-else clause that returns something non-void in a function. By appending dummy @@ -124,24 +107,22 @@ TIntermNode *ElseBlockRewriter::rewriteSelection(TIntermSelection *selection) TString typeString = mFunctionType->getStruct() ? mFunctionType->getStruct()->name() : mFunctionType->getBasicString(); TString rawText = "return (" + typeString + ")0"; - negatedElse = new TIntermRaw(*mFunctionType, rawText); + TIntermRaw *returnNode = new TIntermRaw(*mFunctionType, rawText); + negatedElse = new TIntermAggregate(EOpSequence); + negatedElse->getSequence()->push_back(returnNode); } - TIntermSymbol *conditionSymbolElse = MakeNewTemporary(temporaryName, EbtBool); + TIntermSymbol *conditionSymbolElse = createTempSymbol(boolType); TIntermUnary *negatedCondition = MakeNewUnary(EOpLogicalNot, conditionSymbolElse); falseBlock = new TIntermSelection(negatedCondition, selection->getFalseBlock(), negatedElse); } - TIntermSymbol *conditionSymbolSel = MakeNewTemporary(temporaryName, EbtBool); - TIntermSelection *newSelection = new TIntermSelection(conditionSymbolSel, - selection->getTrueBlock(), falseBlock); - - TIntermAggregate *declaration = new TIntermAggregate(EOpDeclaration); - declaration->getSequence()->push_back(storeCondition); + TIntermSymbol *conditionSymbolSel = createTempSymbol(boolType); + TIntermSelection *newSelection = new TIntermSelection(conditionSymbolSel, selection->getTrueBlock(), falseBlock); TIntermAggregate *block = new TIntermAggregate(EOpSequence); - block->getSequence()->push_back(declaration); + block->getSequence()->push_back(storeCondition); block->getSequence()->push_back(newSelection); return block; @@ -149,9 +130,10 @@ TIntermNode *ElseBlockRewriter::rewriteSelection(TIntermSelection *selection) } -void RewriteElseBlocks(TIntermNode *node) +void RewriteElseBlocks(TIntermNode *node, unsigned int *temporaryIndex) { ElseBlockRewriter rewriter; + rewriter.useTemporaryIndex(temporaryIndex); node->traverse(&rewriter); } |