Commit cccf2b00 by Olli Etuaho Committed by Commit Bot

Reorganize AST traversal utility code

Define TIntermTraverser and TIntermLValueTrackingTraverser in a separate header file. hash() function is moved out from TIntermTraverser as it is not related to the core functionality of traversing and transforming ASTs. Also reorganize some traversers to follow common conventions: - Intermediate output is now in OutputTree.h/.cpp - Max tree depth check is now in IsASTDepthBelowLimit.h/.cpp BUG=angleproject:1490 TEST=angle_unittests Change-Id: Id4968aa9d4e24d0c5bac90dc147fc9f310de0184 Reviewed-on: https://chromium-review.googlesource.com/559531Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent a3e1f5f7
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
'compiler/translator/FindSymbolNode.h', 'compiler/translator/FindSymbolNode.h',
'compiler/translator/FlagStd140Structs.cpp', 'compiler/translator/FlagStd140Structs.cpp',
'compiler/translator/FlagStd140Structs.h', 'compiler/translator/FlagStd140Structs.h',
'compiler/translator/HashNames.cpp',
'compiler/translator/HashNames.h', 'compiler/translator/HashNames.h',
'compiler/translator/InfoSink.cpp', 'compiler/translator/InfoSink.cpp',
'compiler/translator/InfoSink.h', 'compiler/translator/InfoSink.h',
...@@ -75,11 +76,16 @@ ...@@ -75,11 +76,16 @@
'compiler/translator/IntermNodePatternMatcher.cpp', 'compiler/translator/IntermNodePatternMatcher.cpp',
'compiler/translator/IntermNodePatternMatcher.h', 'compiler/translator/IntermNodePatternMatcher.h',
'compiler/translator/IntermTraverse.cpp', 'compiler/translator/IntermTraverse.cpp',
'compiler/translator/IntermTraverse.h',
'compiler/translator/Intermediate.h', 'compiler/translator/Intermediate.h',
'compiler/translator/Intermediate.cpp', 'compiler/translator/Intermediate.cpp',
'compiler/translator/IsASTDepthBelowLimit.cpp',
'compiler/translator/IsASTDepthBelowLimit.h',
'compiler/translator/NodeSearch.h', 'compiler/translator/NodeSearch.h',
'compiler/translator/Operator.cpp', 'compiler/translator/Operator.cpp',
'compiler/translator/Operator.h', 'compiler/translator/Operator.h',
'compiler/translator/OutputTree.cpp',
'compiler/translator/OutputTree.h',
'compiler/translator/ParamType.h', 'compiler/translator/ParamType.h',
'compiler/translator/ParseContext.cpp', 'compiler/translator/ParseContext.cpp',
'compiler/translator/ParseContext.h', 'compiler/translator/ParseContext.h',
...@@ -151,7 +157,6 @@ ...@@ -151,7 +157,6 @@
'compiler/translator/glslang_lex.cpp', 'compiler/translator/glslang_lex.cpp',
'compiler/translator/glslang_tab.cpp', 'compiler/translator/glslang_tab.cpp',
'compiler/translator/glslang_tab.h', 'compiler/translator/glslang_tab.h',
'compiler/translator/intermOut.cpp',
'compiler/translator/length_limits.h', 'compiler/translator/length_limits.h',
'compiler/translator/util.cpp', 'compiler/translator/util.cpp',
'compiler/translator/util.h', 'compiler/translator/util.h',
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "compiler/translator/ASTMetadataHLSL.h" #include "compiler/translator/ASTMetadataHLSL.h"
#include "compiler/translator/CallDAG.h" #include "compiler/translator/CallDAG.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
namespace sh namespace sh
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "compiler/translator/AddAndTrueToLoopCondition.h" #include "compiler/translator/AddAndTrueToLoopCondition.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "compiler/translator/ArrayReturnValueToOutParameter.h" #include "compiler/translator/ArrayReturnValueToOutParameter.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "BreakVariableAliasingInInnerLoops.h" #include "BreakVariableAliasingInInnerLoops.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
// A HLSL compiler developer gave us more details on the root cause and the workaround needed: // A HLSL compiler developer gave us more details on the root cause and the workaround needed:
// The root problem is that if the HLSL compiler is applying aliasing information even on // The root problem is that if the HLSL compiler is applying aliasing information even on
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "angle_gl.h"
#include "compiler/translator/BuiltInFunctionEmulator.h" #include "compiler/translator/BuiltInFunctionEmulator.h"
#include "compiler/translator/SymbolTable.h" #include "angle_gl.h"
#include "compiler/translator/Cache.h" #include "compiler/translator/Cache.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h"
namespace sh namespace sh
{ {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "compiler/translator/CallDAG.h" #include "compiler/translator/CallDAG.h"
#include "compiler/translator/Diagnostics.h" #include "compiler/translator/Diagnostics.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
namespace sh namespace sh
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "compiler/translator/Initialize.h" #include "compiler/translator/Initialize.h"
#include "compiler/translator/InitializeVariables.h" #include "compiler/translator/InitializeVariables.h"
#include "compiler/translator/IntermNodePatternMatcher.h" #include "compiler/translator/IntermNodePatternMatcher.h"
#include "compiler/translator/IsASTDepthBelowLimit.h"
#include "compiler/translator/OutputTree.h"
#include "compiler/translator/ParseContext.h" #include "compiler/translator/ParseContext.h"
#include "compiler/translator/PruneEmptyDeclarations.h" #include "compiler/translator/PruneEmptyDeclarations.h"
#include "compiler/translator/RegenerateStructNames.h" #include "compiler/translator/RegenerateStructNames.h"
...@@ -578,7 +580,7 @@ bool TCompiler::compile(const char *const shaderStrings[], ...@@ -578,7 +580,7 @@ bool TCompiler::compile(const char *const shaderStrings[],
if (root) if (root)
{ {
if (compileOptions & SH_INTERMEDIATE_TREE) if (compileOptions & SH_INTERMEDIATE_TREE)
TIntermediate::outputTree(root, infoSink.info); OutputTree(root, infoSink.info);
if (compileOptions & SH_OBJECT_CODE) if (compileOptions & SH_OBJECT_CODE)
translate(root, compileOptions); translate(root, compileOptions);
...@@ -910,10 +912,7 @@ bool TCompiler::pruneUnusedFunctions(TIntermBlock *root) ...@@ -910,10 +912,7 @@ bool TCompiler::pruneUnusedFunctions(TIntermBlock *root)
bool TCompiler::limitExpressionComplexity(TIntermBlock *root) bool TCompiler::limitExpressionComplexity(TIntermBlock *root)
{ {
TMaxDepthTraverser traverser(maxExpressionComplexity + 1); if (!IsASTDepthBelowLimit(root, maxExpressionComplexity))
root->traverse(&traverser);
if (traverser.getMaxDepth() > maxExpressionComplexity)
{ {
mDiagnostics.globalError("Expression too complex."); mDiagnostics.globalError("Expression too complex.");
return false; return false;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "compiler/translator/FindMain.h" #include "compiler/translator/FindMain.h"
#include "compiler/translator/InitializeVariables.h" #include "compiler/translator/InitializeVariables.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
namespace sh namespace sh
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "compiler/translator/EmulateGLFragColorBroadcast.h" #include "compiler/translator/EmulateGLFragColorBroadcast.h"
#include "compiler/translator/FindMain.h" #include "compiler/translator/FindMain.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#ifndef COMPILER_TRANSLATOR_EMULATE_PRECISION_H_ #ifndef COMPILER_TRANSLATOR_EMULATE_PRECISION_H_
#define COMPILER_TRANSLATOR_EMULATE_PRECISION_H_ #define COMPILER_TRANSLATOR_EMULATE_PRECISION_H_
#include "GLSLANG/ShaderLang.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/Compiler.h" #include "compiler/translator/Compiler.h"
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "GLSLANG/ShaderLang.h"
// This class gathers all compound assignments from the AST and can then write // This class gathers all compound assignments from the AST and can then write
// the functions required for their precision emulation. This way there is no // the functions required for their precision emulation. This way there is no
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <set> #include <set>
#include <string> #include <string>
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "compiler/translator/FindSymbolNode.h" #include "compiler/translator/FindSymbolNode.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef COMPILER_TRANSLATOR_FLAGSTD140STRUCTS_H_ #ifndef COMPILER_TRANSLATOR_FLAGSTD140STRUCTS_H_
#define COMPILER_TRANSLATOR_FLAGSTD140STRUCTS_H_ #define COMPILER_TRANSLATOR_FLAGSTD140STRUCTS_H_
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh 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.
//
#include "compiler/translator/HashNames.h"
namespace sh
{
TString HashName(const TString &name, ShHashFunction64 hashFunction)
{
if (hashFunction == nullptr || name.empty())
return name;
khronos_uint64_t number = (*hashFunction)(name.c_str(), name.length());
TStringStream stream;
stream << HASHED_NAME_PREFIX << std::hex << number;
TString hashedName = stream.str();
return hashedName;
}
} // namespace sh
...@@ -9,10 +9,20 @@ ...@@ -9,10 +9,20 @@
#include <map> #include <map>
#include "compiler/translator/IntermNode.h" #include "GLSLANG/ShaderLang.h"
#include "compiler/translator/Common.h"
#define HASHED_NAME_PREFIX "webgl_" #define HASHED_NAME_PREFIX "webgl_"
namespace sh
{
typedef std::map<TPersistString, TPersistString> NameMap; typedef std::map<TPersistString, TPersistString> NameMap;
// Return the original name if hash function pointer is NULL;
// otherwise return the hashed name.
TString HashName(const TString &name, ShHashFunction64 hashFunction);
} // namespace sh
#endif // COMPILER_TRANSLATOR_HASHNAMES_H_ #endif // COMPILER_TRANSLATOR_HASHNAMES_H_
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "common/debug.h" #include "common/debug.h"
#include "compiler/translator/FindMain.h" #include "compiler/translator/FindMain.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/util.h" #include "compiler/translator/util.h"
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "common/mathutil.h" #include "common/mathutil.h"
#include "common/matrix_utils.h" #include "common/matrix_utils.h"
#include "compiler/translator/Diagnostics.h" #include "compiler/translator/Diagnostics.h"
#include "compiler/translator/HashNames.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermNode.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/util.h" #include "compiler/translator/util.h"
...@@ -3306,149 +3305,4 @@ TConstantUnion *TIntermConstantUnion::FoldAggregateBuiltIn(TIntermAggregate *agg ...@@ -3306,149 +3305,4 @@ TConstantUnion *TIntermConstantUnion::FoldAggregateBuiltIn(TIntermAggregate *agg
return resultArray; return resultArray;
} }
// static
TString TIntermTraverser::hash(const TString &name, ShHashFunction64 hashFunction)
{
if (hashFunction == nullptr || name.empty())
return name;
khronos_uint64_t number = (*hashFunction)(name.c_str(), name.length());
TStringStream stream;
stream << HASHED_NAME_PREFIX << std::hex << number;
TString hashedName = stream.str();
return hashedName;
}
bool TIntermTraverser::CompareInsertion(const NodeInsertMultipleEntry &a,
const NodeInsertMultipleEntry &b)
{
if (a.parent != b.parent)
{
return a.parent > b.parent;
}
return a.position > b.position;
}
void TIntermTraverser::updateTree()
{
// Sort the insertions so that insertion position is decreasing. This way multiple insertions to
// the same parent node are handled correctly.
std::sort(mInsertions.begin(), mInsertions.end(), CompareInsertion);
for (size_t ii = 0; ii < mInsertions.size(); ++ii)
{
// We can't know here what the intended ordering of two insertions to the same position is,
// so it is not supported.
ASSERT(ii == 0 || mInsertions[ii].position != mInsertions[ii - 1].position ||
mInsertions[ii].parent != mInsertions[ii - 1].parent);
const NodeInsertMultipleEntry &insertion = mInsertions[ii];
ASSERT(insertion.parent);
if (!insertion.insertionsAfter.empty())
{
bool inserted = insertion.parent->insertChildNodes(insertion.position + 1,
insertion.insertionsAfter);
ASSERT(inserted);
}
if (!insertion.insertionsBefore.empty())
{
bool inserted =
insertion.parent->insertChildNodes(insertion.position, insertion.insertionsBefore);
ASSERT(inserted);
}
}
for (size_t ii = 0; ii < mReplacements.size(); ++ii)
{
const NodeUpdateEntry &replacement = mReplacements[ii];
ASSERT(replacement.parent);
bool replaced =
replacement.parent->replaceChildNode(replacement.original, replacement.replacement);
ASSERT(replaced);
if (!replacement.originalBecomesChildOfReplacement)
{
// In AST traversing, a parent is visited before its children.
// After we replace a node, if its immediate child is to
// be replaced, we need to make sure we don't update the replaced
// node; instead, we update the replacement node.
for (size_t jj = ii + 1; jj < mReplacements.size(); ++jj)
{
NodeUpdateEntry &replacement2 = mReplacements[jj];
if (replacement2.parent == replacement.original)
replacement2.parent = replacement.replacement;
}
}
}
for (size_t ii = 0; ii < mMultiReplacements.size(); ++ii)
{
const NodeReplaceWithMultipleEntry &replacement = mMultiReplacements[ii];
ASSERT(replacement.parent);
bool replaced = replacement.parent->replaceChildNodeWithMultiple(replacement.original,
replacement.replacements);
ASSERT(replaced);
}
clearReplacementQueue();
}
void TIntermTraverser::clearReplacementQueue()
{
mReplacements.clear();
mMultiReplacements.clear();
mInsertions.clear();
}
void TIntermTraverser::queueReplacement(TIntermNode *original,
TIntermNode *replacement,
OriginalNode originalStatus)
{
queueReplacementWithParent(getParentNode(), original, replacement, originalStatus);
}
void TIntermTraverser::queueReplacementWithParent(TIntermNode *parent,
TIntermNode *original,
TIntermNode *replacement,
OriginalNode originalStatus)
{
bool originalBecomesChild = (originalStatus == OriginalNode::BECOMES_CHILD);
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;
}
} // namespace sh } // namespace sh
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
...@@ -621,6 +622,152 @@ void TIntermTraverser::traverseAggregate(TIntermAggregate *node) ...@@ -621,6 +622,152 @@ void TIntermTraverser::traverseAggregate(TIntermAggregate *node)
visitAggregate(PostVisit, node); visitAggregate(PostVisit, node);
} }
bool TIntermTraverser::CompareInsertion(const NodeInsertMultipleEntry &a,
const NodeInsertMultipleEntry &b)
{
if (a.parent != b.parent)
{
return a.parent > b.parent;
}
return a.position > b.position;
}
void TIntermTraverser::updateTree()
{
// Sort the insertions so that insertion position is decreasing. This way multiple insertions to
// the same parent node are handled correctly.
std::sort(mInsertions.begin(), mInsertions.end(), CompareInsertion);
for (size_t ii = 0; ii < mInsertions.size(); ++ii)
{
// We can't know here what the intended ordering of two insertions to the same position is,
// so it is not supported.
ASSERT(ii == 0 || mInsertions[ii].position != mInsertions[ii - 1].position ||
mInsertions[ii].parent != mInsertions[ii - 1].parent);
const NodeInsertMultipleEntry &insertion = mInsertions[ii];
ASSERT(insertion.parent);
if (!insertion.insertionsAfter.empty())
{
bool inserted = insertion.parent->insertChildNodes(insertion.position + 1,
insertion.insertionsAfter);
ASSERT(inserted);
}
if (!insertion.insertionsBefore.empty())
{
bool inserted =
insertion.parent->insertChildNodes(insertion.position, insertion.insertionsBefore);
ASSERT(inserted);
}
}
for (size_t ii = 0; ii < mReplacements.size(); ++ii)
{
const NodeUpdateEntry &replacement = mReplacements[ii];
ASSERT(replacement.parent);
bool replaced =
replacement.parent->replaceChildNode(replacement.original, replacement.replacement);
ASSERT(replaced);
if (!replacement.originalBecomesChildOfReplacement)
{
// In AST traversing, a parent is visited before its children.
// After we replace a node, if its immediate child is to
// be replaced, we need to make sure we don't update the replaced
// node; instead, we update the replacement node.
for (size_t jj = ii + 1; jj < mReplacements.size(); ++jj)
{
NodeUpdateEntry &replacement2 = mReplacements[jj];
if (replacement2.parent == replacement.original)
replacement2.parent = replacement.replacement;
}
}
}
for (size_t ii = 0; ii < mMultiReplacements.size(); ++ii)
{
const NodeReplaceWithMultipleEntry &replacement = mMultiReplacements[ii];
ASSERT(replacement.parent);
bool replaced = replacement.parent->replaceChildNodeWithMultiple(replacement.original,
replacement.replacements);
ASSERT(replaced);
}
clearReplacementQueue();
}
void TIntermTraverser::clearReplacementQueue()
{
mReplacements.clear();
mMultiReplacements.clear();
mInsertions.clear();
}
void TIntermTraverser::queueReplacement(TIntermNode *original,
TIntermNode *replacement,
OriginalNode originalStatus)
{
queueReplacementWithParent(getParentNode(), original, replacement, originalStatus);
}
void TIntermTraverser::queueReplacementWithParent(TIntermNode *parent,
TIntermNode *original,
TIntermNode *replacement,
OriginalNode originalStatus)
{
bool originalBecomesChild = (originalStatus == OriginalNode::BECOMES_CHILD);
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,
const TSymbolTable &symbolTable,
int shaderVersion)
: TIntermTraverser(preVisit, inVisit, postVisit),
mOperatorRequiresLValue(false),
mInFunctionCallOutParameter(false),
mSymbolTable(symbolTable),
mShaderVersion(shaderVersion)
{
}
void TLValueTrackingTraverser::traverseFunctionPrototype(TIntermFunctionPrototype *node) void TLValueTrackingTraverser::traverseFunctionPrototype(TIntermFunctionPrototype *node)
{ {
TIntermSequence *sequence = node->getSequence(); TIntermSequence *sequence = node->getSequence();
......
...@@ -54,8 +54,6 @@ class TIntermediate ...@@ -54,8 +54,6 @@ class TIntermediate
const TVectorFields &fields, const TVectorFields &fields,
const TSourceLoc &dotLocation); const TSourceLoc &dotLocation);
static void outputTree(TIntermNode *, TInfoSinkBase &);
TIntermTyped *foldAggregateBuiltIn(TIntermAggregate *aggregate, TDiagnostics *diagnostics); TIntermTyped *foldAggregateBuiltIn(TIntermAggregate *aggregate, TDiagnostics *diagnostics);
private: private:
......
//
// 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.
//
#include "compiler/translator/IsASTDepthBelowLimit.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh
{
namespace
{
// Traverse the tree and compute max depth. Takes a maximum depth limit to prevent stack overflow.
class MaxDepthTraverser : public TIntermTraverser
{
public:
MaxDepthTraverser(int depthLimit) : TIntermTraverser(true, true, false), mDepthLimit(depthLimit)
{
}
bool visitBinary(Visit, TIntermBinary *) override { return depthCheck(); }
bool visitUnary(Visit, TIntermUnary *) override { return depthCheck(); }
bool visitTernary(Visit, TIntermTernary *) override { return depthCheck(); }
bool visitSwizzle(Visit, TIntermSwizzle *) override { return depthCheck(); }
bool visitIfElse(Visit, TIntermIfElse *) override { return depthCheck(); }
bool visitAggregate(Visit, TIntermAggregate *) override { return depthCheck(); }
bool visitBlock(Visit, TIntermBlock *) override { return depthCheck(); }
bool visitLoop(Visit, TIntermLoop *) override { return depthCheck(); }
bool visitBranch(Visit, TIntermBranch *) override { return depthCheck(); }
protected:
bool depthCheck() const { return mMaxDepth < mDepthLimit; }
int mDepthLimit;
};
} // anonymous namespace
bool IsASTDepthBelowLimit(TIntermNode *root, int maxDepth)
{
MaxDepthTraverser traverser(maxDepth + 1);
root->traverse(&traverser);
return traverser.getMaxDepth() <= maxDepth;
}
} // 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.
//
// IsASTDepthBelowLimit: Check whether AST depth is below a specific limit.
#ifndef COMPILER_TRANSLATOR_ISASTDEPTHBELOWLIMIT_H_
#define COMPILER_TRANSLATOR_ISASTDEPTHBELOWLIMIT_H_
namespace sh
{
class TIntermNode;
bool IsASTDepthBelowLimit(TIntermNode *root, int maxDepth);
} // namespace sh
#endif // COMPILER_TRANSLATOR_ISASTDEPTHBELOWLIMIT_H_
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef COMPILER_TRANSLATOR_NODESEARCH_H_ #ifndef COMPILER_TRANSLATOR_NODESEARCH_H_
#define COMPILER_TRANSLATOR_NODESEARCH_H_ #define COMPILER_TRANSLATOR_NODESEARCH_H_
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "compiler/translator/OutputGLSL.h" #include "compiler/translator/OutputGLSL.h"
#include "compiler/translator/Compiler.h"
namespace sh namespace sh
{ {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "common/mathutil.h" #include "common/mathutil.h"
#include "compiler/translator/Compiler.h"
#include <cfloat> #include <cfloat>
...@@ -1160,7 +1161,7 @@ TString TOutputGLSLBase::hashName(const TName &name) ...@@ -1160,7 +1161,7 @@ TString TOutputGLSLBase::hashName(const TName &name)
NameMap::const_iterator it = mNameMap.find(name.getString().c_str()); NameMap::const_iterator it = mNameMap.find(name.getString().c_str());
if (it != mNameMap.end()) if (it != mNameMap.end())
return it->second.c_str(); return it->second.c_str();
TString hashedName = TIntermTraverser::hash(name.getString(), mHashFunction); TString hashedName = HashName(name.getString(), mHashFunction);
mNameMap[name.getString().c_str()] = hashedName.c_str(); mNameMap[name.getString().c_str()] = hashedName.c_str();
return hashedName; return hashedName;
} }
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
#include <set> #include <set>
#include "compiler/translator/IntermNode.h" #include "compiler/translator/HashNames.h"
#include "compiler/translator/ParseContext.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "compiler/translator/ASTMetadataHLSL.h" #include "compiler/translator/ASTMetadataHLSL.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/Compiler.h"
#include "compiler/translator/ParseContext.h" #include "compiler/translator/IntermTraverse.h"
class BuiltInFunctionEmulator; class BuiltInFunctionEmulator;
......
//
// 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.
//
// Output the AST intermediate representation of the GLSL code.
#ifndef COMPILER_TRANSLATOR_OUTPUTTREE_H_
#define COMPILER_TRANSLATOR_OUTPUTTREE_H_
namespace sh
{
class TIntermNode;
class TInfoSinkBase;
// Output the AST along with metadata.
void OutputTree(TIntermNode *root, TInfoSinkBase &out);
} // namespace sh
#endif // COMPILER_TRANSLATOR_OUTPUTTREE_H_
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "compiler/translator/PruneEmptyDeclarations.h" #include "compiler/translator/PruneEmptyDeclarations.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "compiler/translator/PrunePureLiteralStatements.h" #include "compiler/translator/PrunePureLiteralStatements.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "compiler/translator/RecordConstantPrecision.h" #include "compiler/translator/RecordConstantPrecision.h"
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef COMPILER_TRANSLATOR_REGENERATESTRUCTNAMES_H_ #ifndef COMPILER_TRANSLATOR_REGENERATESTRUCTNAMES_H_
#define COMPILER_TRANSLATOR_REGENERATESTRUCTNAMES_H_ #define COMPILER_TRANSLATOR_REGENERATESTRUCTNAMES_H_
#include "compiler/translator/Intermediate.h" #include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include <set> #include <set>
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "compiler/translator/RemoveDynamicIndexing.h" #include "compiler/translator/RemoveDynamicIndexing.h"
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/IntermNodePatternMatcher.h" #include "compiler/translator/IntermNodePatternMatcher.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
namespace sh namespace sh
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "compiler/translator/RemoveInvariantDeclaration.h" #include "compiler/translator/RemoveInvariantDeclaration.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "compiler/translator/RemovePow.h" #include "compiler/translator/RemovePow.h"
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef COMPILER_TRANSLATOR_REMOVESWITCHFALLTHROUGH_H_ #ifndef COMPILER_TRANSLATOR_REMOVESWITCHFALLTHROUGH_H_
#define COMPILER_TRANSLATOR_REMOVESWITCHFALLTHROUGH_H_ #define COMPILER_TRANSLATOR_REMOVESWITCHFALLTHROUGH_H_
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "compiler/translator/RewriteDoWhile.h" #include "compiler/translator/RewriteDoWhile.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "compiler/translator/RewriteTexelFetchOffset.h" #include "compiler/translator/RewriteTexelFetchOffset.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
namespace sh namespace sh
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "compiler/translator/RewriteUnaryMinusOperatorFloat.h" #include "compiler/translator/RewriteUnaryMinusOperatorFloat.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "compiler/translator/RewriteUnaryMinusOperatorInt.h" #include "compiler/translator/RewriteUnaryMinusOperatorInt.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef COMPILER_TRANSLATOR_SEARCHSYMBOL_H_ #ifndef COMPILER_TRANSLATOR_SEARCHSYMBOL_H_
#define COMPILER_TRANSLATOR_SEARCHSYMBOL_H_ #define COMPILER_TRANSLATOR_SEARCHSYMBOL_H_
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/ParseContext.h" #include "compiler/translator/ParseContext.h"
namespace sh namespace sh
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "compiler/translator/SeparateDeclarations.h" #include "compiler/translator/SeparateDeclarations.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "compiler/translator/SeparateExpressionsReturningArrays.h" #include "compiler/translator/SeparateExpressionsReturningArrays.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/IntermNodePatternMatcher.h" #include "compiler/translator/IntermNodePatternMatcher.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "compiler/translator/SimplifyLoopConditions.h" #include "compiler/translator/SimplifyLoopConditions.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/IntermNodePatternMatcher.h" #include "compiler/translator/IntermNodePatternMatcher.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "compiler/translator/SplitSequenceOperator.h" #include "compiler/translator/SplitSequenceOperator.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/IntermNodePatternMatcher.h" #include "compiler/translator/IntermNodePatternMatcher.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#define COMPILER_TRANSLATOR_UNFOLDSHORTCIRCUITAST_H_ #define COMPILER_TRANSLATOR_UNFOLDSHORTCIRCUITAST_H_
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "compiler/translator/UnfoldShortCircuitToIf.h" #include "compiler/translator/UnfoldShortCircuitToIf.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/IntermNodePatternMatcher.h" #include "compiler/translator/IntermNodePatternMatcher.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "compiler/translator/ValidateGlobalInitializer.h" #include "compiler/translator/ValidateGlobalInitializer.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/ParseContext.h" #include "compiler/translator/ParseContext.h"
namespace sh namespace sh
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "compiler/translator/Diagnostics.h" #include "compiler/translator/Diagnostics.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/ParseContext.h" #include "compiler/translator/ParseContext.h"
namespace sh namespace sh
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "compiler/translator/Diagnostics.h" #include "compiler/translator/Diagnostics.h"
#include "compiler/translator/FindSymbolNode.h" #include "compiler/translator/FindSymbolNode.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
namespace sh namespace sh
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <set> #include <set>
#include "compiler/translator/InfoSink.h" #include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/ParseContext.h" #include "compiler/translator/ParseContext.h"
namespace sh namespace sh
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "compiler/translator/ValidateSwitch.h" #include "compiler/translator/ValidateSwitch.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/Diagnostics.h" #include "compiler/translator/Diagnostics.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "common/utilities.h" #include "common/utilities.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/HashNames.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/util.h" #include "compiler/translator/util.h"
...@@ -440,7 +441,7 @@ void CollectVariablesTraverser::setCommonVariableProperties(const TType &type, ...@@ -440,7 +441,7 @@ void CollectVariablesTraverser::setCommonVariableProperties(const TType &type,
} }
} }
variableOut->name = name.c_str(); variableOut->name = name.c_str();
variableOut->mappedName = TIntermTraverser::hash(name, mHashFunction).c_str(); variableOut->mappedName = HashName(name, mHashFunction).c_str();
variableOut->arraySize = type.getArraySize(); variableOut->arraySize = type.getArraySize();
} }
...@@ -504,8 +505,7 @@ InterfaceBlock CollectVariablesTraverser::recordInterfaceBlock(const TIntermSymb ...@@ -504,8 +505,7 @@ InterfaceBlock CollectVariablesTraverser::recordInterfaceBlock(const TIntermSymb
InterfaceBlock interfaceBlock; InterfaceBlock interfaceBlock;
interfaceBlock.name = blockType->name().c_str(); interfaceBlock.name = blockType->name().c_str();
interfaceBlock.mappedName = interfaceBlock.mappedName = HashName(blockType->name().c_str(), mHashFunction).c_str();
TIntermTraverser::hash(blockType->name().c_str(), mHashFunction).c_str();
interfaceBlock.instanceName = interfaceBlock.instanceName =
(blockType->hasInstanceName() ? blockType->instanceName().c_str() : ""); (blockType->hasInstanceName() ? blockType->instanceName().c_str() : "");
interfaceBlock.arraySize = variable.getArraySize(); interfaceBlock.arraySize = variable.getArraySize();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef COMPILER_TRANSLATOR_VERSIONGLSL_H_ #ifndef COMPILER_TRANSLATOR_VERSIONGLSL_H_
#define COMPILER_TRANSLATOR_VERSIONGLSL_H_ #define COMPILER_TRANSLATOR_VERSIONGLSL_H_
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/Pragma.h" #include "compiler/translator/Pragma.h"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/FindMain.h" #include "compiler/translator/FindMain.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "tests/test_utils/ShaderCompileTreeTest.h" #include "tests/test_utils/ShaderCompileTreeTest.h"
#include <algorithm> #include <algorithm>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// //
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "tests/test_utils/ShaderCompileTreeTest.h" #include "tests/test_utils/ShaderCompileTreeTest.h"
#include "tests/test_utils/compiler_test.h" #include "tests/test_utils/compiler_test.h"
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <vector> #include <vector>
#include "common/mathutil.h" #include "common/mathutil.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermTraverse.h"
#include "tests/test_utils/ShaderCompileTreeTest.h" #include "tests/test_utils/ShaderCompileTreeTest.h"
namespace sh namespace sh
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "tests/test_utils/ShaderCompileTreeTest.h" #include "tests/test_utils/ShaderCompileTreeTest.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/TranslatorESSL.h" #include "compiler/translator/TranslatorESSL.h"
namespace sh namespace sh
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "compiler/translator/Compiler.h" #include "compiler/translator/Compiler.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh namespace sh
{ {
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "third_party/compiler/ArrayBoundsClamper.h" #include "third_party/compiler/ArrayBoundsClamper.h"
#include "compiler/translator/IntermTraverse.h"
// The built-in 'clamp' instruction only accepts floats and returns a float. I // The built-in 'clamp' instruction only accepts floats and returns a float. I
// iterated a few times with our driver team who examined the output from our // iterated a few times with our driver team who examined the output from our
// compiler - they said the multiple casts generates more code than a single // compiler - they said the multiple casts generates more code than a single
......
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