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 @@ ...@@ -8,6 +8,8 @@
#include "compiler/translator/IntermNode_util.h" #include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/SymbolTable.h"
namespace sh namespace sh
{ {
...@@ -164,4 +166,11 @@ TIntermBlock *EnsureBlock(TIntermNode *node) ...@@ -164,4 +166,11 @@ TIntermBlock *EnsureBlock(TIntermNode *node)
return blockNode; 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 } // namespace sh
...@@ -35,6 +35,8 @@ TIntermConstantUnion *CreateBoolNode(bool value); ...@@ -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. // If the input node is not a block node, put it inside a block node and return that.
TIntermBlock *EnsureBlock(TIntermNode *node); TIntermBlock *EnsureBlock(TIntermNode *node);
TIntermSymbol *ReferToGlobalSymbol(const TString &name, const TSymbolTable &symbolTable);
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_INTERMNODEUTIL_H_ #endif // COMPILER_TRANSLATOR_INTERMNODEUTIL_H_
\ No newline at end of file
...@@ -35,28 +35,13 @@ void AddFieldUseStatements(const ShaderVariable &var, ...@@ -35,28 +35,13 @@ void AddFieldUseStatements(const ShaderVariable &var,
name = name.substr(0, pos); name = name.substr(0, pos);
} }
} }
const TType *type; TIntermSymbol *symbol = ReferToGlobalSymbol(name, symbolTable);
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);
if (var.isArray()) 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); sequence->insert(sequence->begin(), element);
} }
} }
...@@ -66,6 +51,16 @@ void AddFieldUseStatements(const ShaderVariable &var, ...@@ -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, void InsertUseCode(TIntermSequence *sequence,
const InterfaceBlockList &blocks, const InterfaceBlockList &blocks,
const TSymbolTable &symbolTable) const TSymbolTable &symbolTable)
...@@ -79,37 +74,22 @@ void InsertUseCode(TIntermSequence *sequence, ...@@ -79,37 +74,22 @@ void InsertUseCode(TIntermSequence *sequence,
AddFieldUseStatements(var, sequence, symbolTable); AddFieldUseStatements(var, sequence, symbolTable);
} }
} }
else if (block.arraySize > 0) else if (block.arraySize > 0u)
{ {
TString name = TString(block.instanceName.c_str()); TString name(block.instanceName.c_str());
TVariable *ubInfo = reinterpret_cast<TVariable *>(symbolTable.findGlobal(name)); TIntermSymbol *arraySymbol = ReferToGlobalSymbol(name, symbolTable);
ASSERT(ubInfo); for (unsigned int i = 0u; i < block.arraySize; ++i)
TIntermSymbol *arraySymbol = new TIntermSymbol(0, name, ubInfo->getType());
for (unsigned int i = 0; i < block.arraySize; ++i)
{ {
TIntermBinary *instanceSymbol = TIntermBinary *elementSymbol =
new TIntermBinary(EOpIndexDirect, arraySymbol, CreateIndexNode(i)); new TIntermBinary(EOpIndexDirect, arraySymbol->deepCopy(), CreateIndexNode(i));
for (unsigned int j = 0; j < block.fields.size(); ++j) InsertUseCode(block, elementSymbol, sequence);
{
TIntermBinary *element = new TIntermBinary(EOpIndexDirectInterfaceBlock,
instanceSymbol, CreateIndexNode(j));
sequence->insert(sequence->begin(), element);
}
} }
} }
else else
{ {
TString name = TString(block.instanceName.c_str()); TString name(block.instanceName.c_str());
TVariable *ubInfo = reinterpret_cast<TVariable *>(symbolTable.findGlobal(name)); TIntermSymbol *blockSymbol = ReferToGlobalSymbol(name, symbolTable);
ASSERT(ubInfo); InsertUseCode(block, blockSymbol, 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, CreateIndexNode(i));
sequence->insert(sequence->begin(), element);
}
} }
} }
} }
......
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