Commit 0a7f0c21 by Nicolas Capens

Pass the shader version to the symbol table.

This refactoring prepares for version-specific builtin symbol lookups. Bug 19331817 Change-Id: I65b46a2b35872802a249a45b2f97a1d3c1e35dfe Reviewed-on: https://swiftshader-review.googlesource.com/2330Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 7d626796
...@@ -741,7 +741,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t ...@@ -741,7 +741,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t
bool builtIn = false; bool builtIn = false;
bool sameScope = false; bool sameScope = false;
TSymbol* symbol = symbolTable.find(identifier, &builtIn, &sameScope); TSymbol* symbol = symbolTable.find(identifier, shaderVersion, &builtIn, &sameScope);
if (symbol == 0 || !sameScope) { if (symbol == 0 || !sameScope) {
if (reservedErrorCheck(line, identifier)) if (reservedErrorCheck(line, identifier))
return true; return true;
...@@ -800,7 +800,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t ...@@ -800,7 +800,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t
bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, TSourceLoc line) bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, TSourceLoc line)
{ {
bool builtIn = false; bool builtIn = false;
TSymbol* symbol = symbolTable.find(node->getSymbol(), &builtIn); TSymbol* symbol = symbolTable.find(node->getSymbol(), shaderVersion, &builtIn);
if (symbol == 0) { if (symbol == 0) {
error(line, " undeclared identifier", node->getSymbol().c_str()); error(line, " undeclared identifier", node->getSymbol().c_str());
return true; return true;
...@@ -813,7 +813,7 @@ bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, ...@@ -813,7 +813,7 @@ bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size,
// special casing to test index value of gl_FragData. If the accessed index is >= gl_MaxDrawBuffers // special casing to test index value of gl_FragData. If the accessed index is >= gl_MaxDrawBuffers
// its an error // its an error
if (node->getSymbol() == "gl_FragData") { if (node->getSymbol() == "gl_FragData") {
TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", &builtIn); TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", shaderVersion, &builtIn);
ASSERT(fragData); ASSERT(fragData);
int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst(); int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst();
...@@ -974,9 +974,9 @@ const TFunction* TParseContext::findFunction(int line, TFunction* call, bool *bu ...@@ -974,9 +974,9 @@ const TFunction* TParseContext::findFunction(int line, TFunction* call, bool *bu
{ {
// First find by unmangled name to check whether the function name has been // First find by unmangled name to check whether the function name has been
// hidden by a variable name or struct typename. // hidden by a variable name or struct typename.
const TSymbol* symbol = symbolTable.find(call->getName(), builtIn); const TSymbol* symbol = symbolTable.find(call->getName(), shaderVersion, builtIn);
if (symbol == 0) { if (symbol == 0) {
symbol = symbolTable.find(call->getMangledName(), builtIn); symbol = symbolTable.find(call->getMangledName(), shaderVersion, builtIn);
} }
if (symbol == 0) { if (symbol == 0) {
...@@ -1056,7 +1056,7 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu ...@@ -1056,7 +1056,7 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu
variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer()); variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());
} }
} else if (initializer->getAsSymbolNode()) { } else if (initializer->getAsSymbolNode()) {
const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol()); const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol(), shaderVersion);
const TVariable* tVar = static_cast<const TVariable*>(symbol); const TVariable* tVar = static_cast<const TVariable*>(symbol);
ConstantUnion* constArray = tVar->getConstPointer(); ConstantUnion* constArray = tVar->getConstPointer();
......
...@@ -38,7 +38,8 @@ ...@@ -38,7 +38,8 @@
// //
// Symbol base class. (Can build functions or variables out of these...) // Symbol base class. (Can build functions or variables out of these...)
// //
class TSymbol { class TSymbol
{
public: public:
POOL_ALLOCATOR_NEW_DELETE(); POOL_ALLOCATOR_NEW_DELETE();
TSymbol(const TString *n) : name(n) { } TSymbol(const TString *n) : name(n) { }
...@@ -67,7 +68,8 @@ protected: ...@@ -67,7 +68,8 @@ protected:
// different values for different types polymorphically, so this is // different values for different types polymorphically, so this is
// just simple and pragmatic. // just simple and pragmatic.
// //
class TVariable : public TSymbol { class TVariable : public TSymbol
{
public: public:
TVariable(const TString *name, const TType& t, bool uT = false ) : TSymbol(name), type(t), userType(uT), unionArray(0), arrayInformationType(0) { } TVariable(const TString *name, const TType& t, bool uT = false ) : TSymbol(name), type(t), userType(uT), unionArray(0), arrayInformationType(0) { }
virtual ~TVariable() { } virtual ~TVariable() { }
...@@ -111,7 +113,8 @@ protected: ...@@ -111,7 +113,8 @@ protected:
// The function sub-class of symbols and the parser will need to // The function sub-class of symbols and the parser will need to
// share this definition of a function parameter. // share this definition of a function parameter.
// //
struct TParameter { struct TParameter
{
TString *name; TString *name;
TType *type; TType *type;
}; };
...@@ -119,7 +122,8 @@ struct TParameter { ...@@ -119,7 +122,8 @@ struct TParameter {
// //
// The function sub-class of a symbol. // The function sub-class of a symbol.
// //
class TFunction : public TSymbol { class TFunction : public TSymbol
{
public: public:
TFunction(TOperator o) : TFunction(TOperator o) :
TSymbol(0), TSymbol(0),
...@@ -142,7 +146,7 @@ public: ...@@ -142,7 +146,7 @@ public:
} }
void addParameter(TParameter& p) void addParameter(TParameter& p)
{ {
parameters.push_back(p); parameters.push_back(p);
mangledName = mangledName + p.type->getMangledName(); mangledName = mangledName + p.type->getMangledName();
} }
...@@ -173,7 +177,8 @@ protected: ...@@ -173,7 +177,8 @@ protected:
}; };
class TSymbolTableLevel { class TSymbolTableLevel
{
public: public:
typedef TMap<TString, TSymbol*> tLevel; typedef TMap<TString, TSymbol*> tLevel;
typedef tLevel::const_iterator const_iterator; typedef tLevel::const_iterator const_iterator;
...@@ -214,7 +219,8 @@ protected: ...@@ -214,7 +219,8 @@ protected:
static int uniqueId; // for unique identification in code generation static int uniqueId; // for unique identification in code generation
}; };
class TSymbolTable { class TSymbolTable
{
public: public:
TSymbolTable() TSymbolTable()
{ {
...@@ -247,13 +253,13 @@ public: ...@@ -247,13 +253,13 @@ public:
} }
void pop() void pop()
{ {
delete table[currentLevel()]; delete table[currentLevel()];
table.pop_back(); table.pop_back();
precisionStack.pop_back(); precisionStack.pop_back();
} }
bool insert(TSymbol& symbol) bool insert(TSymbol &symbol)
{ {
return table[currentLevel()]->insert(symbol); return table[currentLevel()]->insert(symbol);
} }
...@@ -287,7 +293,7 @@ public: ...@@ -287,7 +293,7 @@ public:
return insert(*function); return insert(*function);
} }
TSymbol* find(const TString& name, bool* builtIn = 0, bool *sameScope = 0) TSymbol *find(const TString &name, int shaderVersion, bool *builtIn = false, bool *sameScope = false) const
{ {
int level = currentLevel(); int level = currentLevel();
TSymbol* symbol; TSymbol* symbol;
...@@ -303,29 +309,35 @@ public: ...@@ -303,29 +309,35 @@ public:
return symbol; return symbol;
} }
TSymbol *findBuiltIn(const TString &name) TSymbol *findBuiltIn(const TString &name, int shaderVersion) const
{ {
return table[0]->find(name); return table[0]->find(name);
} }
TSymbolTableLevel* getGlobalLevel() { TSymbolTableLevel *getGlobalLevel() const
{
assert(table.size() >= 2); assert(table.size() >= 2);
return table[1]; return table[1];
} }
TSymbolTableLevel* getOuterLevel() { TSymbolTableLevel *getOuterLevel() const
{
assert(table.size() >= 2); assert(table.size() >= 2);
return table[currentLevel() - 1]; return table[currentLevel() - 1];
} }
void relateToOperator(const char* name, TOperator op) { void relateToOperator(const char* name, TOperator op)
{
table[0]->relateToOperator(name, op); table[0]->relateToOperator(name, op);
} }
void relateToExtension(const char* name, const TString& ext) {
void relateToExtension(const char* name, const TString& ext)
{
table[0]->relateToExtension(name, ext); table[0]->relateToExtension(name, ext);
} }
bool setDefaultPrecision( const TPublicType& type, TPrecision prec ){ bool setDefaultPrecision(const TPublicType &type, TPrecision prec)
{
if (IsSampler(type.type)) if (IsSampler(type.type))
return true; // Skip sampler types for the time being return true; // Skip sampler types for the time being
if (type.type != EbtFloat && type.type != EbtInt) if (type.type != EbtFloat && type.type != EbtInt)
...@@ -359,8 +371,8 @@ public: ...@@ -359,8 +371,8 @@ public:
return prec; return prec;
} }
protected: protected:
int currentLevel() const { return static_cast<int>(table.size()) - 1; } int currentLevel() const { return static_cast<int>(table.size() - 1); }
std::vector<TSymbolTableLevel*> table; std::vector<TSymbolTableLevel*> table;
typedef std::map< TBasicType, TPrecision > PrecisionStackLevel; typedef std::map< TBasicType, TPrecision > PrecisionStackLevel;
......
...@@ -440,7 +440,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate* node) ...@@ -440,7 +440,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate* node)
bool valid = true; bool valid = true;
TSymbolTable& symbolTable = GetGlobalParseContext()->symbolTable; TSymbolTable& symbolTable = GetGlobalParseContext()->symbolTable;
TSymbol* symbol = symbolTable.find(node->getName()); TSymbol* symbol = symbolTable.find(node->getName(), GetGlobalParseContext()->shaderVersion);
ASSERT(symbol && symbol->isFunction()); ASSERT(symbol && symbol->isFunction());
TFunction* function = static_cast<TFunction*>(symbol); TFunction* function = static_cast<TFunction*>(symbol);
for (ParamIndex::const_iterator i = pIndex.begin(); for (ParamIndex::const_iterator i = pIndex.begin();
......
...@@ -386,7 +386,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -386,7 +386,7 @@ int check_type(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
int token = IDENTIFIER; int token = IDENTIFIER;
TSymbol* symbol = yyextra->symbolTable.find(yytext); TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) { if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
TVariable* variable = static_cast<TVariable*>(symbol); TVariable* variable = static_cast<TVariable*>(symbol);
if (variable->isUserType()) { if (variable->isUserType()) {
......
...@@ -1025,7 +1025,7 @@ function_prototype ...@@ -1025,7 +1025,7 @@ function_prototype
// //
// Redeclarations are allowed. But, return types and parameter qualifiers must match. // Redeclarations are allowed. But, return types and parameter qualifiers must match.
// //
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find($1->getMangledName())); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find($1->getMangledName(), context->shaderVersion));
if (prevDec) { if (prevDec) {
if (prevDec->getReturnType() != $1->getReturnType()) { if (prevDec->getReturnType() != $1->getReturnType()) {
context->error($2.line, "overloaded functions must have the same return type", $1->getReturnType().getBasicString()); context->error($2.line, "overloaded functions must have the same return type", $1->getReturnType().getBasicString());
...@@ -2129,7 +2129,7 @@ function_definition ...@@ -2129,7 +2129,7 @@ function_definition
: function_prototype { : function_prototype {
TFunction* function = $1.function; TFunction* function = $1.function;
const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName()); const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->shaderVersion);
if (builtIn) if (builtIn)
{ {
...@@ -2137,7 +2137,7 @@ function_definition ...@@ -2137,7 +2137,7 @@ function_definition
context->recover(); context->recover();
} }
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName())); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->shaderVersion));
// //
// Note: 'prevDec' could be 'function' if this is the first time we've seen function // Note: 'prevDec' could be 'function' if this is the first time we've seen function
// as it would have just been put in the symbol table. Otherwise, we're looking up // as it would have just been put in the symbol table. Otherwise, we're looking up
......
...@@ -3163,7 +3163,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -3163,7 +3163,7 @@ int check_type(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
int token = IDENTIFIER; int token = IDENTIFIER;
TSymbol* symbol = yyextra->symbolTable.find(yytext); TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) { if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
TVariable* variable = static_cast<TVariable*>(symbol); TVariable* variable = static_cast<TVariable*>(symbol);
if (variable->isUserType()) { if (variable->isUserType()) {
......
...@@ -3209,7 +3209,7 @@ yyreduce: ...@@ -3209,7 +3209,7 @@ yyreduce:
// //
// Redeclarations are allowed. But, return types and parameter qualifiers must match. // Redeclarations are allowed. But, return types and parameter qualifiers must match.
// //
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find((yyvsp[(1) - (2)].interm.function)->getMangledName())); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find((yyvsp[(1) - (2)].interm.function)->getMangledName(), context->shaderVersion));
if (prevDec) { if (prevDec) {
if (prevDec->getReturnType() != (yyvsp[(1) - (2)].interm.function)->getReturnType()) { if (prevDec->getReturnType() != (yyvsp[(1) - (2)].interm.function)->getReturnType()) {
context->error((yyvsp[(2) - (2)].lex).line, "overloaded functions must have the same return type", (yyvsp[(1) - (2)].interm.function)->getReturnType().getBasicString()); context->error((yyvsp[(2) - (2)].lex).line, "overloaded functions must have the same return type", (yyvsp[(1) - (2)].interm.function)->getReturnType().getBasicString());
...@@ -4671,7 +4671,7 @@ yyreduce: ...@@ -4671,7 +4671,7 @@ yyreduce:
{ {
TFunction* function = (yyvsp[(1) - (1)].interm).function; TFunction* function = (yyvsp[(1) - (1)].interm).function;
const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName()); const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->shaderVersion);
if (builtIn) if (builtIn)
{ {
...@@ -4679,7 +4679,7 @@ yyreduce: ...@@ -4679,7 +4679,7 @@ yyreduce:
context->recover(); context->recover();
} }
TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName())); TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->shaderVersion));
// //
// Note: 'prevDec' could be 'function' if this is the first time we've seen function // Note: 'prevDec' could be 'function' if this is the first time we've seen function
// as it would have just been put in the symbol table. Otherwise, we're looking up // as it would have just been put in the symbol table. Otherwise, we're looking up
......
...@@ -2934,8 +2934,6 @@ const GLubyte* GL_APIENTRY glGetString(GLenum name) ...@@ -2934,8 +2934,6 @@ const GLubyte* GL_APIENTRY glGetString(GLenum name)
{ {
TRACE("(GLenum name = 0x%X)", name); TRACE("(GLenum name = 0x%X)", name);
es2::Context *context = es2::getContext();
switch(name) switch(name)
{ {
case GL_VENDOR: case GL_VENDOR:
......
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