Commit 3ec75686 by Olli Etuaho

Collect AST transform utilities to a separate file

Collect static functions that are used to create nodes in AST transformations into a single file. BUG=angleproject:1490 TEST=angle_unittests Change-Id: I6f87422988fa088f2f4b48986e378a2909705cb7
parent 84db5733
......@@ -75,10 +75,10 @@
'compiler/translator/IntermNode.cpp',
'compiler/translator/IntermNodePatternMatcher.cpp',
'compiler/translator/IntermNodePatternMatcher.h',
'compiler/translator/IntermNode_util.cpp',
'compiler/translator/IntermNode_util.h',
'compiler/translator/IntermTraverse.cpp',
'compiler/translator/IntermTraverse.h',
'compiler/translator/Intermediate.h',
'compiler/translator/Intermediate.cpp',
'compiler/translator/IsASTDepthBelowLimit.cpp',
'compiler/translator/IsASTDepthBelowLimit.h',
'compiler/translator/NodeSearch.h',
......
......@@ -10,6 +10,7 @@
#include "compiler/translator/AddDefaultReturnStatements.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/util.h"
namespace sh
......@@ -46,8 +47,7 @@ void AddDefaultReturnStatements(TIntermBlock *root)
TIntermFunctionDefinition *definition = node->getAsFunctionDefinition();
if (definition != nullptr && NeedsReturnStatement(definition, &returnType))
{
TIntermBranch *branch =
new TIntermBranch(EOpReturn, TIntermTyped::CreateZero(returnType));
TIntermBranch *branch = new TIntermBranch(EOpReturn, CreateZeroNode(returnType));
TIntermBlock *bodyNode = definition->getBody();
bodyNode->getSequence()->push_back(branch);
......
......@@ -10,6 +10,7 @@
#include "BreakVariableAliasingInInnerLoops.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/IntermTraverse.h"
// A HLSL compiler developer gave us more details on the root cause and the workaround needed:
......@@ -68,7 +69,7 @@ class AliasingBreaker : public TIntermTraverser
// to
// A = (B + typeof<B>(0));
TIntermBinary *bPlusZero = new TIntermBinary(EOpAdd, B, TIntermTyped::CreateZero(type));
TIntermBinary *bPlusZero = new TIntermBinary(EOpAdd, B, CreateZeroNode(type));
bPlusZero->setLine(B->getLine());
binary->replaceChildNode(B, bPlusZero);
......
......@@ -14,6 +14,7 @@
#include "compiler/translator/EmulateGLFragColorBroadcast.h"
#include "compiler/translator/FindMain.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh
......@@ -53,7 +54,7 @@ TIntermBinary *GLFragColorBroadcastTraverser::constructGLFragDataNode(int index)
gl_FragDataType.setArraySize(mMaxDrawBuffers);
TIntermSymbol *symbol = new TIntermSymbol(0, "gl_FragData", gl_FragDataType);
TIntermTyped *indexNode = TIntermTyped::CreateIndexNode(index);
TIntermTyped *indexNode = CreateIndexNode(index);
TIntermBinary *binary = new TIntermBinary(EOpIndexDirect, symbol, indexNode);
return binary;
......
......@@ -9,6 +9,7 @@
#include "angle_gl.h"
#include "common/debug.h"
#include "compiler/translator/FindMain.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/util.h"
......@@ -29,7 +30,7 @@ void AddArrayZeroInitSequence(const TIntermTyped *initializedNode,
TIntermBinary *CreateZeroInitAssignment(const TIntermTyped *initializedNode)
{
TIntermTyped *zero = TIntermTyped::CreateZero(initializedNode->getType());
TIntermTyped *zero = CreateZeroNode(initializedNode->getType());
return new TIntermBinary(EOpAssign, initializedNode->deepCopy(), zero);
}
......@@ -40,8 +41,8 @@ void AddStructZeroInitSequence(const TIntermTyped *initializedNode,
TStructure *structType = initializedNode->getType().getStruct();
for (int i = 0; i < static_cast<int>(structType->fields().size()); ++i)
{
TIntermBinary *element = new TIntermBinary(
EOpIndexDirectStruct, initializedNode->deepCopy(), TIntermTyped::CreateIndexNode(i));
TIntermBinary *element = new TIntermBinary(EOpIndexDirectStruct,
initializedNode->deepCopy(), CreateIndexNode(i));
if (element->isArray())
{
AddArrayZeroInitSequence(element, initSequenceOut);
......@@ -69,8 +70,8 @@ void AddArrayZeroInitSequence(const TIntermTyped *initializedNode, TIntermSequen
// http://crbug.com/709317
for (unsigned int i = 0; i < initializedNode->getArraySize(); ++i)
{
TIntermBinary *element = new TIntermBinary(EOpIndexDirect, initializedNode->deepCopy(),
TIntermTyped::CreateIndexNode(i));
TIntermBinary *element =
new TIntermBinary(EOpIndexDirect, initializedNode->deepCopy(), CreateIndexNode(i));
if (element->getType().isStructureContainingArrays())
{
AddStructZeroInitSequence(element, initSequenceOut);
......@@ -175,8 +176,8 @@ class InitializeLocalsTraverser : public TIntermTraverser
}
else
{
TIntermBinary *init = new TIntermBinary(
EOpInitialize, symbol, TIntermTyped::CreateZero(symbol->getType()));
TIntermBinary *init =
new TIntermBinary(EOpInitialize, symbol, CreateZeroNode(symbol->getType()));
queueReplacementWithParent(node, symbol, init, OriginalNode::BECOMES_CHILD);
}
}
......
......@@ -558,105 +558,6 @@ bool TIntermTyped::isConstructorWithOnlyConstantUnionParameters()
return true;
}
// static
TIntermTyped *TIntermTyped::CreateIndexNode(int index)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setIConst(index);
TType type(EbtInt, EbpUndefined, EvqConst, 1);
TIntermConstantUnion *node = new TIntermConstantUnion(u, type);
return node;
}
// static
TIntermTyped *TIntermTyped::CreateZero(const TType &type)
{
TType constType(type);
constType.setQualifier(EvqConst);
if (!type.isArray() && type.getBasicType() != EbtStruct)
{
size_t size = constType.getObjectSize();
TConstantUnion *u = new TConstantUnion[size];
for (size_t i = 0; i < size; ++i)
{
switch (type.getBasicType())
{
case EbtFloat:
u[i].setFConst(0.0f);
break;
case EbtInt:
u[i].setIConst(0);
break;
case EbtUInt:
u[i].setUConst(0u);
break;
case EbtBool:
u[i].setBConst(false);
break;
default:
// CreateZero is called by ParseContext that keeps parsing even when an error
// occurs, so it is possible for CreateZero to be called with non-basic types.
// This happens only on error condition but CreateZero needs to return a value
// with the correct type to continue the typecheck. That's why we handle
// non-basic type by setting whatever value, we just need the type to be right.
u[i].setIConst(42);
break;
}
}
TIntermConstantUnion *node = new TIntermConstantUnion(u, constType);
return node;
}
if (type.getBasicType() == EbtVoid)
{
// Void array. This happens only on error condition, similarly to the case above. We don't
// have a constructor operator for void, so this needs special handling. We'll end up with a
// value without the array type, but that should not be a problem.
constType.clearArrayness();
return CreateZero(constType);
}
TIntermSequence *arguments = new TIntermSequence();
if (type.isArray())
{
TType elementType(type);
elementType.clearArrayness();
size_t arraySize = type.getArraySize();
for (size_t i = 0; i < arraySize; ++i)
{
arguments->push_back(CreateZero(elementType));
}
}
else
{
ASSERT(type.getBasicType() == EbtStruct);
TStructure *structure = type.getStruct();
for (const auto &field : structure->fields())
{
arguments->push_back(CreateZero(*field->type()));
}
}
return TIntermAggregate::CreateConstructor(constType, arguments);
}
// static
TIntermTyped *TIntermTyped::CreateBool(bool value)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setBConst(value);
TType type(EbtBool, EbpUndefined, EvqConst, 1);
TIntermConstantUnion *node = new TIntermConstantUnion(u, type);
return node;
}
TIntermConstantUnion::TIntermConstantUnion(const TIntermConstantUnion &node) : TIntermTyped(node)
{
mUnionArrayPointer = node.mUnionArrayPointer;
......
......@@ -180,10 +180,6 @@ class TIntermTyped : public TIntermNode
bool isConstructorWithOnlyConstantUnionParameters();
static TIntermTyped *CreateIndexNode(int index);
static TIntermTyped *CreateZero(const TType &type);
static TIntermTyped *CreateBool(bool value);
protected:
TType mType;
......
//
// Copyright (c) 2017 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.
//
// IntermNode_util.cpp: High-level utilities for creating AST nodes and node hierarchies. Mostly
// meant to be used in AST transforms.
#include "compiler/translator/IntermNode_util.h"
namespace sh
{
namespace
{
TName GetInternalFunctionName(const char *name)
{
TString nameStr(name);
TName nameObj(nameStr);
nameObj.setInternal(true);
return nameObj;
}
} // anonymous namespace
TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode(const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId)
{
TIntermFunctionPrototype *functionNode = new TIntermFunctionPrototype(returnType, functionId);
functionNode->getFunctionSymbolInfo()->setNameObj(GetInternalFunctionName(name));
return functionNode;
}
TIntermFunctionDefinition *CreateInternalFunctionDefinitionNode(const TType &returnType,
const char *name,
TIntermBlock *functionBody,
const TSymbolUniqueId &functionId)
{
TIntermFunctionPrototype *prototypeNode =
CreateInternalFunctionPrototypeNode(returnType, name, functionId);
return new TIntermFunctionDefinition(prototypeNode, functionBody);
}
TIntermAggregate *CreateInternalFunctionCallNode(const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId,
TIntermSequence *arguments)
{
TIntermAggregate *functionNode = TIntermAggregate::CreateFunctionCall(
returnType, functionId, GetInternalFunctionName(name), arguments);
return functionNode;
}
TIntermTyped *CreateZeroNode(const TType &type)
{
TType constType(type);
constType.setQualifier(EvqConst);
if (!type.isArray() && type.getBasicType() != EbtStruct)
{
size_t size = constType.getObjectSize();
TConstantUnion *u = new TConstantUnion[size];
for (size_t i = 0; i < size; ++i)
{
switch (type.getBasicType())
{
case EbtFloat:
u[i].setFConst(0.0f);
break;
case EbtInt:
u[i].setIConst(0);
break;
case EbtUInt:
u[i].setUConst(0u);
break;
case EbtBool:
u[i].setBConst(false);
break;
default:
// CreateZeroNode is called by ParseContext that keeps parsing even when an
// error occurs, so it is possible for CreateZeroNode to be called with
// non-basic types. This happens only on error condition but CreateZeroNode
// needs to return a value with the correct type to continue the typecheck.
// That's why we handle non-basic type by setting whatever value, we just need
// the type to be right.
u[i].setIConst(42);
break;
}
}
TIntermConstantUnion *node = new TIntermConstantUnion(u, constType);
return node;
}
if (type.getBasicType() == EbtVoid)
{
// Void array. This happens only on error condition, similarly to the case above. We don't
// have a constructor operator for void, so this needs special handling. We'll end up with a
// value without the array type, but that should not be a problem.
constType.clearArrayness();
return CreateZeroNode(constType);
}
TIntermSequence *arguments = new TIntermSequence();
if (type.isArray())
{
TType elementType(type);
elementType.clearArrayness();
size_t arraySize = type.getArraySize();
for (size_t i = 0; i < arraySize; ++i)
{
arguments->push_back(CreateZeroNode(elementType));
}
}
else
{
ASSERT(type.getBasicType() == EbtStruct);
TStructure *structure = type.getStruct();
for (const auto &field : structure->fields())
{
arguments->push_back(CreateZeroNode(*field->type()));
}
}
return TIntermAggregate::CreateConstructor(constType, arguments);
}
TIntermConstantUnion *CreateIndexNode(int index)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setIConst(index);
TType type(EbtInt, EbpUndefined, EvqConst, 1);
TIntermConstantUnion *node = new TIntermConstantUnion(u, type);
return node;
}
TIntermConstantUnion *CreateBoolNode(bool value)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setBConst(value);
TType type(EbtBool, EbpUndefined, EvqConst, 1);
TIntermConstantUnion *node = new TIntermConstantUnion(u, type);
return node;
}
TIntermBlock *EnsureBlock(TIntermNode *node)
{
if (node == nullptr)
return nullptr;
TIntermBlock *blockNode = node->getAsBlock();
if (blockNode != nullptr)
return blockNode;
blockNode = new TIntermBlock();
blockNode->setLine(node->getLine());
blockNode->appendStatement(node);
return blockNode;
}
} // namespace sh
//
// Copyright (c) 2017 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.
//
// IntermNode_util.h: High-level utilities for creating AST nodes and node hierarchies. Mostly meant
// to be used in AST transforms.
#ifndef COMPILER_TRANSLATOR_INTERMNODEUTIL_H_
#define COMPILER_TRANSLATOR_INTERMNODEUTIL_H_
#include "compiler/translator/IntermNode.h"
namespace sh
{
TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode(const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId);
TIntermFunctionDefinition *CreateInternalFunctionDefinitionNode(const TType &returnType,
const char *name,
TIntermBlock *functionBody,
const TSymbolUniqueId &functionId);
TIntermAggregate *CreateInternalFunctionCallNode(const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId,
TIntermSequence *arguments);
TIntermTyped *CreateZeroNode(const TType &type);
TIntermConstantUnion *CreateIndexNode(int index);
TIntermConstantUnion *CreateBoolNode(bool value);
// If the input node is nullptr, return nullptr.
// If the input node is a block node, return it.
// If the input node is not a block node, put it inside a block node and return that.
TIntermBlock *EnsureBlock(TIntermNode *node);
} // namespace sh
#endif // COMPILER_TRANSLATOR_INTERMNODEUTIL_H_
\ No newline at end of file
......@@ -713,46 +713,6 @@ void TIntermTraverser::queueReplacementWithParent(TIntermNode *parent,
mReplacements.push_back(NodeUpdateEntry(parent, original, replacement, originalBecomesChild));
}
TName TIntermTraverser::GetInternalFunctionName(const char *name)
{
TString nameStr(name);
TName nameObj(nameStr);
nameObj.setInternal(true);
return nameObj;
}
TIntermFunctionPrototype *TIntermTraverser::CreateInternalFunctionPrototypeNode(
const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId)
{
TIntermFunctionPrototype *functionNode = new TIntermFunctionPrototype(returnType, functionId);
functionNode->getFunctionSymbolInfo()->setNameObj(GetInternalFunctionName(name));
return functionNode;
}
TIntermFunctionDefinition *TIntermTraverser::CreateInternalFunctionDefinitionNode(
const TType &returnType,
const char *name,
TIntermBlock *functionBody,
const TSymbolUniqueId &functionId)
{
TIntermFunctionPrototype *prototypeNode =
CreateInternalFunctionPrototypeNode(returnType, name, functionId);
return new TIntermFunctionDefinition(prototypeNode, functionBody);
}
TIntermAggregate *TIntermTraverser::CreateInternalFunctionCallNode(
const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId,
TIntermSequence *arguments)
{
TIntermAggregate *functionNode = TIntermAggregate::CreateFunctionCall(
returnType, functionId, GetInternalFunctionName(name), arguments);
return functionNode;
}
TLValueTrackingTraverser::TLValueTrackingTraverser(bool preVisit,
bool inVisit,
bool postVisit,
......
......@@ -102,20 +102,6 @@ class TIntermTraverser : angle::NonCopyable
// Start creating temporary symbols from the given temporary symbol index + 1.
void useTemporaryId(TSymbolUniqueId *temporaryId);
static TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode(
const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId);
static TIntermFunctionDefinition *CreateInternalFunctionDefinitionNode(
const TType &returnType,
const char *name,
TIntermBlock *functionBody,
const TSymbolUniqueId &functionId);
static TIntermAggregate *CreateInternalFunctionCallNode(const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId,
TIntermSequence *arguments);
protected:
// Should only be called from traverse*() functions
void incrementDepth(TIntermNode *current)
......@@ -261,8 +247,6 @@ class TIntermTraverser : angle::NonCopyable
std::vector<NodeInsertMultipleEntry> mInsertions;
private:
static TName GetInternalFunctionName(const char *name);
static bool CompareInsertion(const NodeInsertMultipleEntry &a,
const NodeInsertMultipleEntry &b);
......
//
// Copyright (c) 2002-2014 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.
//
//
// Build the intermediate representation.
//
#include <float.h>
#include <limits.h>
#include <algorithm>
#include "compiler/translator/Intermediate.h"
#include "compiler/translator/SymbolTable.h"
namespace sh
{
////////////////////////////////////////////////////////////////////////////
//
// First set of functions are to help build the intermediate representation.
// These functions are not member functions of the nodes.
// They are called from parser productions.
//
/////////////////////////////////////////////////////////////////////////////
// If the input node is nullptr, return nullptr.
// If the input node is a block node, return it.
// If the input node is not a block node, put it inside a block node and return that.
TIntermBlock *TIntermediate::EnsureBlock(TIntermNode *node)
{
if (node == nullptr)
return nullptr;
TIntermBlock *blockNode = node->getAsBlock();
if (blockNode != nullptr)
return blockNode;
blockNode = new TIntermBlock();
blockNode->setLine(node->getLine());
blockNode->appendStatement(node);
return blockNode;
}
} // namespace sh
//
// Copyright (c) 2002-2014 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.
//
#ifndef COMPILER_TRANSLATOR_INTERMEDIATE_H_
#define COMPILER_TRANSLATOR_INTERMEDIATE_H_
#include "compiler/translator/IntermNode.h"
namespace sh
{
//
// Set of helper functions to help build the tree.
// TODO(oetuaho@nvidia.com): Clean this up, it doesn't need to be a class.
//
class TIntermediate
{
public:
static TIntermBlock *EnsureBlock(TIntermNode *node);
private:
TIntermediate(){};
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_INTERMEDIATE_H_
......@@ -12,6 +12,7 @@
#include "common/mathutil.h"
#include "compiler/preprocessor/SourceLocation.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/ValidateGlobalInitializer.h"
#include "compiler/translator/ValidateSwitch.h"
#include "compiler/translator/glslang.h"
......@@ -1875,7 +1876,7 @@ TIntermNode *TParseContext::addLoop(TLoopType type,
(typedCond->getBasicType() == EbtBool && !typedCond->isArray() &&
!typedCond->isVector()));
node = new TIntermLoop(type, init, typedCond, expr, TIntermediate::EnsureBlock(body));
node = new TIntermLoop(type, init, typedCond, expr, EnsureBlock(body));
node->setLine(line);
return node;
}
......@@ -1898,8 +1899,7 @@ TIntermNode *TParseContext::addLoop(TLoopType type,
TIntermBinary *conditionInit = new TIntermBinary(EOpAssign, declarator->getLeft()->deepCopy(),
declarator->getRight()->deepCopy());
TIntermLoop *loop =
new TIntermLoop(type, init, conditionInit, expr, TIntermediate::EnsureBlock(body));
TIntermLoop *loop = new TIntermLoop(type, init, conditionInit, expr, EnsureBlock(body));
block->appendStatement(loop);
loop->setLine(line);
block->setLine(line);
......@@ -1917,16 +1917,15 @@ TIntermNode *TParseContext::addIfElse(TIntermTyped *cond,
{
if (cond->getAsConstantUnion()->getBConst(0) == true)
{
return TIntermediate::EnsureBlock(code.node1);
return EnsureBlock(code.node1);
}
else
{
return TIntermediate::EnsureBlock(code.node2);
return EnsureBlock(code.node2);
}
}
TIntermIfElse *node = new TIntermIfElse(cond, TIntermediate::EnsureBlock(code.node1),
TIntermediate::EnsureBlock(code.node2));
TIntermIfElse *node = new TIntermIfElse(cond, EnsureBlock(code.node1), EnsureBlock(code.node2));
node->setLine(loc);
return node;
......@@ -3084,14 +3083,14 @@ TIntermTyped *TParseContext::addConstructor(TIntermSequence *arguments,
{
error(line, "implicitly sized array constructor must have at least one argument", "[]");
type.setArraySize(1u);
return TIntermTyped::CreateZero(type);
return CreateZeroNode(type);
}
type.setArraySize(static_cast<unsigned int>(arguments->size()));
}
if (!checkConstructorArguments(line, arguments, type))
{
return TIntermTyped::CreateZero(type);
return CreateZeroNode(type);
}
TIntermAggregate *constructorNode = TIntermAggregate::CreateConstructor(type, arguments);
......@@ -3350,7 +3349,7 @@ TIntermTyped *TParseContext::addIndexExpression(TIntermTyped *baseExpression,
error(location, " left of '[' is not of type array, matrix, or vector ", "expression");
}
return TIntermTyped::CreateZero(TType(EbtFloat, EbpHigh, EvqConst));
return CreateZeroNode(TType(EbtFloat, EbpHigh, EvqConst));
}
TIntermConstantUnion *indexConstantUnion = indexExpression->getAsConstantUnion();
......@@ -3537,7 +3536,7 @@ TIntermTyped *TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpre
}
if (fieldFound)
{
TIntermTyped *index = TIntermTyped::CreateIndexNode(i);
TIntermTyped *index = CreateIndexNode(i);
index->setLine(fieldLocation);
TIntermBinary *node =
new TIntermBinary(EOpIndexDirectStruct, baseExpression, index);
......@@ -3573,7 +3572,7 @@ TIntermTyped *TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpre
}
if (fieldFound)
{
TIntermTyped *index = TIntermTyped::CreateIndexNode(i);
TIntermTyped *index = CreateIndexNode(i);
index->setLine(fieldLocation);
TIntermBinary *node =
new TIntermBinary(EOpIndexDirectInterfaceBlock, baseExpression, index);
......@@ -4577,7 +4576,7 @@ TIntermTyped *TParseContext::addBinaryMathBooleanResult(TOperator op,
{
binaryOpError(loc, GetOperatorString(op), left->getCompleteString(),
right->getCompleteString());
node = TIntermTyped::CreateZero(TType(EbtBool, EbpUndefined, EvqConst));
node = CreateBoolNode(false);
node->setLine(loc);
}
return node;
......@@ -5011,7 +5010,7 @@ TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunction *fnCall,
}
// Error message was already written. Put on a dummy node for error recovery.
return TIntermTyped::CreateZero(TType(EbtFloat, EbpMedium, EvqConst));
return CreateZeroNode(TType(EbtFloat, EbpMedium, EvqConst));
}
TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond,
......
......@@ -9,7 +9,6 @@
#include "compiler/translator/Compiler.h"
#include "compiler/translator/Diagnostics.h"
#include "compiler/translator/DirectiveHandler.h"
#include "compiler/translator/Intermediate.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/QualifierTypes.h"
#include "compiler/preprocessor/Preprocessor.h"
......
......@@ -11,6 +11,7 @@
#include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNodePatternMatcher.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h"
......@@ -94,7 +95,7 @@ TIntermBinary *CreateIndexDirectBaseSymbolNode(const TType &indexedType,
{
TIntermSymbol *baseSymbol = CreateBaseSymbol(indexedType, baseQualifier);
TIntermBinary *indexNode =
new TIntermBinary(EOpIndexDirect, baseSymbol, TIntermTyped::CreateIndexNode(index));
new TIntermBinary(EOpIndexDirect, baseSymbol, CreateIndexNode(index));
return indexNode;
}
......@@ -199,8 +200,8 @@ TIntermFunctionDefinition *GetIndexFunctionDefinition(TType type,
}
std::string functionName = GetIndexFunctionName(type, write);
TIntermFunctionPrototype *prototypeNode = TIntermTraverser::CreateInternalFunctionPrototypeNode(
returnType, functionName.c_str(), functionId);
TIntermFunctionPrototype *prototypeNode =
CreateInternalFunctionPrototypeNode(returnType, functionName.c_str(), functionId);
TQualifier baseQualifier = EvqInOut;
if (!write)
......@@ -352,8 +353,8 @@ TIntermAggregate *CreateIndexFunctionCall(TIntermBinary *node,
TType fieldType = GetFieldType(node->getLeft()->getType());
std::string functionName = GetIndexFunctionName(node->getLeft()->getType(), false);
TIntermAggregate *indexingCall = TIntermTraverser::CreateInternalFunctionCallNode(
fieldType, functionName.c_str(), functionId, arguments);
TIntermAggregate *indexingCall =
CreateInternalFunctionCallNode(fieldType, functionName.c_str(), functionId, arguments);
indexingCall->setLine(node->getLine());
indexingCall->getFunctionSymbolInfo()->setKnownToNotHaveSideEffects(true);
return indexingCall;
......@@ -372,8 +373,8 @@ TIntermAggregate *CreateIndexedWriteFunctionCall(TIntermBinary *node,
arguments->push_back(writtenValue);
std::string functionName = GetIndexFunctionName(node->getLeft()->getType(), true);
TIntermAggregate *indexedWriteCall = TIntermTraverser::CreateInternalFunctionCallNode(
TType(EbtVoid), functionName.c_str(), functionId, arguments);
TIntermAggregate *indexedWriteCall =
CreateInternalFunctionCallNode(TType(EbtVoid), functionName.c_str(), functionId, arguments);
indexedWriteCall->setLine(node->getLine());
return indexedWriteCall;
}
......
......@@ -9,7 +9,7 @@
#include "compiler/translator/RewriteElseBlocks.h"
#include "compiler/translator/Intermediate.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/NodeSearch.h"
#include "compiler/translator/SymbolTable.h"
......@@ -84,8 +84,7 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse)
// returns (that are unreachable) we can silence this compile error.
if (mFunctionType && mFunctionType->getBasicType() != EbtVoid)
{
TIntermNode *returnNode =
new TIntermBranch(EOpReturn, TIntermTyped::CreateZero(*mFunctionType));
TIntermNode *returnNode = new TIntermBranch(EOpReturn, CreateZeroNode(*mFunctionType));
negatedElse = new TIntermBlock();
negatedElse->appendStatement(returnNode);
}
......@@ -94,7 +93,7 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse)
TIntermUnary *negatedCondition = new TIntermUnary(EOpLogicalNot, conditionSymbolElse);
TIntermIfElse *falseIfElse =
new TIntermIfElse(negatedCondition, ifElse->getFalseBlock(), negatedElse);
falseBlock = TIntermediate::EnsureBlock(falseIfElse);
falseBlock = EnsureBlock(falseIfElse);
}
TIntermSymbol *conditionSymbolSel = createTempSymbol(boolType);
......
......@@ -9,6 +9,7 @@
#include "compiler/translator/RewriteTexelFetchOffset.h"
#include "common/angleutils.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h"
......@@ -107,7 +108,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
TIntermSequence *constructOffsetIvecArguments = new TIntermSequence();
constructOffsetIvecArguments->push_back(sequence->at(3)->getAsTyped());
TIntermTyped *zeroNode = TIntermTyped::CreateZero(TType(EbtInt));
TIntermTyped *zeroNode = CreateZeroNode(TType(EbtInt));
constructOffsetIvecArguments->push_back(zeroNode);
offsetNode = TIntermAggregate::CreateConstructor(texCoordNode->getType(),
......
......@@ -6,6 +6,7 @@
#include "compiler/translator/RewriteUnaryMinusOperatorFloat.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh
......@@ -72,7 +73,7 @@ bool Traverser::visitUnary(Visit visit, TIntermUnary *node)
}
// 0.0 - float
TIntermTyped *zero = TIntermTyped::CreateZero(fValue->getType());
TIntermTyped *zero = CreateZeroNode(fValue->getType());
zero->setLine(fValue->getLine());
TIntermBinary *sub = new TIntermBinary(EOpSub, zero, fValue);
sub->setLine(fValue->getLine());
......
......@@ -15,6 +15,7 @@
#include "angle_gl.h"
#include "common/angleutils.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh
......@@ -47,15 +48,14 @@ bool ContainsVectorNode(const TIntermSequence &sequence)
TIntermBinary *ConstructVectorIndexBinaryNode(TIntermSymbol *symbolNode, int index)
{
return new TIntermBinary(EOpIndexDirect, symbolNode, TIntermTyped::CreateIndexNode(index));
return new TIntermBinary(EOpIndexDirect, symbolNode, CreateIndexNode(index));
}
TIntermBinary *ConstructMatrixIndexBinaryNode(TIntermSymbol *symbolNode, int colIndex, int rowIndex)
{
TIntermBinary *colVectorNode = ConstructVectorIndexBinaryNode(symbolNode, colIndex);
return new TIntermBinary(EOpIndexDirect, colVectorNode,
TIntermTyped::CreateIndexNode(rowIndex));
return new TIntermBinary(EOpIndexDirect, colVectorNode, CreateIndexNode(rowIndex));
}
class ScalarizeArgsTraverser : public TIntermTraverser
......
......@@ -11,6 +11,7 @@
#include "compiler/translator/SimplifyLoopConditions.h"
#include "compiler/translator/IntermNodePatternMatcher.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh
......@@ -19,15 +20,6 @@ namespace sh
namespace
{
TIntermConstantUnion *CreateBoolConstantNode(bool value)
{
TConstantUnion *u = new TConstantUnion;
u->setBConst(value);
TIntermConstantUnion *node =
new TIntermConstantUnion(u, TType(EbtBool, EbpUndefined, EvqConst, 1));
return node;
}
class SimplifyLoopConditionsTraverser : public TLValueTrackingTraverser
{
public:
......@@ -188,7 +180,7 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node)
// s0 = expr;
// } while (s0);
TIntermSequence tempInitSeq;
tempInitSeq.push_back(createTempInitDeclaration(CreateBoolConstantNode(true)));
tempInitSeq.push_back(createTempInitDeclaration(CreateBoolNode(true)));
insertStatementsInParentBlock(tempInitSeq);
TIntermBlock *newBody = new TIntermBlock();
......@@ -237,7 +229,7 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node)
}
else
{
conditionInitializer = TIntermTyped::CreateBool(true);
conditionInitializer = CreateBoolNode(true);
}
loopScopeSequence->push_back(createTempInitDeclaration(conditionInitializer));
......
......@@ -12,6 +12,7 @@
#include "compiler/translator/FindMain.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/util.h"
......@@ -55,8 +56,7 @@ void AddFieldUseStatements(const ShaderVariable &var,
{
for (unsigned int i = 0; i < var.arraySize; ++i)
{
TIntermBinary *element =
new TIntermBinary(EOpIndexDirect, symbol, TIntermTyped::CreateIndexNode(i));
TIntermBinary *element = new TIntermBinary(EOpIndexDirect, symbol, CreateIndexNode(i));
sequence->insert(sequence->begin(), element);
}
}
......@@ -87,13 +87,12 @@ void InsertUseCode(TIntermSequence *sequence,
TIntermSymbol *arraySymbol = new TIntermSymbol(0, name, ubInfo->getType());
for (unsigned int i = 0; i < block.arraySize; ++i)
{
TIntermBinary *instanceSymbol = new TIntermBinary(EOpIndexDirect, arraySymbol,
TIntermTyped::CreateIndexNode(i));
TIntermBinary *instanceSymbol =
new TIntermBinary(EOpIndexDirect, arraySymbol, CreateIndexNode(i));
for (unsigned int j = 0; j < block.fields.size(); ++j)
{
TIntermBinary *element =
new TIntermBinary(EOpIndexDirectInterfaceBlock, instanceSymbol,
TIntermTyped::CreateIndexNode(j));
TIntermBinary *element = new TIntermBinary(EOpIndexDirectInterfaceBlock,
instanceSymbol, CreateIndexNode(j));
sequence->insert(sequence->begin(), element);
}
}
......@@ -106,8 +105,8 @@ void InsertUseCode(TIntermSequence *sequence,
TIntermSymbol *blockSymbol = new TIntermSymbol(0, name, ubInfo->getType());
for (unsigned int i = 0; i < block.fields.size(); ++i)
{
TIntermBinary *element = new TIntermBinary(
EOpIndexDirectInterfaceBlock, blockSymbol, TIntermTyped::CreateIndexNode(i));
TIntermBinary *element = new TIntermBinary(EOpIndexDirectInterfaceBlock,
blockSymbol, CreateIndexNode(i));
sequence->insert(sequence->begin(), element);
}
......
......@@ -10,6 +10,7 @@
#include "common/angleutils.h"
#include "compiler/translator/FindMain.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/IntermTraverse.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
......@@ -77,7 +78,7 @@ ExpectedLValues CreateIndexedLValueNodeList(const TString &lValueName,
{
expected[index] =
new TIntermBinary(EOpIndexDirect, new TIntermSymbol(0, lValueName, elementType),
TIntermTyped::CreateIndexNode(static_cast<int>(index)));
CreateIndexNode(static_cast<int>(index)));
}
return expected;
}
......
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