Commit 4cafb867 by Olli Etuaho Committed by Commit Bot

Sanitize AST nodes created by UseInterfaceBlockFields

Don't add the same node pointer to the AST more than once, and assign the right symbol ids to symbol nodes. BUG=angleproject:1490 TEST=angle_unittests, angle_end2end_tests Change-Id: I3f00e9234245fe4b81a2388df3f83e13c4c24856 Reviewed-on: https://chromium-review.googlesource.com/559534Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent cca63f2e
......@@ -8,6 +8,8 @@
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/SymbolTable.h"
namespace sh
{
......@@ -164,4 +166,11 @@ TIntermBlock *EnsureBlock(TIntermNode *node)
return blockNode;
}
TIntermSymbol *ReferToGlobalSymbol(const TString &name, const TSymbolTable &symbolTable)
{
TVariable *var = reinterpret_cast<TVariable *>(symbolTable.findGlobal(name));
ASSERT(var);
return new TIntermSymbol(var->getUniqueId(), name, var->getType());
}
} // namespace sh
......@@ -35,6 +35,8 @@ TIntermConstantUnion *CreateBoolNode(bool value);
// If the input node is not a block node, put it inside a block node and return that.
TIntermBlock *EnsureBlock(TIntermNode *node);
TIntermSymbol *ReferToGlobalSymbol(const TString &name, const TSymbolTable &symbolTable);
} // namespace sh
#endif // COMPILER_TRANSLATOR_INTERMNODEUTIL_H_
\ No newline at end of file
......@@ -35,28 +35,13 @@ void AddFieldUseStatements(const ShaderVariable &var,
name = name.substr(0, pos);
}
}
const TType *type;
TType basicType;
if (var.isStruct())
{
TVariable *structInfo = reinterpret_cast<TVariable *>(symbolTable.findGlobal(name));
ASSERT(structInfo);
const TType &structType = structInfo->getType();
type = &structType;
}
else
{
basicType = sh::GetShaderVariableBasicType(var);
type = &basicType;
}
ASSERT(type);
TIntermSymbol *symbol = new TIntermSymbol(0, name, *type);
TIntermSymbol *symbol = ReferToGlobalSymbol(name, symbolTable);
if (var.isArray())
{
for (unsigned int i = 0; i < var.arraySize; ++i)
for (unsigned int i = 0u; i < var.arraySize; ++i)
{
TIntermBinary *element = new TIntermBinary(EOpIndexDirect, symbol, CreateIndexNode(i));
TIntermBinary *element =
new TIntermBinary(EOpIndexDirect, symbol->deepCopy(), CreateIndexNode(i));
sequence->insert(sequence->begin(), element);
}
}
......@@ -66,6 +51,16 @@ void AddFieldUseStatements(const ShaderVariable &var,
}
}
void InsertUseCode(const InterfaceBlock &block, TIntermTyped *blockNode, TIntermSequence *sequence)
{
for (unsigned int i = 0; i < block.fields.size(); ++i)
{
TIntermBinary *element = new TIntermBinary(EOpIndexDirectInterfaceBlock,
blockNode->deepCopy(), CreateIndexNode(i));
sequence->insert(sequence->begin(), element);
}
}
void InsertUseCode(TIntermSequence *sequence,
const InterfaceBlockList &blocks,
const TSymbolTable &symbolTable)
......@@ -79,37 +74,22 @@ void InsertUseCode(TIntermSequence *sequence,
AddFieldUseStatements(var, sequence, symbolTable);
}
}
else if (block.arraySize > 0)
else if (block.arraySize > 0u)
{
TString name = TString(block.instanceName.c_str());
TVariable *ubInfo = reinterpret_cast<TVariable *>(symbolTable.findGlobal(name));
ASSERT(ubInfo);
TIntermSymbol *arraySymbol = new TIntermSymbol(0, name, ubInfo->getType());
for (unsigned int i = 0; i < block.arraySize; ++i)
TString name(block.instanceName.c_str());
TIntermSymbol *arraySymbol = ReferToGlobalSymbol(name, symbolTable);
for (unsigned int i = 0u; i < block.arraySize; ++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, CreateIndexNode(j));
sequence->insert(sequence->begin(), element);
}
TIntermBinary *elementSymbol =
new TIntermBinary(EOpIndexDirect, arraySymbol->deepCopy(), CreateIndexNode(i));
InsertUseCode(block, elementSymbol, sequence);
}
}
else
{
TString name = TString(block.instanceName.c_str());
TVariable *ubInfo = reinterpret_cast<TVariable *>(symbolTable.findGlobal(name));
ASSERT(ubInfo);
TIntermSymbol *blockSymbol = new TIntermSymbol(0, name, ubInfo->getType());
for (unsigned int i = 0; i < block.fields.size(); ++i)
{
TIntermBinary *element = new TIntermBinary(EOpIndexDirectInterfaceBlock,
blockSymbol, CreateIndexNode(i));
sequence->insert(sequence->begin(), element);
}
TString name(block.instanceName.c_str());
TIntermSymbol *blockSymbol = ReferToGlobalSymbol(name, symbolTable);
InsertUseCode(block, blockSymbol, sequence);
}
}
}
......
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