Commit 5d69db12 by Olli Etuaho Committed by Commit Bot

Reset symbol unique id counter between compilations

This guarantees identical compilation results on different compilations using the same compiler instance, guards against overflow, and is useful as a building block for tracking more symbol information in the symbol table. BUG=angleproject:2267 TEST=angle_unittests Change-Id: Ib5a7cec2fff6712ead969d935d238d28a87fd4a7 Reviewed-on: https://chromium-review.googlesource.com/796795Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent da854a27
...@@ -734,6 +734,8 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -734,6 +734,8 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable); IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
symbolTable.markBuiltInInitializationFinished();
return true; return true;
} }
...@@ -868,6 +870,8 @@ void TCompiler::clearResults() ...@@ -868,6 +870,8 @@ void TCompiler::clearResults()
nameMap.clear(); nameMap.clear();
mSourcePath = nullptr; mSourcePath = nullptr;
symbolTable.clearCompilationResults();
} }
bool TCompiler::initCallDag(TIntermNode *root) bool TCompiler::initCallDag(TIntermNode *root)
......
...@@ -291,7 +291,8 @@ TInterfaceBlockName *TSymbolTable::insertInterfaceBlockNameExt(ESymbolLevel leve ...@@ -291,7 +291,8 @@ TInterfaceBlockName *TSymbolTable::insertInterfaceBlockNameExt(ESymbolLevel leve
const TString *name) const TString *name)
{ {
TInterfaceBlockName *blockNameSymbol = new TInterfaceBlockName(this, name); TInterfaceBlockName *blockNameSymbol = new TInterfaceBlockName(this, name);
if (insert(level, ext, blockNameSymbol)) blockNameSymbol->relateToExtension(ext);
if (insert(level, blockNameSymbol))
{ {
return blockNameSymbol; return blockNameSymbol;
} }
...@@ -324,7 +325,8 @@ TVariable *TSymbolTable::insertVariableExt(ESymbolLevel level, ...@@ -324,7 +325,8 @@ TVariable *TSymbolTable::insertVariableExt(ESymbolLevel level,
const TType &type) const TType &type)
{ {
TVariable *var = new TVariable(this, NewPoolTString(name), type); TVariable *var = new TVariable(this, NewPoolTString(name), type);
if (insert(level, ext, var)) var->relateToExtension(ext);
if (insert(level, var))
{ {
if (var->getType().getBasicType() == EbtStruct) if (var->getType().getBasicType() == EbtStruct)
{ {
...@@ -583,6 +585,7 @@ TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const ...@@ -583,6 +585,7 @@ TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const
void TSymbolTable::insertUnmangledBuiltInName(const char *name, ESymbolLevel level) void TSymbolTable::insertUnmangledBuiltInName(const char *name, ESymbolLevel level)
{ {
ASSERT(level >= 0 && level < static_cast<ESymbolLevel>(table.size())); ASSERT(level >= 0 && level < static_cast<ESymbolLevel>(table.size()));
ASSERT(mUserDefinedUniqueIdsStart == -1);
table[level]->insertUnmangledBuiltInName(std::string(name)); table[level]->insertUnmangledBuiltInName(std::string(name));
} }
...@@ -619,4 +622,23 @@ bool TSymbolTable::hasUnmangledBuiltInForShaderVersion(const char *name, int sha ...@@ -619,4 +622,23 @@ bool TSymbolTable::hasUnmangledBuiltInForShaderVersion(const char *name, int sha
return false; return false;
} }
void TSymbolTable::markBuiltInInitializationFinished()
{
mUserDefinedUniqueIdsStart = mUniqueIdCounter;
}
void TSymbolTable::clearCompilationResults()
{
mUniqueIdCounter = mUserDefinedUniqueIdsStart;
// User-defined scopes should have already been cleared when the compilation finished.
ASSERT(table.size() == LAST_BUILTIN_LEVEL + 1u);
}
int TSymbolTable::nextUniqueIdValue()
{
ASSERT(mUniqueIdCounter < std::numeric_limits<int>::max());
return ++mUniqueIdCounter;
}
} // namespace sh } // namespace sh
...@@ -287,7 +287,7 @@ const int GLOBAL_LEVEL = 5; ...@@ -287,7 +287,7 @@ const int GLOBAL_LEVEL = 5;
class TSymbolTable : angle::NonCopyable class TSymbolTable : angle::NonCopyable
{ {
public: public:
TSymbolTable() : mUniqueIdCounter(0), mEmptySymbolId(this) TSymbolTable() : mUniqueIdCounter(0), mUserDefinedUniqueIdsStart(-1), mEmptySymbolId(this)
{ {
// The symbol table cannot be used until push() is called, but // The symbol table cannot be used until push() is called, but
// the lack of an initial call to push() can be used to detect // the lack of an initial call to push() can be used to detect
...@@ -358,7 +358,8 @@ class TSymbolTable : angle::NonCopyable ...@@ -358,7 +358,8 @@ class TSymbolTable : angle::NonCopyable
TConstantUnion *unionArray = new TConstantUnion[1]; TConstantUnion *unionArray = new TConstantUnion[1];
unionArray[0].setIConst(value); unionArray[0].setIConst(value);
constant->shareConstPointer(unionArray); constant->shareConstPointer(unionArray);
return insert(level, ext, constant); constant->relateToExtension(ext);
return insert(level, constant);
} }
bool insertConstIvec3(ESymbolLevel level, bool insertConstIvec3(ESymbolLevel level,
...@@ -509,19 +510,20 @@ class TSymbolTable : angle::NonCopyable ...@@ -509,19 +510,20 @@ class TSymbolTable : angle::NonCopyable
// Checks whether there is a built-in accessible by a shader with the specified version. // Checks whether there is a built-in accessible by a shader with the specified version.
bool hasUnmangledBuiltInForShaderVersion(const char *name, int shaderVersion); bool hasUnmangledBuiltInForShaderVersion(const char *name, int shaderVersion);
void markBuiltInInitializationFinished();
void clearCompilationResults();
private: private:
friend class TSymbolUniqueId; friend class TSymbolUniqueId;
int nextUniqueIdValue() { return ++mUniqueIdCounter; } int nextUniqueIdValue();
ESymbolLevel currentLevel() const { return static_cast<ESymbolLevel>(table.size() - 1); } ESymbolLevel currentLevel() const { return static_cast<ESymbolLevel>(table.size() - 1); }
TVariable *insertVariable(ESymbolLevel level, const TString *name, const TType &type); TVariable *insertVariable(ESymbolLevel level, const TString *name, const TType &type);
bool insert(ESymbolLevel level, TSymbol *symbol) { return table[level]->insert(symbol); } bool insert(ESymbolLevel level, TSymbol *symbol)
bool insert(ESymbolLevel level, TExtension ext, TSymbol *symbol)
{ {
symbol->relateToExtension(ext); ASSERT(level > LAST_BUILTIN_LEVEL || mUserDefinedUniqueIdsStart == -1);
return table[level]->insert(symbol); return table[level]->insert(symbol);
} }
...@@ -537,6 +539,11 @@ class TSymbolTable : angle::NonCopyable ...@@ -537,6 +539,11 @@ class TSymbolTable : angle::NonCopyable
int mUniqueIdCounter; int mUniqueIdCounter;
// -1 before built-in init has finished, one past the last built-in id afterwards.
// TODO(oetuaho): Make this a compile-time constant once the symbol table is initialized at
// compile time. http://anglebug.com/1432
int mUserDefinedUniqueIdsStart;
const TSymbolUniqueId mEmptySymbolId; const TSymbolUniqueId mEmptySymbolId;
}; };
......
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