Commit b28964b6 by Nicolas Capens

Parse the shader version number.

Bug 19331817 Change-Id: I53f24cec92052eb7367219c299222b02301f3a19 Reviewed-on: https://swiftshader-review.googlesource.com/2288Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent b97ad2e8
......@@ -73,6 +73,7 @@ TCompiler::~TCompiler()
bool TCompiler::Init(const ShBuiltInResources& resources)
{
shaderVersion = 100;
maxCallStackDepth = resources.MaxCallStackDepth;
TScopedPoolAllocator scopedAlloc(&allocator, false);
......@@ -123,6 +124,9 @@ bool TCompiler::compile(const char* const shaderStrings[],
bool success =
(PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) &&
(parseContext.treeRoot != NULL);
shaderVersion = parseContext.shaderVersion();
if (success) {
TIntermNode* root = parseContext.treeRoot;
success = intermediate.postProcess(root);
......@@ -257,4 +261,4 @@ void FreeCompilerGlobals()
{
FreeParseContextIndex();
FreePoolIndex();
}
\ No newline at end of file
}
......@@ -92,6 +92,7 @@ public:
int compileOptions);
// Get results of the last compilation.
int getShaderVersion() const { return shaderVersion; }
TInfoSink& getInfoSink() { return infoSink; }
protected:
......@@ -124,6 +125,7 @@ private:
TExtensionBehavior extensionBehavior;
// Results of compilation.
int shaderVersion;
TInfoSink infoSink; // Output sink.
// Memory allocator. Allocates and tracks memory required by the compiler.
......
......@@ -11,6 +11,7 @@
#include "preprocessor/SourceLocation.h"
TDiagnostics::TDiagnostics(TInfoSink& infoSink) :
mShaderVersion(100),
mInfoSink(infoSink),
mNumErrors(0),
mNumWarnings(0)
......@@ -21,6 +22,11 @@ TDiagnostics::~TDiagnostics()
{
}
void TDiagnostics::setShaderVersion(int version)
{
mShaderVersion = version;
}
void TDiagnostics::writeInfo(Severity severity,
const pp::SourceLocation& loc,
const std::string& reason,
......
......@@ -17,11 +17,14 @@ class TDiagnostics : public pp::Diagnostics
TDiagnostics(TInfoSink& infoSink);
virtual ~TDiagnostics();
int shaderVersion() const { return mShaderVersion; }
TInfoSink& infoSink() { return mInfoSink; }
int numErrors() const { return mNumErrors; }
int numWarnings() const { return mNumWarnings; }
void setShaderVersion(int version);
void writeInfo(Severity severity,
const pp::SourceLocation& loc,
const std::string& reason,
......@@ -36,6 +39,8 @@ class TDiagnostics : public pp::Diagnostics
const std::string& text);
private:
int mShaderVersion;
TInfoSink& mInfoSink;
int mNumErrors;
int mNumWarnings;
......
......@@ -148,9 +148,12 @@ void TDirectiveHandler::handleExtension(const pp::SourceLocation& loc,
void TDirectiveHandler::handleVersion(const pp::SourceLocation& loc,
int version)
{
static const int kVersion = 100;
if (version != kVersion)
if (version == 100 ||
version == 300)
{
mDiagnostics.setShaderVersion(version);
}
else
{
std::stringstream stream;
stream << version;
......
......@@ -65,6 +65,7 @@ struct TParseContext {
pp::Preprocessor preprocessor;
void* scanner;
int shaderVersion() const { return diagnostics.shaderVersion(); }
int numErrors() const { return diagnostics.numErrors(); }
TInfoSink& infoSink() { return diagnostics.infoSink(); }
void error(TSourceLoc loc, const char *reason, const char* token,
......
......@@ -708,7 +708,9 @@ void DirectiveParser::parseVersion(Token* token)
enum State
{
VERSION_NUMBER
VERSION_NUMBER,
VERSION_PROFILE,
VERSION_ENDLINE
};
bool valid = true;
......@@ -716,12 +718,12 @@ void DirectiveParser::parseVersion(Token* token)
int state = VERSION_NUMBER;
mTokenizer->lex(token);
while ((token->type != '\n') && (token->type != Token::LAST))
while (valid && (token->type != '\n') && (token->type != Token::LAST))
{
switch (state++)
switch (state)
{
case VERSION_NUMBER:
if (valid && (token->type != Token::CONST_INT))
if (token->type != Token::CONST_INT)
{
mDiagnostics->report(Diagnostics::INVALID_VERSION_NUMBER,
token->location, token->text);
......@@ -733,26 +735,41 @@ void DirectiveParser::parseVersion(Token* token)
token->location, token->text);
valid = false;
}
break;
default:
if (valid)
{
mDiagnostics->report(Diagnostics::UNEXPECTED_TOKEN,
state = (version < 300) ? VERSION_ENDLINE : VERSION_PROFILE;
}
break;
case VERSION_PROFILE:
if (token->type != Token::IDENTIFIER || token->text != "es")
{
mDiagnostics->report(Diagnostics::INVALID_VERSION_DIRECTIVE,
token->location, token->text);
valid = false;
}
state = VERSION_ENDLINE;
break;
default:
mDiagnostics->report(Diagnostics::UNEXPECTED_TOKEN,
token->location, token->text);
valid = false;
break;
}
mTokenizer->lex(token);
}
if (valid && (state != VERSION_NUMBER + 1))
if (valid && (state != VERSION_ENDLINE))
{
mDiagnostics->report(Diagnostics::INVALID_VERSION_DIRECTIVE,
token->location, token->text);
valid = false;
}
if (valid)
{
mDirectiveHandler->handleVersion(token->location, version);
}
}
void DirectiveParser::parseLine(Token* token)
......
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